Constructor
new InstancedMesh3D(mesh, count, tileInfoopt, coloropt)
Create a set of instances of a mesh, each at the origin in the object's color until it is set
| Name | Type | Attributes | Description |
|---|---|---|---|
mesh | Mesh | ||
count | number | How many instances there is room for, all of them draw until count is lowered | |
tileInfo | TileInfo | | <optional> | Texture for all of them |
color | Color | <optional> | The color they start with |
- Source
const forest = new InstancedMesh3D(treeMesh, 1000);
for (let i = 0; i < 1000; ++i)
forest.setMatrixAt(i, buildMatrix(randomGroundPos(), vec3(0, rand(2*PI), 0)));Extends
- EngineObject3D
Members
count
Properties| Type | Description |
|---|---|
| number | How many instances draw, the first ones, up to the count it was made with |
- Source
dirtyEnd
Properties| Type | Description |
|---|---|
| number | One past the last instance to upload, so nothing uploads when it is not past dirtyStart |
- Source
dirtyStart
Properties| Type | Description |
|---|---|
| number | First instance to upload before the next draw |
- Source
instanceData
Properties| Type | Description |
|---|---|
| Float32Array | The per instance values the shader reads, 24 floats each: the matrix, the color and the uv rect; edit it directly and call markDirty for the instances changed |
- Source
maxCount
Properties| Type | Description |
|---|---|
| number | How many instances it was made with |
- Source
radius
Properties| Type | Description |
|---|---|
| number | Radius of the sphere around the origin that holds every instance set so far, for culling |
- Source
Methods
destroy(immediateopt)
Destroy the set and free its GPU buffer
| Name | Type | Attributes | Description |
|---|---|---|---|
immediate | boolean | <optional> |
- Source
getMatrixAt(i) → {Matrix4}
The matrix of an instance
| Name | Type | Description |
|---|---|---|
i | number |
- Source
- Type:
- Matrix4
markDirty(i)
Note that an instance changed, so it uploads before the next draw; setMatrixAt and setColorAt call this
| Name | Type | Description |
|---|---|---|
i | number |
- Source
render3D()
Draws every instance as one call, uploading the ones that changed first
- Source
setColorAt(i, color)
Color an instance
| Name | Type | Description |
|---|---|---|
i | number | |
color | Color |
- Source
setMatrixAt(i, matrix)
Place an instance, in world space
| Name | Type | Description |
|---|---|---|
i | number | |
matrix | Matrix4 |
- Source