trimesh.primitives¶
primitives.py¶
Subclasses of Trimesh objects that are parameterized as primitives.
Useful because you can move boxes and spheres around, and then use trimesh operations on them at any point.
Classes:










class
trimesh.primitives.
Box
(*args, **kwargs)¶ Bases:
trimesh.primitives._Primitive
Methods:
Return a Path3D containing the outline of the box.
sample_grid
([count, step])Return a 3D grid which is contained by the box.
sample_volume
(count)Return random samples from inside the volume of the box.
Attributes:
Returns whether or not the current box is rotated at all.
Volume of the box Primitive.

as_outline
()¶ Return a Path3D containing the outline of the box.
 Returns
outline – Outline of box primitive
 Return type

property
is_oriented
¶ Returns whether or not the current box is rotated at all.

sample_grid
(count=None, step=None)¶ Return a 3D grid which is contained by the box. Samples are either ‘step’ distance apart, or there are ‘count’ samples per box side.
 Parameters
count (int or (3,) int) – If specified samples are spaced with np.linspace
step (float or (3,) float) – If specified samples are spaced with np.arange
 Returns
grid – Points inside the box
 Return type
(n, 3) float

sample_volume
(count)¶ Return random samples from inside the volume of the box.
 Parameters
count (int) – Number of samples to return
 Returns
samples – Points inside the volume
 Return type
(count, 3) float

property
volume
¶ Volume of the box Primitive.
 Returns
volume
 Return type
float, volume of box


class
trimesh.primitives.
Capsule
(*args, **kwargs)¶ Bases:
trimesh.primitives._Primitive
Attributes:
The direction of the capsule’s axis.

property
direction
¶ The direction of the capsule’s axis.
 Returns
axis
 Return type
(3,) float, vector along the cylinder axis

property

class
trimesh.primitives.
Cylinder
(*args, **kwargs)¶ Bases:
trimesh.primitives._Primitive
Methods:
buffer
(distance)Return a cylinder primitive which covers the source cylinder by distance: radius is inflated by distance, height by twice the distance.
Attributes:
The direction of the cylinder’s axis.
The analytic inertia tensor of the cylinder primitive.
A line segment which if inflated by cylinder radius would represent the cylinder primitive.
The analytic volume of the cylinder primitive.

buffer
(distance)¶ Return a cylinder primitive which covers the source cylinder by distance: radius is inflated by distance, height by twice the distance.
 Parameters
distance (float) – Distance to inflate cylinder radius and height
 Returns
buffered – Cylinder primitive inflated by distance
 Return type

property
direction
¶ The direction of the cylinder’s axis.
 Returns
axis
 Return type
(3,) float, vector along the cylinder axis

property
moment_inertia
¶ The analytic inertia tensor of the cylinder primitive.
 Returns
tensor
 Return type
(3,3) float, 3D inertia tensor

property
segment
¶ A line segment which if inflated by cylinder radius would represent the cylinder primitive.
 Returns
segment – Points representing a single line segment
 Return type
(2, 3) float

property
volume
¶ The analytic volume of the cylinder primitive.
 Returns
volume – Volume of the cylinder
 Return type
float


class
trimesh.primitives.
Extrusion
(triangle_args=None, *args, **kwargs)¶ Bases:
trimesh.primitives._Primitive
Attributes:
The surface area of the primitive extrusion.
An oriented bounding box for the current mesh.
Based on the extrudes transform what is the vector along which the polygon will be extruded.
Based on the extrude transform what is the origin of the plane it is extruded from.
The volume of the Extrusion primitive.
Methods:
buffer
(distance[, distance_height])Return a new Extrusion object which is expanded in profile and in height by a specified distance.
slide
(distance)Alter the transform of the current extrusion to slide it along its extrude_direction vector
to_dict
()
property
area
¶ The surface area of the primitive extrusion.
Calculated from polygon and height to avoid mesh creation.
 Returns
area – Surface area of 3D extrusion
 Return type
float

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

buffer
(distance, distance_height=None, **kwargs)¶ Return a new Extrusion object which is expanded in profile and in height by a specified distance.
 Parameters
distance (float) – Distance to buffer polygon
distance_height (float) – Distance to buffer above and below extrusion
kwargs (dict) – Passed to Extrusion constructor
 Returns
buffered – Extrusion object with new values
 Return type

property
direction
¶ Based on the extrudes transform what is the vector along which the polygon will be extruded.
 Returns
direction – Unit direction vector
 Return type
(3,) float

property
origin
¶ Based on the extrude transform what is the origin of the plane it is extruded from.
 Returns
origin – Origin of extrusion plane
 Return type
(3,) float

slide
(distance)¶ Alter the transform of the current extrusion to slide it along its extrude_direction vector
 Parameters
distance (float) – Distance along self.extrude_direction to move

to_dict
()¶

property
volume
¶ The volume of the Extrusion primitive. Calculated from polygon and height to avoid mesh creation.
 Returns
volume – Volume of 3D extrusion
 Return type
float

property

class
trimesh.primitives.
Sphere
(*args, **kwargs)¶ Bases:
trimesh.primitives._Primitive
Methods:
apply_transform
(matrix)Apply a transform to the sphere primitive
Attributes:
Surface area of the current sphere primitive.
An oriented bounding box for the current mesh.
The axis aligned bounds of the faces of the mesh.
The analytic inertia tensor of the sphere primitive.
Volume of the current sphere primitive.

apply_transform
(matrix)¶ Apply a transform to the sphere primitive
 Parameters
matrix ((4,4) float, homogeneous transformation) –

property
area
¶ Surface area of the current sphere primitive.
 Returns
area
 Return type
float, surface area of the sphere Primitive

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

property
bounds
¶ The axis aligned bounds of the faces of the mesh.
 Returns
bounds – Bounding box with [min, max] coordinates If mesh is empty will return None
 Return type
(2, 3) float or None

property
moment_inertia
¶ The analytic inertia tensor of the sphere primitive.
 Returns
tensor
 Return type
(3,3) float, 3D inertia tensor

property
volume
¶ Volume of the current sphere primitive.
 Returns
volume
 Return type
float, volume of the sphere Primitive
