Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Convert quads to triangles in trimesh conversion for non-pure quad/triangle meshes #1126

Closed
MartinSmeyer opened this issue Jul 8, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@MartinSmeyer
Copy link
Member

Describe your feature request

Currently, the bop writer fails for objects that contain mixed quad and triangular faces. This can be fixed by triangulating the quad faces.

Describe a possible solution

 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])
     # 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)
     ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants