mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
The voice runner drives the globe engine (an `engine` option, by default the one registered for the viewer) instead of the Cesium viewer: track_entity, stop_tracking (camera.following().stop()), frame_overhead (camera.flyToSphere with the pose heading), fly_to_location, zoom_to_globe (follow released through camera.following()), adjust_camera_zoom, next_iss_pass / next_satellite_pass, select_nearest_aircraft and the analyst view context, get_current_view_state, get_entity_context (projector.worldToWindow), the view target (picker.pickPosition, then camera.pickEllipsoid, then picker.pickGlobe) and its moveEnd prewarm, and the viewport samples. getBasemapLabelContext takes the engine or a viewer with a registered engine (the HUD). Without a viewer the tools that still need one (VIEWER_ONLY_ACTIONS: control_scene, annotate_map, clear_annotations, fly_route, move_camera, control_cockpit, set_context_mode, control_radio, control_cctv) answer a structured refusal (code UNAVAILABLE_ON_ENGINE) instead of throwing. Point-and-ask picks with engine.picker and keys the camera pose from engine.camera.pose(); the viewport capture reads engine.host.canvas and waits for the engine's postRender (both engines keep their drawing buffer: Cesium's contextOptions, Navara's own WebGL2 canvas, S4). Tests: gevActionsEngine.test.mjs runs each moved action on the fake engine. gevActions.test.mjs keeps its expectations; its runner helper now registers an engine for the test viewer (the Cesium engine over it, or a fake engine at its positionCartographic) and the two harness cameras gain roll and frustum for camera.pose().
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
import * as geo from '../geo/index.js';
|
|
import { resolvePickedContext } from '../data/pickedContext.js';
|
|
import { cameraPoseKey } from './pointerContext.js';
|
|
import * as defaultAnnotationResolver from '../annotations/annotationResolver.js';
|
|
|
|
/** "Around here" radius as a share of camera height, clamped to sane bounds. */
|
|
export function pointerRadiusKm(cameraHeightM) {
|
|
const heightKm = Number(cameraHeightM) / 1000;
|
|
if (!Number.isFinite(heightKm) || heightKm <= 0) return 50;
|
|
return Math.round(Math.min(400, Math.max(5, heightKm * 0.75)));
|
|
}
|
|
|
|
/**
|
|
* The globe side of point-and-ask: one object pick (engine.picker.pick) and
|
|
* one depth-aware world pick at canvas CSS pixels, on either engine. Called
|
|
* lazily by the pointer tracker (dwell and snapshot only), never per mouse
|
|
* move.
|
|
* @param {object} options
|
|
* @param {object} options.engine The globe engine.
|
|
* @param {object} [options.dataManager] Layer lifecycle.
|
|
* @param {Function} [options.pickWorldFromScreen] Normalized-pixel world pick.
|
|
* @returns {(x: number, y: number) => {entity: object|null, ground: object|null, radiusKm: number}|null}
|
|
*/
|
|
export function createPointerPicker({
|
|
engine,
|
|
dataManager = null,
|
|
pickWorldFromScreen = defaultAnnotationResolver.pickWorldFromScreen,
|
|
}) {
|
|
return function pickPointer(x, y) {
|
|
if (!engine || engine.isDestroyed?.()) return null;
|
|
const { width, height } = engine.host.size();
|
|
if (!width || !height) return null;
|
|
let picked = null;
|
|
try {
|
|
picked = engine.picker.pick(geo.cartesian2.create(x, y)) ?? null;
|
|
} catch {
|
|
picked = null;
|
|
}
|
|
const entity = resolvePickedContext(picked, { dataManager });
|
|
let ground = null;
|
|
try {
|
|
const hit = pickWorldFromScreen(engine, x / width, y / height);
|
|
if (hit && Number.isFinite(hit.lat) && Number.isFinite(hit.lon))
|
|
ground = {
|
|
lat: hit.lat,
|
|
lon: hit.lon,
|
|
heightM: Number.isFinite(hit.height) ? Math.round(hit.height) : null,
|
|
};
|
|
} catch {
|
|
ground = null;
|
|
}
|
|
return {
|
|
entity,
|
|
ground,
|
|
radiusKm: pointerRadiusKm(engine.camera.height()),
|
|
cameraKey: cameraPoseKey(engine),
|
|
};
|
|
};
|
|
}
|