instancedMesh
Creates a direct reference in TSL to a `THREE.InstancedMesh` object from JavaScript to easily access its built-in instance transform matrix (`instanceMatrix`) and color (`instanceColor`).
Core Advantages
It completely abstracts Three.js's internal implementation (like the naming of 'instanceMatrix'), providing a type-safe, semantically clear interface that greatly improves code readability, robustness, and maintainability.
Common Uses
Physics engine-driven simulations (real-time instance matrix updates)
Large-scale static scene rendering (e.g., forests, building complexes)
Dynamically modifying the color of individual instances (via `setColorAt`)
Data visualization (mapping data to instance poses)
How to adjust
Adjustments are made entirely by manipulating the passed-in InstancedMesh object in JavaScript. By calling `myMesh.setMatrixAt(index, matrix)` or `myMesh.setColorAt(index, color)`, and then setting `myMesh.instanceMatrix.needsUpdate = true`, you can change the position, rotation, scale, or color of an individual instance in real-time.
Code Examples
1// Apply the unique transform matrix of the instance in the vertex shader
2const finalModelView = modelViewMatrix.mul( instancedMesh( myMesh ).instanceMatrix );
3
4// Get the unique color of the instance in the fragment shader
5const instanceColor = instancedMesh( myMesh ).color;