Skip to content

Commit

Permalink
Merge pull request DLR-RM#915 from DLR-RM/iss_914_quad_trimesh_conver…
Browse files Browse the repository at this point in the history
…sion

fix(DLR-RM#914): Allow quad meshes to be converted to trimesh
  • Loading branch information
cornerfarmer authored Jun 2, 2023
2 parents a2d1fce + c40d4dd commit 5b5d903
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions blenderproc/python/types/MeshObjectUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,18 @@ def mesh_as_trimesh(self) -> Trimesh:
# get mesh data
mesh = self.get_mesh()

# get vertices and faces
# get vertices
verts = np.array([[v.co[0], v.co[1], v.co[2]] for v in mesh.vertices])
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)



def create_from_blender_mesh(blender_mesh: bpy.types.Mesh, object_name: str = None) -> "MeshObject":
""" Creates a new Mesh object using the given blender mesh.
Expand Down

0 comments on commit 5b5d903

Please sign in to comment.