Skip to main content

@math.gl/geometry/processing

From v4.2

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โ€‹

FeatureSupportNotes
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]]);