From de59c6b58c53535d4dd87a6de552d89d30984ea2 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sat, 21 Jan 2023 18:59:34 +0100 Subject: Fix rigid-body mass-properties being incorrect after disable/enable --- src/pipeline/user_changes.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pipeline/user_changes.rs b/src/pipeline/user_changes.rs index eeda97a..a047256 100644 --- a/src/pipeline/user_changes.rs +++ b/src/pipeline/user_changes.rs @@ -161,16 +161,6 @@ 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, - ); - } - if changes.contains(RigidBodyChanges::ENABLED_OR_DISABLED) { // Propagate the rigid-body’s enabled/disable status to its colliders. for handle in rb.colliders.0.iter() { @@ -208,6 +198,19 @@ pub(crate) fn handle_user_changes_to_rigid_bodies( } } + // NOTE: recompute the mass-properties AFTER dealing with the rigid-body changes + // that imply a collider change (in particular, after propagation of the + // enabled/disabled status). + if changes + .intersects(RigidBodyChanges::LOCAL_MASS_PROPERTIES | RigidBodyChanges::COLLIDERS) + { + rb.mprops.recompute_mass_properties_from_colliders( + colliders, + &rb.colliders, + &rb.pos.position, + ); + } + rb.ids = ids; rb.activation = activation; } -- cgit