Scene.traverseVisible¶
Summary¶
Scene.traverseVisible iterates only over meshes with visible === true. This avoids manual filtering when applying per-frame logic to rendered meshes only. Traversal order is insertion order within the mesh list.
Syntax¶
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
callback |
(mesh: Mesh) => void |
Yes | Function executed once per visible mesh. |
Returns¶
void - No value is returned.
Type Details¶
Example¶
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const scene = wgpu.createScene();
const a = wgpu.createMesh(wgpu.geometry.box(1, 1, 1), wgpu.material.unlit({ color: [0.9, 0.3, 0.2] }));
const b = wgpu.createMesh(wgpu.geometry.box(1, 1, 1), wgpu.material.unlit({ color: [0.2, 0.8, 1.0] }));
b.visible = false;
scene.add(a).add(b);
scene.traverseVisible((mesh) => mesh.transform.translate(0.02, 0, 0));