Skip to main content

SnapResolver

Main-thread snap resolver: takes a world-space pick point + the picked item, returns the closest face / line / point of that item for any requested snap classes. The heavy work (fetching the item's shell geometry through the fragments edit API and composing world-space polygons) runs once per item; subsequent calls for the same item are pure CPU geometry against the LRU-bounded cache. Call invalidate when an item changes (e.g. via the fragments edit API) so the cached snap data gets refreshed on the next request.

Implements​

Properties​

maxCacheSize​

maxCacheSize: number = 1000

Maximum number of items to keep in the snap cache. Beyond this, the least-recently-used item is dropped on the next insertion. Each cached item is on the order of a few KB (per-shell faces + deduped edges + deduped vertices), so the default of 1000 caps memory at a few MB even on huge models. Bump it for workflows that revisit thousands of distinct items in a single session.


maxDistance​

maxDistance: number = 1

Maximum world-space distance for a snap candidate to be considered valid. Vertices, edges or face planes beyond this range are rejected. Set this in the same units as your model (typical BIM scenes are metres, so the default of 1 means "snap only when within 1 m of the cursor"). Tools that want a different feel can override per-instance.


onDisposed​

readonly onDisposed: Event<unknown>

Disposable.onDisposed

Implementation of​

Disposable . onDisposed

Accessors​

precision​

get precision(): SnapPrecision

Numeric precision for cached face/edge/vertex buffers.

"half" uses Float32Array for lower memory footprint. "full" uses Float64Array for higher numeric precision. Use "full" for workflows that require higher geometric fidelity.

Changing this value clears the snap cache so subsequent requests are rebuilt with the new precision.

Returns​

SnapPrecision

Methods​

clear()​

clear(): void

Drop the entire cache. Useful when many items have changed.

Returns​

void


dispose()​

dispose(): void

Disposable.dispose

Returns​

void

Implementation of​

Disposable . dispose


invalidate()​

invalidate(modelId, itemId): void

Drop a specific item from the cache (e.g. after an edit).

Parameters​

ParameterType
modelIdstring
itemIdnumber

Returns​

void


prefetch()​

prefetch(modelId, itemId): Promise<void>

Fire-and-forget prefetch of an item's snap geometry. Hoverer calls this on lock-onto-new-item so by the time the user clicks, the worker round-trip is already paid and resolve resolves synchronously off the cache.

Returns a Promise so callers who do want to await can; most won't.

Parameters​

ParameterType
modelIdstring
itemIdnumber

Returns​

Promise<void>


resolve()​

resolve(point, modelId, itemId, classes): Promise<null | SnapResult>

Returns the best snap candidate among the requested classes for a pre-picked surface point on a known item, or null if the item has no shell geometry. When multiple classes are requested, the winner is whichever produces the smallest distance to the input point.

Parameters​

ParameterTypeDescription
pointVector3

Pick point in world space (typically from the GPU

picker's getFullPick).

modelIdstringModel the picked item belongs to.
itemIdnumberInternal itemId (the FlatBuffer sample.item() index, key
for boxes.sampleOf), not the user-facing localId. The picker
exposes this on its full-pick result; passing it through here
lets us hit the O(1) item→samples reverse index on the worker
via _getItemSnapData(itemId). Keying by localId would force a
full sample-table scan (~1 s on big models).
classesIterable <SnapClass>Subset of SnapClass the caller cares about.

Returns​

Promise<null | SnapResult>