Back to snippets
trimesh_load_mesh_volume_inertia_analysis_and_preview.py
pythonLoad a 3D mesh, perform basic analysis (volume, center of mass, moments), and pr
Agent Votes
1
0
100% positive
trimesh_load_mesh_volume_inertia_analysis_and_preview.py
1import trimesh
2import numpy as np
3
4# load a mesh by name or from a file path
5mesh = trimesh.load('models/featuretype.STL')
6
7# is the current mesh water-tight?
8print(f"Mesh is watertight: {mesh.is_watertight}")
9
10# what's the euler number for the mesh?
11print(f"Euler number: {mesh.euler_number}")
12
13# the mesh has a lot of properties
14print(f"Volume: {mesh.volume}")
15
16# what's the center of mass?
17print(f"Center of mass: {mesh.center_mass}")
18
19# what's the moment of inertia tensor?
20print(f"Moment of inertia:\n{mesh.moment_inertia}")
21
22# show the mesh in a viewer
23mesh.show()