From 03aee7ddc9d932df9664da8e6f2cfc7080abaaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 26 Feb 2023 18:33:54 +0100 Subject: [PATCH] Fix collision-detection regression with convex polyhedron caused by the internal edges handling --- .../contact_manifolds/contact_manifolds_pfm_pfm.rs | 13 +++++++++---- src/shape/convex_polyhedron.rs | 4 ++++ src/shape/polygonal_feature_map.rs | 7 +++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs b/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs index 836ccf70..84731271 100644 --- a/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs +++ b/src/query/contact_manifolds/contact_manifolds_pfm_pfm.rs @@ -6,6 +6,7 @@ use crate::query::{ }; use crate::shape::{PackedFeatureId, PolygonalFeature, PolygonalFeatureMap, Shape}; use na::Unit; +use std::any::Any; /// Computes the contact manifold between two convex shapes implementing the `PolygonalSupportMap` /// trait, both represented as `Shape` trait-objects. @@ -92,13 +93,17 @@ pub fn contact_manifold_pfm_pfm<'a, ManifoldData, ContactData, S1, S2>( false, ); - if manifold.points.is_empty() { - // cfg!(feature = "dim3") || (cfg!(feature = "dim2") && manifold.points.is_empty()) { + if (cfg!(feature = "dim2") && manifold.points.is_empty()) + // TODO: this test is a workaround until we figure-out a way to + // determine the feature ids for the GJK/EPA contact. + || pfm1.is_convex_polyhedron() + || pfm2.is_convex_polyhedron() + { let contact = TrackedContact::new( p1, pos12.inverse_transform_point(&p2_1), - PackedFeatureId::UNKNOWN, // FIXME: We don't know what features are involved. - PackedFeatureId::UNKNOWN, // FIXME + PackedFeatureId::UNKNOWN, // TODO: We don't know what features are involved. + PackedFeatureId::UNKNOWN, (p2_1 - p1).dot(&dir), ); manifold.points.push(contact); diff --git a/src/shape/convex_polyhedron.rs b/src/shape/convex_polyhedron.rs index 948bce26..81c553a9 100644 --- a/src/shape/convex_polyhedron.rs +++ b/src/shape/convex_polyhedron.rs @@ -558,6 +558,10 @@ impl PolygonalFeatureMap for ConvexPolyhedron { out_feature.fid = PackedFeatureId::face(best_fid as u32); out_feature.num_vertices = num_vertices as usize; } + + fn is_convex_polyhedron(&self) -> bool { + true + } } /* diff --git a/src/shape/polygonal_feature_map.rs b/src/shape/polygonal_feature_map.rs index 82cc7aad..f5ac81f2 100644 --- a/src/shape/polygonal_feature_map.rs +++ b/src/shape/polygonal_feature_map.rs @@ -17,6 +17,13 @@ use na::{ComplexField, RealField}; // for .abs() and .copysign() pub trait PolygonalFeatureMap: SupportMap { /// Compute the support polygonal face of `self` towards the `dir`. fn local_support_feature(&self, dir: &Unit>, out_feature: &mut PolygonalFeature); + + // TODO: this is currently just a workaround for https://github.com/dimforge/rapier/issues/417 + // until we get a better way to deal with the issue without breaking internal edges + // handling. + fn is_convex_polyhedron(&self) -> bool { + false + } } impl PolygonalFeatureMap for Segment {