

Trimesh is a pure Python 3.8+ library for loading and using triangular meshes with an emphasis on watertight surfaces. The goal of the library is to provide a full featured and well tested Trimesh object which allows for easy manipulation and analysis, in the style of the Polygon object in the Shapely library.
The API is mostly stable, but this should not be relied on and is not guaranteed: install a specific version if you plan on deploying something using trimesh.
Pull requests are appreciated and responded to promptly! If you'd like to contribute, here a quick development and contributing guide.
Basic Installation
Keeping trimesh easy to install is a core goal, thus the only hard dependency is numpy. Installing other packages adds functionality but is not required. For the easiest install with just numpy:
pip install trimesh
The minimal install can load many supported formats (STL, PLY, OBJ, GLTF/GLB) into numpy.ndarray values. More functionality is available when soft dependencies are installed, including convex hulls (scipy), graph operations (networkx), fast ray queries (embreex), vector path handling (shapely and rtree), XML formats like 3DXML/XAML/3MF (lxml), preview windows (pyglet), faster cache checks (xxhash), etc.
To install trimesh with the soft dependencies that generally install cleanly from binaries on Linux x86_64, MacOS ARM, and Windows x86_64 using pip:
pip install trimesh[easy]
If you are supporting a different platform or are freezing dependencies for an application we recommend you do not use extras, i.e. depend on trimesh scipy versus trimesh[easy]. Further information is available in the advanced installation documentation.
Quick Start
Here is an example of loading a mesh from file and colorizing its faces (nicely formatted notebook version of this example.
import numpy as np
import trimesh
trimesh.util.attach_to_log()
mesh = trimesh.Trimesh(vertices=[[0, 0, 0], [0, 0, 1], [0, 1, 0]],
faces=[[0, 1, 2]])
mesh = trimesh.Trimesh(vertices=[[0, 0, 0], [0, 0, 1], [0, 1, 0]],
faces=[[0, 1, 2]],
process=False)
mesh = trimesh.load_mesh('models/CesiumMilkTruck.glb')
mesh.is_watertight
mesh.euler_number
print(mesh.volume / mesh.convex_hull.volume)
mesh.apply_translation(-mesh.center_mass)
mesh.moment_inertia
mesh.split()
for facet in mesh.facets:
mesh.visual.face_colors[facet] = trimesh.visual.random_color()
mesh.show()
mesh.apply_transform(trimesh.transformations.random_rotation_matrix())
mesh.bounding_box.extents
mesh.bounding_box_oriented.primitive.extents
mesh.bounding_box_oriented.primitive.transform
(mesh + mesh.bounding_box_oriented).show()
print(mesh.bounding_box_oriented.volume,
mesh.bounding_cylinder.volume,
mesh.bounding_sphere.volume)
Features
- Import meshes from binary/ASCII STL, Wavefront OBJ, ASCII OFF, binary/ASCII PLY, GLTF/GLB 2.0, 3MF, XAML, 3DXML, etc.
- Export meshes as GLB/GLTF, binary STL, binary PLY, ASCII OFF, OBJ, COLLADA, etc.
- Import and export 2D or 3D vector paths with DXF or SVG files
- Preview meshes using an OpenGL
pyglet window, or in-line in jupyter or marimo notebooks using three.js
- Automatic hashing from a subclassed numpy array for change tracking using MD5, zlib CRC, or xxhash, and internal caching of expensive values.
- Calculate face adjacencies, face angles, vertex defects, convex hulls, etc.
- Calculate cross sections for a 2D outline, or slice a mesh for a 3D remainder mesh, i.e. slicing for 3D-printing.
- Split mesh based on face connectivity using networkx, or scipy.sparse
- Calculate mass properties, including volume, center of mass, moment of inertia, principal components of inertia, etc.
- Repair simple problems with triangle winding, normals, and quad/triangle holes
- Compute rotation/translation/tessellation invariant identifier and find duplicate meshes
- Check if a mesh is watertight, convex, etc.
- Sample the surface of a mesh
- Ray-mesh queries including location, triangle index, etc.
- Boolean operations on meshes (intersection, union, difference) using Manifold3D or Blender.
- Voxelize watertight meshes
- Smooth watertight meshes using Laplacian smoothing algorithms (Classic, Taubin, Humphrey)
- Subdivide faces of a mesh
- Approximate minimum volume oriented bounding boxes and spheres for meshes.
- Calculate nearest point on mesh surface and signed distance
- Primitive objects (Box, Cylinder, Sphere, Extrusion) which are subclassed Trimesh objects and have all the same features (inertia, viewers, etc)
- Simple scene graph and transform tree which can be rendered (pyglet window, three.js in a jupyter/marimo notebook or exported.
- Many utility functions, like transforming points, unitizing vectors, aligning vectors, tracking numpy arrays for changes, grouping rows, etc.
Additional Notes
- Check out some cool stuff people have done in the GitHub network.
- Generally
trimesh API changes should have a one-year period of printing a warnings.DeprecationWarning although that's not always possible (i.e. the pyglet2 viewer rewrite that's been back-burnered for several years.)
- Docker containers are available on Docker Hub as
trimesh/trimesh and there's a container guide in the docs.
- If you're choosing which format to use, you may want to try GLB as a fast modern option.