Skip to content

WasmGPU.createSelectionStore().values

Summary

WasmGPU.createSelectionStore().values returns a snapshot array of current selection entries. Each entry includes hit metadata plus a stable key string (objectId:elementIndex).

Syntax

WasmGPU.createSelectionStore().values(): SelectionEntry[]
const entries = selection.values();

Parameters

This API does not take parameters.

Returns

SelectionEntry[] - Array copy of all selected entries at call time.

Type Details

type SelectionEntry = {
    key: string; // "<objectId>:<elementIndex>"
    kind: "mesh" | "pointcloud" | "glyphfield";
    object: Mesh | PointCloud | GlyphField;
    objectId: number;
    elementIndex: number;
    worldPosition: [number, number, number];
    ndIndex: number[] | null;
    attributes: PickAttributes | null;
};

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const scene = wgpu.createScene();
const camera = wgpu.createCamera.perspective({ fov: 60, aspect: canvas.clientWidth / canvas.clientHeight, near: 0.1, far: 1000 });
const selection = wgpu.createSelectionStore();

const region = await wgpu.pickRect(scene, camera, 40, 40, 220, 180, { maxHits: 1000 });
selection.replace(region.hits);
for (const entry of selection.values()) {
    console.log(entry.key, entry.kind, entry.worldPosition);
}

See Also