Skip to main content

Built-in Geometries

@luma.gl/engine exports several ready-made geometry classes. All of them extend Geometry and populate standard glTF mesh attribute semantics such as POSITION, NORMAL, and TEXCOORD_0.

The engine exports are compatibility adapters over the tessellators in @math.gl/geometry. They retain legacy size defaults, plane axis options, and cube face identifiers. New code can import primitives directly from @math.gl/geometry and pass them to Model; use explicit sizes and radii because math.gl defaults follow glTF shape conventions. GPU buffer layouts and interleaving remain engine responsibilities.

Overview​

ClassNotes
ConeGeometryCone with optional caps.
CubeGeometryUnit cube geometry.
CylinderGeometryCylinder built on top of TruncatedConeGeometry.
IcoSphereGeometryIcosahedron-based sphere approximation.
PlaneGeometryGrid plane in x,y, x,z, or y,z.
SphereGeometryLatitude/longitude sphere.
TruncatedConeGeometryGeneralized cone or frustum primitive.

Common Pattern​

import {SphereGeometry} from '@luma.gl/engine';

const geometry = new SphereGeometry({radius: 2});

Selected Constructor Props​

ConeGeometry​

  • radius?
  • cap?
  • Inherits radial, vertical, height, and axis options from TruncatedConeGeometry

CylinderGeometry​

  • radius?
  • Inherits cap, radial, vertical, height, and axis options from TruncatedConeGeometry

TruncatedConeGeometry​

  • topRadius?
  • bottomRadius?
  • topCap?
  • bottomCap?
  • height?
  • nradial?
  • nvertical?
  • verticalAxis?

PlaneGeometry​

  • type?
  • xlen?, ylen?, zlen?
  • nx?, ny?, nz?
  • offset?

SphereGeometry​

  • radius?
  • nlat?
  • nlong?

IcoSphereGeometry​

  • iterations?

Remarks​

  • These classes are convenience wrappers around typed-array geometry generation.
  • Most built-in primitives generate indexed geometry by default. CubeGeometry({indices: false}) and PlaneGeometry({unpack: true}) are non-indexed variants.
  • When uploaded through Model or makeGPUGeometry(), built-in primitives are interleaved into one vertex buffer plus an optional index buffer.

TorusGeometry​

TorusGeometry wraps the shared @math.gl/geometry tessellator with luma.gl's CPU Geometry container. It preserves indexed POSITION, NORMAL, and TEXCOORD_0 semantics and caller-provided attribute overrides.

import {TorusGeometry} from '@luma.gl/engine';

const geometry = new TorusGeometry({
majorRadius: 1,
minorRadius: 0.3,
majorSegments: 48,
minorSegments: 24,
arc: Math.PI * 1.5
});

The defaults above apply except that arc defaults to 2 * Math.PI. The ring lies around Y, starts at +X and sweeps toward −Z. Partial sweeps have open ends. Radii must be positive, the minor radius must be smaller than the major radius, and each segment count must be an integer of at least three.

RingGeometry​

RingGeometry constructs a closed annular prism or capped ring segment by assembling shared math.gl lathe/plane meshes. Props are innerRadius (0.5), outerRadius (1), height (0.2), segments (48), startAngle (0) and angle (2 * Math.PI). Zero inner radius creates a disk. Partial sweeps include both radial caps; cap/wall corners have hard normals. The source mesh retains indexed glTF attribute semantics and caller-provided attribute overrides.

Uploading geometry for GPUVectorModel​

makeGPUVectorGeometry(device, geometry) converts a CPU Geometry into a GPUVectorGeometry. It interleaves vertex attributes before upload and preserves attribute layouts, indices, topology, and draw count. Pass the result to new GPUVectorModel(device, {geometry: gpuGeometry, ...shaderProps}).

The returned geometry owns its uploaded buffers. Call gpuGeometry.destroy() after all models using it have been destroyed or switched to other geometry. GPUVectorModel borrows the geometry and does not destroy it. Geometry constructed with new GPUVectorGeometry(...) continues to borrow its input vectors.