{"id":1885,"library":"trimesh","title":"Trimesh","description":"Trimesh is a Python library for loading, viewing, processing, and analyzing triangular meshes, with a strong emphasis on vectorized operations for performance. It's actively developed and frequently updated, providing a comprehensive set of tools for 3D geometry manipulation.","status":"active","version":"4.11.5","language":"en","source_language":"en","source_url":"https://github.com/mikedh/trimesh","tags":["3d","mesh","geometry","cad","visualization","numpy","scipy"],"install":[{"cmd":"pip install trimesh","lang":"bash","label":"Basic installation"},{"cmd":"pip install trimesh[full]","lang":"bash","label":"Full installation with common dependencies"}],"dependencies":[{"reason":"Required for many advanced mesh operations (e.g., convex hulls, path planning, distance calculations).","package":"scipy","optional":true},{"reason":"Recommended for robust and offscreen 3D visualization, especially in headless environments.","package":"pyrender","optional":true},{"reason":"Required for importing/exporting some XML-based formats like DAE and SVG.","package":"lxml","optional":true}],"imports":[{"note":"While technically possible, `trimesh.Trimesh` is the public-facing and recommended way to instantiate.","wrong":"from trimesh.base import Trimesh","symbol":"Trimesh","correct":"import trimesh\nmesh = trimesh.Trimesh(...)"},{"note":"`trimesh.io` functions are internally used; `trimesh.load` is the stable public API since v3.0.","wrong":"import trimesh.io; mesh = trimesh.io.load('path/to/mesh.obj')","symbol":"load","correct":"import trimesh\nmesh = trimesh.load('path/to/mesh.obj')"},{"symbol":"Scene","correct":"import trimesh\nscene = trimesh.Scene(...)"}],"quickstart":{"code":"import trimesh\nimport numpy as np\n\n# 1. Create a simple mesh (a box)\nmesh = trimesh.creation.box()\n\n# 2. Perform basic analyses\nvolume = mesh.volume\narea = mesh.area\ninertia = mesh.moment_inertia\n\nprint(f\"Mesh volume: {volume:.2f}\")\nprint(f\"Mesh surface area: {area:.2f}\")\nprint(f\"Mesh moment of inertia:\\n{inertia}\")\n\n# 3. Load a remote mesh (requires network access)\ntry:\n    # Using a known stable URL for demonstration\n    mesh_loaded = trimesh.load_remote('https://raw.githubusercontent.com/mikedh/trimesh/main/models/feature.stl')\n    print(f\"Loaded remote mesh, volume: {mesh_loaded.volume:.2f}\")\nexcept Exception as e:\n    print(f\"Could not load remote mesh: {e}. Check internet connection or URL.\")","lang":"python","description":"This quickstart demonstrates creating a basic mesh, performing common analyses like volume and area calculation, and loading a mesh from a remote URL. It focuses on core functionality that doesn't require interactive display."},"warnings":[{"fix":"Install `trimesh[full]` to get most common optional dependencies, or install specific packages as needed (e.g., `pip install trimesh scipy pyrender`). Consult the official documentation for feature-specific dependencies.","message":"Trimesh has many optional dependencies for different features (e.g., `scipy` for algorithms, `pyrender` for visualization, `lxml` for file formats, `rtree` for spatial queries). Missing dependencies lead to `AttributeError` or `ModuleNotFoundError` when trying to use those features.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the `trimesh` documentation for your specific version regarding visualization. For robust rendering, consider using `pyrender` directly or `open3d` integration rather than `trimesh.show()` which relies on `pyglet`.","message":"The `trimesh.visual` module and visualization backend configuration have seen significant API changes and refactors, particularly around versions 3.x and 4.x. Old visualization code, especially custom `ColorVisuals` or direct `viewer` interaction, may break.","severity":"breaking","affected_versions":">=3.0, >=4.0"},{"fix":"For headless visualization, use `pyrender` or `open3d` which support offscreen rendering, or export your mesh to a common file format (e.g., OBJ, STL). For interactive use, ensure `pyglet` is installed and your environment has a working OpenGL display server.","message":"The `trimesh.show()` function relies on `pyglet` and an active OpenGL context, which often fails in headless environments (e.g., CI/CD, cloud instances, WSL without display server) or systems with non-standard display drivers, resulting in a blank window or errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}