Uint16Array below 65536 vertices, Uint32Array at or above. Not a micro-
optimization: WebGL1-era OES_element_index_uint aside, the real reason is that
three sets geometry.index.array verbatim, and a Uint32Array index forces the
32-bit path for every draw. Meshes in this domain are usually well under 65k
vertices per node.
That rationale only holds on the WebGL backends: the WebGPU backend widens a
narrow index attribute to Uint32Array in place at first upload, so the narrow
choice buys nothing there — see applyMeshIndices for the detail. It is
still the right allocation, because WebGL never gets that widening for free.
The threshold is on vertexCount, not on the max index present: vertexCount is
fixed for the node, whereas the largest index actually drawn changes with the slice.
Keying off the observed maximum would let the dtype differ between epochs, which
would defeat the buffer reuse in applyMeshIndices — a dtype flip forces a
fresh setIndex call, orphaning the old attribute's GPU buffer, which is exactly
the leak applyMeshIndices exists to avoid.
Choose the index-buffer dtype.
Uint16Arraybelow 65536 vertices,Uint32Arrayat or above. Not a micro- optimization: WebGL1-eraOES_element_index_uintaside, the real reason is that three setsgeometry.index.arrayverbatim, and aUint32Arrayindex forces the 32-bit path for every draw. Meshes in this domain are usually well under 65k vertices per node.That rationale only holds on the WebGL backends: the WebGPU backend widens a narrow index attribute to Uint32Array in place at first upload, so the narrow choice buys nothing there — see applyMeshIndices for the detail. It is still the right allocation, because WebGL never gets that widening for free.
The threshold is on
vertexCount, not on the max index present:vertexCountis fixed for the node, whereas the largest index actually drawn changes with the slice. Keying off the observed maximum would let the dtype differ between epochs, which would defeat the buffer reuse in applyMeshIndices — a dtype flip forces a freshsetIndexcall, orphaning the old attribute's GPU buffer, which is exactly the leak applyMeshIndices exists to avoid.