Buffer capacity
The capacity is the maximum number of
instances the internal buffers can hold.
It defaults to 1000 and grows automatically when needed, so it doesn’t have to be exact.
const iMesh = new InstancedMesh2(geo, mat, { capacity: 10000 });Automatic Growth
When the requested number of instances exceeds the current capacity, the buffers are resized to:
newCapacity = capacity + (capacity >> 1) + 512That is about 1.5x the current capacity plus 512, and the calculation is repeated until the new capacity is large enough.
This is the same geometric growth strategy used by JavaScript arrays in V8: adding instances one by one is amortized O(1),
and resizes become rarer as the mesh grows.
Resize Buffers
Buffers can also be resized manually, for example to reduce the capacity and free memory after many instances have been removed:
iMesh.resizeBuffers(1000);