Skip to main content

@math.gl/geometry

From v4.2

Loading SphereGeometryโ€ฆ

The @math.gl/geometry module provides renderer-independent CPU mesh data and primitive tessellators. Built-in box, capsule, cylinder, plane and sphere dimensions follow the glTF 2.1 draft shape proposal. Cube, cone, truncated-cone and icosphere convenience classes are adapted from the corresponding luma.gl primitives.

All generated meshes use triangle-list topology and expose POSITION, NORMAL and TEXCOORD_0 typed-array attributes. Index buffers automatically use 32-bit values when a mesh has more than 65,535 vertices.

Entry pointsโ€‹

Import pathUse it to
@math.gl/geometry/primitivesGenerate primitive and parametric meshes.
@math.gl/geometry/curvesRepresent and sample curves.
@math.gl/geometry/polygonClip, triangulate, and subdivide polygons and polylines.
@math.gl/geometry/cullingQuery analytic shapes, bounding volumes, and rays.
@math.gl/geometry/processingProcess meshes, indices, and attributes.
@math.gl/geometry/spatial-indexIndex points, boxes, and triangles.
@math.gl/geometry/arrowTessellate GeoArrow polygons.
@math.gl/geometry/lightingSample photometric profiles.

Usageโ€‹

import {SphereGeometry} from '@math.gl/geometry/primitives';

const geometry = new SphereGeometry({radius: 1});
const positions = geometry.attributes.POSITION.value;
const indices = geometry.indices?.value;

Pass these CPU buffers to the renderer of your choice. The module does not create GPU resources.

Featuresโ€‹

FeatureSupportNotes
Primitive mesh tessellationโœ…Boxes, capsules, cylinders, planes, spheres and convenience shapes produce renderer-independent indexed buffers.
Parametric surfaces, lathes and toriโœ…ParametricGeometry, TorusGeometry and LatheGeometry sample explicit surface functions.
Normals, UVs and index-width selectionโœ…Primitive POSITION/NORMAL/TEXCOORD_0 attributes and automatic Uint32 promotion for large meshes.
Projected boundsโœ…Sample edges and interiors with an explicit approximate/conservative qualification.
Projected texture coordinatesโœ…Prepare image UVs from packed CPU positions without a rendering dependency.
Mesh processingโœ…Transform, merge, and weld indexed meshes.
Curve evaluationโœ…Sample Cartesian curves and compute transport frames.
Rigid articulated panel forestsโœ…Experimental HingeTree evaluates hinge transforms with reusable matrix output.
Analytic queriesโœ…Bounding volumes, rays, and shapes for Euclidean containment and intersection.
Polygon processingโœ…Clip, triangulate, and subdivide polygons.
Spatial indexingโœ…BoxIndex, PointIndex, and TriangleBVH accelerate repeated queries.
General solid modeling and manifold repairโŒNo public 3D Boolean solid, arbitrary remeshing, or general manifold-repair engine.
Deformable or constrained rigid-body simulationโŒHingeTree has no closed-loop constraints, collisions, forces, or bending solver.
Photometry and color LUTsโœ…Optional lighting and color utilities sample angular intensity, integrate luminous flux and transform RGB/RGBA buffers.
GPU resource allocation and renderingโŒThe module supplies CPU data; GPU buffers, materials, draw calls, and device lifetime belong to rendering libraries.

Installationโ€‹

npm install @math.gl/geometry

APIโ€‹

  • Geometry stores CPU attributes, optional indices, topology and draw count.
  • unpackIndexedGeometry() expands an indexed mesh into non-indexed attributes.
  • BoxGeometry, CapsuleGeometry, CylinderGeometry, PlaneGeometry, SphereGeometry implement the glTF shape conventions.
  • CubeGeometry, ConeGeometry, TruncatedConeGeometry, IcoSphereGeometry provide additional common tessellators.
  • PrismGeometry provides closed flat-sided polygons, including hexagonal prisms; RingGeometry provides solid annuli and capped ring segments.

An infinite glTF plane cannot be tessellated, so PlaneGeometry requires finite sizeX and sizeZ values. Use PlaneShape from @math.gl/geometry/culling when infinite or partially infinite analytic planes are required.

Primitive referenceโ€‹

Parametric surfacesโ€‹

ParametricGeometry, TorusGeometry, and LatheGeometry provide sampled surface generators from @math.gl/geometry/primitives, with an interactive gallery.

The experimental HingeTree evaluates rigid panels connected by hinges. See the HingeTree API and unfolding polyhedra example.