Skip to content

Commit

Permalink
Fix(MeshObjectUtility): indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSmeyer authored Jul 8, 2024
1 parent 823d221 commit 8e9ef02
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions blenderproc/python/types/MeshObjectUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,33 +506,33 @@ def add_geometry_nodes(self):
modifier = self.blender_obj.modifiers[-1]
return modifier.node_group

def mesh_as_trimesh(self) -> Trimesh:
""" Returns a trimesh.Trimesh instance of the MeshObject.
:return: The object as trimesh.Trimesh.
"""

# get mesh data
mesh = self.get_mesh()

# check if faces are pure tris or quads and triangulate quads if this is not the case
if not all(len(f.vertices[:]) == len(mesh.polygons[0].vertices[:]) for f in mesh.polygons):
# Triangulate quads
self.select()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.quads_convert_to_tris(quad_method='FIXED', ngon_method='BEAUTY')
bpy.ops.object.mode_set(mode='OBJECT')
self.deselect()

# get vertices
verts = np.array([[v.co[0], v.co[1], v.co[2]] for v in mesh.vertices])
# re-scale the vertices since scale operations doesn't apply to the mesh data
verts *= self.blender_obj.scale
# 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 mesh_as_trimesh(self) -> Trimesh:
""" Returns a trimesh.Trimesh instance of the MeshObject.
:return: The object as trimesh.Trimesh.
"""
# get mesh data
mesh = self.get_mesh()
# check if faces are pure tris or quads and triangulate quads if this is not the case
if not all(len(f.vertices[:]) == len(mesh.polygons[0].vertices[:]) for f in mesh.polygons):
# Triangulate quads
self.select()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.quads_convert_to_tris(quad_method='FIXED', ngon_method='BEAUTY')
bpy.ops.object.mode_set(mode='OBJECT')
self.deselect()
# get vertices
verts = np.array([[v.co[0], v.co[1], v.co[2]] for v in mesh.vertices])
# re-scale the vertices since scale operations doesn't apply to the mesh data
verts *= self.blender_obj.scale
# 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 8e9ef02

Please sign in to comment.