indirectBatchMatrix
indirectBatchMatrix(batchMesh : IndirectBatchedMesh, idNode : Node<int>) : Node<mat4>Fetch the batch matrix for a given instance id in an {@link IndirectBatchedMesh}.
Use this to access instance transforms in custom vertex shaders or for computing world-space positions in fragment shaders.
Example: Custom vertex animation with instance matrix
Parameters
The batched mesh instance.
idNodeoptionalNode<int>Instance id to sample.
Default is
Default is
instanceIndex.Returns
Node<mat4> — Batch transform matrix.Example
import { IndirectBatchedMesh, indirectBatch, indirectBatchId, indirectBatchMatrix } from '@three-blocks/core';
import { positionLocal, time, sin, vec3 } from 'three/tsl';
import { MeshStandardNodeMaterial } from 'three/webgpu';
const material = new MeshStandardNodeMaterial();
const mesh = new IndirectBatchedMesh(1000, 10000, 30000, material);
// Get instance ID and matrix
const instanceId = indirectBatchId(mesh);
const matrix = indirectBatchMatrix(mesh, instanceId);
// Extract position from matrix (column 3)
const instancePos = vec3(matrix[3].x, matrix[3].y, matrix[3].z);
// Add wave animation based on instance world position
const wave = sin(time.add(instancePos.x.mul(0.5))).mul(0.2);
material.positionNode = positionLocal.add(vec3(0, wave, 0));