From e63fa60d06f57b1f33c71ee7c09caffc7ef7597d Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Mon, 2 May 2022 13:13:01 +0200 Subject: Backport fix for bug where changing collision groups would not be taken into account for pre-existing contacts. --- src/geometry/contact_pair.rs | 7 +++++++ src/geometry/narrow_phase.rs | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/geometry/contact_pair.rs b/src/geometry/contact_pair.rs index f4e7834..f57f0fa 100644 --- a/src/geometry/contact_pair.rs +++ b/src/geometry/contact_pair.rs @@ -77,6 +77,13 @@ impl ContactPair { } } + /// Clears all the contacts of this contact pair. + pub fn clear(&mut self) { + self.manifolds.clear(); + self.has_any_active_contact = false; + self.workspace = None; + } + /// Finds the contact with the smallest signed distance. /// /// If the colliders involved in this contact pair are penetrating, then diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 18900b9..e4ee955 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -377,9 +377,9 @@ impl NarrowPhase { let co_changes: Option<&ColliderChanges> = colliders.get(handle.0); if let Some(co_changes) = co_changes { - if co_changes.needs_narrow_phase_update() { + if !co_changes.needs_narrow_phase_update() { // No flag relevant to the narrow-phase is enabled for this collider. - return; + continue; } if let Some(gid) = self.graph_indices.get(handle.0) { @@ -745,11 +745,13 @@ impl NarrowPhase { if !co_flags1.active_collision_types.test(rb_type1, rb_type2) && !co_flags2.active_collision_types.test(rb_type1, rb_type2) { + edge.weight = false; return; } // Filter based on collision groups. if !co_flags1.collision_groups.test(co_flags2.collision_groups) { + edge.weight = false; return; } @@ -760,6 +762,7 @@ impl NarrowPhase { if !co_flags1.active_collision_types.test(rb_type1, rb_type2) && !co_flags2.active_collision_types.test(rb_type1, rb_type2) { + edge.weight = false; return; } @@ -775,6 +778,7 @@ impl NarrowPhase { if !hooks.filter_intersection_pair(&context) { // No intersection allowed. + edge.weight = false; return; } } @@ -867,11 +871,13 @@ impl NarrowPhase { if !co_flags1.active_collision_types.test(rb_type1, rb_type2) && !co_flags2.active_collision_types.test(rb_type1, rb_type2) { + pair.clear(); return; } // Filter based on collision groups. if !co_flags1.collision_groups.test(co_flags2.collision_groups) { + pair.clear(); return; } @@ -892,6 +898,7 @@ impl NarrowPhase { solver_flags } else { // No contact allowed. + pair.clear(); return; } } else { -- cgit