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:
German Khokhlov committed 2026-11-07 08:46:30 +04:00
1 parent 406dd9122e
commit f1ec9d4a22
61 files changed
+823 -1230

No files matched your search

+4 -4
View File
@@ -13,11 +13,11 @@ import {
} from './layers/renderers.js';
import {
governorRequestRender,
installRenderGovernor,
installEngineRenderGovernor,
uninstallRenderGovernor,
} from '../renderGovernor.js';
import { attachSessionVoice } from './sessionVoice.js';
import { initNavaraImageryBoxTool } from '../ui/imageryBoxNavara.js';
import { initImageryBoxTool } from '../ui/imageryBoxTool.js';
import {
attachNavaraAnnotations,
attachNavaraDraw,
@@ -368,7 +368,7 @@ export function attachViewerlessTools(
});
const recentImagery = dataManager.layers.get('recent-imagery')?.module;
if (recentImagery) {
const tool = initNavaraImageryBoxTool({
const tool = initImageryBoxTool({
engine,
onBox: (box) => recentImagery.setBox(box),
onPreview: (box) => recentImagery.setBoxPreview(box),
@@ -397,7 +397,7 @@ export function attachViewerlessTools(
}
// Holds drive engine.render.setContinuous; requests go to the engine. A
// parked engine uninstalls it (createNavaraScene suspend).
installRenderGovernor(engine);
installEngineRenderGovernor(engine);
const syncVisibility = () => {
if (document.hidden && !isEmbeddedInline()) return;
data.presentation.flushVisible();
+2 -2
View File
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
import { createApplicationScene } from './scene.js';
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
import {
installRenderGovernor,
installEngineRenderGovernor,
isRenderGovernorInstalled,
} from '../renderGovernor.js';
@@ -164,7 +164,7 @@ test('the Navara scene tears down the controller, then the globe', async (t) =>
const run = await startScene();
// The tools install the governor on the engine (src/app/tools.js); the
// scene removes it before the engine goes.
installRenderGovernor(run.engine);
installEngineRenderGovernor(run.engine);
const view = globalThis.window;
await run.teardown();
assert.equal(run.globeDestroyed(), 1);
+4 -3
View File
@@ -275,7 +275,7 @@ function attachViewerTools(
resolver: operations.annotationResolver,
defer,
});
annotations.attachScene({ viewer, tileset });
annotations.attachScene({ viewer, engine, tileset });
defer(() => annotations.detachScene());
// UTILITIES ▸ Draw on this viewer (src/app/sessionTools.js): the tool
// claims this viewer's pointer while a sketch is open.
@@ -285,7 +285,7 @@ function attachViewerTools(
styleManager,
defer,
});
drawTool?.attachScene({ viewer, navigation: styleManager });
drawTool?.attachScene({ viewer, engine, navigation: styleManager });
defer(() => drawTool?.detachScene());
// UTILITIES ▸ Import on this viewer: the next Cesium viewer reads the
// session's files again. The drop listeners belong to this viewer.
@@ -309,8 +309,9 @@ function attachViewerTools(
if (recentImagery) {
recentImagery.attachTileset(tileset);
const imageryBoxTool = initImageryBoxTool({
viewer,
engine,
onBox: (box) => recentImagery.setBox(box),
onPreview: (box) => recentImagery.setBoxPreview(box),
onCancel: (reason, message, box) => {
if (message) recentImagery.reportBoxRefusal(message, box);
},
+10
View File
@@ -6,6 +6,16 @@ import {
globeOutOfFrame,
} from '../globeInView.js';
// Dev convenience: expose the app's Cesium instance for console/preview probing
// (single shared module instance — avoids dual-Cesium state bugs when testing).
// A getter, because the production build's Cesium global loads only with the
// first Cesium globe.
if (typeof window !== 'undefined' && !('__CESIUM__' in window))
Object.defineProperty(window, '__CESIUM__', {
configurable: true,
get: () => Cesium,
});
const PINCH_ZOOM_MULTIPLIER = 8;
const MAX_PINCH_PIXEL_DELTA = 120;