@math.gl/geometry/processing
Loading Geometry processing workshopโฆ
Utilities for processing renderer-independent geometry stored in typed arrays. The module is designed for loaders and applications that need to inspect, normalize, or decode geometry without depending on a WebGL or WebGPU runtime.
Usageโ
import {computeVertexNormals, octDecode} from '@math.gl/geometry/processing';
import {Vector3} from '@math.gl/core/matrix';
const normals = computeVertexNormals({
topology: 'triangle-list',
attributes: {
POSITION: {value: new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0]), size: 3}
}
});
const decodedNormal = octDecode(128, 128, new Vector3());
Featuresโ
| Feature | Support | Notes |
|---|---|---|
| Attribute and primitive traversal | โ | Geometry utilities inspect layouts and iterate attributes/primitives. |
| Vertex normals | โ | CPU normal generation for the documented primitive modes. |
| Transform, merge and weld meshes | โ | Mesh processing preserves explicit attribute and index contracts. |
| Degenerate-triangle inspection | โ | Inspection reports degenerate triangles; callers choose how to handle the result. |
| Projected bounds | โ | Sample nonlinear boxes; conservative inflation requires a qualified global Lipschitz contract. |
| Projected texture coordinates | โ | Generate float64 UVs with a prepared source-to-image transform and explicit image bounds. |
| Packed attribute interpolation | โ | Mixed linear/flat interpolation policies consume subdivision provenance without per-vertex object unpacking. |
| Compact attribute encodings | โ | RGB565, octahedral normals, texture-coordinate compression and ZigZag delta decoding. |
| Automatic topology repair or Boolean modeling | โ | Welding and degeneracy inspection do not provide a manifold-repair or solid Boolean engine. |
| General mesh simplification and UV unwrapping | โ | No public quadric-error simplifier, arbitrary UV atlas generator, or tangent-space generation pipeline. |
Installationโ
npm install @math.gl/geometry
Mesh processingโ
Transform, merge, weld and inspect triangle meshes. The inline workshop combines these operations on two sphere meshes. Expand the infobox to stretch or reflect a mesh, compare vertex counts, and inspect wireframe topology.
Interpolate interleaved attributes from polygon subdivision provenance without unpacking every vertex into JavaScript objects. Declare linear and flat policies explicitly, including mixed policies within one attribute.
APIโ
- Geometry inspection and traversal:
isGeometry,makeAttributeIterator,makePrimitiveIterator,computeVertexNormals - Typed arrays:
concatTypedArrays - Packed attributes:
interpolatePackedAttributes,encodeRGB565,decodeRGB565, octahedral vector encoding, texture-coordinate compression, and ZigZag delta decoding - Coordinate helpers:
emod
The initial API is based on the geometry utilities previously maintained in @loaders.gl/math.
Planar Delaunay triangulationโ
triangulateDelaunay(points) returns triples of indices into an array of finite XY coordinate
pairs. It uses the first index for coincident points and returns an empty array for collinear
inputs and inputs with fewer than three distinct points. Triangle order and the diagonal chosen
for cocircular points are unspecified. Supply coordinates in the plane where distances should
be measured.
import {triangulateDelaunay} from '@math.gl/geometry/processing';
const triangles = triangulateDelaunay([[0, 0], [3, 0], [0, 4], [1, 1]]);