BufferPolygonCollection

Collection of polygons held in ArrayBuffer storage for performance and memory optimization.

Default buffer memory allocation is arbitrary, and collections cannot be resized, so specific per-buffer capacities should be provided in the collection constructor when available.

import earcut from "earcut";

const collection = new BufferPolygonCollection({
primitiveCountMax: 1024,
vertexCountMax: 4096,
holeCountMax: 1024,
triangleCountMax: 2048,
});

const polygon = new BufferPolygon();
const positions = [ ... ];
const holes = [ ... ];
const material = new BufferPolygonMaterial({color: Color.WHITE});

// Create a new polygon, temporarily bound to 'polygon' local variable.
collection.add({
positions: new Float64Array(positions),
holes: new Uint32Array(holes),
triangles: new Uint32Array(earcut(positions, holes, 3)),
material
}, polygon);

// Iterate over all polygons in collection, temporarily binding 'polygon'
// local variable to each, and updating polygon material.
for (let i = 0; i < collection.primitiveCount; i++) {
collection.get(i, polygon);
polygon.setMaterial(material);
}

See also

Constructors

Link copied to clipboard

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Properties

Link copied to clipboard

Total byte length of buffers owned by this collection. Includes any unused space allocated by primitiveCountMax, even if no polygons have yet been added in that space.

Link copied to clipboard

Number of holes in collection. Must be <= holeCountMax.

Link copied to clipboard

Maximum number of holes in collection. Must be >= holeCount.

Link copied to clipboard

Number of triangles in collection. Must be <= triangleCountMax.

Link copied to clipboard

Maximum number of triangles in collection. Must be >= triangleCount.

Functions

Link copied to clipboard

Adds a new polygon to the collection, with the specified options. A BufferPolygon instance is linked to the new polygon, using the 'result' argument if given, or a new instance if not. For repeated calls, prefer to reuse a single BufferPolygon instance rather than allocating a new instance on each call.