Builtin Library
- ..
- .metadata245 B
- README.md1.8 KB
- init.luau7.7 KB
- readings.module
README.md
geometry.to_sdf
Read an existing closed mesh back into a distance field, so a modelled or imported shape can be smooth-unioned, shelled, repeated or displaced like any sdf.* primitive. The mesh is sampled onto a Grid (grid.box) on the device: every cell centre takes its distance to the nearest triangle, signed by the winding number (negative inside), and the grid is read back the way sdf.from_grid reads one. The grid's size is known before anything is allocated, and the work is bounded: a request past max_samples or max_work is refused naming the resolution that fits. A geometry with no triangles, or with bounds of no extent, is refused.
Inputs
geometry(Surface). The closed mesh being sampled.resolution(Float, default 32, at least 2). How many cells span the longest side of the sampled box. The field carries no detail finer than one cell, so a shape with thin walls needs enough cells to hold them.padding(Float, default 0.1). How far the sampled box extends beyond the mesh's own bounds (at least a thousandth of the longest side). Outside the sampled box the field reports the distance to the box plus the value at its wall.max_samples(Float, default 300000). How many grid cells may be sampled: the memory bound.max_work(Float, default 1000000000). How many cell-against-triangle tests the sampling may perform: the time bound.
Outputs
sdf(Sdf). The distance field, assdf.from_gridanswers it.grid(Grid). The sampled grid, its points carryingdistance.info(Data).samples,divisions({ x, y, z }cells),cellSize,triangles,distanceTestsandbounds({ min, max }of the sampled box).
local field = g.geometry.to_sdf({ geometry = g.mesh.box({}), resolution = 16 }).sdf