aboutsummaryrefslogtreecommitdiff
path: root/src/pipeline/user_changes.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-07-05 15:47:59 +0200
committerGitHub <noreply@github.com>2022-07-05 15:47:59 +0200
commit06ec9a0e76cea7a035b4335c591cd3fddd0d9999 (patch)
tree39d57c778ee69399b654e11fa967e03b375f7ec2 /src/pipeline/user_changes.rs
parentb8d46a6b1d3a639769c877f13f60f0dfc60536e3 (diff)
parent7831ebfc3109d4a4c2029f50e432dd1d4be9ef82 (diff)
downloadrapier-06ec9a0e76cea7a035b4335c591cd3fddd0d9999.tar.gz
rapier-06ec9a0e76cea7a035b4335c591cd3fddd0d9999.tar.bz2
rapier-06ec9a0e76cea7a035b4335c591cd3fddd0d9999.zip
Merge pull request #360 from dimforge/easier-mass-props
Improve the API for initializing/setting mass-properties
Diffstat (limited to 'src/pipeline/user_changes.rs')
-rw-r--r--src/pipeline/user_changes.rs36
1 files changed, 19 insertions, 17 deletions
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;