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

+69 -3
View File
@@ -1,12 +1,71 @@
/**
* Test doubles for the input dispatcher: a stand-in for Cesium's
* `ScreenSpaceEventHandler`, and a dispatcher made on it ahead of the code
* under test, so that code's `inputFor(viewer)` gets the fake.
* under test, so that code's `inputFor(viewer)` gets the fake. Imported by
* tests only.
*
* The dispatcher's input port is the Cesium adapter's (`findInput`, over the
* fake handler), and its clicks pick through {@link sceneQuery}: the
* viewer's renderer's query port where it has one that picks, else the
* viewer double's own `scene.pick` and `drillPick`, read as the renderer's
* picks are.
*/
import { HANDLER_EVENT_TYPES, inputFor } from './dispatcher.js';
import * as Cesium from 'cesium';
// The adapter's unbound input port and a click's own Cesium picks.
import '../render/cesium/input.js';
import '../render/cesium/nativeClick.js';
import { rendererOf } from '../render/rendererOf.js';
import { fakeScenePicks } from '../testSupport/fakeCesiumScene.mjs';
import { provideStyleStageAlias } from '../styles/styleStages.js';
import { inputFor } from './dispatcher.js';
/** Cesium's own event types, the ones the input port binds. */
export const FAKE_EVENT_TYPES = HANDLER_EVENT_TYPES;
export const FAKE_EVENT_TYPES = Cesium.ScreenSpaceEventType;
// Tests record sensor styles on the viewer double's scene, as the code under
// them once did: the dispatcher, which looks them up by the viewer, finds
// them there too.
provideStyleStageAlias((viewer) => viewer?.scene ?? null);
/**
* A query port for a viewer double's clicks: its renderer's, where that
* picks; else one over the double's scene (`fakeScenePicks`), with its depth
* and ellipsoid picks.
* @param {object} viewer
*/
export function sceneQuery(viewer) {
const bound = () => {
const query = rendererOf(viewer)?.query;
return typeof query?.pick === 'function' ? query : null;
};
const at = (x, y) => new Cesium.Cartesian2(x, y);
const own = {
...fakeScenePicks(viewer),
pickPosition(x, y) {
const scene = viewer.scene;
if (
!scene?.pickPositionSupported ||
typeof scene.pickPosition !== 'function'
)
return null;
return scene.pickPosition(at(x, y)) ?? null;
},
pickEllipsoid(x, y) {
const camera = viewer.camera ?? viewer.scene?.camera;
return camera?.pickEllipsoid?.(at(x, y)) ?? null;
},
};
return new Proxy(own, {
get(target, key) {
const query = bound();
if (query) {
const value = query[key];
return typeof value === 'function' ? value.bind(query) : value;
}
return target[key];
},
});
}
export class FakeScreenSpaceEventHandler {
constructor() {
@@ -45,9 +104,16 @@ export class FakeScreenSpaceEventHandler {
*/
export function fakeInput(viewer, { now } = {}) {
const handler = new FakeScreenSpaceEventHandler();
// A Cesium viewer's canvas is its scene's.
if (!('canvas' in viewer))
Object.defineProperty(viewer, 'canvas', {
configurable: true,
get: () => viewer.scene?.canvas,
});
const input = inputFor(viewer, {
createHandler: () => handler,
document: null,
query: sceneQuery(viewer),
...(now ? { now } : {}),
});
const T = FAKE_EVENT_TYPES;