dimforge / dimforge/parry

mesh_intersection between two meshes with co-planner triangles crashes the test

Open
#289 2 comments 0 reactions 0 assignees View on GitHub
C-Bug D-Medium P-Critical
Dominant language
Rust
Stars
867
Forks
157
Avg merge
7d 13h
Merged PRs (30d)
2

Description

I found a couple of issues while playing with parry for mesh intersections.
Even after upgrading to 0.17.3, I still find below test result for co-planner meshes is still crash with below message. Hope my test case is helpful.

```text
thread 'test::test_mesh_intersection_2' panicked at /home/user/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/spade-2.12.1/src/cdt.rs:550:53:
Constraint edges must not intersect.
stack backtrace:
0: rust_begin_unwind
1: core::panicking::panic_fmt
2: spade::cdt::ConstrainedDelaunayTriangulation::add_constraint
3: spade::delaunay_core::bulk_load::bulk_load_stable
4: parry3d_f64::transformation::mesh_intersection::mesh_intersection::merge_triangle_sets
5: parry3d_f64::transformation::mesh_intersection::mesh_intersection::intersect_meshes_with_tolerances
6: basalt_clash::test::test_mesh_intersection_2
7: core::ops::function::FnOnce::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test test::test_mesh_intersection_2 ... FAILED
```

## two meshes with co-planner triangles


![e4a99aa9001e792db8d0e9c2127d660](https://github.com/user-attachments/assets/104a45df-484c-41e6-b745-cf0737a973af)

## test code

```rust
#[cfg(test)]
mod test {
use nalgebra::{Point3, Vector3};
use obj::Obj;
use obj::ObjData;
use parry3d_f64::math::{Isometry, Real};
use parry3d_f64::shape::{TriMesh, TriMeshFlags};
use parry3d_f64::transformation::intersect_meshes_with_tolerances;
use std::path::PathBuf;

fn load_trimesh_from_obj(objfile: &str) -> TriMesh {
let Obj {
data: ObjData {
position, objects, ..
},
..
} = Obj::load(objfile).unwrap();

let mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::>(),
objects[0].groups[0]
.polys
.iter()
.map(|p| [p.0[0].0 as u32, p.0[1].0 as u32, p.0[2].0 as u32])
.collect::>(),
TriMeshFlags::all(),
);

mesh
}

#[test]
fn test_mesh_intersection_2() {
let colliders = vec!["1.obj", "2.obj"];

let mesh_a = load_trimesh_from_obj(&colliders[0]);
let mesh_b = load_trimesh_from_obj(&colliders[1]);

mesh_a.to_obj_file(&PathBuf::from(format!("intersection_test-2-a.obj")));
mesh_b.to_obj_file(&PathBuf::from(format!("intersection_test-2-b.obj")));

let mut tolerance = parry3d_f64::transformation::MeshIntersectionTolerances::default();
tolerance.global_insertion_epsilon = 0.001;
tolerance.angle_epsilon = (0.1_f64).to_radians();

let mut result = intersect_meshes_with_tolerances(
&Isometry::identity(),
&mesh_a,
false,
&Isometry::translation(0.0, 0.0, 0.0),
&mesh_b,
false,
tolerance,
)
.unwrap();

if let Some(result) = result {
let _ = result.to_obj_file(&PathBuf::from("intersection_test_result.obj"));
}
}
}

```

## sample obj files

See attched objs.zip
[objs.zip](https://github.com/user-attachments/files/17893810/objs.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.