Skip to content

levelset(): let edge be one spacing per axis - #274

Merged
revarbat merged 1 commit into
mainfrom
feat/levelset-vector-edge
Oct 10, 2026
Merged

revarbat merged 1 commit into
mainfrom
feat/levelset-vector-edge

Conversation

@revarbat

Copy link
Copy Markdown
Member

Refs BelfrySCAD/BelfrySCAD#729

edge=[ex,ey,ez] (or [ex,ey] for a 2D bounds) samples each axis at its own spacing — the equivalent of BOSL2 isosurface()'s vector voxel_size, which the reporter needs to use levelset() as a drop-in for BOSL2's marching cubes.

How: Manifold::LevelSet takes a single edge length, so the 3D path meshes the field squashed to unit spacing on every axis and Scales the mesh back. This is exact, not an approximation: with tolerance −1 each vertex is a linear interpolation along a lattice edge, and that commutes with an axis scale. AVectorEdgeIsExactlyAStretchedLattice pins it: a sphere stretched 4× in z, sampled 4× coarser in z, gives the same triangle count and exactly 4× the volume (1e-6). The 2D path already had separate x/y spacings, so it just reads them from the vector.

A plain number takes the old code path unchanged, so existing scripts mesh identically.

Also fixed on the way: a non-positive edge= given with a grid field warned, then left edge at 0 and passed that to LevelSet; it now falls back to the grid spacing.

Feature level: supported_feature("levelset") is now 2, so a library can probe for a vector edge. FeatureDetection.EveryDocumentedFeatureReportsALevel checked for the digit 1 in the echo; it now checks >= 1.

closed=false (also asked for in the issue) is not included: it means an open surface, which can't be a solid.

Tests: 6 new LevelSetFn cases; full suite 1485 passed, 0 failed.

🤖 Generated with Claude Code

edge=[ex,ey,ez] (or [ex,ey] in 2D) samples each axis at its own spacing,
as BOSL2's isosurface() takes voxel_size. Manifold's LevelSet takes one
edge length, so the 3D path meshes the field squashed to unit spacing and
scales the mesh back, which is exact: with tolerance -1 a vertex is a
linear interpolation along a lattice edge, and that commutes with an axis
scale. A plain number takes the old path unchanged.

Also: a non-positive edge= on a grid field now falls back to the grid
spacing instead of handing Manifold an edge length of 0.

supported_feature("levelset") is now 2, so a library can tell a build
that accepts a vector edge from one that rejects it.

Refs BelfrySCAD/BelfrySCAD#729

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@revarbat
revarbat merged commit af7a349 into main Oct 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant