trimesh.parent module

parent.py

The base class for Trimesh, PointCloud, and Scene objects

class trimesh.parent.Geometry

Bases: ABC

Geometry is the parent class for all geometry.

By decorating a method with abc.abstractmethod it means the objects that inherit from Geometry MUST implement those methods.

apply_scale(scaling)

Scale the mesh.

Parameters:

scaling (float or (3,) float) – Scale factor to apply to the mesh

abstract apply_transform(matrix: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) Any
apply_translation(translation: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])

Translate the current mesh.

Parameters:

translation ((3,) float) – Translation in XYZ

abstract property bounds: ndarray[Any, dtype[float64]]
abstract copy()
abstract export(file_obj, file_type=None)
abstract property extents: ndarray[Any, dtype[float64]]
abstract property is_empty: bool
metadata: dict
property scale: float

A loosely specified “order of magnitude scale” for the geometry which always returns a value and can be used to make code more robust to large scaling differences.

It returns the diagonal of the axis aligned bounding box or if anything is invalid or undefined, 1.0.

Returns:

scale – Approximate order of magnitude scale of the geometry.

Return type:

float

abstract show()
property units: str | None

Definition of units for the mesh.

Returns:

units – Unit system mesh is in, or None if not defined

Return type:

str

class trimesh.parent.Geometry3D

Bases: Geometry

The Geometry3D object is the parent object of geometry objects which are three dimensional, including Trimesh, PointCloud, and Scene objects.

apply_obb(**kwargs)

Apply the oriented bounding box transform to the current mesh.

This will result in a mesh with an AABB centered at the origin and the same dimensions as the OBB.

Parameters:

kwargs – Passed through to bounds.oriented_bounds

Returns:

matrix – Transformation matrix that was applied to mesh to move it into OBB frame

Return type:

(4, 4) float

property bounding_box

An axis aligned bounding box for the current mesh.

Returns:

aabb – Box object with transform and extents defined representing the axis aligned bounding box of the mesh

Return type:

trimesh.primitives.Box

property bounding_box_oriented

An oriented bounding box for the current mesh.

Returns:

obb – Box object with transform and extents defined representing the minimum volume oriented bounding box of the mesh

Return type:

trimesh.primitives.Box

property bounding_cylinder

A minimum volume bounding cylinder for the current mesh.

Returns:

mincyl – Cylinder primitive containing current mesh

Return type:

trimesh.primitives.Cylinder

property bounding_primitive

The minimum volume primitive (box, sphere, or cylinder) that bounds the mesh.

Returns:

bounding_primitive – Smallest primitive which bounds the mesh: trimesh.primitives.Sphere trimesh.primitives.Box trimesh.primitives.Cylinder

Return type:

object

property bounding_sphere

A minimum volume bounding sphere for the current mesh.

Note that the Sphere primitive returned has an unpadded exact sphere_radius so while the distance of every vertex of the current mesh from sphere_center will be less than sphere_radius, the faceted sphere primitive may not contain every vertex.

Returns:

minball – Sphere primitive containing current mesh

Return type:

trimesh.primitives.Sphere