Coverage for trimesh/decomposition.py: 100%
5 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-24 04:40 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-24 04:40 +0000
1import numpy as np
4def convex_decomposition(mesh, **kwargs) -> list[dict]:
5 """
6 Compute an approximate convex decomposition of a mesh.
8 VHACD Parameters which can be passed as kwargs:
10 Name Default
11 -----------------------------------------
12 maxConvexHulls 64
13 resolution 400000
14 minimumVolumePercentErrorAllowed 1.0
15 maxRecursionDepth 10
16 shrinkWrap True
17 fillMode "flood"
18 maxNumVerticesPerCH 64
19 asyncACD True
20 minEdgeLength 2
21 findBestPlane False
23 Parameters
24 ----------
25 mesh : trimesh.Trimesh
26 Mesh to be decomposed into convex parts
27 **kwargs : VHACD keyword arguments
29 Returns
30 -------
31 mesh_args : list
32 List of **kwargs for Trimeshes that are nearly
33 convex and approximate the original.
34 """
35 from vhacdx import compute_vhacd
37 # the faces are triangulated in a (len(face), ...vertex-index)
38 # for vtkPolyData
39 # i.e. so if shaped to four columns the first column is all 3
40 faces = (
41 np.column_stack((np.ones(len(mesh.faces), dtype=np.int64) * 3, mesh.faces))
42 .ravel()
43 .astype(np.uint32)
44 )
46 return [
47 {"vertices": v, "faces": f}
48 for v, f in compute_vhacd(mesh.vertices, faces, **kwargs)
49 ]