trimesh.creation
creation.py
Create meshes from primitives, or with operations.
- trimesh.creation.annulus(r_min, r_max, height=None, sections=None, transform=None, segment=None, **kwargs)
Create a mesh of an annular cylinder along Z centered at the origin.
- Parameters
r_min (float) – The inner radius of the annular cylinder
r_max (float) – The outer radius of the annular cylinder
height (float) – The height of the annular cylinder
sections (int or None) – How many pie wedges should the annular cylinder have
transform ((4, 4) float or None) – Transform to apply to move result from the origin
segment (None or (2, 3) float) – Override transform and height with a line segment
**kwargs – passed to Trimesh to create annulus
- Returns
annulus – Mesh of annular cylinder
- Return type
- trimesh.creation.axis(origin_size=0.04, transform=None, origin_color=None, axis_radius=None, axis_length=None)
Return an XYZ axis marker as a Trimesh, which represents position and orientation. If you set the origin size the other parameters will be set relative to it.
- Parameters
transform ((4, 4) float) – Transformation matrix
origin_size (float) – Radius of sphere that represents the origin
origin_color ((3,) float or int, uint8 or float) – Color of the origin
axis_radius (float) – Radius of cylinder that represents x, y, z axis
axis_length (float) – Length of cylinder that represents x, y, z axis
- Returns
marker – Mesh geometry of axis indicators
- Return type
- trimesh.creation.box(extents=None, transform=None, **kwargs)
Return a cuboid.
- Parameters
extents (float, or (3,) float) – Edge lengths
transform ((4, 4) float) – Transformation matrix
**kwargs – passed to Trimesh to create box
- Returns
geometry – Mesh of a cuboid
- Return type
- trimesh.creation.camera_marker(camera, marker_height=0.4, origin_size=None)
Create a visual marker for a camera object, including an axis and FOV.
- Parameters
camera (trimesh.scene.Camera) – Camera object with FOV and transform defined
marker_height (float) – How far along the camera Z should FOV indicators be
origin_size (float) – Sphere radius of the origin (default: marker_height / 10.0)
- Returns
meshes – Contains Trimesh and Path3D objects which can be visualized
- Return type
list
- trimesh.creation.capsule(height=1.0, radius=1.0, count=[32, 32])
Create a mesh of a capsule, or a cylinder with hemispheric ends.
- Parameters
height (float) – Center to center distance of two spheres
radius (float) – Radius of the cylinder and hemispheres
count ((2,) int) – Number of sections on latitude and longitude
- Returns
capsule –
- Capsule geometry with:
cylinder axis is along Z
one hemisphere is centered at the origin
other hemisphere is centered along the Z axis at height
- Return type
- trimesh.creation.cone(radius, height, sections=None, transform=None, **kwargs)
Create a mesh of a cone along Z centered at the origin.
- Parameters
radius (float) – The radius of the cylinder
height (float) – The height of the cylinder
sections (int or None) – How many pie wedges per revolution
transform ((4, 4) float or None) – Transform to apply after creation
**kwargs (dict) – Passed to Trimesh constructor
- Returns
cone – Resulting mesh of a cone
- Return type
- trimesh.creation.cylinder(radius, height=None, sections=None, segment=None, transform=None, **kwargs)
Create a mesh of a cylinder along Z centered at the origin.
- Parameters
radius (float) – The radius of the cylinder
height (float or None) – The height of the cylinder
sections (int or None) – How many pie wedges should the cylinder have
segment ((2, 3) float) – Endpoints of axis, overrides transform and height
transform ((4, 4) float) – Transform to apply
**kwargs – passed to Trimesh to create cylinder
- Returns
cylinder – Resulting mesh of a cylinder
- Return type
- trimesh.creation.extrude_polygon(polygon, height, transform=None, triangle_args=None, **kwargs)
Extrude a 2D shapely polygon into a 3D mesh
- Parameters
polygon (shapely.geometry.Polygon) – 2D geometry to extrude
height (float) – Distance to extrude polygon along Z
triangle_args (str or None) – Passed to triangle
**kwargs – passed to Trimesh
- Returns
mesh – Resulting extrusion as watertight body
- Return type
- trimesh.creation.extrude_triangulation(vertices, faces, height, transform=None, **kwargs)
Extrude a 2D triangulation into a watertight mesh.
- Parameters
vertices ((n, 2) float) – 2D vertices
faces ((m, 3) int) – Triangle indexes of vertices
height (float) – Distance to extrude triangulation
**kwargs (dict) – Passed to Trimesh constructor
- Returns
mesh – Mesh created from extrusion
- Return type
- trimesh.creation.icosahedron()
Create an icosahedron, a 20 faced polyhedron.
- Returns
ico – Icosahederon centered at the origin.
- Return type
- trimesh.creation.icosphere(subdivisions=3, radius=1.0, color=None)
Create an isophere centered at the origin.
- Parameters
subdivisions (int) – How many times to subdivide the mesh. Note that the number of faces will grow as function of 4 ** subdivisions, so you probably want to keep this under ~5
radius (float) – Desired radius of sphere
color ((3,) float or uint8) – Desired color of sphere
- Returns
ico – Meshed sphere
- Return type
- trimesh.creation.random_soup(face_count=100)
Return random triangles as a Trimesh
- Parameters
face_count (int) – Number of faces desired in mesh
- Returns
soup – Geometry with face_count random faces
- Return type
- trimesh.creation.revolve(linestring, angle=None, sections=None, transform=None, **kwargs)
Revolve a 2D line string around the 2D Y axis, with a result with the 2D Y axis pointing along the 3D Z axis.
This function is intended to handle the complexity of indexing and is intended to be used to create all radially symmetric primitives, eventually including cylinders, annular cylinders, capsules, cones, and UV spheres.
Note that if your linestring is closed, it needs to be counterclockwise if you would like face winding and normals facing outwards.
- Parameters
linestring ((n, 2) float) – Lines in 2D which will be revolved
angle (None or float) – Angle in radians to revolve curve by
sections (None or int) – Number of sections result should have If not specified default is 32 per revolution
transform (None or (4, 4) float) – Transform to apply to mesh after construction
**kwargs (dict) – Passed to Trimesh constructor
- Returns
revolved – Mesh representing revolved result
- Return type
- trimesh.creation.sweep_polygon(polygon, path, angles=None, **kwargs)
Extrude a 2D shapely polygon into a 3D mesh along an arbitrary 3D path. Doesn’t handle sharp curvature well.
- Parameters
polygon (shapely.geometry.Polygon) – Profile to sweep along path
path ((n, 3) float) – A path in 3D
angles ((n,) float) – Optional rotation angle relative to prior vertex at each vertex
- Returns
mesh – Geometry of result
- Return type
- trimesh.creation.triangulate_polygon(polygon, triangle_args=None, engine=None, **kwargs)
Given a shapely polygon create a triangulation using a python interface to triangle.c or mapbox-earcut. > pip install triangle > pip install mapbox_earcut
- Parameters
polygon (Shapely.geometry.Polygon) – Polygon object to be triangulated
triangle_args (str or None) – Passed to triangle.triangulate i.e: ‘p’, ‘pq30’
engine (None or str) – Any value other than ‘earcut’ will use triangle
- Returns
vertices ((n, 2) float) – Points in space
faces ((n, 3) int) – Index of vertices that make up triangles
- trimesh.creation.truncated_prisms(tris, origin=None, normal=None)
Return a mesh consisting of multiple watertight prisms below a list of triangles, truncated by a specified plane.
- Parameters
triangles ((n, 3, 3) float) – Triangles in space
origin (None or (3,) float) – Origin of truncation plane
normal (None or (3,) float) – Unit normal vector of truncation plane
- Returns
mesh – Triangular mesh
- Return type
- trimesh.creation.uv_sphere(radius=1.0, count=[32, 32], theta=None, phi=None)
Create a UV sphere (latitude + longitude) centered at the origin. Roughly one order of magnitude faster than an icosphere but slightly uglier.
- Parameters
radius (float) – Radius of sphere
count ((2,) int) – Number of latitude and longitude lines
theta ((n,) float) – Optional theta angles in radians
phi ((n,) float) – Optional phi angles in radians
- Returns
mesh – Mesh of UV sphere with specified parameters
- Return type