samples.scatter
Stable, seeded, nested sample points over the faces of a mesh, as Points geometry with ids, anchors, spacing and levels.
Usage
Samples.scatter(geometry: Mesh | Geometry | NurbsSurface, options?: SampleScatterOptions): Result<Geometry>Parameters
geometryMesh | Geometry | NurbsSurfaceThe source: a Mesh, or polygon Geometry (its id, idFrom, primId and primIdFrom are read when present), or a NurbsSurface (since 0.11.0: a fixed 32 × 32 grid of cells over its normalised knot domain, candidates accepted against each cell’s area bound, one hard core over the whole surface).
options.scopestringThe id of the host’s sample node; each sample’s id is minted under it and it is their minter. Default
undefined (every sample has minter 0).options.seednumberA u32. A new seed moves and renumbers every sample; nothing else renumbers them. Default
0. Range [0, 4294967295] count.options.spacingnumberLevel-0 target spacing on a face of weight 1: one sample per spacing² of area. At least 1e-150, so its density is finite. Default
bounding-box diagonal / 100. Range [1e-150, 1.7976931348623157e+308] model.options.countnumberAbout this many samples at the finest level, instead of spacing. With poisson the density is bisected on the kept count, so the finest level holds at most count samples, and close to it, on any mesh. Required. Range [1, 9007199254740991] count.
options.weightsreadonly { select, weight }[]Density multipliers: select is a selector or a prim set, weight ≥ 0; the last matching clause wins and an unmatched face has weight 1. Default
[].options.distribution"poisson" | "stratified"poisson: blue noise, no two samples of one face family closer than 0.56 / sqrt(2^(levels−1)·d·w), the hard core of the finest level (see ensures); stratified: every candidate up to the count. Default
"poisson". One ofpoisson,stratified.options.levelsnumberLevels of detail: level l has density d·2^l, and each level contains the coarser ones. Default
1. Range [1, 6] count.options.maxCountnumberMost samples returned; above it the density is scaled down until the finest level fits. Default
100000. Range [1, 1000000] count.options.surfaceId{ primId?, primIdFrom? }On a NurbsSurface: the persistent id and minter the host gives the surface (its anchorPrim / anchorPrimFrom and the family its ids are minted from); minter 0 gives every sample minter 0. Default
{ primId: 1, primIdFrom: 0 }.
Returns
Ok with Points geometry, one point per sample, in face-family then candidate order: P and N (Float64 ×3), id and idFrom (Int32), seed (Uint32), anchorPrim / anchorPrimFrom (Int32), anchorCorners / anchorCornersFrom (Int32 ×3, the corners’ point ids), anchorBary (Float64 ×3), spacing (Float64), level (Uint8), parent (Int32, the id of the nearest coarser sample on the same face family, 0 for none), thinning (Uint32 holding a 16-bit value: the sample’s stratified place among its face family’s samples of its own level plus a per-family dither, modulo 1, times 2¹⁶; since 0.11.0), and the Detail attribute sampleCap. A mesh with no area gives an empty Points geometry.
Errors
Guarantees
- a smaller spacing or a larger count only adds samples: every sample of the sparser set is in the denser one at the same position, and with the same id when its minter is non-zero in both; a sample whose key’s first id collides, or is taken by the fallback of another sample, can be renumbered with minter 0 (SAMPLE_IDS_UNSTABLE)
- with an explicit spacing, and when the cap does not apply (no SAMPLE_COUNT_CAPPED, sampleCap = 1, before and after), an edit of one face adds or removes samples on that face only; when capped, d is rescaled globally, so samples can appear or disappear on any face, but none move
- the same input gives the same bytes (geometryContentHash), natively and in WASM
- ids are unique; idFrom is scopeIdBase(scope) or 0
- with poisson, two samples of one face family are at least 0.56 / sqrt(2^(levels−1)·d·w) apart, where d is the level-0 density used after any cap; the samples of level ≤ l are at least 0.56 / sqrt(2^l·d·w) apart
- the result has at most maxCount points
- The same result on every machine.
Example
const r = Samples.scatter(Mesh.box().value, { scope: 'scatter1', seed: 1, spacing: 0.1 })
r.ok || r.diagnostics[0].code // → about 100 points per face once loadGeometryKernel() has run