Mesh

InstancedMesh

A special version of Mesh with instanced rendering support. Use InstancedMesh if you have to render a large number of objects with the same geometry and material but with different world transformations. The usage of InstancedMesh will help you to reduce the number of draw calls and thus improve the overall rendering performance in your application.

Constructor

InstancedMesh(geometry : BufferGeometry, material : Material, count : Integer)

Properties

See the base Mesh class for common properties.

.count : Integer

The number of instances. The count value passed into the constructor represents the maximum number of instances of this mesh. You can change the number of instances at runtime to an integer value in the range [0, count].

If you need more instances than the original count value, you have to create a new InstancedMesh.

.instanceColor : InstancedBufferAttribute

Represents the colors of all instances. null by default. You have to set its needsUpdate flag to true if you modify instanced data via .setColorAt().

.instanceMatrix : InstancedBufferAttribute

Represents the local transformation of all instances. You have to set its needsUpdate flag to true if you modify instanced data via .setMatrixAt().

.isInstancedMesh : Boolean

Read-only flag to check if a given object is of type InstancedMesh.

Methods

See the base Mesh class for common methods.

.dispose()

Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.

.getColorAt(index : Integer, color : Color)

Get the color of the defined instance.

.getMatrixAt(index : Integer, matrix : Matrix4)

Get the local transformation matrix of the defined instance.

.setColorAt(index : Integer, color : Color)

Sets the given color to the defined instance. Make sure you set .instanceColor.needsUpdate to true after updating all the colors.

.setMatrixAt(index : Integer, matrix : Matrix4)

Sets the given local transformation matrix to the defined instance. Make sure you set .instanceMatrix.needsUpdate to true after updating all the matrices.

Puzzles

Use the following puzzle to create instanced meshes without coding: create instances.

Source

For more info on how to obtain the source code of this module see this page.