diff options
| author | Sébastien Crozet <sebcrozet@dimforge.com> | 2022-05-31 11:23:46 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebcrozet@dimforge.com> | 2022-05-31 11:23:46 +0200 |
| commit | 8b3c091ba785d5cba049015c213eb49bb6378762 (patch) | |
| tree | f235c408372aaea9dd4007838e3c51044d310daf | |
| parent | 31cfce4db30efeb15ccb8c51e6c20ff07406987c (diff) | |
| download | rapier-disabled-flag.tar.gz rapier-disabled-flag.tar.bz2 rapier-disabled-flag.zip | |
Start experimenting with collider/rigid-body disabling.disabled-flag
| -rw-r--r-- | src/dynamics/rigid_body.rs | 23 | ||||
| -rw-r--r-- | src/dynamics/rigid_body_components.rs | 3 | ||||
| -rw-r--r-- | src/geometry/collider.rs | 21 | ||||
| -rw-r--r-- | src/geometry/collider_components.rs | 9 | ||||
| -rw-r--r-- | src/pipeline/user_changes.rs | 10 |
5 files changed, 61 insertions, 5 deletions
diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 5eca5a2..085ee0c 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -36,6 +36,7 @@ pub struct RigidBody { pub(crate) body_type: RigidBodyType, /// The dominance group this rigid-body is part of. pub(crate) dominance: RigidBodyDominance, + pub(crate) enabled: bool, /// User-defined data associated to this rigid-body. pub user_data: u128, } @@ -62,6 +63,7 @@ impl RigidBody { changes: RigidBodyChanges::all(), body_type: RigidBodyType::Dynamic, dominance: RigidBodyDominance::default(), + enabled: true, user_data: 0, } } @@ -71,6 +73,17 @@ impl RigidBody { self.ids = Default::default(); } + /// Is this rigid-body enabled? + pub fn is_enabled(&self) -> bool { + self.enabled + } + + /// Sets whether or not this rigid-body is enabled. + pub fn set_enabled(&mut self, enabled: bool) { + self.changes |= RigidBodyChanges::ENABLED; + self.enabled = enabled; + } + /// The activation status of this rigid-body. pub fn activation(&self) -> &RigidBodyActivation { &self.activation @@ -869,6 +882,8 @@ pub struct RigidBodyBuilder { /// /// CCD prevents tunneling, but may still allow limited interpenetration of colliders. pub ccd_enabled: bool, + /// Is this rigid-body enabled after its creation? + pub enabled: bool, /// The dominance group of the rigid-body to be built. pub dominance_group: i8, /// An arbitrary user-defined 128-bit integer associated to the rigid-bodies built by this builder. @@ -891,6 +906,7 @@ impl RigidBodyBuilder { can_sleep: true, sleeping: false, ccd_enabled: false, + enabled: true, dominance_group: 0, user_data: 0, } @@ -1037,6 +1053,12 @@ impl RigidBodyBuilder { self } + /// Is this rigid-body enabled after its creation? + pub fn enabled(mut self, is_enabled: bool) -> self { + self.enabled = is_enabled; + self + } + /// Sets the additional mass of the rigid-body being built. /// /// This is only the "additional" mass because the total mass of the rigid-body is @@ -1167,6 +1189,7 @@ impl RigidBodyBuilder { rb.vels.linvel = self.linvel; rb.vels.angvel = self.angvel; rb.body_type = self.body_type; + rb.enabled = self.enabled; rb.user_data = self.user_data; if self.additional_mass_properties != MassProperties::default() { diff --git a/src/dynamics/rigid_body_components.rs b/src/dynamics/rigid_body_components.rs index 3d35d17..ec20a6e 100644 --- a/src/dynamics/rigid_body_components.rs +++ b/src/dynamics/rigid_body_components.rs @@ -73,7 +73,6 @@ pub enum RigidBodyType { /// modified by the user and is independent from any contact or joint it is involved in. KinematicVelocityBased = 3, // Semikinematic, // A kinematic that performs automatic CCD with the fixed environment to avoid traversing it? - // Disabled, } impl RigidBodyType { @@ -110,6 +109,8 @@ bitflags::bitflags! { const TYPE = 1 << 4; /// Flag indicating that the `RigidBodyDominance` component of this rigid-body has been modified. const DOMINANCE = 1 << 5; + /// Flag indicating that the `RigidBody::enabled` status was changed. + const ENABLED = 1 << 6; } } diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 8d9b005..d12f7b2 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -46,6 +46,17 @@ impl Collider { self.coll_type.is_sensor() } + /// Is this collider enabled? + pub fn is_enabled(&self) -> bool { + self.flags.enabled + } + + /// Sets whether or not this collider is enabled. + pub fn set_enabled(&mut self, enabled: bool) { + self.changes.insert(ColliderChanges::ENABLED); + self.flags.enabled = enabled; + } + /// The physics hooks enabled for this collider. pub fn active_hooks(&self) -> ActiveHooks { self.flags.active_hooks @@ -309,6 +320,8 @@ pub struct ColliderBuilder { pub position: Isometry<Real>, /// Is this collider a sensor? pub is_sensor: bool, + /// Is this collider enabled after its creation? + pub enabled: bool, /// Contact pairs enabled for this collider. pub active_collision_types: ActiveCollisionTypes, /// Physics hooks enabled for this collider. @@ -334,6 +347,7 @@ impl ColliderBuilder { restitution: 0.0, position: Isometry::identity(), is_sensor: false, + enabled: true, user_data: 0, collision_groups: InteractionGroups::all(), solver_groups: InteractionGroups::all(), @@ -594,6 +608,12 @@ impl ColliderBuilder { self } + /// Is this collider enabled after its creation? + pub fn enabled(mut self, is_enabled: bool) -> Self { + self.enabled = is_enabled; + self + } + /// Sets the collision groups used by this collider. /// /// Two colliders will interact iff. their collision groups are compatible. @@ -775,6 +795,7 @@ impl ColliderBuilder { active_collision_types: self.active_collision_types, active_hooks: self.active_hooks, active_events: self.active_events, + enabled: self.enabled, }; let changes = ColliderChanges::all(); let pos = ColliderPosition(self.position); diff --git a/src/geometry/collider_components.rs b/src/geometry/collider_components.rs index 22f75e7..ab746a4 100644 --- a/src/geometry/collider_components.rs +++ b/src/geometry/collider_components.rs @@ -57,11 +57,13 @@ bitflags::bitflags! { const SHAPE = 1 << 4; // => BF & NF update. NF pair workspace invalidation. /// Flag indicating that the `ColliderType` component of the collider has been modified. const TYPE = 1 << 5; // => NF update. NF pair invalidation. + /// Flag indicating that this `Collider` or its parent `RigidBody` enabled status was changed. + const ENABLED = 1 << 6; // => NF update. /// Flag indicating that the dominance groups of the parent of this collider have been modified. /// /// This flags is automatically set by the `PhysicsPipeline` when the `RigidBodyChanges::DOMINANCE` /// or `RigidBodyChanges::TYPE` of the parent rigid-body of this collider is detected. - const PARENT_EFFECTIVE_DOMINANCE = 1 << 6; // NF update. + const PARENT_EFFECTIVE_DOMINANCE = 1 << 7; // NF update. } } @@ -309,7 +311,7 @@ impl ActiveCollisionTypes { // First, we associate the following bit masks: // - DYNAMIC = 0001 // - FIXED = 0010 - // - KINEMATIC = 1100 + // - KINEMATIC = 0011 // These are equal to the bits indexed by `RigidBodyType as u32`. // The bit masks defined by ActiveCollisionTypes are defined is such a way // that the first part of the variant name (e.g. DYNAMIC_*) indicates which @@ -368,6 +370,8 @@ pub struct ColliderFlags { pub active_hooks: ActiveHooks, /// The events enabled for this collider. pub active_events: ActiveEvents, + /// Whether the collider takes part into the simulation or should be igonred. + pub enabled: bool, } impl Default for ColliderFlags { @@ -378,6 +382,7 @@ impl Default for ColliderFlags { solver_groups: InteractionGroups::all(), active_hooks: ActiveHooks::empty(), active_events: ActiveEvents::empty(), + enabled: true, } } } diff --git a/src/pipeline/user_changes.rs b/src/pipeline/user_changes.rs index 9872208..be2cec3 100644 --- a/src/pipeline/user_changes.rs +++ b/src/pipeline/user_changes.rs @@ -151,15 +151,21 @@ pub(crate) fn handle_user_changes_to_rigid_bodies( if changes.contains(RigidBodyChanges::DOMINANCE) || changes.contains(RigidBodyChanges::TYPE) + || changes.contains(RigidBodyChanges::ENABLED) { + // Propagate the modified flags to the attached colliders. + let flags = if changes.contains(RigidBodyChanges::ENABLED) { + ColliderChanges::ENABLED + } else { + ColliderChanges::PARENT_EFFECTIVE_DOMINANCE + }; for handle in rb.colliders.0.iter() { let co = colliders.index_mut_internal(*handle); if !co.changes.contains(ColliderChanges::MODIFIED) { modified_colliders.push(*handle); } - co.changes |= - ColliderChanges::MODIFIED | ColliderChanges::PARENT_EFFECTIVE_DOMINANCE; + co.changes |= ColliderChanges::MODIFIED | flags; } } |
