Skip to content

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 ​

typescript
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 ​

ts
new GPUPicker(renderer): GPUPicker;

Defined in: utils/GPUPicker.ts:256

Parameters ​

renderer ​

WebGLRenderer

Returns ​

GPUPicker

Methods ​

addSurface() ​

ts
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() ​

ts
removeSurface(id): boolean;

Defined in: utils/GPUPicker.ts:323

Remove a surface from the picker.

Parameters ​

id ​

string

Returns ​

boolean


syncTransforms() ​

ts
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() ​

ts
setEnabled(enabled): void;

Defined in: utils/GPUPicker.ts:356

Enable or disable GPU picking.

Parameters ​

enabled ​

boolean

Returns ​

void


isEnabled() ​

ts
isEnabled(): boolean;

Defined in: utils/GPUPicker.ts:363

Check if GPU picking is enabled.

Returns ​

boolean


setThrottleMs() ​

ts
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() ​

ts
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 ​

GPUPickResult

Pick result with surface ID, vertex index, and world position


pickNDC() ​

ts
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 ​

GPUPickResult


isSupported() ​

ts
static isSupported(renderer): boolean;

Defined in: utils/GPUPicker.ts:545

Check if the renderer supports GPU picking.

Parameters ​

renderer ​

WebGLRenderer

Returns ​

boolean


dispose() ​

ts
dispose(): void;

Defined in: utils/GPUPicker.ts:553

Dispose of all resources.

Returns ​

void

Released under the MIT License.