fromCollection

fun <T : BufferPrimitive> fromCollection(collection: BufferPrimitiveCollection<T>, options: BufferPrimitiveCollectionOptions? = definedExternally, predicate: Function<*>? = definedExternally): BufferPrimitiveCollection<T>(source)

Returns a copy of the given collection, overriding any constructor options provided. Omitted options are inherited from the source collection. Any resized buffers must be large enough to hold every primitive.

Collection-level state (model matrix, blend option, picking, bounding-volume mode, etc.) is carried over, but GPU resources are not: the source collection retains ownership of its renderer resources, so the caller is responsible for calling BufferPrimitiveCollection.destroy on the source once it is no longer needed.

const grown = BufferPrimitiveCollection.fromCollection(collection, {
primitiveCountMax: collection.primitiveCountMax * 2,
vertexCountMax: collection.vertexCountMax * 2,
});
collection.destroy(); // release the source collection's GPU resources
// Grow while dropping hidden primitives.
const compacted = BufferPrimitiveCollection.fromCollection(
collection,
{ primitiveCountMax: collection.primitiveCountMax * 2 },
(primitive) => primitive.show,
);

Parameters

collection

Source collection to copy.

options

Constructor options to override. Omitted options are inherited from the source collection.

predicate

When provided, only primitives for which this returns true are copied. Surviving primitives are compacted into contiguous indices.

See also