mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Restore ground, picking and horizon parity through the globe contract
Draw launch-pad zones as radial ground discs with the original fill, rim, transitions, emission and depth bias. Drape Transit history and its backing on ground corridors. Keep the current age bands and once-per-second updates; advance the active head with a reveal fraction and rebuild only at segment crossings. Its wider dark edge and colour core blend once, as on Cesium. Navara composes these looks after tone mapping. Build reveal corridors and dynamic Transit history synchronously once shared terrain bounds are loaded. Keep requesting frames until the visible globe tiles and committed primitives are ready: classification needs current surface depth after a camera move. Retain the reference radial material, its alpha envelope and the head's material-only reveal updates. Remove the empty Navara ground effect from the render chain when the last shown set is hidden or destroyed. It otherwise remains as the insertion anchor for later pulse effects after its packed textures have been disposed. Cover reveal, destruction and replacement with fresh-state comparisons for corridors, polygons, discs and cells. Cesium drawing is unchanged by this fix. Keep the radial pixel check at a 500 metre radius and 4 kilometre view, sample the brightest of six inner points around the native fill gap, and sample across the rim width. Restore its view during arrival flights and run it last among ground checks. Both suite launchers wait for the linked view to arrive before checking. Keep these checks with the radial look. Pass rectangular pick windows and drill limits through input subscriptions. Street Level uses its 9 pixel window and CCTV uses its 14 pixel window and six-result drill. Down picks stay synchronous, moves coalesce per frame and Navara clicks keep the GPU answer from their gesture. Add a projector ellipsoid option and use WGS84 radii reduced by 1,000 metres for Street Level. These changes restore the original Cesium pad fill and ground trail rather than the temporary ring and raised lines. Navara follows the same appearance and horizon policy, and now honours explicit CPU pick windows. Existing callers without these options retain their defaults. The four debts share the contract, suite and engine implementations, so keep them together. No coupling count grew or fell: renderer lines remain 0 and 189, external Cesium imports 3, external viewer lines 891, engine-kind checks 1, engine resolution calls 0, extension reads 3, ground passes 1, SDK loads 3, screen handler files 4 and engine-name lines 32. The contract and ground suites now wait until the camera has reached the view in their link before checking, because the app's restore flight could land in the middle of a check; that was also the cause of the intermittent camera-events failure. The radial check uses a launch pad's size and samples the fill at several inner points: Cesium's own old pad leaves the same gap in a small ground disc's fill. The pulse-band check takes its base frame once the surface has settled. Checked in the browser, keyless: the contract suite passes on both engines (84 and 85 checks), the ground suite passes on both, CCTV v2 passes 58 checks, and the space, transit, Street Level and CCTV engine switches pass. The transit and Street Level scripts fail as they do before this change.
This commit is contained in:
1 parent
be08163caa
commit
aa6959c97b
49 files changed
+1727
-455
No files matched your search
@@ -420,7 +420,8 @@ export function createCameraModel({
|
||||
worldToWindow: (position, result) =>
|
||||
projectToWindow(view(), position, result),
|
||||
viewProjection: (result) => viewProjection(view(), result),
|
||||
horizonVisible: (position) => horizonVisible(state.position, position),
|
||||
horizonVisible: (position, options) =>
|
||||
horizonVisible(state.position, position, options),
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
cancelCurrentFlight();
|
||||
|
||||
@@ -235,7 +235,8 @@ export function createNavaraEngine(
|
||||
projector: {
|
||||
worldToWindow: (position, result) =>
|
||||
model.worldToWindow(position, result),
|
||||
horizonVisible: (position) => model.horizonVisible(position),
|
||||
horizonVisible: (position, options) =>
|
||||
model.horizonVisible(position, options),
|
||||
},
|
||||
camera: model.camera,
|
||||
movers: () => moversPort?.pickables?.() ?? [],
|
||||
@@ -285,8 +286,9 @@ export function createNavaraEngine(
|
||||
registerMeshPicker: (pick) => picking.registerMeshPicker(pick),
|
||||
// The CPU pick of movers and lines (picking.js); 3D tiles carry no ids.
|
||||
// Clicks with { pick } get Navara's GPU pick of the gesture instead.
|
||||
pick: (screen) => picking.pick(screen),
|
||||
drillPick: (screen, limit) => picking.drillPick(screen, limit),
|
||||
pick: (screen, width, height) => picking.pick(screen, width, height),
|
||||
drillPick: (screen, limit, width, height) =>
|
||||
picking.drillPick(screen, limit, width, height),
|
||||
pickPosition(screen) {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const hit = view.pickDepthPosition(
|
||||
@@ -416,7 +418,8 @@ export function createNavaraEngine(
|
||||
worldToWindow: (position, result) =>
|
||||
model.worldToWindow(position, result),
|
||||
viewProjection: (result) => model.viewProjection(result),
|
||||
horizonVisible: (position) => model.horizonVisible(position),
|
||||
horizonVisible: (position, options) =>
|
||||
model.horizonVisible(position, options),
|
||||
},
|
||||
frames,
|
||||
render: {
|
||||
|
||||
@@ -46,7 +46,7 @@ const E2 =
|
||||
/** Item looks as the shader reads them: glow, pulse and dash bits. */
|
||||
export const LOOK = Object.freeze({ glow: 1, pulse: 2, dash: 4, pattern: 8 });
|
||||
/** RGBA32F texels per corridor item. */
|
||||
export const ITEM_TEXELS = 5;
|
||||
export const ITEM_TEXELS = 7;
|
||||
|
||||
const wrap180 = (degrees) => degrees - 360 * Math.round(degrees / 360);
|
||||
const geodetic = (latcDeg) =>
|
||||
@@ -54,7 +54,7 @@ const geodetic = (latcDeg) =>
|
||||
? latcDeg
|
||||
: Math.atan(Math.tan(latcDeg * DEG) / (1 - E2)) / DEG;
|
||||
|
||||
/** One item's look: five texels (colour, widths, glow/pulse, dash). */
|
||||
/** One item's look: colour, widths, glow/pulse, dash and reveal. */
|
||||
function itemTexels(item, lengthM) {
|
||||
const { glow, pulse, dash, pattern } = item.animation ?? {};
|
||||
const flags =
|
||||
@@ -64,7 +64,7 @@ function itemTexels(item, lengthM) {
|
||||
(pattern ? LOOK.pattern : 0);
|
||||
return [
|
||||
...item.fill,
|
||||
item.widthPx ?? 0,
|
||||
item.animation?.backing?.widthPx ?? item.widthPx ?? 0,
|
||||
item.widthM ?? 0,
|
||||
lengthM,
|
||||
flags,
|
||||
@@ -80,6 +80,11 @@ function itemTexels(item, lengthM) {
|
||||
dash?.emission ?? 0,
|
||||
pattern?.lengthPx ?? 0,
|
||||
pattern?.pattern ?? 0,
|
||||
1,
|
||||
item.widthPx / (item.animation?.backing?.widthPx ?? item.widthPx) || 1,
|
||||
0,
|
||||
0,
|
||||
...(item.animation?.backing?.color ?? [0, 0, 0, 0]),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
import { createGroundRegistry } from '../../ground.js';
|
||||
import { composeGround, packHeights, packSet } from './pack.js';
|
||||
import { ITEM_TEXELS } from './corridors.js';
|
||||
|
||||
// Frames before the first new try at a set's missing terrain heights; each
|
||||
// later try waits twice as long, up to RETRIES tries.
|
||||
@@ -60,6 +61,8 @@ export function createNavaraGround(
|
||||
};
|
||||
const pack = (entry) => {
|
||||
entry.pack = packSet(entry.options.kind, entry.items, { terrainHeight });
|
||||
for (let at = 20; at < entry.pack.items.length; at += ITEM_TEXELS * 4)
|
||||
entry.pack.items[at] = entry.fraction;
|
||||
entry.wait = entry.pack.heights.some(Number.isNaN) ? RETRY_FRAMES : 0;
|
||||
};
|
||||
const sampleAgain = (entry) => {
|
||||
@@ -70,6 +73,12 @@ export function createNavaraGround(
|
||||
const drawn = [...entries]
|
||||
.filter((entry) => entry.shown && entry.pack?.count)
|
||||
.sort((a, b) => a.options.order - b.options.order);
|
||||
for (const entry of entries) entry.offset = null;
|
||||
let offset = 0;
|
||||
for (const entry of drawn) {
|
||||
entry.offset = offset;
|
||||
offset += entry.pack.items.length;
|
||||
}
|
||||
pass.set(
|
||||
drawn.length ? composeGround(drawn.map(({ pack }) => pack)) : null,
|
||||
);
|
||||
@@ -94,6 +103,8 @@ export function createNavaraGround(
|
||||
const entry = {
|
||||
options,
|
||||
shown: true,
|
||||
fraction: 1,
|
||||
offset: null,
|
||||
items: [],
|
||||
pack: null,
|
||||
tries: 0,
|
||||
@@ -107,6 +118,21 @@ export function createNavaraGround(
|
||||
pack(entry);
|
||||
compose();
|
||||
},
|
||||
reveal(fraction) {
|
||||
if (entry.fraction === fraction) return;
|
||||
entry.fraction = fraction;
|
||||
if (entry.pack) {
|
||||
for (let at = 20; at < entry.pack.items.length; at += ITEM_TEXELS * 4)
|
||||
entry.pack.items[at] = fraction;
|
||||
if (entry.offset !== null)
|
||||
pass.reveal(
|
||||
entry.offset,
|
||||
entry.pack.items.length / (ITEM_TEXELS * 4),
|
||||
fraction,
|
||||
);
|
||||
}
|
||||
view.forceUpdate();
|
||||
},
|
||||
show(visible) {
|
||||
if (entry.shown === visible) return;
|
||||
entry.shown = visible;
|
||||
|
||||
@@ -1,7 +1,43 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { registerHooks } from 'node:module';
|
||||
import { createNavaraGround } from './index.js';
|
||||
|
||||
// The pass owns real data textures; the view below does not create GPU effects.
|
||||
const hooks = registerHooks({
|
||||
resolve(specifier, context, nextResolve) {
|
||||
return specifier === '@navaramap/three'
|
||||
? {
|
||||
url: 'data:text/javascript,export class EffectDesc {} export class Effect {}',
|
||||
shortCircuit: true,
|
||||
}
|
||||
: nextResolve(specifier, context);
|
||||
},
|
||||
});
|
||||
const { createGroundPass } = await import('./pass.js');
|
||||
hooks.deregister();
|
||||
|
||||
function passView() {
|
||||
const effects = new Set();
|
||||
return Object.assign(fakeView(), {
|
||||
effects,
|
||||
registerEffect() {},
|
||||
addEffect(config) {
|
||||
const handle = {
|
||||
config,
|
||||
update(next) {
|
||||
Object.assign(config, next);
|
||||
},
|
||||
delete() {
|
||||
effects.delete(handle);
|
||||
},
|
||||
};
|
||||
effects.add(handle);
|
||||
return handle;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function fakeView({ height = () => 12 } = {}) {
|
||||
const listeners = new Map();
|
||||
return {
|
||||
@@ -125,3 +161,116 @@ test('while a shown set pulses or dashes, every frame asks for the next', () =>
|
||||
queued.shift()();
|
||||
assert.equal(view.frames, destroyed, 'none after destroy');
|
||||
});
|
||||
|
||||
test('corridor reveal updates item data without repacking geometry, including hide and commit', () => {
|
||||
const pass = fakePass(),
|
||||
updates = [];
|
||||
pass.reveal = (...args) => updates.push(args);
|
||||
const port = createNavaraGround(fakeView(), { createPass: () => pass });
|
||||
const set = port.ground.createSet({
|
||||
id: 'head',
|
||||
kind: 'corridor',
|
||||
reveal: true,
|
||||
});
|
||||
const items = [
|
||||
{
|
||||
positions: [
|
||||
[20, 10],
|
||||
[20.001, 10],
|
||||
],
|
||||
widthPx: 5,
|
||||
color: [0, 1, 0, 0.8],
|
||||
},
|
||||
];
|
||||
set.replace(items);
|
||||
set.commit();
|
||||
const state = pass.owner.state;
|
||||
const count = pass.states.length;
|
||||
set.setReveal(0.25);
|
||||
set.setReveal(0.5);
|
||||
assert.equal(pass.states.length, count);
|
||||
assert.equal(pass.owner.state.segments, state.segments);
|
||||
assert.deepEqual(updates, [
|
||||
[0, 1, 0.25],
|
||||
[0, 1, 0.5],
|
||||
]);
|
||||
set.show(false);
|
||||
set.setReveal(0.75);
|
||||
set.show(true);
|
||||
assert.equal(pass.owner.state.items.data[20], 0.75);
|
||||
set.replace(items);
|
||||
set.commit();
|
||||
assert.equal(pass.owner.state.items.data[20], 0.75);
|
||||
set.destroy();
|
||||
port.destroy();
|
||||
});
|
||||
|
||||
test('destroying a revealed corridor leaves the next ground set with fresh pass data', () => {
|
||||
const corridor = {
|
||||
positions: [
|
||||
[20, 10],
|
||||
[20.1, 10],
|
||||
],
|
||||
widthPx: 12,
|
||||
color: [1, 0, 1, 1],
|
||||
};
|
||||
const view = passView();
|
||||
const pass = createGroundPass(view);
|
||||
const port = createNavaraGround(view, { createPass: () => pass });
|
||||
const set = port.ground.createSet({
|
||||
id: 'reveal',
|
||||
kind: 'corridor',
|
||||
reveal: true,
|
||||
});
|
||||
set.replace([corridor]);
|
||||
set.commit();
|
||||
set.setReveal(0.25);
|
||||
assert.equal(pass.owner.state.items.data[20], 0.25);
|
||||
set.destroy();
|
||||
assert.equal(pass.owner.state, null);
|
||||
assert.equal(pass.owner.textures, null);
|
||||
assert.equal(
|
||||
view.effects.size,
|
||||
0,
|
||||
'no retired ground effect remains in the pulse insertion path',
|
||||
);
|
||||
|
||||
for (const [kind, item] of [
|
||||
['corridor', corridor],
|
||||
['polygon', square(20)],
|
||||
['disc', { center: [20, 10], radiusM: 500, fill: [0, 1, 0, 1] }],
|
||||
['cell', { west: 20, east: 21, south: 10, north: 11, fill: [0, 0, 1, 1] }],
|
||||
]) {
|
||||
const freshView = passView();
|
||||
const freshPass = createGroundPass(freshView);
|
||||
const fresh = createNavaraGround(freshView, {
|
||||
createPass: () => freshPass,
|
||||
});
|
||||
const next = port.ground.createSet({ id: 'next', kind });
|
||||
const expected = fresh.ground.createSet({ id: 'next', kind });
|
||||
for (const target of [next, expected]) {
|
||||
target.replace([item]);
|
||||
target.commit();
|
||||
}
|
||||
for (const key of [
|
||||
'styles',
|
||||
'segments',
|
||||
'bins',
|
||||
'runs',
|
||||
'items',
|
||||
'frames',
|
||||
'grid',
|
||||
'candidates',
|
||||
])
|
||||
assert.deepEqual(
|
||||
pass.owner.state[key],
|
||||
freshPass.owner.state[key],
|
||||
`${kind}: ${key}`,
|
||||
);
|
||||
assert.throws(() => set.setReveal(0.9), /destroyed/);
|
||||
assert.deepEqual(pass.owner.state.items, freshPass.owner.state.items);
|
||||
next.destroy();
|
||||
fresh.destroy();
|
||||
}
|
||||
port.destroy();
|
||||
});
|
||||
@@ -195,7 +195,7 @@ const OPEN = 1e30;
|
||||
// anti-aliasing in pixels; a metre one its half width in metres and the
|
||||
// half pixel.
|
||||
const reachOf = (item) => [
|
||||
(item.widthPx ?? 0) / 2 + 0.5,
|
||||
(item.animation?.backing?.widthPx ?? item.widthPx ?? 0) / 2 + 0.5,
|
||||
(item.widthM ?? 0) / 2,
|
||||
];
|
||||
|
||||
@@ -351,6 +351,13 @@ export function packSet(
|
||||
const frame = frameAt(item.center[0], item.center[1]);
|
||||
const radius = frame.radius * Math.tan(item.radiusM / frame.radius);
|
||||
style.shape = [KIND.disc, item.outline?.widthPx ?? 0, 0, radius];
|
||||
if (item.radial) {
|
||||
const { fillAlpha, rimAlpha, rimStart, rimEnd, emission } =
|
||||
item.radial;
|
||||
style.shape[2] = 1;
|
||||
style.bins = [fillAlpha, rimAlpha, rimStart, rimEnd];
|
||||
style.origin = [emission, 0, 0, 0];
|
||||
}
|
||||
emit(
|
||||
frame,
|
||||
style,
|
||||
|
||||
@@ -480,3 +480,25 @@ test('screen-space dash masks keep their CSS length and all sixteen bits in the
|
||||
assert.deepEqual(Array.from(pack.items.slice(18, 20)), [18, 0xa55a]);
|
||||
assert.equal(pack.items.length, ITEM_TEXELS * 4);
|
||||
});
|
||||
|
||||
test('radial discs pack both transitions, alpha and emission without segment data', () => {
|
||||
const radial = {
|
||||
fillAlpha: 0.105,
|
||||
rimAlpha: 0.72,
|
||||
rimStart: 0.952,
|
||||
rimEnd: 0.985,
|
||||
emission: 0.35,
|
||||
};
|
||||
const pack = packSet(
|
||||
'disc',
|
||||
items('disc', [
|
||||
{ center: [20, 10], radiusM: 100, fill: [0, 1, 1, 1], radial },
|
||||
]),
|
||||
);
|
||||
assert.equal(pack.styles[10], 1);
|
||||
assert.deepEqual(
|
||||
Array.from(pack.styles.slice(16, 21)),
|
||||
Array.from(Float32Array.of(0.105, 0.72, 0.952, 0.985, 0.35)),
|
||||
);
|
||||
assert.equal(pack.segments.length, 0);
|
||||
});
|
||||
@@ -11,7 +11,7 @@
|
||||
// blended in display space, in draw order, as Cesium blends translucent
|
||||
// ground primitives; a corridor's glow, pulse and dash follow Cesium's
|
||||
// materials, from the time uniform (src/globe/ground.js groundSeconds).
|
||||
// Costs nothing while no item is drawn (the effect is hidden).
|
||||
// No effect remains in the chain while no item is drawn.
|
||||
|
||||
import { EffectDesc, Effect as NavaraEffect } from '@navaramap/three';
|
||||
import { Effect, EffectAttribute } from 'postprocessing';
|
||||
@@ -72,6 +72,7 @@ vec3 toLinear(vec3 c) {
|
||||
vec3 blendCorridor(vec3 color, int item, float nearest, vec2 normal, float along, vec2 localDx, vec2 localDy) {
|
||||
int at = item * ${ITEM_TEXELS};
|
||||
vec4 shape = atSlot(tItems, at + 1);
|
||||
if (along / max(shape.z, 1e-6) > atSlot(tItems, at + 5).x) return color;
|
||||
// Metres a pixel spans across the line (the screen gradient of the
|
||||
// distance to it): its width in pixels the same at any angle, as Cesium's.
|
||||
float pixel = max(length(vec2(dot(normal, localDx), dot(normal, localDy))), 1e-4);
|
||||
@@ -110,6 +111,12 @@ vec3 blendCorridor(vec3 color, int item, float nearest, vec2 normal, float along
|
||||
alpha *= max(on, dash.x);
|
||||
}
|
||||
}
|
||||
float core = atSlot(tItems, at + 5).y;
|
||||
if (core < 1.0 && nearest / max(halfWidth, 1e-6) > core) {
|
||||
vec4 backing = atSlot(tItems, at + 6);
|
||||
rgb = backing.rgb;
|
||||
alpha = backing.a * cover;
|
||||
}
|
||||
return min(color * (1.0 - alpha) + min(rgb * alpha, vec3(1.0)), vec3(1.0));
|
||||
}
|
||||
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
||||
@@ -301,6 +308,15 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor)
|
||||
// Metres one pixel spans across the boundary.
|
||||
float pixel = max(abs(dot(normal, localDx)) + abs(dot(normal, localDy)), 1e-4);
|
||||
float inward = inside ? nearest : -nearest;
|
||||
if (kind == ${KIND.disc} && shape.z > 0.5) {
|
||||
vec4 radial = atSlot(tStyles, id * ${STYLE_TEXELS} + 4);
|
||||
float emission = atSlot(tStyles, id * ${STYLE_TEXELS} + 5).x;
|
||||
float radius = length(local) / shape.w;
|
||||
float inside = 1.0 - smoothstep(radial.w, 1.0, radius);
|
||||
float rim = smoothstep(radial.z, radial.w, radius) * inside;
|
||||
float alpha = fillColor.a * inside * mix(radial.x, radial.y, rim);
|
||||
color = min(color * (1.0 - alpha) + fillColor.rgb * (1.0 + rim * emission) * alpha, vec3(1.0));
|
||||
} else
|
||||
if (fillColor.a > 0.0)
|
||||
color = mix(color, fillColor.rgb, fillColor.a * clamp(inward / pixel + 0.5, 0.0, 1.0));
|
||||
if (lineColor.a > 0.0 && shape.y > 0.0)
|
||||
@@ -465,7 +481,7 @@ const registered = new WeakSet();
|
||||
|
||||
/**
|
||||
* The pass of one view: set(state) shows a composed state (null: nothing,
|
||||
* the effect hidden) and disposes the one before.
|
||||
* the effect removed) and disposes the one before.
|
||||
*/
|
||||
export function createGroundPass(view) {
|
||||
if (!registered.has(view)) {
|
||||
@@ -481,7 +497,10 @@ export function createGroundPass(view) {
|
||||
owner.state = state && state.count ? state : null;
|
||||
owner.textures = owner.state ? texturesFor(owner.state) : null;
|
||||
const visible = owner.state !== null;
|
||||
if (visible && !handle)
|
||||
if (!visible) {
|
||||
handle?.delete();
|
||||
handle = null;
|
||||
} else if (!handle)
|
||||
handle = view.addEffect({
|
||||
[GROUND_EFFECT_KEY]: { owner },
|
||||
visible: true,
|
||||
@@ -489,6 +508,12 @@ export function createGroundPass(view) {
|
||||
else handle?.update({ visible });
|
||||
previous?.dispose();
|
||||
},
|
||||
reveal(offset, count, fraction) {
|
||||
if (!owner.state) return;
|
||||
for (let i = 0; i < count; i++)
|
||||
owner.state.items.data[offset + i * ITEM_TEXELS * 4 + 20] = fraction;
|
||||
owner.textures.items.needsUpdate = true;
|
||||
},
|
||||
textureBytes: () => textureBytes(owner.state),
|
||||
destroy() {
|
||||
handle?.delete();
|
||||
|
||||
@@ -50,10 +50,27 @@ export function createNavaraInput(
|
||||
let last = null;
|
||||
|
||||
const pointer = createExclusivePointer();
|
||||
const gestures = new WeakMap();
|
||||
const delivery = createPickDelivery({
|
||||
pick: (position, type) =>
|
||||
type === 'move' ? picker?.pick(position) : picker?.clickPick(position),
|
||||
drill: (position, limit) => picker?.drillPick(position, limit) ?? [],
|
||||
pick: (position, type, window) => {
|
||||
if (type === 'move' || type === 'down')
|
||||
return picker?.pick(position, window?.width, window?.height);
|
||||
let gesture = gestures.get(position);
|
||||
if (!gesture) {
|
||||
gesture = Promise.resolve(picker?.clickPick(position));
|
||||
gestures.set(position, gesture);
|
||||
}
|
||||
if (!window) return gesture;
|
||||
return gesture.then(
|
||||
(hit) =>
|
||||
hit ??
|
||||
(window
|
||||
? picker?.pick(position, window.width, window.height)
|
||||
: undefined),
|
||||
);
|
||||
},
|
||||
drill: (position, limit, window) =>
|
||||
picker?.drillPick(position, limit, window?.width, window?.height) ?? [],
|
||||
schedule: (run) => scheduleFrame(() => !destroyed && run()),
|
||||
});
|
||||
const positionOf = (event) => {
|
||||
@@ -126,7 +143,10 @@ export function createNavaraInput(
|
||||
const input = {
|
||||
acquirePointer: () => pointer.acquire(),
|
||||
on(type, listener, options = {}) {
|
||||
const { modifier, pick, drill } = normalizeInputOptions(type, options);
|
||||
const { modifier, pick, drill, pickWindow } = normalizeInputOptions(
|
||||
type,
|
||||
options,
|
||||
);
|
||||
if (destroyed) return () => {};
|
||||
if (!attached) {
|
||||
attached = true;
|
||||
@@ -138,6 +158,7 @@ export function createNavaraInput(
|
||||
modifier,
|
||||
pick,
|
||||
drill,
|
||||
pickWindow,
|
||||
pointer: options.pointer,
|
||||
};
|
||||
listeners.get(type).add(entry);
|
||||
|
||||
@@ -265,3 +265,63 @@ test('exclusive pointer drops deferred picks across ownership changes and releas
|
||||
next.release();
|
||||
assert.equal(input.acquirePointer(), null);
|
||||
});
|
||||
|
||||
test('custom windows keep down synchronous, moves coalesced and clicks on one GPU gesture', async () => {
|
||||
const canvas = fakeCanvas();
|
||||
const calls = [],
|
||||
seen = [];
|
||||
let resolve,
|
||||
frame,
|
||||
clicks = 0;
|
||||
const { input, destroy } = createNavaraInput(
|
||||
{ canvas, camera: {} },
|
||||
{
|
||||
picker: {
|
||||
pick: (at, w, h) => {
|
||||
calls.push(['pick', w, h]);
|
||||
return { id: 'cpu' };
|
||||
},
|
||||
drillPick: (at, limit, w, h) => {
|
||||
calls.push(['drill', limit, w, h]);
|
||||
return [{ id: 'cpu' }];
|
||||
},
|
||||
clickPick: () => {
|
||||
clicks++;
|
||||
return new Promise((done) => {
|
||||
resolve = done;
|
||||
});
|
||||
},
|
||||
},
|
||||
scheduleFrame: (run) => {
|
||||
frame = run;
|
||||
},
|
||||
},
|
||||
);
|
||||
const options = { drill: 6, pickWindow: { width: 11, height: 7 } };
|
||||
input.on('down', (event) => seen.push(event), options);
|
||||
input.on('move', (event) => seen.push(event), options);
|
||||
input.on('click', (event) => seen.push(event), options);
|
||||
input.on('click', (event) => seen.push(event), { pick: true });
|
||||
canvas.dispatchEvent(pointer('pointerdown', 110, 60));
|
||||
assert.equal(seen[0].picked.id, 'cpu');
|
||||
assert.deepEqual(calls, [
|
||||
['pick', 11, 7],
|
||||
['drill', 6, 11, 7],
|
||||
]);
|
||||
canvas.dispatchEvent(pointer('pointermove', 111, 60));
|
||||
canvas.dispatchEvent(pointer('pointermove', 112, 60));
|
||||
assert.equal(seen.length, 1);
|
||||
frame();
|
||||
assert.equal(seen.length, 2);
|
||||
assert.equal(seen[1].endPosition.x, 12);
|
||||
canvas.dispatchEvent(pointer('pointerup', 112, 60));
|
||||
assert.equal(clicks, 1);
|
||||
assert.equal(seen.length, 2);
|
||||
resolve({ id: 'gpu' });
|
||||
await new Promise((done) => setTimeout(done, 0));
|
||||
assert.deepEqual(
|
||||
seen.slice(2).map((event) => event.picked.id),
|
||||
['gpu', 'gpu'],
|
||||
);
|
||||
destroy();
|
||||
});
|
||||
@@ -102,8 +102,9 @@ export function createNavaraPicking({
|
||||
meshPickers.add(pick);
|
||||
return () => meshPickers.delete(pick);
|
||||
},
|
||||
pick: (at) => drillPick(at, 1)[0],
|
||||
drillPick: (at, limit) => drillPick(at, limit ?? Infinity),
|
||||
pick: (at, width, height) => drillPick(at, 1, { width, height })[0],
|
||||
drillPick: (at, limit, width, height) =>
|
||||
drillPick(at, limit ?? Infinity, { width, height }),
|
||||
/** The answer for a click at `at`: the GPU pick of its gesture. */
|
||||
clickPick(at) {
|
||||
const gesture = early;
|
||||
|
||||
Reference in new issue
Block a user