dimforge / parry

2D and 3D collision-detection library for Rust.
https://parry.rs
Apache License 2.0
534 stars 93 forks source link

TriMesh.connected_components() gives multiple duplicate faces for quite simple meshes #115

Closed wlinna closed 1 year ago

wlinna commented 1 year ago

TriMeshConnectedComponents.face_groups data contains lots of duplicate values. Here's a minimalist test code to reproduce the problem.

    #[test]
    fn test_components_grouped_faces() {
        let verts = vec![
            // Originally face 126
            na::Point3::new(15.82, 6.455, -0.15),
            na::Point3::new(9.915, 6.455, -0.15),
            na::Point3::new(9.915, 6.4, 0.0),

            // Originally face 127
            na::Point3::new(15.82, 6.455, -0.15),
            na::Point3::new(9.915, 6.4, 0.0),
            na::Point3::new(15.82, 6.4, 0.0),
        ];

        let mut roof = TriMesh::new(
            verts,
            vec![[0, 1, 2], [3, 4, 5]],
        );

        if let Err(e) = roof.set_flags(TriMeshFlags::MERGE_DUPLICATE_VERTICES | TriMeshFlags::CONNECTED_COMPONENTS) {
            dbg!(e);
            assert!(false);
        }

        let components = roof.connected_components().unwrap();
        dbg!(components);
    }

Output:

[X] components = TriMeshConnectedComponents {
    face_colors: [0, 0,],
    grouped_faces: [0, 1, 1, 0, 0, ],
    ranges: [ 0, 5,],
}

I think the duplicates should be eliminated by parry. Otherwise downstream is forced to make sure their code works with duplicate faces.

I noticed this first on parry3d 0.10.0, but it appears with parry3d 0.11.1 as well. rustc 1.66.0