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

+82 -1
View File
@@ -7,6 +7,7 @@ import {
listenerList,
} from './ports.js';
import { updateCameraChanged } from './internals.js';
import { createNativeClick } from './nativeClick.js';
test('capabilities follow what the scene supports', () => {
const effects = [
@@ -121,7 +122,11 @@ function fakeWidget(overrides = {}) {
const calls = [];
const primitives = [];
const scene = {
camera: { moveStart: event(), moveEnd: event() },
camera: {
moveStart: event(),
moveEnd: event(),
pickEllipsoid: () => undefined,
},
primitives: {
add: (p) => primitives.push(p),
remove: (p) => primitives.splice(primitives.indexOf(p), 1),
@@ -221,6 +226,82 @@ test('pick under something unpickable stops at what hides the rest', () => {
ports.dispose();
});
test('a surface hit over the ellipsoid makes its depth pick only when its position is read', () => {
let depthPicks = 0;
const { widget, scene } = fakeWidget({
pickPosition: () => (depthPicks++, { x: 6378200, y: 0, z: 0 }),
});
scene.camera.pickEllipsoid = () => ({ x: 6378137, y: 0, z: 0 });
const ports = createCesiumPorts(widget, { capabilities: all });
const hit = ports.query.pick(1, 1);
assert.equal(hit.surface, true);
assert.equal(depthPicks, 0, 'no depth pass for a click nobody grounds');
assert.equal(hit.position.x, 6378200, 'the rendered surface, once read');
assert.equal(hit.position.x, 6378200);
assert.equal(depthPicks, 1);
// Over the sky the depth pick decides whether there is a surface at all.
scene.camera.pickEllipsoid = () => undefined;
scene.pickPosition = () => undefined;
assert.equal(ports.query.pick(1, 1), null);
ports.dispose();
});
test('a sky pick makes no depth pass unless something may be there', () => {
let depthPicks = 0;
let globeHit = null;
let picked;
const { widget, scene } = fakeWidget({
pick: () => picked,
pickPosition: () => (depthPicks++, { x: 6378200, y: 0, z: 0 }),
});
scene.camera.pickEllipsoid = () => undefined;
scene.camera.getPickRay = () => ({
origin: { x: 7e6, y: 0, z: 0 },
direction: { x: 0, y: 1, z: 0 },
});
scene.globe.pick = () => globeHit;
const ports = createCesiumPorts(widget, { capabilities: all });
assert.equal(ports.query.pick(1, 1), null, 'nothing there: the sky');
assert.equal(depthPicks, 0);
// A mountain above the horizon: a globe tile on the ray.
globeHit = { x: 6378000, y: 0, z: 0 };
assert.equal(ports.query.pick(1, 1).surface, true);
assert.equal(depthPicks, 1);
// Something drawn outside the sets against the sky.
globeHit = null;
picked = { primitive: {} };
ports.query.pick(1, 1);
assert.equal(depthPicks, 2);
// A failing depth pick finds no surface, so what was picked is still read.
scene.pickPosition = () => {
throw new Error('no depth');
};
assert.equal(ports.query.pick(1, 1), null);
// A throwing camera answers nothing rather than failing the pick.
picked = undefined;
scene.camera.pickEllipsoid = () => {
throw new Error('no camera');
};
assert.equal(ports.query.pick(1, 1), null);
ports.dispose();
});
test("an empty click's renderer pick and its own Cesium pick are one pass", () => {
let passes = 0;
const { widget, scene } = fakeWidget({
pick: () => (passes++, undefined),
pickPosition: () => (passes++, { x: 6378200, y: 0, z: 0 }),
});
scene.camera.pickEllipsoid = () => ({ x: 6378137, y: 0, z: 0 });
const ports = createCesiumPorts(widget, { capabilities: all });
assert.equal(ports.query.pick(4, 5).surface, true);
const click = createNativeClick(scene, { x: 4, y: 5 });
assert.equal(click.foreign(), null);
assert.equal(click.native.pick, undefined);
assert.equal(passes, 1);
ports.dispose();
});
test('rayCast answers against the surface asked for', async () => {
const seen = [];
const { widget } = fakeWidget({