How mikedh/trimesh works
Project Type and Purpose
• Trimesh is a pure-Python 3.7+ library for loading, manipulating, analyzing, and exporting triangular mesh data.
• Soft dependencies (scipy, networkx, pyglet, embree, etc.) add optional features.
Top-Level Components
a. Core Geometry (trimesh/base.py, boolean.py, convex.py, curvature.py, etc.)
b. Exchange (trimesh/exchange) – loaders & exporters for STL, OBJ, PLY, GLTF/GLB, DXF, SVG, 3MF, XAML, 3DXML, URDF, etc.
c. Path Module (trimesh/path) – 2D/3D vector path creation, manipulation, DXF/SVG I/O, packing, rasterization.
e. Voxel & Volume (trimesh/voxel) – voxelization, morphology, encoding, transforms.
f. Interfaces (trimesh/interfaces) – external tools: Blender, Gmsh, generic command-line.
g. Viewer (trimesh/viewer) – pyglet window, Jupyter inline three.js widget.
h. Resources (trimesh/resources) – JSON schemas, JavaScript viewer, templates, unit conversion data.
i. Utilities & Caching (trimesh/util.py, caching.py, constants, resolvers, etc.)
Relationships & Data Flow
• Core operations (boolean, convex hull, slicing, mass properties) all operate on Trimesh objects and return new Trimesh or geometric results.
• Trimesh & Scene objects feed into:
– Exporters in Exchange → output files/formats
– Viewer for display (pyglet, three.js)
– Voxel module (for voxelization pipelines)
– Path module (2D cross sections & paths from mesh slices)
Architectural Patterns & Principles
• Layered architecture:
– Bottom: Utilities & caching
– Middle: Core geometry algorithms
– Top: I/O (Exchange), Voxel, Path, Scene, Visual, Viewer
• API-first design: Trimesh and Scene classes are the central data models.
• Plugin-style I/O: each file format lives in its own module under exchange.
• Resource bundling: JSON schemas and viewer assets are packaged under resources.