Skip to content

Commit 5e5429f

Browse files
authored
feat: Cleanup editor UI for CollidableComponents (#2700)
1 parent 1e2cc66 commit 5e5429f

File tree

3 files changed

+62
-35
lines changed

3 files changed

+62
-35
lines changed

sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/BodyComponent.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class BodyComponent : CollidableComponent
4646
/// <summary>
4747
/// When kinematic is set, the object will not be affected by physics forces like gravity or collisions but will still push away bodies it collides with.
4848
/// </summary>
49+
[Display(category: CategoryForces)]
4950
public bool Kinematic
5051
{
5152
get => _kinematic;
@@ -67,6 +68,7 @@ public bool Kinematic
6768

6869
/// <summary> Whether gravity should affect the simulation's <see cref="BepuSimulation.PoseGravity"/> </summary>
6970
/// <remarks> Gravity is always active if <see cref="BepuSimulation.UsePerBodyAttributes"/> is false </remarks>
71+
[Display(category: CategoryForces)]
7072
public bool Gravity
7173
{
7274
get => _gravity;
@@ -80,28 +82,13 @@ public bool Gravity
8082
}
8183
}
8284

83-
/// <summary>
84-
/// Controls whether and how the motion of this body is smoothed out between physics update
85-
/// </summary>
86-
public InterpolationMode InterpolationMode
87-
{
88-
get => _interpolationMode;
89-
set
90-
{
91-
if (_interpolationMode == InterpolationMode.None && value != InterpolationMode.None)
92-
Simulation?.RegisterInterpolated(this);
93-
if (_interpolationMode != InterpolationMode.None && value == InterpolationMode.None)
94-
Simulation?.UnregisterInterpolated(this);
95-
_interpolationMode = value;
96-
}
97-
}
98-
9985
/// <summary>
10086
/// Whether the object's path or only its destination is checked for collision when moving, prevents objects from passing through each other at higher speed
10187
/// </summary>
10288
/// <remarks>
10389
/// This property is a shortcut to the <see cref="ContinuousDetection"/>.<see cref="ContinuousDetection.Mode"/> property
10490
/// </remarks>
91+
[Display(category: CategoryForces)]
10592
public ContinuousDetectionMode ContinuousDetectionMode
10693
{
10794
get => _continuous.Mode;
@@ -120,10 +107,28 @@ public ContinuousDetectionMode ContinuousDetectionMode
120107
}
121108
}
122109

