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.
This commit is contained in:
Sameh Khamis committed 2026-11-09 00:47:30 -08:00
1 parent 6eb9ceef46
commit 8bcaced6ad
52 files changed
+1836 -484

No files matched your search

+42 -36
View File
@@ -11,35 +11,34 @@
* that belong to someone else and leave them alone.
*/
import { isSurfacePick } from './scenePick.js';
/**
* A click's hits are the renderer contract's `Hit` (src/render/contract/
* query.d.ts), plus, for something drawn outside the draw port, a `Hit`
* with no set (`set: ''`, `id` null when it has none) named by the renderer
* adapter
* (`nativeClickOf`, src/render/rendererOf.js). The raw forms of these
* rules, for code that still holds a Cesium pick, are the adapter's
* (src/render/cesium/nativeClick.js).
*/
/** Whether a hit is the map itself, or nothing. */
const isSurface = (hit) => !hit || hit.surface === true;
/** @type {Map<string, (pickedId: string) => boolean>} layerId -> ownership predicate */
const _owners = new Map();
/**
* Resolves a scene.pick() result to a String pick id for the ownership scan.
* A hit's canonical pick id, for the ownership scan: its item's id. Layers'
* ids differ (strings, satellites' NORAD catalog numbers as strings), but a
* draw-set item's id is always a string.
*
* Layers use heterogeneous pick ids: flights/military/vessels/bikeshare/CCTV
* use strings, satellites use numeric NORAD catalog ids, and entity picks
* surface the Cesium Entity (identity = its string `id`). Everything is
* coerced to a String so predicates match against one canonical form.
*
* @param {object|null|undefined} picked - Result of `scene.pick()`.
* @returns {string|null} Canonical pick id, or null when the pick carries none.
* @param {import('../render/contract/query').Hit|null|undefined} hit
* @returns {string|null} Its id (an empty one is still an id); null for the
* map, nothing, or something with no id.
*/
export function resolvePickId(picked) {
if (!picked) return null;
const unwrap = (id) => {
if (id === null || id === undefined) return undefined;
if (typeof id === 'object') {
// A Cesium Entity (.id string)
if (typeof id.id === 'string' || typeof id.id === 'number') return id.id;
return undefined;
}
return id;
};
let id = unwrap(picked.id);
if (id === undefined) id = unwrap(picked.primitive?.id);
export function resolvePickId(hit) {
if (isSurface(hit)) return null;
const id = hit.id;
return typeof id === 'string' || typeof id === 'number' ? String(id) : null;
}
@@ -103,25 +102,28 @@ export function isOwnedByOtherLayer(layerId, pickedId) {
/**
* Resolve a moving-contact click without letting map tiles hide a nearby touch
* target. Exact picks always win; only a coarse primary pointer may expand a
* surface miss. Every consumer uses the same ordered, bounded scene hits, so sibling layers
* do not each choose their own contact under one tap.
* Unowned non-surface objects remain barriers, not permission to pick through.
* surface miss. Every consumer uses the same ordered, bounded hits, so sibling
* layers do not each choose their own contact under one tap.
* Unowned items remain barriers, not permission to pick through.
*
* @param {object} scene Cesium scene with pick and optional drillPick.
* @param {import('../render/contract/query').QueryPort} query
* @param {{x: number, y: number}} position Screen position in CSS pixels.
* @param {{picked?: object|null, drill?: (limit: number, width: number, height: number) => object[]}} [options]
* @param {{picked?: import('../render/contract/query').Hit|null, drill?: (limit: number, width: number, height: number) => import('../render/contract/query').Hit[]}} [options]
* The click's own passes when the caller has them, so a click is picked
* once: `picked` is `scene.pick(position)` (a miss is passed as `undefined`
* too, so the key's presence counts), `drill` a shared `scene.drillPick`.
* @returns {object|null|undefined} Original pick or the first registered touch hit.
* once: `picked` is `query.pick(position)` (a miss is passed as `null`
* too, so the key's presence counts), `drill` a shared `query.drillPick`.
* @returns {import('../render/contract/query').Hit|null} The pick, or the
* first registered touch hit.
*/
export function pickContact(scene, position, options = {}) {
const picked = 'picked' in options ? options.picked : scene.pick(position);
export function pickContact(query, position, options = {}) {
const picked =
'picked' in options
? options.picked
: (query.pick(position.x, position.y) ?? null);
if (
!globalThis.matchMedia?.('(pointer: coarse)').matches ||
findPickOwner(resolvePickId(picked)) ||
!isSurfacePick(picked) ||
typeof scene.drillPick !== 'function'
!isSurface(picked)
)
return picked;
let hits;
@@ -129,13 +131,17 @@ export function pickContact(scene, position, options = {}) {
hits =
(options.drill
? options.drill(8, 14, 14)
: scene.drillPick(position, 8, 14, 14)) || [];
: query.drillPick(position.x, position.y, {
width: 14,
height: 14,
limit: 8,
})) || [];
} catch {
return picked;
}
for (const hit of hits.slice(0, 8)) {
if (findPickOwner(resolvePickId(hit))) return hit;
if (!isSurfacePick(hit)) break;
if (!isSurface(hit)) break;
}
return picked;
}