geom-distribute
v1.0.0
Published
Distribute points on the faces of a triangle mesh: by count or density, random or Poisson disk, weighted by a per-vertex density, with stable per-face seeds and interpolated vertex attributes.
Maintainers
Readme
geom-distribute
Distribute points on the faces of a triangle mesh: by count or density, random or Poisson disk, weighted by a per-vertex density, with stable per-face seeds and interpolated vertex attributes.
Installation
npm install geom-distributeUsage
See the example and its source.
import { distribute } from "geom-distribute";
import { sphere } from "primitive-geometry";
const geometry = sphere();
// 1000 points uniformly distributed by area
const points = distribute(geometry, { count: 1000, seed: 1 });
// => { positions, normals, uvs, faceIndices, barycentrics }
// 500 points per unit area, following the faces when the mesh deforms
const dense = distribute(geometry, { density: 500, maxCount: 10000 });
// Poisson disk: exactly 1000 well spaced points
const even = distribute(geometry, { count: 1000, method: "poisson" });
// Poisson disk: points at least 0.05 apart
const spaced = distribute(geometry, {
density: 2000,
method: "poisson",
distanceMin: 0.05,
});
// Per-vertex density: more points towards the top
const weights = geometry.positions
.filter((_, i) => i % 3 === 1)
.map((y) => y + 0.5);
const weighted = distribute(geometry, { count: 1000, weights });
// Only positions and normals
const light = distribute(geometry, { attributes: ["normals"] });API
Modules
Typedefs
geomDistribute
geomDistribute.distribute(geometry, [options]) ⇒ PointGeometry
Distribute points on the faces of a triangle mesh, uniformly by area or weighted by a per-vertex density.
Kind: static method of geomDistribute
| Param | Type | Default | | --------- | ---------------------------------------------------- | --------------- | | geometry | SimplicialComplex | | | [options] | DistributeOptions | {} |
SimplicialComplex : object
Triangle cells over shared positions. Any other Float32Array or number[] property whose length is a multiple of the vertex count is a per-vertex attribute (normals, uvs, vertexColors...), its stride being that multiple.
Kind: global typedef Properties
| Name | Type | Description | | --------- | ----------------------------------------------------- | ----------------------------- | | positions | Float32Array | | | cells | module:primitive-geometry~TypedArrayLike | Flat triangle vertex indices. |
PointGeometry : object
Distributed points and their per-vertex attributes interpolated from the source geometry.
Kind: global typedef Properties
| Name | Type | Description | | ------------ | ------------------------- | ----------------------------------------------- | | positions | Float32Array | | | faceIndices | Uint32Array | Source face of each point. | | barycentrics | Float32Array | Weights of the source face vertices (stride 3). |
DistributeOptions : object
Kind: global typedef Properties
| Name | Type | Default | Description |
| -------------- | ------------------------------------------------------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| [count] | module:primitive-geometry~NonNegativeInteger | 1000 | Number of points. |
| [density] | number | | Points per unit area, finite and >= 0. Overrides count. Points stay on their face when the mesh deforms. |
| [maxCount] | number | Infinity | Upper bound on the number of points in density mode, lowering the density when reached. |
| [method] | "random" | "poisson" | "random" | Poisson disk distributions space points evenly: exactly count points, or points at least distanceMin apart in density mode. |
| [oversampling] | module:primitive-geometry~PositiveInteger | 5 | Candidates per point in Poisson count mode: more is evener but slower. |
| [distanceMin] | number | 0 | Minimum distance between points in Poisson density mode, where weights are 1. |
| [weights] | Float32Array | Array.<number> | | Per-vertex density factors, one per vertex: relative in count mode, multiplying density otherwise. Poisson spacing scales with 1 / sqrt(weight). |
| [seed] | number | string | 0 | |
| [attributes] | Array.<string> | | Per-vertex attributes to interpolate. Defaults to all of them. |
| [normalize] | boolean | Array.<string> | true | Attributes renormalized after interpolation, true for normals, tangents and binormals. Only their first three components are normalized. |
License
MIT. See license file.