110+
/// <summary>
111+
/// Controls whether and how the motion of this body is smoothed out between physics update
112+
/// </summary>
113+
[Display(category: CategoryForces)]
114+
public InterpolationMode InterpolationMode
115+
{
116+
get => _interpolationMode;
117+
set
118+
{
119+
if (_interpolationMode == InterpolationMode.None && value != InterpolationMode.None)
120+
Simulation?.RegisterInterpolated(this);
121+
if (_interpolationMode != InterpolationMode.None && value == InterpolationMode.None)
122+
Simulation?.UnregisterInterpolated(this);
123+
_interpolationMode = value;
124+
}
125+
}
126+
123127
/// <summary>
124128
/// Threshold of squared combined velocity under which the body is allowed to go to sleep.
125129
/// Setting this to a negative value guarantees the body cannot go to sleep without user action.
126130
/// </summary>
131+
[Display(category: CategoryActivity)]
127132
public float SleepThreshold
128133
{
129134
get => _sleepThreshold;
@@ -147,6 +152,7 @@ public float SleepThreshold
147152
/// The number of time steps that the body must be under the sleep threshold before the body becomes a sleeping candidate.
148153
/// Note that the body is not guaranteed to go to sleep immediately after meeting this minimum.
149154
/// </summary>
155+
[Display(category: CategoryActivity)]
150156
public byte MinimumTimestepCountUnderThreshold
151157
{
152158
get => _minimumTimestepCountUnderThreshold;

sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/CollidableComponent.cs

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@
1818

1919
namespace Stride.BepuPhysics;
2020

21+
[CategoryOrder(5, CategoryCollider)]
22+
[CategoryOrder(10, CategoryForces, Expand = ExpandRule.Once)]
23+
[CategoryOrder(15, CategoryContacts, Expand = ExpandRule.Once)]
24+
[CategoryOrder(20, CategoryActivity, Expand = ExpandRule.Once)]
2125
[DataContract(Inherited = true)]
2226
[DefaultEntityComponentProcessor(typeof(CollidableProcessor), ExecutionMode = ExecutionMode.Runtime)]
2327
public abstract class CollidableComponent : EntityComponent
2428
{
29+
public const string CategoryCollider = "Collider";
30+
public const string CategoryForces = "Forces";
31+
public const string CategoryContacts = "Contacts";
32+
public const string CategoryActivity = "Activity";
33+
2534
private static uint IdCounter;
2635
private static uint VersioningCounter;
2736

@@ -62,7 +71,8 @@ public abstract class CollidableComponent : EntityComponent
6271
/// <remarks>
6372
/// Changing this value will reset some of the internal physics state of this body
6473
/// </remarks>
65-
[Display(Expand = ExpandRule.Always)]
74+
[NotNull]
75+
[Display(category: CategoryCollider, Expand = ExpandRule.Always)]
6676
public required ICollider Collider
6777
{
6878
get
@@ -92,6 +102,7 @@ public required ICollider Collider
92102
/// but the integrator timestep is only 60hz,
93103
/// the unrepresentable motion will get damped out and the body won't bounce as much.
94104
/// </remarks>
105+
[Display(category: CategoryForces)]
95106
public float SpringFrequency
96107
{
97108
get
@@ -108,6 +119,7 @@ public float SpringFrequency
108119
/// <summary>
109120
/// The amount of energy/velocity lost when this collidable bounces off
110121
/// </summary>
122+
[Display(category: CategoryForces)]
111123
public float SpringDampingRatio
112124
{
113125
get
@@ -121,6 +133,7 @@ public float SpringDampingRatio
121133
}
122134
}
123135

136+
[Display(category: CategoryForces)]
124137
public float FrictionCoefficient
125138
{
126139
get => _frictionCoefficient;
@@ -134,6 +147,7 @@ public float FrictionCoefficient
134147
/// <summary>
135148
/// The maximum speed this object will exit out of the collision when overlapping another collidable
136149
/// </summary>
150+
[Display(category: CategoryForces)]
137151
public float MaximumRecoveryVelocity
138152
{
139153
get => _maximumRecoveryVelocity;
@@ -144,12 +158,33 @@ public float MaximumRecoveryVelocity
144158
}
145159
}
146160

161+
/// <summary>
162+
/// Which simulation this object is assigned to
163+
/// </summary>
164+
[NotNull]
165+
[DefaultValueIsSceneBased]
166+
[Display(category: CategoryContacts)]
167+
public ISimulationSelector SimulationSelector
168+
{
169+
get
170+
{
171+
return _simulationSelector;
172+
}
173+
set
174+
{
175+
_simulationSelector = value;
176+
if (Processor is not null)
177+
ReAttach(_simulationSelector.Pick(Processor.BepuConfiguration, Entity));
178+
}
179+
}
180+
147181
/// <summary>
148182
/// Controls how this object interacts with other objects, allow or prevent collisions between
149183
/// it and other groups based on how <see cref="BepuSimulation.CollisionMatrix"/> is set up.
150184
/// </summary>
151185
[DefaultValue(CollisionLayer.Layer0)]
152186
[DataAlias("CollisionMask")]
187+
[Display(category: CategoryContacts)]
153188
public CollisionLayer CollisionLayer
154189
{
155190
get => _collisionLayer;
@@ -162,6 +197,7 @@ public CollisionLayer CollisionLayer
162197

163198
/// <inheritdoc cref="Stride.BepuPhysics.Definitions.CollisionGroup"/>
164199
[DataAlias("FilterByDistance")]
200+
[Display(category: CategoryContacts)]
165201
public CollisionGroup CollisionGroup
166202
{
167203
get => _collisionGroup;
@@ -172,27 +208,10 @@ public CollisionGroup CollisionGroup
172208
}
173209
}
174210

175-
/// <summary>
176-
/// Which simulation this object is assigned to
177-
/// </summary>
178-
[DefaultValueIsSceneBased]
179-
public ISimulationSelector SimulationSelector
180-
{
181-
get
182-
{
183-
return _simulationSelector;
184-
}
185-
set
186-
{
187-
_simulationSelector = value;
188-
if (Processor is not null)
189-
ReAttach(_simulationSelector.Pick(Processor.BepuConfiguration, Entity));
190-
}
191-
}
192-
193211
/// <summary>
194212
/// Provides the ability to collect and mutate contact data when this object collides with other objects.
195213
/// </summary>
214+
[Display(category: CategoryContacts)]
196215
public IContactEventHandler? ContactEventHandler
197216
{
198217
get

sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/Definitions/Colliders/CompoundCollider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Stride.Core;
88
using Stride.Core.Mathematics;
99
using Stride.BepuPhysics.Systems;
10+
using Stride.Core.Annotations;
1011
using NRigidPose = BepuPhysics.RigidPose;
1112

1213
namespace Stride.BepuPhysics.Definitions.Colliders;
@@ -18,6 +19,7 @@ public sealed class CompoundCollider : ICollider
1819
private readonly ListOfColliders _colliders;
1920
private CollidableComponent? _component;
2021

22+
[MemberCollection(NotNullItems = true)]
2123
[DataMember]
2224
public IList<ColliderBase> Colliders => _colliders;
2325

0 commit comments

Comments
 (0)