diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-07-05 14:59:14 +0200 |
|---|---|---|
| committer | Sébastien Crozet <developer@crozet.re> | 2022-07-05 14:59:14 +0200 |
| commit | ba081fb6f567dd547cee86095480dd443aff2c4c (patch) | |
| tree | 351c1dcc4fda388fd7dde60aa493ae9e0dc49bec /src/pipeline | |
| parent | b8d46a6b1d3a639769c877f13f60f0dfc60536e3 (diff) | |
| download | rapier-ba081fb6f567dd547cee86095480dd443aff2c4c.tar.gz rapier-ba081fb6f567dd547cee86095480dd443aff2c4c.tar.bz2 rapier-ba081fb6f567dd547cee86095480dd443aff2c4c.zip | |
Improve the API for initializing/setting mass-properties
Diffstat (limited to 'src/pipeline')
| -rw-r--r-- | src/pipeline/physics_pipeline.rs | 10 | ||||
| -rw-r--r-- | src/pipeline/user_changes.rs | 36 |
2 files changed, 24 insertions, 22 deletions
diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs index d347637..71ab578 100644 --- a/src/pipeline/physics_pipeline.rs +++ b/src/pipeline/physics_pipeline.rs @@ -407,6 +407,9 @@ impl PhysicsPipeline { hooks: &dyn PhysicsHooks, events: &dyn EventHandler, ) { + self.counters.reset(); + self.counters.step_started(); + // Apply some of delayed wake-ups. for handle in impulse_joints .to_wake_up @@ -417,18 +420,15 @@ impl PhysicsPipeline { } // Apply modifications. - let modified_bodies = bodies.take_modified(); let mut modified_colliders = colliders.take_modified(); let mut removed_colliders = colliders.take_removed(); - - self.counters.reset(); - self.counters.step_started(); - super::user_changes::handle_user_changes_to_colliders( bodies, colliders, &modified_colliders[..], ); + + let modified_bodies = bodies.take_modified(); super::user_changes::handle_user_changes_to_rigid_bodies( Some(islands), bodies, diff --git a/src/pipeline/user_changes.rs b/src/pipeline/user_changes.rs index 9872208..e7da68a 100644 --- a/src/pipeline/user_changes.rs +++ b/src/pipeline/user_changes.rs @@ -2,17 +2,12 @@ use crate::dynamics::{ IslandManager, RigidBodyChanges, RigidBodyHandle, RigidBodySet, RigidBodyType, }; use crate::geometry::{ColliderChanges, ColliderHandle, ColliderPosition, ColliderSet}; -use parry::utils::hashmap::HashMap; pub(crate) fn handle_user_changes_to_colliders( bodies: &mut RigidBodySet, colliders: &mut ColliderSet, modified_colliders: &[ColliderHandle], ) { - // TODO: avoid this hashmap? We could perhaps add a new flag to RigidBodyChanges to - // indicated that the mass properties need to be recomputed? - let mut mprops_to_update = HashMap::default(); - for handle in modified_colliders { // NOTE: we use `get` because the collider may no longer // exist if it has been removed. @@ -26,22 +21,19 @@ pub(crate) fn handle_user_changes_to_colliders( } } - if co.changes.contains(ColliderChanges::SHAPE) { - if let Some(co_parent) = co.parent { - mprops_to_update.insert(co_parent.handle, ()); + if co + .changes + .intersects(ColliderChanges::SHAPE | ColliderChanges::LOCAL_MASS_PROPERTIES) + { + if let Some(rb) = co + .parent + .and_then(|p| bodies.get_mut_internal_with_modification_tracking(p.handle)) + { + rb.changes |= RigidBodyChanges::LOCAL_MASS_PROPERTIES; } } } } - - for (to_update, _) in mprops_to_update { - let rb = bodies.index_mut_internal(to_update); - rb.mprops.recompute_mass_properties_from_colliders( - colliders, - &rb.colliders, - &rb.pos.position, - ); - } } pub(crate) fn handle_user_changes_to_rigid_bodies( @@ -163,6 +155,16 @@ pub(crate) fn handle_user_changes_to_rigid_bodies( } } + if changes + .intersects(RigidBodyChanges::LOCAL_MASS_PROPERTIES | RigidBodyChanges::COLLIDERS) + { + rb.mprops.recompute_mass_properties_from_colliders( + colliders, + &rb.colliders, + &rb.pos.position, + ); + } + rb.changes = RigidBodyChanges::empty(); rb.ids = ids; rb.activation = activation; |
