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
Each instance's data, 4 floats, made by the first setDataAt: what a
Shader's snippets read as vec4 instanceData; edit it directly and call markDataDirty for the instances
changed
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 a run of instances' data changed, for code that writes dataValues directly; setDataAt calls this
start numberFirst instance
end number optionalOne past the last
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
Give an instance four numbers of the game's own, which a Shader's snippets read as vec4 instanceData, in the
vertex code and the fragment code, the shadow map too, like a tile's height or a sprite's foot line; an
instance not given any reads zeros, and so does every draw that is not of a set with data
i numberx number optional, default 0y number optional, default 0z number optional, default 0w number optional, default 0
Place an instance, in world space
i numbermatrix Matrix4