Skip to content

Introduction

InstancedMesh2 is an enhanced alternative to InstancedMesh, offering improved performance and usability with features such as:

  • Per-instance frustum cullingSkips rendering for out-of-view instances.
  • SortingReduces overdraw and efficiently manages transparent objects.
  • Spatial indexing (dynamic BVH)Speeds up raycasting and frustum culling.
  • Dynamic capacitySeamlessly add or remove instances.
  • Per-instance visibility and opacityIndividually toggle visibility and set opacity.
  • Object3D-like instancesInstances behave like Object3D, supporting transforms and custom data.
  • Per-instance uniformsAssign unique shader data to individual instances.
  • Level of Detail (LOD)Dynamically adjust instance detail based on distance.
  • Shadow LODOptimize shadow rendering by reducing detail for distant instances.
  • SkinningApply skeletal animations for complex and dynamic movements.

Differences from InstancedMesh

InstancedMesh
  • Uses an InstancedBufferAttribute to store instance matrices and data.
  • Renders instances sequentially, meaning all instances are processed in the order they were added, without skipping or reordering. This can be inefficient when dealing with a large number of instances, especially if many are off-screen or require different sorting orders for transparency.
InstancedMesh2
  • Uses SquareDataTexture (an extended version of DataTexture supporting partial updates) to store instance matrices and data.
  • Uses an InstancedBufferAttribute to manage the indexes of instances to be rendered, allowing for selective rendering, efficient culling, and sorting before sending data to the GPU.