Capítulo 4 de 859

Chapter 4: InstancedMesh

Core Idea

A special version of a mesh with instanced rendering support. Use this class if you have to render a large number of objects with the same geometry and material(s) 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.

Key Concepts

  • boundingBox : Box3: The bounding box of the instanced mesh. Can be computed via InstancedMesh#computeBoundingBox.
  • boundingSphere : Sphere: The bounding sphere of the instanced mesh. Can be computed via [InstancedMesh#computeBoundingSphere](InstancedMesh.html#computeBoundingSphe…
  • count : number: The number of instances.
  • instanceColor : InstancedBufferAttribute: Represents the color of all instances. You have to set its BufferAttribute#needsUpdate flag to true if …
  • instanceMatrix : InstancedBufferAttribute: Represents the local transformation of all instances. You have to set its BufferAttribute#needsUpdate f…
  • isInstancedMesh : boolean (readonly): This flag can be used for type testing.
  • morphTexture : DataTexture: Represents the morph target weights of all instances. You have to set its Texture#needsUpdate flag to true if y…

Reference Tables

Constructor

Signature
`new InstancedMesh( geometry : BufferGeometry, material : Material

Properties

PropertyDescription
.boundingBox : Box3The bounding box of the instanced mesh. Can be computed via InstancedMesh#computeBoundingBox.
.boundingSphere : SphereThe bounding sphere of the instanced mesh. Can be computed via InstancedMesh#computeBoundingSphere.
.count : numberThe number of instances.
.instanceColor : InstancedBufferAttributeRepresents the color of all instances. You have to set its BufferAttribute#needsUpdate flag to true if you modify instanced data via [InstancedMesh#setColorAt](Ins…
.instanceMatrix : InstancedBufferAttributeRepresents the local transformation of all instances. You have to set its BufferAttribute#needsUpdate flag to true if you modify instanced data via [InstancedMesh#…
.isInstancedMesh : boolean (readonly)This flag can be used for type testing.
.morphTexture : DataTextureRepresents the morph target weights of all instances. You have to set its Texture#needsUpdate flag to true if you modify instanced data via [InstancedMesh#setMorphAt](Inst…

Methods

MethodDescription
.computeBoundingBox()Computes the bounding box of the instanced mesh, and updates InstancedMesh#boundingBox. The bounding box is not automatically computed by the engine; this method mus…
.computeBoundingSphere()Computes the bounding sphere of the instanced mesh, and updates InstancedMesh#boundingSphere The engine automatically computes the bounding sphere when it is need…
.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 : number, color : Color ) : ColorGets the color of the defined instance.
.getMatrixAt( index : number, matrix : Matrix4 ) : Matrix4Gets the local transformation matrix of the defined instance.
.getMorphAt( index : number, object : Mesh )Gets the morph target weights of the defined instance.
.setColorAt( index : number, color : Color ) : InstancedMeshSets the given color to the defined instance. Make sure you set the needsUpdate flag of InstancedMesh#instanceColor to true after updating all the colors.
.setMatrixAt( index : number, matrix : Matrix4 ) : InstancedMeshSets the given local transformation matrix to the defined instance. Make sure you set the needsUpdate flag of InstancedMesh#instanceMatrix to true after updat…
.setMorphAt( index : number, object : Mesh ) : InstancedMeshSets the morph target weights to the defined instance. Make sure you set the needsUpdate flag of InstancedMesh#morphTexture to true after updating all the influ…

Key Takeaways

  1. InstancedMesh extends: EventDispatcher → Object3D → Mesh
  2. Most relevant properties: boundingBox, boundingSphere, count, instanceColor.
  3. Key methods: computeBoundingBox, computeBoundingSphere, dispose, getColorAt.

Connects To