diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-11-03 14:29:47 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-11-03 14:29:47 +0100 |
| commit | 036a24614171eff0f99495b8b6f1c09e58cb4f9a (patch) | |
| tree | 65ab16c69b8f7d7d8ade0163a13979c79afdcbf2 /src/geometry | |
| parent | 0cc850dc505a4034103d229fdce22f9ec7bc410a (diff) | |
| download | rapier-036a24614171eff0f99495b8b6f1c09e58cb4f9a.tar.gz rapier-036a24614171eff0f99495b8b6f1c09e58cb4f9a.tar.bz2 rapier-036a24614171eff0f99495b8b6f1c09e58cb4f9a.zip | |
Make cloning rigid-bodies and colliders more idiomatic.
Fix #53
Diffstat (limited to 'src/geometry')
| -rw-r--r-- | src/geometry/collider.rs | 19 | ||||
| -rw-r--r-- | src/geometry/collider_set.rs | 4 |
2 files changed, 11 insertions, 12 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index f53d75a..524f265 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -188,6 +188,7 @@ impl<'de> serde::Deserialize<'de> for ColliderShape { } #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +#[derive(Clone)] /// A geometric entity that can be attached to a body so it can be affected by contacts and proximity queries. /// /// To build a new collider, use the `ColliderBuilder` structure. @@ -212,20 +213,14 @@ pub struct Collider { pub user_data: u128, } -impl Clone for Collider { - fn clone(&self) -> Self { - Self { - shape: self.shape.clone(), - parent: RigidBodySet::invalid_handle(), - contact_graph_index: ColliderGraphIndex::new(crate::INVALID_U32), - proximity_graph_index: ColliderGraphIndex::new(crate::INVALID_U32), - proxy_index: crate::INVALID_USIZE, - ..*self - } +impl Collider { + pub(crate) fn reset_internal_links(&mut self) { + self.parent = RigidBodySet::invalid_handle(); + self.contact_graph_index = ColliderGraphIndex::new(crate::INVALID_U32); + self.proximity_graph_index = ColliderGraphIndex::new(crate::INVALID_U32); + self.proxy_index = crate::INVALID_USIZE; } -} -impl Collider { /// The rigid body this collider is attached to. pub fn parent(&self) -> RigidBodyHandle { self.parent diff --git a/src/geometry/collider_set.rs b/src/geometry/collider_set.rs index 5ac9658..d2bb8cc 100644 --- a/src/geometry/collider_set.rs +++ b/src/geometry/collider_set.rs @@ -59,6 +59,10 @@ impl ColliderSet { parent_handle: RigidBodyHandle, bodies: &mut RigidBodySet, ) -> ColliderHandle { + // Make sure the internal links are reset, they may not be + // if this rigid-body was obtained by cloning another one. + coll.reset_internal_links(); + coll.parent = parent_handle; let parent = bodies .get_mut_internal(parent_handle) |
