Skip to content

Commit

Permalink
fix(DLR-RM#914): throw exception if mesh is not pure
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSmeyer authored Jun 2, 2023
1 parent 188b81d commit c40d4dd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions blenderproc/python/types/MeshObjectUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,12 @@ def mesh_as_trimesh(self) -> Trimesh:
# get vertices
verts = np.array([[v.co[0], v.co[1], v.co[2]] for v in mesh.vertices])

# get faces
if len(mesh.polygons[0].vertices[:]) == 4:
faces = np.array([f.vertices[:] for f in mesh.polygons if len(f.vertices[:]) == 4])
else:
faces = np.array([[f.vertices[0], f.vertices[1], f.vertices[2]] for f in mesh.polygons])
# check if faces are pure tris or quads
if not all(len(f.vertices[:]) == len(mesh.polygons[0].vertices[:]) for f in mesh.polygons):
raise Exception("The mesh {} must have pure triangular or pure quad faces".format(self.get_name()))

# get faces
faces = np.array([f.vertices[:] for f in mesh.polygons if len(f.vertices[:]) in [3, 4]])

return Trimesh(vertices=verts, faces=faces)

Expand Down

0 comments on commit c40d4dd

Please sign in to comment.