API Reference · Geometry

SurfaceNets

Namespace: Ava3D

public static class SurfaceNets

Turns a signed-distance field into a Mesh.

Naive surface nets over a regular grid. The field is sampled once at every grid corner; every cell whose corners disagree about the sign gets one vertex, at the mean of the points where the field crosses that cell's twelve edges; and every grid edge whose two ends disagree becomes two triangles joining the vertices of the four cells around it. No lookup tables, one vertex per cell, and near-uniform triangles that shade well and simplify well. Sharp creases come out rounded — the price of placing a vertex by averaging rather than by solving for the corner.

Normals come from the field, not from the triangles: the gradient of a distance function is its surface normal, so the shading is smooth at any resolution and the geometry can be coarse.

The result is deterministic — the same field, box and options give byte-identical arrays on every run and on any machine, because every pass is sequential and nothing depends on the thread count. What the box clips is left open: a field that crosses zero on the box's faces produces a surface with a hole there, and a field that never crosses zero inside the box produces an empty mesh.

Methods

MemberDescription
static Mesh Extract(ScalarField field, BoundingBox bounds, int cellsAlongLongestAxis, SurfaceNetsOptions options = null, Threading.CancellationToken cancellationToken = default)

Finds the surface where field is zero inside bounds.

field

Negative inside, positive outside. Sampled once per grid corner, and six times per vertex more when SurfaceNetsOptions.Gradient is not given.

bounds

The box to sample. The mesh lies inside it; anything the field does outside it is not seen.

cellsAlongLongestAxis

How many cells across the box's longest side. The other two sides get as many cells as keeps them the same size, so the cells are cubes or nearly so. Memory is four bytes a corner plus four a cell, and time is dominated by evaluating the field once per corner.

options

Callbacks, the triangle budget and vertex placement; null for the defaults.

cancellationToken

Checked between slabs of the grid in every pass, and before any work.

returns

A mesh with positions, normals and indices; texture coordinates, tangents and colours when the options ask for them. Wound so the normals point out of the negative region. Empty, rather than null, when the field does not change sign inside the box.

See also