trimesh
trimesh copied to clipboard
face connectivity issue when using `update_vertices`
I'm using the update_vertices
method of the base class like so
mesh.update_vertices(vertex_mask)
mesh.export("mesh.off")
to select a continuous region of a mesh defined by vertex_mask
. However, doing so is introducing a bunch of erroneous faces that seem to connect all the boundary vertices of the now non-watertight submesh to a random vertex, which seems to always be vertex 0 of the new vertices (after calling mesh.update_vertices
).
I can delete the 0th vertex and all associated faces with it to fix the issue, but then I create a hole that I don't want in my submesh. The picture attached shows an example of the issue (top row), and the fix of deleting the 0th vertex of the submesh (bottom row), but I'm wondering why this is happening in the first place? Hopefully the picture is clear enough... Note that this happens on every mesh I have tried.
@jaredsagendorf I'm facing the same issue right now where a lot of self intersecting geometry is created when removing vertices via update_vertices()
Any ideas @mikedh? Thanks!
I see that indeed the vertices are re-indexed such that all deleted vertices point to 0.
https://github.com/mikedh/trimesh/blob/main/trimesh/base.py#L1145
To me it would make more sense to remove the faces with missing vertices.
Hey, I think you probably want to use mesh.update_faces
not mesh.update_vertices
, with a mask defined how you want it to to behave (i.e. to remove faces containing ANY good vertex, or only keep faces with ALL good vertices):
face_mask = vertex_mask[mesh.faces].all(axis=1)
That's what I ended up doing.
Is there a use case for mesh.update_vertices
in a stand-alone fashion?