Unified picking surface that routes between the CPU-side BVH
picker and the GPU pick path, surfacing snap-to-vertex and
snap-to-edge as part of the same call.
Picking is two distinct problems wearing one hat. The
BVH picker is fast, ray- or matrix-driven, and supports caller
filter callbacks but cannot snap. The GPU picker only accepts a
canvas position but produces world normals, UVs, and snap targets
via a gl.readPixels stall. Most callers want the cheap path most
of the time and the snap enrichment when they ask for it.
The picking module wraps both behind a single
PickStrategy interface, with RoutingPickStrategy
choosing the right backend per call. Snap requests degrade
silently to BVH when the GPU isn't available (no renderer
attached, context lost, etc.).
Common interface — every picker implements PickStrategy
so callers don't branch on backend. Same pick(params) call;
strategies decide what to do with canvasPos / origin+dir /
matrix inputs.
BVHPickStrategy — CPU-side, drives the
collision!SceneCollisionIndex | SceneCollisionIndex.
Accepts ray, matrix, or canvasPos (turned into a ray via the
View's camera). No GPU stall; no snap.
RendererPickStrategy — GPU-side, drives the
WebGLRenderer. Only
canvasPos input; returns world normals, UVs, and snap targets
at the cost of a gl.readPixels per call.
RoutingPickStrategy — composes the two. Without snap,
routes to BVH (cheap); with snap requested, routes to GPU when
ready and falls back to BVH (without snap) otherwise.
MemoisingPickStrategy — wraps any strategy with a
per-canvasPos cache so a hover handler that picks every
pointer-move event doesn't repeat identical queries inside one
frame.
Snap-aware — snapToVertex / snapToEdge + snapRadius
ride along on every pick() call. Strategies that don't
support snap drop the request and return a plain hit.
xeokit Picking
Unified picking surface that routes between the CPU-side BVH picker and the GPU pick path, surfacing snap-to-vertex and snap-to-edge as part of the same call.
Picking is two distinct problems wearing one hat. The BVH picker is fast, ray- or matrix-driven, and supports caller
filtercallbacks but cannot snap. The GPU picker only accepts a canvas position but produces world normals, UVs, and snap targets via agl.readPixelsstall. Most callers want the cheap path most of the time and the snap enrichment when they ask for it.The
pickingmodule wraps both behind a single PickStrategy interface, with RoutingPickStrategy choosing the right backend per call. Snap requests degrade silently to BVH when the GPU isn't available (no renderer attached, context lost, etc.).Shape
Features
pick(params)call; strategies decide what to do withcanvasPos/origin+dir/matrixinputs.canvasPos(turned into a ray via the View's camera). No GPU stall; no snap.canvasPosinput; returns world normals, UVs, and snap targets at the cost of agl.readPixelsper call.canvasPoscache so a hover handler that picks every pointer-move event doesn't repeat identical queries inside one frame.snapToVertex/snapToEdge+snapRadiusride along on everypick()call. Strategies that don't support snap drop the request and return a plain hit.Installation
Quick Start
1) Import the entry points
2) Construct a routing picker
Pass the Scene and the (optional) WebGLRenderer. Without a renderer the strategy is BVH-only; snap requests degrade silently.
3) Cheap object pick (BVH path)
4) Snap-to-vertex / snap-to-edge (GPU when ready, BVH otherwise)
5) Memoise to avoid repeat queries in a hover handler