mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52: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
+21
-14
@@ -67,15 +67,17 @@ const PREVIEW = DRAW_COLOR_CSS;
|
||||
* through the actions it gives `connect`, which returns their disconnect.
|
||||
* A row's fly-to is an immediate navigation through `navigation`, like
|
||||
* Import's, so Cockpit can refuse it and a running orbit or follow lets go.
|
||||
* The globe it draws on is a Cesium `viewer` or a draw `surface` factory
|
||||
* (`surface({ session, cursor })`: the input and preview of a globe without
|
||||
* a viewer, src/annotations/drawInputNavara.js), which gets the open shape
|
||||
* and the rubber band's end as live getters.
|
||||
* @param {{viewer?: Cesium.Viewer, surface?: Function, annotations: {annotate: Function, clear: Function}, navigation?: object, publish?: Function, connect?: Function}} deps
|
||||
* The globe it draws on is a Cesium `viewer` (with its `engine`, which
|
||||
* answers the picks) or a draw `surface` factory (`surface({ session,
|
||||
* cursor })`: the input and preview of a globe without a viewer,
|
||||
* src/annotations/drawInputNavara.js), which gets the open shape and the
|
||||
* rubber band's end as live getters.
|
||||
* @param {{viewer?: Cesium.Viewer, engine?: object, surface?: Function, annotations: {annotate: Function, clear: Function}, navigation?: object, publish?: Function, connect?: Function}} deps
|
||||
* @returns {{destroy: Function}|null}
|
||||
*/
|
||||
export function initDrawTool({
|
||||
viewer = null,
|
||||
engine = null,
|
||||
surface: makeSurface = null,
|
||||
annotations,
|
||||
navigation = null,
|
||||
@@ -119,7 +121,7 @@ export function initDrawTool({
|
||||
const live = { session: () => session, cursor: () => cursor };
|
||||
const surface = makeSurface
|
||||
? makeSurface(live)
|
||||
: cesiumDrawSurface(viewer, live);
|
||||
: cesiumDrawSurface(viewer, engine, live);
|
||||
|
||||
const present = () =>
|
||||
publish({
|
||||
@@ -485,7 +487,7 @@ export function initDrawTool({
|
||||
* click actions on its own handler (select, track); they are borrowed while a
|
||||
* sketch is open and given back on the way out.
|
||||
*/
|
||||
function cesiumDrawSurface(viewer, live) {
|
||||
function cesiumDrawSurface(viewer, engine, live) {
|
||||
const previewEntities = [];
|
||||
const dataSource = new Cesium.CustomDataSource(PREVIEW_DATA_SOURCE_NAME);
|
||||
// `add()` resolves on the NEXT tick, so an init-then-immediate-destroy would
|
||||
@@ -526,12 +528,15 @@ function cesiumDrawSurface(viewer, live) {
|
||||
});
|
||||
return {
|
||||
canvas: viewer.scene.canvas,
|
||||
/** The world point under a canvas position, or null. */
|
||||
/** The world point under a canvas position (the engine's picks), or null. */
|
||||
pick(position) {
|
||||
const canvas = viewer.scene.canvas;
|
||||
const w = canvas.clientWidth || canvas.width || 1;
|
||||
const h = canvas.clientHeight || canvas.height || 1;
|
||||
return pickWorldFromScreen(viewer, position.x / w, position.y / h);
|
||||
if (!engine) return null;
|
||||
const { width, height } = engine.host.size();
|
||||
return pickWorldFromScreen(
|
||||
engine,
|
||||
position.x / (width || 1),
|
||||
position.y / (height || 1),
|
||||
);
|
||||
},
|
||||
/** Show the open shape (null: none) in `color`. */
|
||||
sync(session, color) {
|
||||
@@ -657,8 +662,8 @@ function cesiumDrawSurface(viewer, live) {
|
||||
* The Draw control for the page session. The marks live on the annotation
|
||||
* board and the chosen shape and colour here; the drawing tool itself (its
|
||||
* preview, click handler and Escape/Enter keys) belongs to the attached
|
||||
* globe. `attachScene({ viewer, navigation })` starts the tool on a Cesium
|
||||
* viewer, `attachScene({ surface, navigation })` on a globe without one
|
||||
* globe. `attachScene({ viewer, engine, navigation })` starts the tool on
|
||||
* a Cesium viewer, `attachScene({ surface, navigation })` on a globe without one
|
||||
* (Navara: src/annotations/drawInputNavara.js), with the shape and colour
|
||||
* last chosen; `detachScene()` ends it, an open shape included. Without a
|
||||
* globe the controls answer nothing. Same handle as initDrawTool's
|
||||
@@ -731,6 +736,7 @@ export function createSessionDrawTool({
|
||||
whenSettled: () => inner?.whenSettled() ?? settled,
|
||||
attachScene({
|
||||
viewer = null,
|
||||
engine = null,
|
||||
surface = null,
|
||||
navigation: next = navigation,
|
||||
} = {}) {
|
||||
@@ -740,6 +746,7 @@ export function createSessionDrawTool({
|
||||
if (!viewer && !surface) return;
|
||||
inner = initDrawTool({
|
||||
viewer,
|
||||
engine,
|
||||
surface,
|
||||
annotations,
|
||||
navigation,
|
||||
|
||||
Reference in new issue
Block a user