Create a set of instances of a mesh, each at the origin in the object's color until it is set
mesh Meshcount numberHow many instances there is room for, all of them draw until count is lowered
tileInfo TileInfo|TextureInfo optionalTexture for all of them
color Color optionalThe color they start with
const forest = new InstancedMesh3D(treeMesh, 1000);
for (let i = 0; i < 1000; ++i)
forest.setTransformAt(i, randomGroundPos(), vec3(0, rand(2*PI), 0));
Each instance's color and uv rect, 8 floats, uploaded only when they change; edit
it directly and call markColorDirty for the instances changed
One past the last instance whose color uploads
First instance whose color uploads before the next draw
How many instances draw, the first ones, up to the count it was made with
One past the last instance whose matrix uploads, nothing when it is not past dirtyStart
First instance whose matrix uploads before the next draw
Each instance's matrix, 16 floats, what moving them uploads; edit it directly and
call markDirty for the instances changed
How many instances it was made with
Radius of the sphere around the origin that holds every instance set so far, for culling: the farthest
instance, and the mesh's size at the largest scale; it only grows, and takes in the instances set since it
was last read, so with frustum culling off it is never worked out. Set it to fix the sphere, which a big set
that is culled can use to skip that work, and set it to undefined to go back to the bounds
Destroy the set and free its GPU buffer
immediate boolean optional
The matrix of an instance
i number
Note that an instance's color changed, so it uploads before the next draw; setColorAt calls this, and so must
an edit made straight to colorData
i number
Note that an instance's matrix changed, so it uploads before the next draw and the bounds take it in when
they are read; setTransformAt and setMatrixAt call this, and so must an edit made straight to matrixData
i number
Note that a run of instances' matrices changed, for code that writes matrixData directly, the lowest level
way to move many: they upload before the next draw and the bounds take them in when they are read
start numberFirst instance
end numberOne past the last
Draws every instance as one call, uploading the ones that changed first
Place an instance, in world space
i numbermatrix Matrix4