From d9585de20bc158006e4669c251d5d8b3edfbf188 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 2 Jun 2024 19:23:36 +0200 Subject: feat: add the ability to disable all contacts between two links belonging to the same multibody --- src/geometry/narrow_phase.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/geometry') diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 1eddd73..717fa25 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -835,12 +835,30 @@ impl NarrowPhase { } } - if let Some((_, _, mb_link)) = - multibody_joints.joint_between(co_parent1.handle, co_parent2.handle) - { - if !mb_link.joint.data.contacts_enabled { - pair.clear(); - break 'emit_events; + let link1 = multibody_joints.rigid_body_link(co_parent1.handle); + let link2 = multibody_joints.rigid_body_link(co_parent2.handle); + + if let (Some(link1),Some(link2)) = (link1, link2) { + // If both bodies belong to the same multibody, apply some additional built-in + // contact filtering rules. + if link1.multibody == link2.multibody { + // 1) check if self-contacts is enabled. + if let Some(mb) = multibody_joints.get_multibody(link1.multibody) { + if !mb.self_contacts_enabled() { + pair.clear(); + break 'emit_events; + } + } + + // 2) if they are attached by a joint, check if contacts is disabled. + if let Some((_, _, mb_link)) = + multibody_joints.joint_between(co_parent1.handle, co_parent2.handle) + { + if !mb_link.joint.data.contacts_enabled { + pair.clear(); + break 'emit_events; + } + } } } } -- cgit