trimesh icon indicating copy to clipboard operation
trimesh copied to clipboard

face connectivity issue when using `update_vertices`

Open jaredsagendorf opened this issue 3 years ago • 4 comments

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.

mesh_issue

jaredsagendorf avatar Feb 13 '21 03:02 jaredsagendorf

@jaredsagendorf I'm facing the same issue right now where a lot of self intersecting geometry is created when removing vertices via update_vertices()

grafik

Any ideas @mikedh? Thanks!

kampelmuehler avatar Jan 24 '22 11:01 kampelmuehler

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.

kampelmuehler avatar Jan 25 '22 09:01 kampelmuehler

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)

mikedh avatar Jan 25 '22 16:01 mikedh

That's what I ended up doing. Is there a use case for mesh.update_vertices in a stand-alone fashion?

kampelmuehler avatar Jan 26 '22 06:01 kampelmuehler