From 0affe7c5dd0e7a8a14fb151699289fcc89a23cc2 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Tue, 25 Jul 2023 21:21:15 -0700 Subject: [PATCH 1/4] `RapierContext::colliders` convenience method for getting all of the collider entities attached to a rigid body --- src/plugin/context.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugin/context.rs b/src/plugin/context.rs index 885e68df..524c495d 100644 --- a/src/plugin/context.rs +++ b/src/plugin/context.rs @@ -117,6 +117,20 @@ impl RapierContext { .and_then(|h| self.rigid_body_entity(h)) } + /// If entity is a rigid-body, this returns the collider `Entity`s attached + /// to that rigid-body. + pub fn colliders(&self, entity: Entity) -> impl Iterator + '_ { + self.entity2body() + .get(&entity) + .map(|handle| self.bodies.get(*handle)) + .flatten() + .map(|body| body.colliders()) + .map(|colliders| colliders.iter().filter_map(|handle| self.collider_entity(*handle))) + .map(|colliders| colliders) + .into_iter() + .flatten() + } + /// Retrieve the Bevy entity the given Rapier collider (identified by its handle) is attached. pub fn collider_entity(&self, handle: ColliderHandle) -> Option { Self::collider_entity_with_set(&self.colliders, handle) From a434211e40764d6be5278c990f5ade711748f662 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Tue, 25 Jul 2023 21:23:29 -0700 Subject: [PATCH 2/4] Clean up unnecessary maps --- src/plugin/context.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugin/context.rs b/src/plugin/context.rs index 524c495d..7396f4a3 100644 --- a/src/plugin/context.rs +++ b/src/plugin/context.rs @@ -124,9 +124,11 @@ impl RapierContext { .get(&entity) .map(|handle| self.bodies.get(*handle)) .flatten() - .map(|body| body.colliders()) - .map(|colliders| colliders.iter().filter_map(|handle| self.collider_entity(*handle))) - .map(|colliders| colliders) + .map(|body| { + body.colliders() + .iter() + .filter_map(|handle| self.collider_entity(*handle)) + }) .into_iter() .flatten() } From e8f941ae139e05a12d3e662e9abb012a0ffd889f Mon Sep 17 00:00:00 2001 From: Aceeri Date: Wed, 26 Jul 2023 03:43:54 -0700 Subject: [PATCH 3/4] Simplify a bit --- src/plugin/context.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plugin/context.rs b/src/plugin/context.rs index 7396f4a3..aa71e6d7 100644 --- a/src/plugin/context.rs +++ b/src/plugin/context.rs @@ -122,8 +122,7 @@ impl RapierContext { pub fn colliders(&self, entity: Entity) -> impl Iterator + '_ { self.entity2body() .get(&entity) - .map(|handle| self.bodies.get(*handle)) - .flatten() + .and_then(|handle| self.bodies.get(*handle)) .map(|body| { body.colliders() .iter() From ff2edd80dfc11d66ffae0f4ce5ce4f32e57bbbc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 6 Aug 2023 13:26:26 +0200 Subject: [PATCH 4/4] Rename RapierContext::colliders to ::rigid_body_colliders --- CHANGELOG.md | 4 ++++ src/plugin/context.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc116a5f..71df4c34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased +### Added +- Add `RapierContext::rigid_body_colliders` to retrieve all collider entities attached to this rigid-body. + ## 0.22.0 (10 July 2023) ### Modified - Update to Bevy 0.11. diff --git a/src/plugin/context.rs b/src/plugin/context.rs index aa71e6d7..0dadbc47 100644 --- a/src/plugin/context.rs +++ b/src/plugin/context.rs @@ -119,7 +119,7 @@ impl RapierContext { /// If entity is a rigid-body, this returns the collider `Entity`s attached /// to that rigid-body. - pub fn colliders(&self, entity: Entity) -> impl Iterator + '_ { + pub fn rigid_body_colliders(&self, entity: Entity) -> impl Iterator + '_ { self.entity2body() .get(&entity) .and_then(|handle| self.bodies.get(*handle))