trimesh.repair

repair.py

Fill holes and fix winding and normals of meshes.

trimesh.repair.broken_faces(mesh, color=None)

Return the index of faces in the mesh which break the watertight status of the mesh.

Parameters:
  • mesh (trimesh.Trimesh) – Mesh to check broken faces on

  • color ((4,) uint8 or None) – Will set broken faces to this color if not None

Returns:

broken – Indexes of mesh.faces

Return type:

(n, ) int

trimesh.repair.fill_holes(mesh, use_fan: bool = False)

Fill boundary holes in-place using fans, which may result in bad answers if the holes are non convex!

Face colors and attributes will be padded with default values so shapes match.

Parameters:
  • mesh (trimesh.Trimesh) – Mesh will be repaired in-place.

  • use_fan – If passed, holes larger than quads will be triangulated using fans which are only valid for non-convex holes.

trimesh.repair.fix_inversion(mesh, multibody: bool = False)

Check to see if a mesh has normals pointing “out.”

Parameters:
  • mesh (trimesh.Trimesh) – Mesh to fix in-place.

  • multibody (bool) – If True will try to fix normals on every body

trimesh.repair.fix_normals(mesh, multibody=False)

Fix the winding and direction of a mesh face and face normals in-place.

Really only meaningful on watertight meshes but will orient all faces and winding in a uniform way for non-watertight face patches as well.

Parameters:
  • mesh (trimesh.Trimesh) – Mesh to fix normals on

  • multibody (bool) – if True try to correct normals direction on every body rather than just one

Notes

mesh.faces : will flip columns on inverted faces

trimesh.repair.fix_winding(mesh)

Traverse and change mesh faces in-place to make sure winding is correct with edges on adjacent faces in opposite directions.

Parameters:

mesh (Trimesh) – Source geometry to alter in-place.

trimesh.repair.stitch(mesh, faces=None, insert_vertices=False)

Create a fan stitch over the boundary of the specified faces. If the boundary is non-convex a triangle fan is going to be extremely wonky.

Parameters:
  • mesh (trimesh.Trimesh) – Mesh to create fan stitch on.

  • faces ((n,) int) – Face indexes to stitch with triangle fans.

  • insert_vertices (bool) – Allow stitching to insert new vertices?

Returns:

  • fan ((m, 3) int) – New triangles referencing mesh.vertices.

  • vertices ((p, 3) float) – Inserted vertices (only returned if insert_vertices)