Quick Start¶
Extract a surface in a few lines of code.
import torch
import isoext
from isoext.sdf import SphereSDF, TorusSDF, UnionOp, IntersectionOp, NegationOp, RotationOp
from isoext import viewer
# A high-resolution grid of sample points
grid = isoext.UniformGrid([256, 256, 256])
# A shape built with CSG: a sphere with three interlocking toroidal tunnels
sphere = SphereSDF(radius=0.75)
torus = TorusSDF(R=0.75, r=0.15)
shape = IntersectionOp(
[
sphere,
NegationOp(
UnionOp(
[
torus,
RotationOp(torus, axis=[1, 0, 0], angle=90),
RotationOp(torus, axis=[0, 1, 0], angle=90),
]
)
),
]
)
# Evaluate the shape at every grid point and extract the surface
grid.set_values(shape(grid.get_points()))
vertices, faces = isoext.marching_cubes(grid)
print(f"Extracted {vertices.shape[0]:,} vertices, {faces.shape[0]:,} triangles")
viewer.embed(vertices, faces, color="coral")
Extracted 196,176 vertices, 392,348 triangles
What Just Happened¶
The example built a 256³ grid of sample points, evaluated a signed distance function at each point, and ran marching cubes to mesh the surface where the field crosses zero. If any of those words are new, What Is Iso-Surface Extraction? explains them from scratch; Method Comparisons compares the methods.
Interactive Viewing¶
Outside of these docs, isoext.viewer can also open a live viewer
in your browser:
server = viewer.show(vertices, faces) # prints the URL it serves on
# ... inspect the mesh in the browser ...
server.stop()
viewer.embed, used above, instead records the scene to a static
file next to the notebook, so the rendered page stays interactive
without a running server.
Learn More¶
What Is Iso-Surface Extraction? – what iso-surface extraction is, from zero
Working with Grids – creating grids and setting values, including from neural networks
Marching Cubes, Marching Tetrahedra, Surface Nets, Dual Contouring and Dual Marching Cubes – the extraction methods
SDF Utilities – built-in shape primitives and CSG operations
Viewer – viewing meshes and sharing scenes