feat(globe): picks on input payloads

input.on('click'|'doubleClick'|'move', fn, { pick, drill }) delivers
{ …event, picked, drilled }: PickResult { id, owner, instance, primitive
(Cesium) } names the mover set (and instance) or line hit. One pick (and
one drill, as deep as the deepest listener) per event, shared by its
listeners; moves with picks are coalesced to one delivery per frame with
the latest position (src/globe/pickDelivery.js). Option checks in the
contract (normalizeInputOptions).

- Cesium: scene.pick / drillPick, and the picker names the owner: movers
  map billboards, points and models to their set and instance, lines
  their primitives to the line.
- Navara: a click with pick takes Navara's GPU pick of the same gesture
  (featureClick; its pick helper answers on the same pointerup, usually
  before the engine's click, so a fresh answer waits for it; otherwise
  the click waits up to 250 ms, then the CPU pick). Navara 0.2.1 answers
  clicks in quick succession with the first click's pick: a GPU answer
  whose instance is not drawn near the click is stale and the CPU pick
  answers. Hover, drill and the synchronous picker.pick/drillPick are CPU
  picks (src/globe/cpuPicks.js) of pickable mover sets and pickable lines
  (within half the width + 3 px), behind the globe excluded, nearest
  first; lines are picked on the CPU after an empty GPU answer.
  picker.clickStats() (Navara only) counts the answers and latencies.
- The fake engine picks its own movers and lines on the CPU unless
  scripted.
- The contract suite clicks with real pointer events (puppeteer) on both
  engines: a sprite is picked with its owner and instance, the map picks
  nothing, two sprites in one place drill both, a line is picked, a
  hover picks the sprite under it. Navara, 20 clicks: payload p50 2.8 ms,
  p95 4.1 ms after the click (puppeteer dispatch included), 20/20 GPU
  answers. The Cesium harness keeps the first-run card closed.
This commit is contained in:
German Khokhlov committed 2026-10-16 18:25:12 +04:00
1 parent 86aa0bc9ba
commit b0cb8ce881
26 files changed
+1267 -68

No files matched your search

+54 -9
View File
@@ -21,6 +21,7 @@ import * as geo from '../../geo/index.js';
import {
INPUT_TYPES,
MODIFIERS,
normalizeInputOptions,
SHARPEN_INITIAL,
createEngineEvent,
mergeSharpen,
@@ -28,6 +29,7 @@ import {
import { createAppClock } from '../../time/clock.js';
import { createLineRegistry } from '../lines.js';
import { createMoverRegistry } from '../movers.js';
import { createCpuPicker } from '../cpuPicks.js';
const { cartesian2, cartesian3, cartographic, ellipsoid, math, matrix4 } = geo;
const WGS84 = ellipsoid.WGS84;
@@ -804,6 +806,33 @@ export function createFakeEngine(options = {}) {
size: () => ({ width, height }),
};
// Unscripted picks find the fake's own movers and lines, as Navara's CPU
// pick does (src/globe/cpuPicks.js).
const cpuPick = createCpuPicker({
projector: {
worldToWindow: (position, result) =>
engine.projector.worldToWindow(position, result),
horizonVisible: (position) => engine.projector.horizonVisible(position),
},
camera: {
get livePosition() {
return engine.camera.livePosition;
},
},
movers: () =>
[...moverRegistry.sets.values()].map(({ options, store }) => ({
options,
store,
})),
lines: () =>
[...fakeLines.values()]
.filter((state) => state.shown)
.map((state) => ({
options: state.options,
flat: state.positions,
modelMatrix: state.modelMatrix,
})),
});
const engine = {
kind: options.kind ?? 'cesium',
host,
@@ -811,11 +840,13 @@ export function createFakeEngine(options = {}) {
picker: {
pick(screen, w, h) {
record('picker.pick', [screen, w, h]);
return scripted('pick', [screen, w, h], () => undefined);
return scripted('pick', [screen, w, h], () => cpuPick(screen, 1)[0]);
},
drillPick(screen, limit, w, h) {
record('picker.drillPick', [screen, limit, w, h]);
return scripted('drillPick', [screen, limit, w, h], () => []);
return scripted('drillPick', [screen, limit, w, h], () =>
cpuPick(screen, limit ?? Infinity),
);
},
pickPosition(screen) {
record('picker.pickPosition', [screen]);
@@ -892,12 +923,12 @@ export function createFakeEngine(options = {}) {
input: {
on(type, listener, inputOptions = {}) {
record('input.on', [type, inputOptions]);
const { modifier, pick, drill } = normalizeInputOptions(
type,
inputOptions,
);
const listeners = inputs.get(type);
if (!listeners) throw new TypeError(`Unknown input type: ${type}`);
const modifier = inputOptions.modifier;
if (modifier !== undefined && !MODIFIERS.includes(modifier))
throw new TypeError(`Unknown input modifier: ${modifier}`);
const entry = { listener, modifier };
const entry = { listener, modifier, pick, drill };
listeners.add(entry);
return () => listeners.delete(entry);
},
@@ -1008,8 +1039,22 @@ export function createFakeEngine(options = {}) {
input(type, event, modifier) {
const listeners = inputs.get(type);
if (!listeners) throw new TypeError(`Unknown input type: ${type}`);
for (const entry of [...listeners])
if (entry.modifier === modifier) entry.listener(event);
for (const entry of [...listeners]) {
if (entry.modifier !== modifier) continue;
if (!entry.pick) {
entry.listener(event);
continue;
}
// As the engines: the pick under the position (a move's end).
const at = event.position ?? event.endPosition;
entry.listener({
...event,
picked: engine.picker.pick(at),
...(entry.drill
? { drilled: engine.picker.drillPick(at, entry.drill) }
: {}),
});
}
},
/** Replaces a result with a value or a function of the call's arguments. */
script(name, valueOrFunction) {