render(_:scale:within:)

The Naive Surface Nets smooth voxel meshing algorithm.

SurfaceNetRenderer.swift:65
func render<VOXEL>(_ voxelData: any VoxelAccessible<VOXEL>, scale: VoxelScale<Float>, within bounds: VoxelBounds) -> MeshBuffer where VOXEL : VoxelSurfaceRenderable

Extracts an isosurface mesh from the signed distance field sdf. Each value in the field determines how close that point is to the isosurface. Negative SDF values are considered “interior” of the surface volume, and positive values are considered “exterior.”

These lattice points will be considered corners of unit cubes. For each unit cube, at most one isosurface vertex will be estimated.

In the example below, p is a positive corner value, n is a negative corner value, and s represents an isosurface vertex. The characters | and - represent mesh polygons connecting the vertices.

p   p   p   p
  s---s
p | n | p   p
  s   s---s
p | n   n | p
  s---s---s
p   p   p   p

The set of corners sampled is exactly the set of points in [min, max]. The collection of voxels (voxelData) must contain all of those points.

Note that the scheme illustrated above implies that chunks must be padded with a 1-voxel border copied from neighboring voxels in order to connect seamlessly.