Installation¶
The only thing required to install trimesh is
numpy.
All other dependencies are ‘soft,’ or trimesh will raise the exceptions (usually but not always an ImportError) at runtime if a function is called that requires a package that isn’t installed. If you do the most basic install of trimesh it will only install numpy:
pip install trimesh
This will enable you to load most formats into numpy arrays: STL, PLY, OBJ, GLB, GLTF.
If you’d like most soft dependencies which should install cleanly on Mac, Windows, and Linux, you can use the easy pip extra:
pip install trimesh[easy]
Conda Packages¶
If you prefer a conda environment, trimesh is available on conda-forge (trimesh-feedstock repo)
If you install Miniconda you can then run:
conda install -c conda-forge trimesh
Dependency Overview¶
Trimesh has a lot of soft-required upstream packages, and we try to make sure they’re actively maintained. Here’s a quick summary of what they’re used for:
Package |
Description |
Alternatives |
Level |
|---|---|---|---|
|
The base container for fast array types. |
|
|
|
Provides convex hulls ( |
|
|
|
Parse XML documents. We use this over the built-in ones as it was slightly faster, and there was a format implemented which was extremely annoying to handle without the ability to get parent nodes (which |
Standard library’s XML |
|
|
Pure Python graph library that’s reasonably fast and has a nice API. |
|
|
|
Bindings to |
|
|
|
Query ND rectangles with a spatial tree for a “broad phase” intersection. Used in polygon generation (“given N closed curves which curve contains the other curve?”) and as the broad-phase for the built-in-numpy slow ray query engine. |
|
|
|
Do network queries in |
|
|
|
Evaluate symbolic algebra |
|
|
|
Quickly hash arrays, used for our cache checking |
|
|
|
When we fail to decode text as UTF-8 we then check with charset-normalizer which guesses an encoding, letting us load files even with weird encodings. |
|
|
|
Printing logs with colors. |
|
|
|
Reading raster images for textures and render polygons into raster images. |
|
|
|
Parsing SVG path strings. |
|
|
|
Validating our exports for formats like GLTF. |
|
|
|
Parse |
|
|
|
OpenGL bindings for our simple debug viewer. |
|
|
|
Unwrap meshes to generate UV coordinates quickly and well. |
|
|
|
Do collision queries between meshes |
|
|
|
Provide a viewer with widgets. |
|
|
|
Load additional mesh formats. |
|
|
|
Used in voxel ops |
|
|
|
Triangulate 2D polygons |
|
|
|
Get current memory usage, useful for checking to see if we’re going to run out of memory instantiating a giant array |
|
|
|
A static code analyzer and formatter that replaces |
|
|
|
A test runner. |
|
|
|
A plugin to calculate test coverage. |
|
|
|
A sampling based profiler for performance tweaking. |
|
|
|
A binding for VHACD which provides convex decompositions |
|
|
|
A binding for the Manifold mesh boolean engine |
|
|
|
A binding for OpenCTM loaders enabling |
|
|
|
A binding for OpenCASCADE enabling |
|
Adding A Dependency¶
If there’s no way to implement something reasonably in vectorized Python or there is a mature minimal C++ or Rust implementation of something useful and complicated we may add a dependency. If it’s a major, active project with few dependencies (i.e. jinja2) that’s probably fine. Otherwise it’s a lot more of a commitment than just implementing the function in Python however. An example of this is embree, Intel’s ray check engine: it is a super complicated thing to do well and 50-100x faster than Python ray checks.
There are a few projects that we’ve forked into the trimesh GitHub organization which you can take a look at. The general idea of the requirements for a new compiled dependency are:
is actively maintained and has an MIT/BSD compatible license.
has all source code in the repository or as a submodule, i.e. no mysterious binary blobs.
binding preferably uses pybind11, nanobind or maturin/py03 for Rust projects. Cython is also OK but other options are preferable if possible.
uses
cibuildwheelto publish releases configured inpyproject.toml.has unit tests which run in CI
has minimal dependencies: ideally only
numpy.