Class: GPUPicker
Defined in: src/utils/GPUPicker.ts:214
GPU-based picking for fast, accurate vertex selection on large meshes.
Uses render-to-texture to encode vertex indices into colors, then reads the pixel under the mouse to determine the exact picked vertex.
Benefits over raycasting:
- O(1) picking time regardless of mesh size
- Exact vertex index (no face-to-vertex approximation needed)
- Works correctly with complex shaders and deformations
Example
const picker = new GPUPicker(renderer);
// Register surfaces
picker.addSurface('brain', brainMesh);
// Pick at mouse position
const result = picker.pick(mouseX, mouseY, camera);
if (result.vertexIndex !== null) {
console.log(`Picked vertex ${result.vertexIndex} on ${result.surfaceId}`);
}Constructors
Constructor
new GPUPicker(renderer): GPUPicker;Defined in: src/utils/GPUPicker.ts:236
Parameters
renderer
WebGLRenderer
Returns
GPUPicker
Methods
addSurface()
addSurface(id, mesh): void;Defined in: src/utils/GPUPicker.ts:267
Add a surface mesh to the picker. Creates a pick mesh with vertex ID attributes.
Parameters
id
string
mesh
Mesh
Returns
void
removeSurface()
removeSurface(id): boolean;Defined in: src/utils/GPUPicker.ts:302
Remove a surface from the picker.
Parameters
id
string
Returns
boolean
syncTransforms()
syncTransforms(): void;Defined in: src/utils/GPUPicker.ts:318
Update pick meshes to match their original mesh transforms. Call this before picking if meshes have moved.
Returns
void
setEnabled()
setEnabled(enabled): void;Defined in: src/utils/GPUPicker.ts:330
Enable or disable GPU picking.
Parameters
enabled
boolean
Returns
void
isEnabled()
isEnabled(): boolean;Defined in: src/utils/GPUPicker.ts:337
Check if GPU picking is enabled.
Returns
boolean
setThrottleMs()
setThrottleMs(ms): void;Defined in: src/utils/GPUPicker.ts:344
Set the minimum time between pick operations (for throttling).
Parameters
ms
number
Returns
void
pick()
pick(
cssX,
cssY,
camera,
rect?): GPUPickResult;Defined in: src/utils/GPUPicker.ts:357
Perform GPU picking at the given screen coordinates.
Parameters
cssX
number
X coordinate in CSS pixels (from event.clientX)
cssY
number
Y coordinate in CSS pixels (from event.clientY)
camera
Camera
The camera to pick from
rect?
DOMRect
Optional bounding rect of the canvas (auto-detected if not provided)
Returns
GPUPickResult
Pick result with surface ID, vertex index, and world position
pickNDC()
pickNDC(
ndcX,
ndcY,
camera): GPUPickResult;Defined in: src/utils/GPUPicker.ts:475
Pick using normalized device coordinates (-1 to 1).
Parameters
ndcX
number
ndcY
number
camera
Camera
Returns
GPUPickResult
isSupported()
static isSupported(renderer): boolean;Defined in: src/utils/GPUPicker.ts:501
Check if the renderer supports GPU picking.
Parameters
renderer
WebGLRenderer
Returns
boolean
dispose()
dispose(): void;Defined in: src/utils/GPUPicker.ts:509
Dispose of all resources.
Returns
void