mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Read the navigation and point-and-ask camera through the renderer's ports
The navigation controller and the location navigation cancel flights and read the camera's place through the camera port. Point-and-ask's camera pose key and its "around here" radius read the camera port's pose; its entity pick moves into the input dispatcher (pickAt), which picks as a click does, so the follow's helper still reads as its target. navigationController, locationNavigation and pointerPick leave the Cesium allow-list. Their package entries (./ui/navigation and three voice entries) no longer load the Cesium adapter: given a viewer of a caller's own, they find its camera once the caller loads ./render/cesium/unbound. They are listed as such in the unbound camera test, which fails if one starts loading the factory again.
This commit is contained in:
1 parent
3484bfa56d
commit
a2c4d27b5a
9 files changed
+92
-35
No files matched your search
@@ -2972,6 +2972,7 @@
|
||||
"src/voice/narration.js",
|
||||
"src/voice/earcon.js",
|
||||
"src/voice/pointerContext.js",
|
||||
"src/render/rendererOf.js",
|
||||
"src/voice/pointerReticle.js",
|
||||
"src/i18n/index.js",
|
||||
"src/i18n/locale.js",
|
||||
|
||||
@@ -137,6 +137,29 @@ const dispatchers = new WeakMap();
|
||||
* @property {() => void} destroy
|
||||
*/
|
||||
|
||||
/**
|
||||
* What is under canvas CSS pixel `x, y` now, as a click would see it (a hit
|
||||
* on the follow's helper is a hit on its target), for a reader that is not
|
||||
* handed a click (point-and-ask). Null when nothing is there or the pick
|
||||
* fails.
|
||||
* @param {object} viewer
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @returns {object|null}
|
||||
*/
|
||||
export function pickAt(viewer, x, y) {
|
||||
try {
|
||||
if (!viewer || viewer.isDestroyed?.()) return null;
|
||||
const scene = viewer.scene;
|
||||
if (typeof scene?.pick !== 'function') return null;
|
||||
return (
|
||||
pickThroughFollowHelper(scene.pick(new Cesium.Cartesian2(x, y))) ?? null
|
||||
);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The scene's dispatcher, made on first use.
|
||||
* @param {object} viewer A Cesium viewer (or a test double with `scene`).
|
||||
|
||||
@@ -119,9 +119,6 @@
|
||||
"src/ui/cockpitController.js",
|
||||
"src/ui/flyToDataSource.js",
|
||||
"src/ui/imageryBoxTool.js",
|
||||
"src/ui/locationNavigation.js",
|
||||
"src/ui/navigationController.js",
|
||||
"src/ui/shareFollow.js",
|
||||
"src/voice/gevActions.js",
|
||||
"src/voice/pointerPick.js"
|
||||
"src/voice/gevActions.js"
|
||||
]
|
||||
@@ -86,6 +86,19 @@ const DRAW_FROM_CALLER = new Set([
|
||||
'./layers/air-quality',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Cesium-free entries that reach the camera port but draw nothing: given a
|
||||
* viewer with no renderer bound, they find no camera
|
||||
* (`findCamera` is null) and leave it alone until the caller loads
|
||||
* `./render/cesium/unbound`.
|
||||
*/
|
||||
const CAMERA_FROM_CALLER = new Set([
|
||||
'./ui/navigation',
|
||||
'./voice/commands',
|
||||
'./voice/controller',
|
||||
'./voice/realtime-session',
|
||||
]);
|
||||
|
||||
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
|
||||
/** The browser module an export resolves to, or null for Node-only ones. */
|
||||
@@ -196,6 +209,10 @@ test('every public entry that reaches the renderer bridge loads the unbound came
|
||||
const carrier = INJECTED[key];
|
||||
const loads = (file) => reachable(file, { eager: true }).has(FACTORY);
|
||||
if (DRAW_FROM_CALLER.has(key)) continue;
|
||||
if (CAMERA_FROM_CALLER.has(key)) {
|
||||
assert.ok(!loads(entry), `${key} loads the factory: unlist it`);
|
||||
continue;
|
||||
}
|
||||
if (!loads(entry) && !(carrier && loads(carrier))) missing.push(key);
|
||||
}
|
||||
assert.ok(bridged > 0, 'no entry reaches the bridge: the walk is broken');
|
||||
@@ -231,7 +248,11 @@ function checkLookupFactory(
|
||||
const entry = path.normalize(target.slice(2));
|
||||
if (![...reachable(entry)].some(calls)) continue;
|
||||
reaching += 1;
|
||||
if (fromCaller && DRAW_FROM_CALLER.has(key)) continue;
|
||||
if (
|
||||
fromCaller &&
|
||||
(DRAW_FROM_CALLER.has(key) || CAMERA_FROM_CALLER.has(key))
|
||||
)
|
||||
continue;
|
||||
const carrier = INJECTED[key];
|
||||
const loads = (file) => reachable(file, { eager: true }).has(factory);
|
||||
if (!loads(entry) && !(carrier && loads(carrier))) missing.push(key);
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
toggleCameraTilt,
|
||||
} from './cameraOrientationControls.js';
|
||||
import { NavigationController } from './navigationController.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { entityRecord } from '../data/entityRecords.js';
|
||||
|
||||
function createViewer({ cameraPosition, target, pickPosition = null } = {}) {
|
||||
@@ -600,10 +601,10 @@ test('orientation animation cancels on replacement and explicit cancellation', (
|
||||
test('orientation navigation preserves follow and selection; new navigation cancels animation', () => {
|
||||
const calls = [];
|
||||
const entity = {};
|
||||
const viewer = {
|
||||
trackedEntity: entity,
|
||||
const viewer = { trackedEntity: entity };
|
||||
bindRenderer(viewer, {
|
||||
camera: { cancelFlight: () => calls.push('cancel-flight') },
|
||||
};
|
||||
});
|
||||
let cockpit = false;
|
||||
const navigation = new NavigationController({
|
||||
viewer,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { findCamera } from '../render/cesium/camera.js';
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
import { stopFollowing } from '../data/followed.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { t } from '../i18n/index.js';
|
||||
import { createStateChannel } from '../app/stateChannel.js';
|
||||
import { LocationControls } from './location.js';
|
||||
@@ -387,15 +386,19 @@ export class LocationNavigation {
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
this._endWorldJumpTransition();
|
||||
const carto = this.viewer.camera.positionCartographic;
|
||||
const pose = findCamera(this.viewer)?.pose();
|
||||
const result = {
|
||||
ok: !cancelled,
|
||||
action: 'zoom_to_globe',
|
||||
cancelled,
|
||||
heightKm: Math.round(GLOBE_VIEW.heightM / 1000),
|
||||
centeredOn: {
|
||||
latitude: Number(Cesium.Math.toDegrees(carto.latitude).toFixed(2)),
|
||||
longitude: Number(Cesium.Math.toDegrees(carto.longitude).toFixed(2)),
|
||||
latitude: Number.isFinite(pose?.lat)
|
||||
? Number(pose.lat.toFixed(2))
|
||||
: null,
|
||||
longitude: Number.isFinite(pose?.lon)
|
||||
? Number(pose.lon.toFixed(2))
|
||||
: null,
|
||||
},
|
||||
};
|
||||
this._publishGlobeResetting?.(false);
|
||||
@@ -405,7 +408,7 @@ export class LocationNavigation {
|
||||
};
|
||||
this._cancelGlobeReset = () => finish(true);
|
||||
timer = window.setTimeout(() => {
|
||||
const height = this.viewer.camera.positionCartographic?.height;
|
||||
const height = findCamera(this.viewer)?.pose().height;
|
||||
finish(
|
||||
!Number.isFinite(height) ||
|
||||
Math.abs(height - GLOBE_VIEW.heightM) > 1000,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { findCamera } from '../render/cesium/camera.js';
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
import { stopFollowing } from '../data/followed.js';
|
||||
import { cancelCameraArrival } from '../data/cameraArrival.js';
|
||||
import { createStateChannel } from '../app/stateChannel.js';
|
||||
@@ -217,7 +217,7 @@ export class NavigationController {
|
||||
release: () => {
|
||||
this.interruptCameraMotion('camera-orientation');
|
||||
this.stopOrbit();
|
||||
this.viewer.camera.cancelFlight();
|
||||
findCamera(this.viewer)?.cancelFlight();
|
||||
},
|
||||
navigate,
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*
|
||||
* Provider-neutral and Cesium-free: the pick is injected.
|
||||
*/
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
|
||||
/** Movement below this many CSS pixels is still the same dwell. */
|
||||
const POINTER_DWELL_PX = 12;
|
||||
@@ -55,23 +56,28 @@ const finite = finiteOrNull;
|
||||
|
||||
/**
|
||||
* Camera pose identity: position to 1 m, orientation to about 0.06 degrees.
|
||||
* A pixel read under one key names nothing under another. Reads plain
|
||||
* numbers only, so it needs no Cesium import.
|
||||
* @param {object} viewer Cesium viewer.
|
||||
* A pixel read under one key names nothing under another. Reads the
|
||||
* camera port's pose.
|
||||
* @param {object} viewer The scene object.
|
||||
* @returns {string|null}
|
||||
*/
|
||||
export function cameraPoseKey(viewer) {
|
||||
const camera = viewer?.camera;
|
||||
const p = camera?.positionWC;
|
||||
let pose = null;
|
||||
try {
|
||||
pose = findCamera(viewer)?.pose() ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
const p = pose?.position;
|
||||
if (!p || !Number.isFinite(p.x)) return null;
|
||||
const angle = (value) => Math.round((Number(value) || 0) * 1000);
|
||||
return [
|
||||
Math.round(p.x),
|
||||
Math.round(p.y),
|
||||
Math.round(p.z),
|
||||
angle(camera.heading),
|
||||
angle(camera.pitch),
|
||||
angle(camera.roll),
|
||||
angle(pose.heading),
|
||||
angle(pose.pitch),
|
||||
angle(pose.roll),
|
||||
].join(',');
|
||||
}
|
||||
|
||||
|
||||
+16
-11
@@ -1,5 +1,5 @@
|
||||
import { pickThroughFollowHelper } from '../render/cesium/follow.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { pickAt as defaultPickAt } from '../input/dispatcher.js';
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
import { resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { cameraPoseKey } from './pointerContext.js';
|
||||
import * as defaultAnnotationResolver from '../annotations/annotationResolver.js';
|
||||
@@ -11,20 +11,30 @@ function pointerRadiusKm(cameraHeightM) {
|
||||
return Math.round(Math.min(400, Math.max(5, heightKm * 0.75)));
|
||||
}
|
||||
|
||||
function cameraHeightM(viewer) {
|
||||
try {
|
||||
return findCamera(viewer)?.pose().height;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Cesium side of point-and-ask: one entity pick and one depth-aware world
|
||||
* The scene side of point-and-ask: one entity pick and one depth-aware world
|
||||
* pick at canvas CSS pixels. Called lazily by the pointer tracker (dwell and
|
||||
* snapshot only), never per mouse move.
|
||||
* @param {object} options
|
||||
* @param {object} options.viewer Cesium viewer.
|
||||
* @param {object} options.viewer The scene object.
|
||||
* @param {object} [options.dataManager] Layer lifecycle.
|
||||
* @param {Function} [options.pickWorldFromScreen] Normalized-pixel world pick.
|
||||
* @param {Function} [options.pickAt] Entity pick at canvas CSS pixels.
|
||||
* @returns {(x: number, y: number) => {entity: object|null, ground: object|null, radiusKm: number}|null}
|
||||
*/
|
||||
export function createPointerPicker({
|
||||
viewer,
|
||||
dataManager = null,
|
||||
pickWorldFromScreen = defaultAnnotationResolver.pickWorldFromScreen,
|
||||
pickAt = defaultPickAt,
|
||||
}) {
|
||||
return function pickPointer(x, y) {
|
||||
const scene = viewer?.scene;
|
||||
@@ -33,12 +43,7 @@ export function createPointerPicker({
|
||||
const width = canvas.clientWidth || canvas.width || 0;
|
||||
const height = canvas.clientHeight || canvas.height || 0;
|
||||
if (!width || !height) return null;
|
||||
let picked = null;
|
||||
try {
|
||||
picked = pickThroughFollowHelper(scene.pick(new Cesium.Cartesian2(x, y)));
|
||||
} catch {
|
||||
picked = null;
|
||||
}
|
||||
const picked = pickAt(viewer, x, y);
|
||||
const entity = resolvePickedContext(picked, { dataManager });
|
||||
let ground = null;
|
||||
try {
|
||||
@@ -55,7 +60,7 @@ export function createPointerPicker({
|
||||
return {
|
||||
entity,
|
||||
ground,
|
||||
radiusKm: pointerRadiusKm(viewer.camera?.positionCartographic?.height),
|
||||
radiusKm: pointerRadiusKm(cameraHeightM(viewer)),
|
||||
cameraKey: cameraPoseKey(viewer),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user