Fix trimesh/shape collision-detection when the trimesh was input as the second shape.

This commit is contained in:
Crozet Sébastien
2020-09-28 11:01:42 +02:00
parent f3f2b57f88
commit ba0a85a0a3

View File

@@ -40,6 +40,12 @@ fn do_generate_contacts(
ctxt: &mut ContactGenerationContext, ctxt: &mut ContactGenerationContext,
flipped: bool, flipped: bool,
) { ) {
let ctxt_pair_pair = if flipped {
ctxt.pair.pair.swap()
} else {
ctxt.pair.pair
};
let workspace: &mut TrimeshShapeContactGeneratorWorkspace = ctxt let workspace: &mut TrimeshShapeContactGeneratorWorkspace = ctxt
.pair .pair
.generator_workspace .generator_workspace
@@ -78,7 +84,7 @@ fn do_generate_contacts(
// and rebuilt. In this case, we hate to reconstruct the `old_interferences` // and rebuilt. In this case, we hate to reconstruct the `old_interferences`
// array using the subshape ids from the contact manifolds. // array using the subshape ids from the contact manifolds.
// TODO: always rely on the subshape ids instead of maintaining `.ord_interferences` ? // TODO: always rely on the subshape ids instead of maintaining `.ord_interferences` ?
let ctxt_collider1 = ctxt.pair.pair.collider1; let ctxt_collider1 = ctxt_pair_pair.collider1;
workspace.old_interferences = workspace workspace.old_interferences = workspace
.old_manifolds .old_manifolds
.iter() .iter()
@@ -91,13 +97,16 @@ fn do_generate_contacts(
}) })
.collect(); .collect();
} }
assert_eq!( // This assertion may fire due to the invalid triangle_ids that the
workspace // near-phase may return (due to SIMD sentinels).
.old_interferences //
.len() // assert_eq!(
.min(trimesh1.num_triangles()), // workspace
workspace.old_manifolds.len() // .old_interferences
); // .len()
// .min(trimesh1.num_triangles()),
// workspace.old_manifolds.len()
// );
trimesh1 trimesh1
.waabbs() .waabbs()
@@ -118,6 +127,7 @@ fn do_generate_contacts(
// than the max. // than the max.
continue; continue;
} }
if !same_local_aabb2 { if !same_local_aabb2 {
loop { loop {
match old_inter_it.peek() { match old_inter_it.peek() {
@@ -131,23 +141,13 @@ fn do_generate_contacts(
let manifold = if old_inter_it.peek() != Some(triangle_id) { let manifold = if old_inter_it.peek() != Some(triangle_id) {
// We don't have a manifold for this triangle yet. // We don't have a manifold for this triangle yet.
if flipped { ContactManifold::with_subshape_indices(
ContactManifold::with_subshape_indices( ctxt_pair_pair,
ctxt.pair.pair, collider1,
collider2, collider2,
collider1, *triangle_id,
*triangle_id, 0,
0, )
)
} else {
ContactManifold::with_subshape_indices(
ctxt.pair.pair,
collider1,
collider2,
0,
*triangle_id,
)
}
} else { } else {
// We already have a manifold for this triangle. // We already have a manifold for this triangle.
old_inter_it.next(); old_inter_it.next();
@@ -163,7 +163,7 @@ fn do_generate_contacts(
.dispatcher .dispatcher
.dispatch_primitives(&triangle1, collider2.shape()); .dispatch_primitives(&triangle1, collider2.shape());
let mut ctxt2 = if ctxt.pair.pair.collider1 != manifold.pair.collider1 { let mut ctxt2 = if ctxt_pair_pair.collider1 != manifold.pair.collider1 {
PrimitiveContactGenerationContext { PrimitiveContactGenerationContext {
prediction_distance: ctxt.prediction_distance, prediction_distance: ctxt.prediction_distance,
collider1: collider2, collider1: collider2,