Manifold3d

3.4.1 · active · verified Sat Apr 11

Manifold3d is a Python library providing bindings to the Manifold C++ geometry kernel (v3.4.1). It specializes in creating and operating on topologically robust, manifold triangle meshes, making it ideal for applications in CAD, 3D printing, and simulations. The library guarantees manifold output and leverages parallelization for performance. It has an active development cycle with regular releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating basic 3D primitives (sphere, box) and performing common boolean operations like union and difference. It showcases the core functionality of combining and modifying manifold meshes. For saving or loading complex 3D file formats, integrating with a dedicated mesh I/O library like `trimesh` is recommended.

import manifold3d

# Create a sphere with radius 1 and 60 facets
sphere = manifold3d.Sphere(1, 60)

# Create a cube with dimensions [1, 1, 1]
box = manifold3d.Box([1, 1, 1])

# Translate the box to intersect the sphere
box_translated = box.translate([0.5, 0.5, 0.5])

# Perform a boolean union operation
union_result = sphere.union(box_translated)

# Perform a boolean difference operation
difference_result = sphere.difference(box_translated)

print(f"Sphere triangles: {sphere.num_triangles()}")
print(f"Union result triangles: {union_result.num_triangles()}")
print(f"Difference result triangles: {difference_result.num_triangles()}")

# To export, consider using the 'trimesh' library:
# import trimesh
# mesh_data = union_result.to_mesh()
# trimesh_mesh = trimesh.Trimesh(
#     vertices=mesh_data.vert_properties[:, :3], 
#     faces=mesh_data.tri_verts
# )
# trimesh_mesh.export('union_result.stl')

view raw JSON →