Class: GPUPicker
Defined in: utils/GPUPicker.ts:233
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: utils/GPUPicker.ts:256
Parameters
renderer
WebGLRenderer
Returns
GPUPicker
Methods
addSurface()
addSurface(id, mesh): void;Defined in: utils/GPUPicker.ts:287
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: utils/GPUPicker.ts:323
Remove a surface from the picker.
Parameters
id
string
Returns
boolean
syncTransforms()
syncTransforms(): void;Defined in: utils/GPUPicker.ts:340
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: utils/GPUPicker.ts:356
Enable or disable GPU picking.
Parameters
enabled
boolean
Returns
void
isEnabled()
isEnabled(): boolean;Defined in: utils/GPUPicker.ts:363
Check if GPU picking is enabled.
Returns
boolean
setThrottleMs()
setThrottleMs(ms): void;Defined in: utils/GPUPicker.ts:371
Set the minimum time between rendered picks for throttled picks (pick(..., { throttle: true })). Unthrottled picks ignore it.
Parameters
ms
number
Returns
void
pick()
pick(
cssX,
cssY,
camera,
rect?,
options?
): GPUPickResult;Defined in: utils/GPUPicker.ts:385
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)
options?
GPUPickOptions = {}
Pick options; see GPUPickOptions.throttle
Returns
Pick result with surface ID, vertex index, and world position
pickNDC()
pickNDC(
ndcX,
ndcY,
camera,
options?
): GPUPickResult;Defined in: utils/GPUPicker.ts:518
Pick using normalized device coordinates (-1 to 1).
Parameters
ndcX
number
ndcY
number
camera
Camera
options?
GPUPickOptions = {}
Returns
isSupported()
static isSupported(renderer): boolean;Defined in: utils/GPUPicker.ts:545
Check if the renderer supports GPU picking.
Parameters
renderer
WebGLRenderer
Returns
boolean
dispose()
dispose(): void;Defined in: utils/GPUPicker.ts:553
Dispose of all resources.
Returns
void