diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-09-28 11:01:42 +0200 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-09-28 11:01:42 +0200 |
| commit | ba0a85a0a3f2d31f42624a9c7eb20adf92e36818 (patch) | |
| tree | 7a72ab59ec1f4f628c3e7e1a7ed6075e806c4556 /src | |
| parent | f3f2b57f88475361dd10475a94a6f3ac2793c5f2 (diff) | |
| download | rapier-ba0a85a0a3f2d31f42624a9c7eb20adf92e36818.tar.gz rapier-ba0a85a0a3f2d31f42624a9c7eb20adf92e36818.tar.bz2 rapier-ba0a85a0a3f2d31f42624a9c7eb20adf92e36818.zip | |
Fix trimesh/shape collision-detection when the trimesh was input as the second shape.
Diffstat (limited to 'src')
| -rw-r--r-- | src/geometry/contact_generator/trimesh_shape_contact_generator.rs | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs index 2d2309b..78f26bb 100644 --- a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs +++ b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs @@ -40,6 +40,12 @@ fn do_generate_contacts( ctxt: &mut ContactGenerationContext, flipped: bool, ) { + let ctxt_pair_pair = if flipped { + ctxt.pair.pair.swap() + } else { + ctxt.pair.pair + }; + let workspace: &mut TrimeshShapeContactGeneratorWorkspace = ctxt .pair .generator_workspace @@ -78,7 +84,7 @@ fn do_generate_contacts( // and rebuilt. In this case, we hate to reconstruct the `old_interferences` // array using the subshape ids from the contact manifolds. // 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 .old_manifolds .iter() @@ -91,13 +97,16 @@ fn do_generate_contacts( }) .collect(); } - assert_eq!( - workspace - .old_interferences - .len() - .min(trimesh1.num_triangles()), - workspace.old_manifolds.len() - ); + // This assertion may fire due to the invalid triangle_ids that the + // near-phase may return (due to SIMD sentinels). + // + // assert_eq!( + // workspace + // .old_interferences + // .len() + // .min(trimesh1.num_triangles()), + // workspace.old_manifolds.len() + // ); trimesh1 .waabbs() @@ -118,6 +127,7 @@ fn do_generate_contacts( // than the max. continue; } + if !same_local_aabb2 { loop { match old_inter_it.peek() { @@ -131,23 +141,13 @@ fn do_generate_contacts( let manifold = if old_inter_it.peek() != Some(triangle_id) { // We don't have a manifold for this triangle yet. - if flipped { - ContactManifold::with_subshape_indices( - ctxt.pair.pair, - collider2, - collider1, - *triangle_id, - 0, - ) - } else { - ContactManifold::with_subshape_indices( - ctxt.pair.pair, - collider1, - collider2, - 0, - *triangle_id, - ) - } + ContactManifold::with_subshape_indices( + ctxt_pair_pair, + collider1, + collider2, + *triangle_id, + 0, + ) } else { // We already have a manifold for this triangle. old_inter_it.next(); @@ -163,7 +163,7 @@ fn do_generate_contacts( .dispatcher .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 { prediction_distance: ctxt.prediction_distance, collider1: collider2, |
