mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Move geo import, voice capture, visual settings, scope mask and recent imagery onto the renderer ports
Geo import asks the frame port for renders, the camera port for moveEnd and the globe port's progress for the terrain queue running dry; its data sources are added, removed and shown by the listed geoImportPins module. Voice capture waits on the frame port's postRender. Visual settings toggle the infrared fog through the globe sky port, and the anime style dims the Milky Way through a sky getter it is given. The scope mask reads the camera height and listens on the frame and camera ports. Recent imagery picks the view centre, reads the view rectangle and the field of view through the query and camera ports. Installations claim camera sensitivity from their rendering module. The application shell loads the unbound globe factory.
This commit is contained in:
1 parent
b19fa56565
commit
81d8e3a4a7
20 files changed
+308
-119
No files matched your search
@@ -37,6 +37,7 @@ import { cameraOf, findCamera } from '../render/cesium/camera.js';
|
||||
// and asking the viewer's entities whether Cockpit's aircraft still draws,
|
||||
// keep this module on the Cesium allow-list.
|
||||
import '../render/cesium/effects.js';
|
||||
import '../render/cesium/globe.js';
|
||||
|
||||
import { aircraftTrackingTarget } from '../cockpitTracking.js';
|
||||
|
||||
|
||||
+34
-17
@@ -4,9 +4,20 @@ import {
|
||||
MAX_IMPORTED_FILES,
|
||||
loadGeoFile,
|
||||
} from '../data/geoFileImport.js';
|
||||
import { dataSourcePoints } from '../data/geoImportPins.js';
|
||||
import {
|
||||
addImportedSource,
|
||||
dataSourcePoints,
|
||||
removeImportedSource,
|
||||
showImportedSource,
|
||||
} from '../data/geoImportPins.js';
|
||||
import { formatNumber, t, tn, translateKnown } from '../i18n/index.js';
|
||||
import { flyToFootprint } from './flyToDataSource.js';
|
||||
import {
|
||||
canvasOf,
|
||||
findCamera,
|
||||
findFrame,
|
||||
findGlobe,
|
||||
} from '../render/rendererOf.js';
|
||||
|
||||
/** Fly to the whole footprint of one imported file's data source. */
|
||||
const flyToDataSource = (viewer, dataSource, options) =>
|
||||
@@ -73,7 +84,7 @@ export function initGeoFileImport({
|
||||
hint = text || '';
|
||||
present();
|
||||
};
|
||||
const render = () => viewer.scene?.requestRender?.();
|
||||
const render = () => findFrame(viewer)?.requestRender('geo-import');
|
||||
let groundTimer,
|
||||
groundQueued = false,
|
||||
groundAgain = false;
|
||||
@@ -114,14 +125,20 @@ export function initGeoFileImport({
|
||||
}, 200);
|
||||
};
|
||||
removeMapSource = subscribeMapSource?.(scheduleGround);
|
||||
const ownEvent = (event, listener) => {
|
||||
const remove = event?.addEventListener?.(listener);
|
||||
if (remove) groundRemovers.push(remove);
|
||||
};
|
||||
ownEvent(viewer.camera?.moveEnd, scheduleGround);
|
||||
ownEvent(viewer.scene?.globe?.tileLoadProgressEvent, (pending) => {
|
||||
if (!pending) scheduleGround();
|
||||
});
|
||||
const camera = findCamera(viewer);
|
||||
if (camera) groundRemovers.push(camera.on('moveEnd', scheduleGround));
|
||||
// Terrain tiles finishing loading: the queue running dry, once each time.
|
||||
let terrainPending = null;
|
||||
const globe = findGlobe(viewer);
|
||||
if (globe)
|
||||
groundRemovers.push(
|
||||
globe.on('progress', (progress) => {
|
||||
const pending = progress.terrainPending;
|
||||
if (pending === terrainPending) return;
|
||||
terrainPending = pending;
|
||||
if (!pending) scheduleGround();
|
||||
}),
|
||||
);
|
||||
|
||||
/** Publish the file list and hint; the view renders them. */
|
||||
function present() {
|
||||
@@ -171,7 +188,7 @@ export function initGeoFileImport({
|
||||
const item = find(id);
|
||||
if (!item) return false;
|
||||
item.visible = Boolean(visible);
|
||||
item.dataSource.show = item.visible;
|
||||
showImportedSource(item.dataSource, item.visible);
|
||||
if (item.visible) scheduleGround();
|
||||
present();
|
||||
render();
|
||||
@@ -219,7 +236,7 @@ export function initGeoFileImport({
|
||||
const at = imports.findIndex((item) => item.id === id);
|
||||
if (at < 0) return false;
|
||||
const [item] = imports.splice(at, 1);
|
||||
viewer.dataSources?.remove?.(item.dataSource, true);
|
||||
removeImportedSource(viewer, item.dataSource);
|
||||
item.revoke?.();
|
||||
present();
|
||||
render();
|
||||
@@ -298,9 +315,9 @@ export function initGeoFileImport({
|
||||
revoke: loaded.revoke,
|
||||
refreshGround: loaded.refreshGround,
|
||||
};
|
||||
await viewer.dataSources.add(item.dataSource);
|
||||
await addImportedSource(viewer, item.dataSource);
|
||||
if (destroyed) {
|
||||
viewer.dataSources.remove?.(item.dataSource, true);
|
||||
removeImportedSource(viewer, item.dataSource);
|
||||
item.revoke?.();
|
||||
break;
|
||||
}
|
||||
@@ -341,10 +358,10 @@ export function initGeoFileImport({
|
||||
const gesture = () => {
|
||||
cameraIntent += 1;
|
||||
};
|
||||
listen(viewer.scene?.canvas || container, 'pointerdown', gesture, {
|
||||
listen(canvasOf(viewer) || container, 'pointerdown', gesture, {
|
||||
passive: true,
|
||||
});
|
||||
listen(viewer.scene?.canvas || container, 'wheel', gesture, {
|
||||
listen(canvasOf(viewer) || container, 'wheel', gesture, {
|
||||
passive: true,
|
||||
});
|
||||
const hasFiles = (event) =>
|
||||
@@ -407,7 +424,7 @@ export function initGeoFileImport({
|
||||
clearTimeout(groundTimer);
|
||||
for (const remove of groundRemovers) remove();
|
||||
for (const item of imports.splice(0)) {
|
||||
viewer.dataSources?.remove?.(item.dataSource, true);
|
||||
removeImportedSource(viewer, item.dataSource);
|
||||
item.revoke?.();
|
||||
}
|
||||
for (const [target, type, listener, options] of listeners.splice(0))
|
||||
|
||||
@@ -9,6 +9,7 @@ import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { initGeoFileImport, summarize } from './geoFileImport.js';
|
||||
import { GeoImportError, MAX_IMPORTED_FILES } from '../data/geoFileImport.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
|
||||
class FakeClassList {
|
||||
constructor() {
|
||||
@@ -59,7 +60,13 @@ class FakeElement {
|
||||
}
|
||||
}
|
||||
|
||||
function setup({ load, navigation, flyToSource, subscribeMapSource } = {}) {
|
||||
function setup({
|
||||
load,
|
||||
navigation,
|
||||
flyToSource,
|
||||
subscribeMapSource,
|
||||
ports,
|
||||
} = {}) {
|
||||
const els = {
|
||||
'geo-import-button': new FakeElement('button', 'geo-import-button'),
|
||||
};
|
||||
@@ -90,6 +97,9 @@ function setup({ load, navigation, flyToSource, subscribeMapSource } = {}) {
|
||||
},
|
||||
flyTo: (target) => flights.push(target),
|
||||
};
|
||||
// The renderer's ports, when the test gives them, bound before the import
|
||||
// starts as the application binds its renderer.
|
||||
if (ports) bindRenderer(viewer, ports);
|
||||
const revoked = [];
|
||||
const loads = [];
|
||||
const defaultLoad = async (file, opts) => {
|
||||
@@ -471,6 +481,60 @@ test('ground refresh coalesces map changes and releases its subscription on tear
|
||||
assert.equal(unsubscribed, 1);
|
||||
});
|
||||
|
||||
test('the camera settling and the terrain queue running dry refresh the ground, through the ports', async () => {
|
||||
const listeners = { moveEnd: new Set(), progress: new Set() };
|
||||
const on = (name) => (event, cb) => {
|
||||
assert.equal(event, name);
|
||||
listeners[name].add(cb);
|
||||
return () => listeners[name].delete(cb);
|
||||
};
|
||||
const reasons = [];
|
||||
let refreshed = 0;
|
||||
const t = setup({
|
||||
ports: {
|
||||
camera: { on: on('moveEnd') },
|
||||
globe: { on: on('progress') },
|
||||
frame: { requestRender: (reason) => reasons.push(reason) },
|
||||
},
|
||||
load: async () => ({
|
||||
name: 'point.geojson',
|
||||
format: 'geojson',
|
||||
entityCount: 1,
|
||||
dataSource: {},
|
||||
refreshGround: async () => refreshed++,
|
||||
}),
|
||||
});
|
||||
const settle = () => new Promise((resolve) => setTimeout(resolve, 300));
|
||||
const progress = (terrainPending) => {
|
||||
for (const cb of [...listeners.progress])
|
||||
cb({ tilesPending: 0, imageryPending: 0, terrainPending });
|
||||
};
|
||||
await t.tool.importFiles([file('point.geojson')]);
|
||||
assert.ok(reasons.length > 0 && reasons.every((r) => r === 'geo-import'));
|
||||
for (const cb of [...listeners.moveEnd]) cb();
|
||||
await settle();
|
||||
assert.equal(refreshed, 1, 'the camera settling refreshes once');
|
||||
// The first report of an empty terrain queue counts, then only the queue
|
||||
// running dry again, once each time it does; progress that leaves the
|
||||
// terrain count where it was (imagery only) does not.
|
||||
progress(0);
|
||||
await settle();
|
||||
assert.equal(refreshed, 2);
|
||||
progress(0);
|
||||
await settle();
|
||||
assert.equal(refreshed, 2);
|
||||
progress(3);
|
||||
progress(1);
|
||||
await settle();
|
||||
assert.equal(refreshed, 2);
|
||||
progress(0);
|
||||
await settle();
|
||||
assert.equal(refreshed, 3);
|
||||
t.tool.destroy();
|
||||
assert.equal(listeners.moveEnd.size, 0);
|
||||
assert.equal(listeners.progress.size, 0);
|
||||
});
|
||||
|
||||
test('Fly to is an immediate navigation that Cockpit can refuse', async () => {
|
||||
const flown = [];
|
||||
const nav = navigationDouble({ immediate: false });
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
import { displayDay, displayMetres } from '../layers/recentImagery/display.js';
|
||||
import { formatQuantity } from './unitLabels.js';
|
||||
import { pointerOwnerName } from '../data/pointerOwnerNames.js';
|
||||
import { canvasOf, findGlobe } from '../render/rendererOf.js';
|
||||
import { canvasOf, findFrame, findGlobe } from '../render/rendererOf.js';
|
||||
|
||||
const PANEL_ID = 'recent-imagery-panel';
|
||||
const OVERVIEW_MIN_BOX_KM = 25;
|
||||
@@ -206,7 +206,7 @@ export function createRecentImageryPanel({
|
||||
fetchImpl = globalThis.fetch?.bind(globalThis),
|
||||
createObjectUrl = (blob) => URL.createObjectURL(blob),
|
||||
revokeObjectUrl = (url) => URL.revokeObjectURL(url),
|
||||
requestRender = () => viewer?.scene?.requestRender?.(),
|
||||
requestRender = () => findFrame(viewer)?.requestRender('recent-imagery'),
|
||||
} = {}) {
|
||||
const document = container?.ownerDocument;
|
||||
if (!document?.createElement || !layer) return null;
|
||||
|
||||
@@ -117,6 +117,19 @@ test('visual teardown restores owned fog and aircraft sensor state once', async
|
||||
});
|
||||
const calls = [];
|
||||
const viewer = { scene: { fog: { enabled: false } } };
|
||||
// The fog is the globe port's sky, which writes the scene's, as the
|
||||
// renderer's does.
|
||||
const { bindRenderer } = await import('../render/rendererOf.js');
|
||||
bindRenderer(viewer, {
|
||||
globe: {
|
||||
sky: {
|
||||
get: () => ({ fog: viewer.scene.fog.enabled }),
|
||||
set(settings) {
|
||||
if ('fog' in settings) viewer.scene.fog.enabled = settings.fog;
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const owner = new VisualSettings({
|
||||
viewer,
|
||||
elements: {},
|
||||
|
||||
@@ -40,13 +40,15 @@ export function styleDefinition(name, shader) {
|
||||
export class VisualEffects {
|
||||
/**
|
||||
* @param {object} options - The renderer's effects port (null: records
|
||||
* only), the viewer whose sky the anime style dims, render ownership
|
||||
* only), the viewer, a getter for the globe's sky port the anime
|
||||
* style dims (null: the sky is left alone), render ownership
|
||||
* callbacks and optional clocks. Construction is inert;
|
||||
* initStyles/initPostProcess retain startup ordering.
|
||||
*/
|
||||
constructor({
|
||||
effects = null,
|
||||
viewer,
|
||||
sky = null,
|
||||
requestRender,
|
||||
holdRender,
|
||||
releaseRender,
|
||||
@@ -56,6 +58,7 @@ export class VisualEffects {
|
||||
}) {
|
||||
this.effects = effects;
|
||||
this.viewer = viewer;
|
||||
this.sky = sky;
|
||||
this.requestRender = requestRender;
|
||||
this.holdRender = holdRender;
|
||||
this.releaseRender = releaseRender;
|
||||
@@ -164,11 +167,7 @@ export class VisualEffects {
|
||||
stage.enabled = value > OFF;
|
||||
// Anime's bands turn the faint Milky Way into blotches, and depth cannot
|
||||
// tell the sky from far geometry, so the glow fades with the style.
|
||||
if (
|
||||
stage === this.stages.anime &&
|
||||
this.viewer?.scene?.skyBox?.milkyWayVisibility !== undefined
|
||||
)
|
||||
this.viewer.scene.skyBox.milkyWayVisibility = 1 - value;
|
||||
if (stage === this.stages.anime) this.sky?.()?.set({ milkyWay: 1 - value });
|
||||
this.requestRender('style-stage');
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import test from 'node:test';
|
||||
import { VisualEffects } from './visualEffects.js';
|
||||
import { createCesiumEffects } from '../render/cesium/effects.js';
|
||||
import { styleStagesOf } from '../styles/styleStages.js';
|
||||
import { createCesiumGlobe } from '../render/cesium/globe.js';
|
||||
import { MILKY_WAY_INTENSITY, StarrySky } from '../sky/starrySky.js';
|
||||
import {
|
||||
GLOBAL_POST_DEFAULTS,
|
||||
@@ -63,9 +64,16 @@ function fixture() {
|
||||
},
|
||||
createStage: (options) => ({ ...options, enabled: true }),
|
||||
});
|
||||
// The sky the anime style dims is the globe port's, over the scene.
|
||||
const viewer = { scene };
|
||||
const globe = createCesiumGlobe(viewer, {
|
||||
capabilities: new Set(),
|
||||
requestRender() {},
|
||||
}).port;
|
||||
const effects = new VisualEffects({
|
||||
effects: renderer.port,
|
||||
viewer: { scene },
|
||||
viewer,
|
||||
sky: () => globe.sky,
|
||||
requestRender: (reason) => requests.push(reason),
|
||||
holdRender: (reason) => holds.add(reason),
|
||||
releaseRender: (reason) => holds.delete(reason),
|
||||
|
||||
+17
-10
@@ -5,7 +5,12 @@ import { useDisplayStore } from './stores/display.js';
|
||||
import { applicationPinia } from './vueRuntime.js';
|
||||
import { onLocaleChange, t } from '../i18n/index.js';
|
||||
import { UiLifetime } from './uiLifetime.js';
|
||||
import { findEffects, releaseUnboundEffects } from '../render/rendererOf.js';
|
||||
import {
|
||||
findEffects,
|
||||
findFrame,
|
||||
findGlobe,
|
||||
releaseUnboundEffects,
|
||||
} from '../render/rendererOf.js';
|
||||
import {
|
||||
VisualEffects,
|
||||
STYLES,
|
||||
@@ -198,6 +203,7 @@ export class VisualSettings {
|
||||
this._visualEffects = new VisualEffects({
|
||||
effects: findEffects(viewer),
|
||||
viewer,
|
||||
sky: () => findGlobe(viewer)?.sky,
|
||||
requestRender: services.governorRequestRender,
|
||||
holdRender: services.holdContinuousRender,
|
||||
releaseRender: services.releaseContinuousRender,
|
||||
@@ -424,17 +430,17 @@ export class VisualSettings {
|
||||
// (owner cockpit-FLIR field rounds, 2026-08-16). IR sensors see through
|
||||
// haze, so the boost styles simply turn fog off; the prior state restores
|
||||
// on exit. Transition-guarded so repeated syncs don't clobber the saved value.
|
||||
const scene = this.viewer?.scene;
|
||||
if (scene?.fog && irBoost !== this._irBoostActive) {
|
||||
// The globe's sky draws the fog; setting it asks for a frame.
|
||||
const sky = findGlobe(this.viewer)?.sky;
|
||||
if (sky && irBoost !== this._irBoostActive) {
|
||||
this._irBoostActive = irBoost;
|
||||
if (irBoost) {
|
||||
this._irFogWasEnabled = scene.fog.enabled;
|
||||
scene.fog.enabled = false;
|
||||
this._irFogWasEnabled = sky.get().fog;
|
||||
sky.set({ fog: false });
|
||||
} else if (this._irFogWasEnabled != null) {
|
||||
scene.fog.enabled = this._irFogWasEnabled;
|
||||
sky.set({ fog: this._irFogWasEnabled });
|
||||
this._irFogWasEnabled = null;
|
||||
}
|
||||
scene.requestRender?.();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,7 +629,7 @@ export class VisualSettings {
|
||||
fadeRatio: this._detectionFadePct / 100,
|
||||
outsideOpacity: this._detectionOutsidePct / 100,
|
||||
});
|
||||
this.viewer.scene.requestRender?.();
|
||||
findFrame(this.viewer)?.requestRender('detection-tuning');
|
||||
}
|
||||
|
||||
_setDetectionAllocation(strategy, { syncShare = true, persist = true } = {}) {
|
||||
@@ -1610,8 +1616,9 @@ export class VisualSettings {
|
||||
}
|
||||
releaseIrBoost() {
|
||||
if (!this._irBoostActive) return;
|
||||
if (this._irFogWasEnabled != null && this.viewer?.scene?.fog)
|
||||
this.viewer.scene.fog.enabled = this._irFogWasEnabled;
|
||||
const sky = findGlobe(this.viewer)?.sky;
|
||||
if (this._irFogWasEnabled != null && sky)
|
||||
sky.set({ fog: this._irFogWasEnabled });
|
||||
this._dataManager?.setLayerParams('flights', { irBoost: false });
|
||||
this._dataManager?.setLayerParams('military', { irBoost: false });
|
||||
this._irBoostActive = false;
|
||||
|
||||
Reference in new issue
Block a user