PyMCubes

raw JSON →
0.1.6 verified Fri May 01 auth: no python

A Python library for extracting isosurfaces from volumetric data using the marching cubes algorithm. Version 0.1.6 is the latest, with irregular releases.

pip install pymcubes
error ModuleNotFoundError: No module named 'mcubes'
cause The Python module is 'mcubes', but users try to import 'pymcubes'.
fix
Run 'pip install pymcubes' and then import using 'import mcubes'.
error ImportError: cannot import name 'marching_cubes' from 'mcubes'
cause The function is named 'marching_cubes' (singular), but users often try 'marching_cubes' (plural). Check spelling.
fix
Use 'from mcubes import marching_cubes' (singular).
gotcha The correct import is 'from mcubes import ...' not 'from pymcubes import ...'. The package installs as pymcubes but the module is mcubes.
fix Use 'import mcubes' or 'from mcubes import ...' after pip install pymcubes.
gotcha Marching cubes output vertices in a (N,3) array, not (3,N). Ensure your downstream code expects the correct shape.
fix Check the shape: vertices.shape should be (N,3).

Extract an isosurface from volumetric data and save as OBJ.

import numpy as np
from mcubes import marching_cubes, export_obj

# Create volumetric data: a sphere
X, Y, Z = np.mgrid[-2:2:50j, -2:2:50j, -2:2:50j]
volume = np.sqrt(X**2 + Y**2 + Z**2) - 1.0

# Extract isosurface at level 0
vertices, triangles = marching_cubes(volume, 0)

# Export to OBJ file
export_obj(vertices, triangles, 'sphere.obj')
print('Isosurface extracted and saved to sphere.obj')