Skip to main content

Geometry

Geometry is the CPU-side geometry container used by engine classes. It stores typed-array attributes, optional indices, and a bufferLayout. When a layout is not supplied, Geometry creates a one-buffer-per-attribute layout automatically. Use makeInterleavedGeometry() to pack multiple CPU attributes into one vertex buffer while still representing the result as a normal Geometry.

Usage

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

const geometry = new Geometry({
topology: 'triangle-list',
attributes: {
POSITION: {size: 3, value: new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0])}
}
});

Types

GeometryProps

export type GeometryProps = {
id?: string;
topology: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
vertexCount?: number;
attributes: Record<string, GeometryAttributeInput>;
bufferLayout?: BufferLayout[];
indices?: GeometryAttribute | TypedArray;
};

GeometryAttributeInput

export type GeometryAttributeInput = GeometryAttribute | TypedArray;

GeometryAttribute

export type GeometryAttribute = {
size?: number;
value: TypedArray;
[key: string]: any;
};

Properties

id

Application-provided identifier.

topology

Primitive topology used by consumers of the geometry.

vertexCount

Explicit or auto-calculated vertex count.

indices

Optional index attribute.

attributes

Named geometry attributes. The constructed Geometry stores normalized names: POSITION becomes positions, NORMAL becomes normals, TEXCOORD_0 becomes texCoords, TEXCOORD_1 becomes texCoords1, and COLOR_0 becomes colors.

For non-interleaved geometry, each attribute key normally names one typed-array attribute. For interleaved geometry, the attribute key names the packed buffer, and bufferLayout maps that buffer back to shader attributes.

bufferLayout

The buffer layout for the geometry attributes. It is always populated on constructed Geometry instances. If omitted, the constructor creates one layout entry for each normalized attribute. Explicit bufferLayout entries are normalized with the same semantic-name rules used for attributes.

userData

Application-owned metadata.

Methods

constructor(props: GeometryProps)

Creates a geometry object and normalizes raw typed arrays into GeometryAttribute records.

getVertexCount(): number

Returns the resolved vertex count.

getAttributes(): GeometryAttributes

Returns the geometry attributes, including indices when present.

makeInterleavedGeometry(geometry, options?): Geometry

Packs non-index geometry attributes into one typed-array-backed buffer and returns a normal Geometry. The returned geometry has one attribute, named geometry by default, and a multi-attribute bufferLayout.

import {Geometry, makeInterleavedGeometry} from '@luma.gl/engine';

const geometry = new Geometry({
topology: 'triangle-list',
attributes: {
POSITION: {size: 3, value: new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0])},
TEXCOORD_0: {size: 2, value: new Float32Array([0, 0, 1, 0, 0, 1])}
}
});

const interleavedGeometry = makeInterleavedGeometry(geometry);

interleavedGeometry.attributes.geometry; // packed Uint8Array
interleavedGeometry.bufferLayout; // maps positions and texCoords into the packed buffer

Calling makeInterleavedGeometry() on an already interleaved geometry with the same buffer name is idempotent and returns the original instance.

Remarks

  • POSITION or positions defaults to size: 3 when the size is omitted.
  • bufferLayout is synthesized when omitted.
  • makeGPUGeometry() interleaves CPU Geometry before uploading it to GPU buffers.
  • Use GPUGeometry when geometry data is already uploaded into GPU buffers.