trimesh.voxel.creation

trimesh.voxel.creation.local_voxelize(mesh, point: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], pitch: float | floating | int | integer | unsignedinteger, radius: float | floating | int | integer | unsignedinteger, fill: bool = True, **kwargs) VoxelGrid | None

Voxelize a mesh in the region of a cube around a point. When fill=True, uses proximity.contains to fill the resulting voxels so may be meaningless for non-watertight meshes. Useful to reduce memory cost for small values of pitch as opposed to global voxelization.

Parameters:
  • mesh (trimesh.Trimesh) – Source geometry

  • point ((3, ) float) – Point in space to voxelize around

  • pitch – Side length of a single voxel cube

  • radius – Number of voxel cubes to return in each direction.

  • kwargs – Parameters to pass to voxelize_subdivide

Returns:

voxels – or None if the volume is empty

Return type:

VoxelGrid instance with resolution (m, m, m) where m=2*radius+1

trimesh.voxel.creation.voxelize(mesh, pitch: float | floating | int | integer | unsignedinteger | None, method: Literal['subdivide', 'ray', 'binvox'] = 'subdivide', **kwargs) VoxelGrid | None

Voxelize the given mesh using the specified implementation.

See voxelizers for available implementations or to add your own, e.g. via voxelizers[‘custom_key’] = custom_fn.

custom_fn should have signature (mesh, pitch, **kwargs) -> VoxelGrid and should not modify encoding.

Parameters:
  • mesh – Geometry to voxelize

  • pitch – Side length of each voxel.

  • method – Which voxelization method to use.

  • kwargs – Passed through to the specified implementation.

Returns:

A VoxelGrid instance.

Return type:

grid