trimesh.boolean module

boolean.py

Do boolean operations on meshes using either Blender or Manifold.

trimesh.boolean.boolean_manifold(meshes: Sequence, operation: str, check_volume: bool = True, **kwargs)

Run an operation on a set of meshes using the Manifold engine.

Parameters:
  • meshes (list of trimesh.Trimesh) – Meshes to be processed

  • operation – Which boolean operation to do.

  • check_volume – Raise an error if not all meshes are watertight positive volumes. Advanced users may want to ignore this check as it is expensive.

  • kwargs – Passed through to the engine.

trimesh.boolean.difference(meshes: Sequence, engine: str | None = None, check_volume: bool = True, **kwargs)

Compute the boolean difference between a mesh an n other meshes.

Parameters:
  • meshes (sequence of trimesh.Trimesh) – Meshes to be processed.

  • engine – Which backend to use, i.e. ‘blender’ or ‘manifold’

  • check_volume – Raise an error if not all meshes are watertight positive volumes. Advanced users may want to ignore this check as it is expensive.

  • kwargs – Passed through to the engine.

Returns:

A Trimesh that contains meshes[0] - meshes[1:]

Return type:

difference

trimesh.boolean.intersection(meshes: Sequence, engine: str | None = None, check_volume: bool = True, **kwargs)

Compute the boolean intersection between a mesh and other meshes.

Parameters:
  • meshes (list of trimesh.Trimesh) – Meshes to be processed

  • engine (str) – Which backend to use, i.e. ‘blender’ or ‘manifold’

  • check_volume – Raise an error if not all meshes are watertight positive volumes. Advanced users may want to ignore this check as it is expensive.

  • kwargs – Passed through to the engine.

Returns:

A Trimesh that contains the intersection geometry.

Return type:

intersection

trimesh.boolean.reduce_cascade(operation: Callable, items: Sequence | ndarray[Any, dtype[_ScalarType_co]])

Call an operation function in a cascaded pairwise way against a flat list of items.

This should produce the same result as functools.reduce if operation is commutable like addition or multiplication. This may be faster for an operation that runs with a speed proportional to its largest input, which mesh booleans appear to.

The union of a large number of small meshes appears to be “much faster” using this method.

This only differs from functools.reduce for commutative operation in that it returns None on empty inputs rather than functools.reduce which raises a TypeError.

For example on a b c d e f g this function would run and return:

a b c d e f ab cd ef g abcd efg

-> abcdefg

Where functools.reduce would run and return:

a b ab c abc d abcd e abcde f abcdef g

-> abcdefg

Parameters:
  • operation – The function to call on pairs of items.

  • items – The flat list of items to apply operation against.

trimesh.boolean.union(meshes: Sequence, engine: str | None = None, check_volume: bool = True, **kwargs)

Compute the boolean union between a mesh an n other meshes.

Parameters:
  • meshes (list of trimesh.Trimesh) – Meshes to be processed

  • engine (str) – Which backend to use, i.e. ‘blender’ or ‘manifold’

  • check_volume – Raise an error if not all meshes are watertight positive volumes. Advanced users may want to ignore this check as it is expensive.

  • kwargs – Passed through to the engine.

Returns:

A Trimesh that contains the union of all passed meshes.

Return type:

union