COACD: Approximate Convex Decomposition for 3D Meshes

1.0.10 · active · verified Fri Apr 17

COACD provides a Python interface for Approximate Convex Decomposition (ACD) of 3D meshes, using collision-aware concavity and a tree search algorithm. It's particularly useful for preparing complex geometries for physics simulations or collision detection by breaking them down into simpler convex hulls. The current version is 1.0.10, and releases are typically driven by updates to the underlying C++ library or improvements in the decomposition algorithms.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple 3D mesh using `trimesh` and then decompose it into convex parts using `coacd.run_coacd`. The output `parts` is a list where each element is a tuple containing the vertices and faces of a single convex component. The `resolution` parameter is crucial for balancing speed and accuracy.

import trimesh
import coacd
import numpy as np

# Create a simple mesh (e.g., a box) using trimesh
mesh = trimesh.primitives.Box()

print(f"Original mesh has {len(mesh.vertices)} vertices and {len(mesh.faces)} faces.")

# Perform convex decomposition
# Parameters like threshold, max_iter, resolution affect decomposition quality and speed
parts = coacd.run_coacd(
    mesh.vertices, # Expected as a (N, 3) numpy array
    mesh.faces,    # Expected as a (M, 3) numpy array
    threshold=0.05, # Controls concavity threshold (lower for more parts)
    max_iter=8,     # Max iterations for tree search
    resolution=64,  # Voxel grid resolution, lower for faster but less precise
    render=False,   # Set to True to visualize decomposition (requires PyOpenGL)
    save_meshes=False # Set to True to save individual parts to disk
)

print(f"Decomposed into {len(parts)} convex parts.")

# Each part is a tuple (vertices, faces) for a convex hull
if parts:
    first_part_vertices, first_part_faces = parts[0]
    print(f"First part has {len(first_part_vertices)} vertices and {len(first_part_faces)} faces.")
    # You can reconstruct meshes for each part if needed, e.g., trimesh.Trimesh(v, f)

view raw JSON →