Files
gods-eye-view/src/render/cesium/pickMemo.js
T
Sameh Khamis 8bcaced6ad Take the input dispatcher off Cesium: pointer input from the renderer's input port, picks from the query port
The dispatcher now builds on renderer.input and the query port, with
positions as plain {x, y}. Its viewer access count is zero and it leaves
the Cesium allow-list. Layers that read the raw engine pick read the Hit,
drawHit or event.native instead, and pickRegistry's resolvePickId and
pickContact take a Hit, with the raw versions kept in the Cesium adapter.

rendererOf gains findInput, provideUnboundInput and provideNativeClick.
event.native carries the engine's pick, drill and pickWindow, and picks
through the follow helper happen inside it. An unbound input port
survives the viewer being bound until it is released.

The query port's pick memo is now per task rather than per frame,
because Cesium's own picks advance the frame number. A click on the sky
skips the depth pass when nothing is on the ray. Touch contact search
keeps its eight-deep drill in a 14x14 window.
2026-11-09 00:47:30 -08:00

50 lines
1.5 KiB
JavaScript

/**
* @module render/cesium/pickMemo
* @description Each scene's `pick` passes made in the task running now, as
* Cesium gave them, so a click's own Cesium picks (`nativeClick.js`) reuse
* the query port's pick of the same pixel and window rather than draw the
* pick buffer again. Nothing draws between them: they are forgotten once
* the task that made them ends. No imports.
*/
/**
* Each scene's passes in this task, by pixel and window.
* @type {WeakMap<object, Map<string, unknown>>}
*/
let taskPicks = new WeakMap();
let clearing = false;
const keyOf = (x, y, width, height) => `${x},${y},${width},${height}`;
/**
* Note a `pick` pass `scene.pick` just made, for `recentPick`.
* @param {object} scene
*/
export function rememberPick(scene, x, y, width, height, picked) {
let picks = taskPicks.get(scene);
if (!picks) {
picks = new Map();
taskPicks.set(scene, picks);
}
picks.set(keyOf(x, y, width, height), picked);
if (!clearing) {
clearing = true;
queueMicrotask(() => {
clearing = false;
taskPicks = new WeakMap();
});
}
}
/**
* What the query port's `pick` on `scene` found at exactly this pixel and
* window in the task running now; undefined when it made none there.
* @param {object} scene
* @returns {{picked: unknown} | undefined}
*/
export function recentPick(scene, x, y, width = 3, height = 3) {
const picks = taskPicks.get(scene);
const key = keyOf(x, y, width, height);
return picks?.has(key) ? { picked: picks.get(key) } : undefined;
}