mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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:
1 parent
86aa0bc9ba
commit
b0cb8ce881
26 files changed
+1267
-68
No files matched your search
+44
-3
@@ -128,7 +128,23 @@
|
||||
*
|
||||
* @typedef {'click'|'doubleClick'|'move'|'down'|'up'} InputType
|
||||
* @typedef {'ctrl'|'shift'|'alt'} InputModifier
|
||||
* @typedef {{ position?: Cartesian2, startPosition?: Cartesian2, endPosition?: Cartesian2 }} InputEvent
|
||||
* @typedef {object} InputEvent
|
||||
* @property {Cartesian2} [position] click, doubleClick, down, up.
|
||||
* @property {Cartesian2} [startPosition] move.
|
||||
* @property {Cartesian2} [endPosition] move.
|
||||
* @property {PickResult} [picked] With `pick`: what is drawn under the
|
||||
* position (move: the end position), undefined for the map or nothing.
|
||||
* Cesium picks at once; Navara answers a click from its GPU pick of the
|
||||
* same gesture (a frame or two later; undefined after a timeout), a move
|
||||
* from a CPU pick of movers and lines, at most once per frame.
|
||||
* @property {PickResult[]} [drilled] With `drill`: up to that many objects
|
||||
* under the position, nearest first.
|
||||
*
|
||||
* @typedef {object} InputOptions
|
||||
* @property {InputModifier} [modifier]
|
||||
* @property {boolean} [pick] click, doubleClick and move only. A move
|
||||
* listener with pick gets at most one payload per frame (the latest).
|
||||
* @property {number} [drill] A positive integer (click and doubleClick).
|
||||
*
|
||||
* @typedef {object} GlobeProjector
|
||||
* @property {(position: Cartesian3, result?: Cartesian2) => (Cartesian2 | undefined)} worldToWindow
|
||||
@@ -173,8 +189,11 @@
|
||||
* The sharpening last set (a copy).
|
||||
*
|
||||
* @typedef {object} PickResult
|
||||
* @property {any} id The picked entity or object id; undefined for map tiles.
|
||||
* @property {any} primitive
|
||||
* @property {any} id The picked entity or object id (a mover's or line's
|
||||
* pickId); undefined for map tiles.
|
||||
* @property {string} [owner] The mover set or line the pick belongs to.
|
||||
* @property {number} [instance] The mover instance index.
|
||||
* @property {any} [primitive] Cesium only, for compatibility.
|
||||
* @property {any} [content] 3D tile content when map tiles were picked (what
|
||||
* a surface-pick check reads), else undefined.
|
||||
* @property {any} [object] The engine's own pick result, for engine-specific code.
|
||||
@@ -362,6 +381,28 @@ export const INPUT_TYPES = Object.freeze([
|
||||
'up',
|
||||
]);
|
||||
export const MODIFIERS = Object.freeze(['ctrl', 'shift', 'alt']);
|
||||
/** Input types whose listeners may ask for picks. */
|
||||
export const PICK_INPUT_TYPES = Object.freeze(['click', 'doubleClick', 'move']);
|
||||
|
||||
/**
|
||||
* input.on options checked and defaulted: { modifier, pick, drill } (drill
|
||||
* 0 when not asked), or a TypeError.
|
||||
*/
|
||||
export function normalizeInputOptions(type, options = {}) {
|
||||
const { modifier, pick = false, drill = 0 } = options ?? {};
|
||||
if (!INPUT_TYPES.includes(type))
|
||||
throw new TypeError(`Unknown input type: ${type}`);
|
||||
if (modifier !== undefined && !MODIFIERS.includes(modifier))
|
||||
throw new TypeError(`Unknown input modifier: ${modifier}`);
|
||||
if (typeof pick !== 'boolean')
|
||||
throw new TypeError(`Input pick must be a boolean: ${pick}`);
|
||||
if (!(Number.isInteger(drill) && drill >= 0))
|
||||
throw new TypeError(`Input drill must be a whole number: ${drill}`);
|
||||
if ((pick || drill) && !PICK_INPUT_TYPES.includes(type))
|
||||
throw new TypeError(`Input ${type} cannot pick`);
|
||||
if (drill && type === 'move') throw new TypeError('A move cannot drill');
|
||||
return { modifier, pick: pick || drill > 0, drill };
|
||||
}
|
||||
export const FLIGHT_EASINGS = Object.freeze([
|
||||
'cubicInOut',
|
||||
'sinusoidalInOut',
|
||||
|
||||
Reference in new issue
Block a user