`add_face` duplicates existing half-edges
azazdeaz opened this issue · comments
Hi There! Thanks for the great crate!
It seems like calling add_face
duplicates all the existing half-edges in the Mesh.
To reproduce:
use three_d_asset::Zero;
use tri_mesh::{Mesh, Vec3};
fn main() {
let mut mesh = Mesh::new(&three_d_asset::TriMesh::default());
for _ in 0..23 {
let vertex_id1 = mesh.add_vertex(Vec3::zero());
let vertex_id2 = mesh.add_vertex(Vec3::zero());
let vertex_id3 = mesh.add_vertex(Vec3::zero());
let face_id = mesh.add_face(vertex_id1, vertex_id2, vertex_id3);
println!("Added {:?}, Halfedge count: {:?}", face_id, mesh.no_halfedges());
}
}
Result:
dded FaceID(0), Halfedge count: 6
Added FaceID(1), Halfedge count: 18
Added FaceID(2), Halfedge count: 42
Added FaceID(3), Halfedge count: 90
Added FaceID(4), Halfedge count: 186
Added FaceID(5), Halfedge count: 378
Added FaceID(6), Halfedge count: 762
Added FaceID(7), Halfedge count: 1530
Added FaceID(8), Halfedge count: 3066
Added FaceID(9), Halfedge count: 6138
Added FaceID(10), Halfedge count: 12282
Added FaceID(11), Halfedge count: 24570
Added FaceID(12), Halfedge count: 49146
Added FaceID(13), Halfedge count: 98298
Added FaceID(14), Halfedge count: 196602
Added FaceID(15), Halfedge count: 393210
Added FaceID(16), Halfedge count: 786426
Added FaceID(17), Halfedge count: 1572858
Added FaceID(18), Halfedge count: 3145722
Added FaceID(19), Halfedge count: 6291450
Added FaceID(20), Halfedge count: 12582906
Added FaceID(21), Halfedge count: 25165818
Added FaceID(22), Halfedge count: 50331642
Looks like the issue happens here:
https://github.com/asny/tri-mesh/blob/master/src/mesh/edit.rs#L346-L355
But i haven't figured out how should this work, or how to fix it.
Thank you for your kind words 🙏
It could be because all vertices in that mesh you're constructing are overlapping. What if you created each vertex at a unique position, is it still a problem then?
Yes, non-overlapping vertices had the same result, unfortunately. Also, the same thing happened when i tried to construct larger meshes, not just disconnected triangles.