mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
2.85k stars 566 forks source link

[Beginner Question] Is there a way to check if a given vertex is manifold or not in trimesh ? #2208

Closed aradhyamathur closed 2 months ago

aradhyamathur commented 2 months ago

Hi I wanted to know if there is a way to check if a vertex is manifold or not ? Something like is_vertex_manifold in igl but that returns for individual vertex instead for the entire mesh.

mikedh commented 2 months ago

Hey, I think it depends on exactly what you're looking for, but to find "is a vertex only included in edges that occur exactly twice" it's pretty easy to use boolean masks to get those:

In [1]: import trimesh

In [2]: import numpy as np

In [3]: m = trimesh.load('models/rabbit.obj')

In [4]: m.is_watertight
Out[4]: False

In [5]: edges_ok = trimesh.grouping.group_rows(m.edges_sorted, require_count=2).ravel()

In [8]: vertices_ok = np.zeros(len(m.vertices), dtype=bool)

In [9]: vertices_ok[m.edges_sorted[edges_ok].ravel()] = True

In [10]: vertices_ok.all()
Out[10]: False

# these are indices of vertices that are "bad" 
In [12]: np.nonzero(~vertices_ok)[0]
Out[12]: array([ 16,  77, 341, 364])
aradhyamathur commented 2 months ago

and the vertices that occur in 2 triangle fans like in the example shown here, I think the above wouldn't cover the case ? E.g download