mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Draw the aircraft family, Wildlife Sightings and the Cockpit through the contract
The layers that still had one Cesium and one Navara implementation, or
drew on Cesium only, now draw through engine.movers, engine.lines and
engine.camera on both engines, and application code holds the engine
instead of guessing it from a viewer.
- Aircraft family: flights, military and local ADS-B share one display
(src/layers/aircraft/render/display.js). The Cesium and Navara
renderers are gone. Where they differed, the display follows Cesium:
- attach and visibility tracking, live disableDepthTestDistance
changes, the tracked glyph's distance scale, model ids that change,
local ADS-B markers hidden until shown and its UAT ring as a point;
- the trail head's hidden alpha is 0.45, the contract's
depthFailAlpha scaled by the head's 0.9.
The tracked glyph stays over the fleet, as on Navara. The movers
contract reports readiness per model and reads model axes as the
glTF's own on every engine. Cesium's follow takes any native target
through a proxy entity in the ENU frame and mirrors its readout fields.
- Wildlife Sightings draws badges and the density glow as sprite sets
and its privacy cells as line outlines (no fill yet). It takes clicks
from engine.input and its card anchors to the engine's canvas and
camera, so the layer is in both engines' catalogs again and a switch
keeps the session's layer set.
- Cockpit: cockpitHost takes the engine only. The ridden aircraft is the
engine follow's target, hidden through its sprite; only the Cesium
Viewer's stock double-click is still routed around.
- About forty camera, navigation, share-link, HUD, voice, detection and
layer-lifecycle callers take the engine. isGlobeEngine and
engineFromViewer calls outside src/globe fall from 51 to 14.
The coupling baseline drops accordingly: layer renderer lines from
5239/12331 to 4546/11106 (Cesium/Navara), `viewer` lines from 2424 to
2209, Cesium-importing files from 69 to 66.
This commit is contained in:
1 parent
48988015f1
commit
35e70ec280
145 files changed
+4716
-4212
No files matched your search
@@ -1,18 +1,12 @@
|
||||
import * as geo from '../geo/index.js';
|
||||
import { isPickedWorldPosition } from '../data/scenePick.js';
|
||||
import { isGlobeEngine } from '../globe/contract.js';
|
||||
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
// The camera is the globe engine's, and so is the follow: the followed
|
||||
// entity is engine.camera.following().native (on Cesium also an entity the
|
||||
// app put on viewer.trackedEntity). The viewer, when there is one, is read
|
||||
// only for its clock, and for its tracked entity when the engine reports no
|
||||
// follow: callers pass an engine and that viewer, or a viewer whose engine
|
||||
// is registered (engineFromViewer).
|
||||
const engineOf = (target) => engineFromViewer(target);
|
||||
const trackerOf = (target, tracker) =>
|
||||
tracker ?? (target && !isGlobeEngine(target) ? target : null);
|
||||
// app put on viewer.trackedEntity). The viewer, when callers pass one, is
|
||||
// read only for its clock, and for its tracked entity when the engine
|
||||
// reports no follow.
|
||||
|
||||
// Cesium's EasingFunction.CUBIC_IN_OUT (tween.js Cubic.InOut).
|
||||
function cubicInOut(amount) {
|
||||
@@ -57,11 +51,9 @@ function normalizedHeading(heading) {
|
||||
|
||||
/**
|
||||
* Return the world position under the center of the canvas, when available.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
*/
|
||||
export function pickViewTarget(target) {
|
||||
const engine = engineOf(target);
|
||||
export function pickViewTarget(engine) {
|
||||
if (!engine) return null;
|
||||
const { width, height } = engine.host.size();
|
||||
if (!width || !height) return null;
|
||||
@@ -92,15 +84,12 @@ export function pickViewTarget(target) {
|
||||
|
||||
/**
|
||||
* Describe the camera as an orbit around the current viewport center.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {object} [tracker] The viewer whose tracked entity is the orbit
|
||||
* target (defaults to `target` when that is a viewer).
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
* @param {object | null} [viewer] The Cesium viewer whose tracked entity is
|
||||
* the orbit target.
|
||||
*/
|
||||
export function readCameraTargetFrame(target, tracker) {
|
||||
const engine = engineOf(target);
|
||||
export function readCameraTargetFrame(engine, viewer = null) {
|
||||
if (!engine) return null;
|
||||
const viewer = trackerOf(target, tracker);
|
||||
const entity = followedEntity(engine, viewer);
|
||||
const follow = engineFollow(engine, viewer);
|
||||
const center = entity
|
||||
@@ -137,15 +126,12 @@ export function readCameraTargetFrame(target, tracker) {
|
||||
|
||||
/**
|
||||
* Apply an orbit frame, then return the camera to the fixed-world frame.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
* @param {object} frame From {@link readCameraTargetFrame}.
|
||||
* @param {object} [tracker] As in readCameraTargetFrame.
|
||||
* @param {object | null} [viewer] As in readCameraTargetFrame.
|
||||
*/
|
||||
function setCameraTargetFrame(target, frame, tracker) {
|
||||
const engine = engineOf(target);
|
||||
function setCameraTargetFrame(engine, frame, viewer = null) {
|
||||
if (!engine || !frame?.target || !Number.isFinite(frame.range)) return false;
|
||||
const viewer = trackerOf(target, tracker);
|
||||
const { camera } = engine;
|
||||
// Inside an engine's own follow: the new frame is the follow's offset (a
|
||||
// camera command would end the follow; Cesium's tracked entity keeps its
|
||||
@@ -211,21 +197,21 @@ function frameIsTilted(frame) {
|
||||
}
|
||||
|
||||
/** Toggle between a straight-down map and a useful oblique map angle. */
|
||||
export function toggleCameraTilt(target, tracker) {
|
||||
const frame = readCameraTargetFrame(target, tracker);
|
||||
export function toggleCameraTilt(engine, viewer = null) {
|
||||
const frame = readCameraTargetFrame(engine, viewer);
|
||||
if (!frame) return false;
|
||||
const tilted = frameIsTilted(frame);
|
||||
const pitch = tilted ? STRAIGHT_DOWN_PITCH : OBLIQUE_PITCH;
|
||||
return setCameraTargetFrame(target, { ...frame, pitch }, tracker)
|
||||
return setCameraTargetFrame(engine, { ...frame, pitch }, viewer)
|
||||
? { tilted: !tilted, pitch }
|
||||
: false;
|
||||
}
|
||||
|
||||
/** Rotate around the viewport center until north is at the top. */
|
||||
export function resetCameraNorth(target, tracker) {
|
||||
const frame = readCameraTargetFrame(target, tracker);
|
||||
export function resetCameraNorth(engine, viewer = null) {
|
||||
const frame = readCameraTargetFrame(engine, viewer);
|
||||
if (!frame) return false;
|
||||
return setCameraTargetFrame(target, { ...frame, heading: 0 }, tracker);
|
||||
return setCameraTargetFrame(engine, { ...frame, heading: 0 }, viewer);
|
||||
}
|
||||
|
||||
function headingDegrees(engine) {
|
||||
@@ -234,17 +220,15 @@ function headingDegrees(engine) {
|
||||
|
||||
/**
|
||||
* Ease an orbit without handing off the entity that owns the follow camera.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
* @param {{ now?: () => number, duration?: number, tracker?: object }} [options]
|
||||
* `tracker` as in readCameraTargetFrame.
|
||||
* `tracker`: the viewer, as in readCameraTargetFrame.
|
||||
*/
|
||||
export function createCameraOrientationAnimator(
|
||||
target,
|
||||
{ now = () => performance.now(), duration = 650, tracker } = {},
|
||||
engine,
|
||||
{ now = () => performance.now(), duration = 650, tracker = null } = {},
|
||||
) {
|
||||
const engine = engineOf(target);
|
||||
const viewer = trackerOf(target, tracker);
|
||||
const viewer = tracker;
|
||||
let remove = null;
|
||||
let pending = null;
|
||||
const cancel = () => {
|
||||
@@ -310,12 +294,11 @@ export function createCameraOrientationAnimator(
|
||||
* runNavigation: Function,
|
||||
* showToast?: Function,
|
||||
* animationMs?: number,
|
||||
* }} options `engine` defaults to the one registered for `viewer`; the viewer
|
||||
* is otherwise only read for its clock and tracked entity.
|
||||
* }} options The viewer is only read for its clock and tracked entity.
|
||||
*/
|
||||
export function bindCameraOrientationControls({
|
||||
viewer = null,
|
||||
engine = engineOf(viewer),
|
||||
engine = null,
|
||||
publish,
|
||||
runNavigation,
|
||||
showToast,
|
||||
|
||||
Reference in new issue
Block a user