mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Hand features the engine instead of guessing it from a viewer
No code outside src/globe calls isGlobeEngine or engineFromViewer any more (14 calls left before this). The features that still sniffed take the engine from their caller: - Projection and surface helpers (focus de-emphasis, icon orientation, ground snap, the mesh floor sampler, ground picks) take the engine; the engine view's scene carries its projector instead of registering itself as a viewer. - Credits go only through engine.credits, so annotations and layers share one OSM credit state on Cesium too (it could show twice). - The annotation board and the resolver work on the engine: camera assists, visibility and picks go through engine.camera, engine.projector and src/geo, without Cesium. - The Recent Imagery box tool has one implementation for both engines, on capture-phase canvas pointer events with the layer's engine.ground preview; the Navara copy goes. On Cesium the preview outline is solid now, as on Navara. - Scene interactions take the engine, and the render governor has an engine variant beside the Cesium one. Remaining engine-specific features stay behind explicit seams until the contract covers them: the draw tool's Cesium surface (stock click actions cannot be suspended), the annotation drapes (animated materials), share follow, Cesium post effects and cyber sonar, and data packs (meshes). Coupling: Cesium-importing files fall from 31 to 27, `viewer` lines from 1367 to 1234, engine sniffing calls from 14 to 0.
This commit is contained in:
1 parent
406dd9122e
commit
f1ec9d4a22
61 files changed
+823
-1230
No files matched your search
@@ -116,7 +116,7 @@ export class SceneDirector {
|
||||
});
|
||||
this._sharing = createSceneSharing(this);
|
||||
this._interactionTransitions = 0;
|
||||
this._interactions = createSceneInteractions(viewer, {
|
||||
this._interactions = createSceneInteractions({
|
||||
engine,
|
||||
available: () =>
|
||||
!this._destroyed && !this._running && !this.viewer?.trackedEntity,
|
||||
@@ -255,7 +255,7 @@ export class SceneDirector {
|
||||
});
|
||||
this._cameraHandoffUnsubscribe?.();
|
||||
this._removeCameraInput?.();
|
||||
this._interactions.setScene(null, null);
|
||||
this._interactions.setScene(null);
|
||||
this._dataPacks.setScene(null, null);
|
||||
this._flight?.suspend();
|
||||
this.engine = this.viewer = null;
|
||||
@@ -268,7 +268,7 @@ export class SceneDirector {
|
||||
this._isMapStackAvailable = isAvailable;
|
||||
try {
|
||||
this._dataPacks.setScene(viewer, native, engine.host.container);
|
||||
this._interactions.setScene(viewer, engine, this._dataPacks.getTargets());
|
||||
this._interactions.setScene(engine, this._dataPacks.getTargets());
|
||||
} catch (error) {
|
||||
// Release any packs already drawn before the caller parks the failed globe.
|
||||
this.suspendScene();
|
||||
|
||||
+16
-27
@@ -1,4 +1,3 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { nextTick } from 'vue';
|
||||
import { isPointerFree } from '../data/inputOwnership.js';
|
||||
import { createInteractionSession } from '../director/interactions/session.js';
|
||||
@@ -9,21 +8,19 @@ import { applicationPinia } from '../ui/vueRuntime.js';
|
||||
/**
|
||||
* Own the active shot's pick handler, accessible actions and plain-text
|
||||
* feedback. The Scene actions panel is presented to the scene interactions
|
||||
* store, which its view renders inside the viewer's container.
|
||||
* store, which its view renders inside the globe engine's container. A
|
||||
* feature is picked through engine.input (a click with its pick).
|
||||
*/
|
||||
// Keys each activation's panel, so a new one never reuses an old one's DOM.
|
||||
let activations = 0;
|
||||
|
||||
export function createSceneInteractions(
|
||||
viewer,
|
||||
{
|
||||
execute,
|
||||
engine = null,
|
||||
available = () => true,
|
||||
store = useSceneInteractionsStore(applicationPinia()),
|
||||
},
|
||||
) {
|
||||
let container = engine?.host?.container ?? viewer?.container;
|
||||
export function createSceneInteractions({
|
||||
execute,
|
||||
engine = null,
|
||||
available = () => true,
|
||||
store = useSceneInteractionsStore(applicationPinia()),
|
||||
}) {
|
||||
let container = engine?.host?.container;
|
||||
let panel = null,
|
||||
handler,
|
||||
items = [],
|
||||
@@ -79,7 +76,7 @@ export function createSceneInteractions(
|
||||
return ok;
|
||||
}
|
||||
function bindInput(owner) {
|
||||
if (!engine && !viewer) return;
|
||||
if (!engine) return;
|
||||
const click = (event) => {
|
||||
if (
|
||||
panel?.owner !== owner ||
|
||||
@@ -88,9 +85,7 @@ export function createSceneInteractions(
|
||||
!available()
|
||||
)
|
||||
return;
|
||||
const picked = engine
|
||||
? event.picked?.id
|
||||
: viewer.scene.pick(event.position)?.id;
|
||||
const picked = event.picked?.id;
|
||||
const matches = items.filter(
|
||||
(item) =>
|
||||
targets.get(
|
||||
@@ -108,32 +103,26 @@ export function createSceneInteractions(
|
||||
void nextTick(() => {
|
||||
if (panel?.owner !== owner || !shown()) return;
|
||||
const id = globalThis.CSS?.escape?.(matches[0].id) ?? matches[0].id;
|
||||
(engine?.host.container ?? viewer?.container)
|
||||
engine?.host.container
|
||||
?.querySelector?.(
|
||||
`[data-director-interactions] [data-director-action="${id}"]`,
|
||||
)
|
||||
?.focus({ preventScroll: true });
|
||||
});
|
||||
};
|
||||
if (engine) {
|
||||
handler = { destroy: engine.input.on('click', click, { pick: true }) };
|
||||
} else {
|
||||
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
handler.setInputAction(click, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
}
|
||||
handler = { destroy: engine.input.on('click', click, { pick: true }) };
|
||||
}
|
||||
return {
|
||||
clear,
|
||||
destroy: clear,
|
||||
getState: session.getState,
|
||||
setScene(nextViewer, nextEngine, registered) {
|
||||
setScene(nextEngine, registered) {
|
||||
handler?.destroy();
|
||||
handler = null;
|
||||
viewer = nextViewer;
|
||||
engine = nextEngine;
|
||||
if (registered) targets = registered;
|
||||
if (!panel || (!engine && !viewer)) return;
|
||||
container = engine?.host?.container ?? viewer?.container ?? container;
|
||||
if (!panel || !engine) return;
|
||||
container = engine.host?.container ?? container;
|
||||
update({ container });
|
||||
bindInput(panel.owner);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// src/scenes/interactionsView.test.mjs — the Scene actions panel renders in
|
||||
// the viewer's container from what the scene interactions owner presents.
|
||||
// the engine's container from what the scene interactions owner presents.
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
@@ -8,6 +8,7 @@ import { createPinia } from 'pinia';
|
||||
import { useSceneInteractionsStore } from '../ui/stores/sceneInteractions.js';
|
||||
import SceneInteractions from '../ui/views/panels/SceneInteractions.vue';
|
||||
import { createSceneInteractions } from './interactions.js';
|
||||
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
|
||||
|
||||
const target = (featureId) => ({ packId: 'qa', featureId });
|
||||
const key = (featureId) => JSON.stringify(['qa', featureId]);
|
||||
@@ -36,25 +37,25 @@ function fixture(t, { execute = async () => true } = {}) {
|
||||
const app = createApp(SceneInteractions).use(pinia);
|
||||
app.mount(document.body.appendChild(document.createElement('div')));
|
||||
const executed = [];
|
||||
const interactions = createSceneInteractions(
|
||||
{ container, scene: { canvas, pick: () => null } },
|
||||
{
|
||||
execute: (action, signal) => {
|
||||
executed.push(action.type);
|
||||
return execute(action, signal);
|
||||
},
|
||||
store: useSceneInteractionsStore(pinia),
|
||||
const engine = createFakeEngine({ container, canvas });
|
||||
const interactions = createSceneInteractions({
|
||||
engine,
|
||||
execute: (action, signal) => {
|
||||
executed.push(action.type);
|
||||
return execute(action, signal);
|
||||
},
|
||||
);
|
||||
store: useSceneInteractionsStore(pinia),
|
||||
});
|
||||
t.after(() => {
|
||||
interactions.destroy();
|
||||
app.unmount();
|
||||
engine.destroy();
|
||||
});
|
||||
const $ = (selector) => container.querySelector(selector);
|
||||
const settle = async () => {
|
||||
for (let flush = 0; flush < 4; flush += 1) await nextTick();
|
||||
};
|
||||
return { interactions, container, executed, $, settle, pinia };
|
||||
return { interactions, engine, container, executed, $, settle, pinia };
|
||||
}
|
||||
|
||||
test('a shot with actions shows its panel in the viewer container', async (t) => {
|
||||
@@ -175,11 +176,12 @@ test('a button reused before the next render still belongs to its own panel', as
|
||||
});
|
||||
|
||||
test("an earlier owner leaves a later owner's panel alone", async (t) => {
|
||||
const { interactions, container, $, settle, pinia } = fixture(t);
|
||||
const later = createSceneInteractions(
|
||||
{ container, scene: { canvas: $('canvas'), pick: () => null } },
|
||||
{ execute: async () => true, store: useSceneInteractionsStore(pinia) },
|
||||
);
|
||||
const { interactions, engine, $, settle, pinia } = fixture(t);
|
||||
const later = createSceneInteractions({
|
||||
engine,
|
||||
execute: async () => true,
|
||||
store: useSceneInteractionsStore(pinia),
|
||||
});
|
||||
t.after(() => later.destroy());
|
||||
interactions.activate(SHOT, new Map([[key('point'), {}]]));
|
||||
later.activate(SHOT, new Map([[key('point'), {}]]));
|
||||
@@ -190,3 +192,28 @@ test("an earlier owner leaves a later owner's panel alone", async (t) => {
|
||||
await settle();
|
||||
assert.equal(later.getState().selected, 'fly');
|
||||
});
|
||||
|
||||
test('a click on a feature of the shot outlines its actions through engine.input', async (t) => {
|
||||
const { interactions, engine, $, settle } = fixture(t);
|
||||
const feature = { kind: 'pack-feature' };
|
||||
interactions.activate(SHOT, new Map([[key('point'), feature]]));
|
||||
await settle();
|
||||
engine.fake.script('pick', { id: { kind: 'other' } });
|
||||
engine.fake.input('click', { position: { x: 10, y: 10 } });
|
||||
await settle();
|
||||
assert.deepEqual(interactions.getState().outlined ?? [], []);
|
||||
assert.equal(
|
||||
$('[data-director-action="card"]').style.outline,
|
||||
'',
|
||||
'another object selects nothing',
|
||||
);
|
||||
engine.fake.script('pick', { id: feature });
|
||||
engine.fake.input('click', { position: { x: 10, y: 10 } });
|
||||
await settle();
|
||||
assert.equal(
|
||||
$('[role=status]').textContent,
|
||||
'Selected feature: point. Choose an action.',
|
||||
);
|
||||
assert.ok($('[data-director-action="card"]').style.outline);
|
||||
assert.ok($('[data-director-action="fly"]').style.outline);
|
||||
});
|
||||
Reference in new issue
Block a user