indirectBatchId

@three-blocks/coreWebGPU
indirectBatchId(batchMesh : IndirectBatchedMesh) : Node<int>

Return the stable instance id for an {@link IndirectBatchedMesh}, honoring survivorIdSB when present.

Use this to access per-instance data in custom material nodes. When GPU culling is active, instanceIndex gives the draw index (0 to survivorCount), while indirectBatchId returns the original instance ID from before culling.

Example: Per-instance color variation

Parameters
The batched mesh instance.
Returns
Node<int> — Stable instance id after culling/sorting.
Example
import { IndirectBatchedMesh, indirectBatch, indirectBatchId } from '@three-blocks/core';
import { hash, mix, vec3 } from 'three/tsl';
import { MeshStandardNodeMaterial } from 'three/webgpu';

const material = new MeshStandardNodeMaterial();
const mesh = new IndirectBatchedMesh(1000, 10000, 30000, material);

// Get the stable instance ID (works with culling)
const instanceId = indirectBatchId(mesh);

// Use hash for per-instance random color
const randomHue = hash(instanceId);
material.colorNode = mix(vec3(1, 0, 0), vec3(0, 0, 1), randomHue);