mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +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,7 +1,8 @@
|
||||
// camera.follow on Cesium: the viewer's trackedEntity (Cesium's EntityView
|
||||
// owns the continuous follow, the user turns and zooms around the target).
|
||||
// With `native` the layer's own Entity is tracked; without it an internal
|
||||
// proxy Entity whose position is the caller's `position()`. Each follow gets
|
||||
// A `native` Entity is tracked itself; otherwise an internal proxy Entity
|
||||
// (ENU frame) whose position is the caller's `position()`, which shows a
|
||||
// non-Entity native's tracked-readout fields. Each follow gets
|
||||
// one exact tracked frame on preUpdate (applyTrackedCameraFrame) and the
|
||||
// zoom limits that keep the camera outside the minimum range.
|
||||
// following() also reports a trackedEntity the app set itself, and
|
||||
@@ -21,6 +22,15 @@ import { toCesium3 } from './convert.js';
|
||||
|
||||
const MAX_FRAME_ATTEMPTS = 120;
|
||||
const entityName = (entity) => (entity ? entity.name || entity.id : undefined);
|
||||
// What viewer.trackedEntity readers take from a tracked Entity, read through
|
||||
// a proxy from the layer's own handle.
|
||||
const READOUT_FIELDS = [
|
||||
'gevTrackedId',
|
||||
'gevLabelModel',
|
||||
'gevDisplayPosition',
|
||||
'gevVisualPosition',
|
||||
'gevSelectionOrigin',
|
||||
];
|
||||
const ZOOM_INERTIA_STATES = new WeakMap();
|
||||
|
||||
function acquireStableTrackedZoom(controller, owner, minRange) {
|
||||
@@ -257,7 +267,8 @@ export function createCesiumFollow(viewer, { commanded }) {
|
||||
|
||||
function start(state, options) {
|
||||
state.options = options;
|
||||
let entity = options.native;
|
||||
const { native } = options;
|
||||
let entity = native instanceof Cesium.Entity ? native : null;
|
||||
if (!entity) {
|
||||
const scratch = new Cesium.Cartesian3();
|
||||
entity = state.proxy = viewer.entities.add({
|
||||
@@ -273,6 +284,7 @@ export function createCesiumFollow(viewer, { commanded }) {
|
||||
: undefined;
|
||||
}, false),
|
||||
viewFrom: toCesium3(state.options.viewFrom()),
|
||||
trackingReferenceFrame: Cesium.TrackingReferenceFrame.ENU,
|
||||
// Cesium's EntityView moves the camera only once the tracked
|
||||
// entity has a bounding sphere: a 1 px transparent point gives it
|
||||
// one (an entity without graphics is framed once, then left).
|
||||
@@ -280,14 +292,24 @@ export function createCesiumFollow(viewer, { commanded }) {
|
||||
});
|
||||
// Picks skip it (picker.js).
|
||||
entity.gevFollowProxy = true;
|
||||
if (native)
|
||||
for (const field of READOUT_FIELDS)
|
||||
Object.defineProperty(entity, field, {
|
||||
get: () => native[field],
|
||||
set: (value) => {
|
||||
native[field] = value;
|
||||
},
|
||||
});
|
||||
}
|
||||
state.entity = entity;
|
||||
state.handle.native = options.native;
|
||||
state.handle.native = native;
|
||||
state.handle.label = options.label;
|
||||
viewer.camera.cancelFlight();
|
||||
viewer.trackedEntity = entity;
|
||||
const viewFrom =
|
||||
options.native?.viewFrom ?? toCesium3(state.options.viewFrom());
|
||||
entity === native && native.viewFrom
|
||||
? native.viewFrom
|
||||
: toCesium3(state.options.viewFrom());
|
||||
state.stopFrame =
|
||||
applyTrackedCameraFrame(viewer, entity, viewFrom, {
|
||||
minRange: options.minRange,
|
||||
|
||||
@@ -77,6 +77,38 @@ test('without native the follow tracks a proxy entity at position()', () => {
|
||||
assert.equal(viewer.trackedEntity, undefined);
|
||||
});
|
||||
|
||||
test('a native that is not an Entity is echoed and followed through an ENU proxy that shows its readout fields', () => {
|
||||
const { viewer, camera, frame } = setup();
|
||||
const native = {
|
||||
id: 'flights-tracked-1',
|
||||
gevTrackedId: 'flights:abc123',
|
||||
gevLabelModel: { title: 'DAL123' },
|
||||
gevDisplayPosition: () => TARGET,
|
||||
};
|
||||
const handle = camera.follow({
|
||||
native,
|
||||
position: () => TARGET,
|
||||
viewFrom: () => ({ x: 0, y: -500, z: 200 }),
|
||||
});
|
||||
const proxy = viewer.trackedEntity;
|
||||
assert.ok(proxy instanceof Cesium.Entity);
|
||||
assert.notEqual(proxy, native);
|
||||
assert.equal(handle.native, native);
|
||||
assert.equal(camera.following(), handle);
|
||||
assert.equal(proxy.trackingReferenceFrame, Cesium.TrackingReferenceFrame.ENU);
|
||||
assert.equal(proxy.gevTrackedId, 'flights:abc123');
|
||||
native.gevLabelModel = { title: 'DAL124' };
|
||||
assert.equal(proxy.gevLabelModel.title, 'DAL124', 'read through');
|
||||
assert.equal(proxy.gevDisplayPosition(), TARGET);
|
||||
frame();
|
||||
const [[, offset]] = viewer
|
||||
.callsOf('camera.lookAtTransform')
|
||||
.map((call) => call.args);
|
||||
assert.deepEqual([offset.x, offset.y, offset.z], [0, -500, 200]);
|
||||
handle.stop();
|
||||
assert.equal(viewer.entities.contains(proxy), false);
|
||||
});
|
||||
|
||||
test('a camera command or another tracked entity ends the follow', () => {
|
||||
const { viewer, camera, changes } = setup();
|
||||
const options = { position: () => TARGET, viewFrom: { x: 0, y: -500, z: 0 } };
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
// sprites are a BillboardCollection (screen-aligned, rotation in screen
|
||||
// space, an image per atlas cell cropped from the set's atlas), points a
|
||||
// PointPrimitiveCollection, models one Model per instance in a
|
||||
// PrimitiveCollection. commit() writes the changed instances and requests a
|
||||
// render; nothing else renders. Picks resolve through identify(): the
|
||||
// billboard, point or model a Cesium pick names → its set, instance and
|
||||
// the pickId the layer gave it.
|
||||
// PrimitiveCollection (the glTF's own axes, no axis correction, lit without
|
||||
// Cesium's dynamic environment map). commit() writes the changed instances
|
||||
// and requests a render; nothing else renders. Picks resolve through
|
||||
// identify(): the billboard, point or model a Cesium pick names → its set,
|
||||
// instance and the pickId the layer gave it.
|
||||
|
||||
import * as Cesium from 'cesium';
|
||||
import { horizonVisible } from '../cameraMath.js';
|
||||
@@ -246,6 +247,15 @@ function modelPart(options, store, { factories, requestRender, owners }) {
|
||||
factories
|
||||
.loadModel({
|
||||
url: model.url,
|
||||
// Resources built at once, not spread over frames behind tile jobs.
|
||||
asynchronous: false,
|
||||
// The instance orientation turns the glTF's own axes (the contract's
|
||||
// model frame), as Navara draws them.
|
||||
upAxis: Cesium.Axis.Z,
|
||||
forwardAxis: Cesium.Axis.X,
|
||||
// Navara has no environment map; Cesium's renders the sky around
|
||||
// each model and reads it back from the GPU.
|
||||
environmentMapOptions: { enabled: false },
|
||||
minimumPixelSize: model.minimumPixelSize,
|
||||
...modelBlend(model.colorBlend),
|
||||
allowPicking: pickable,
|
||||
@@ -274,10 +284,12 @@ function modelPart(options, store, { factories, requestRender, owners }) {
|
||||
};
|
||||
return {
|
||||
primitive: collection,
|
||||
// Every drawn instance's model has loaded.
|
||||
ready() {
|
||||
for (let index = 0; index < store.count; index++)
|
||||
if (!models[index]?.ready) return false;
|
||||
// Every drawn instance's model has loaded (with an index, that one's).
|
||||
ready(index) {
|
||||
if (index !== undefined)
|
||||
return index < store.count && models[index]?.ready === true;
|
||||
for (let at = 0; at < store.count; at++)
|
||||
if (!models[at]?.ready) return false;
|
||||
return true;
|
||||
},
|
||||
commit(range) {
|
||||
|
||||
@@ -301,6 +301,22 @@ test('models load per instance with the set options and follow position, orienta
|
||||
assert.equal(options.colorBlendAmount, 0.4);
|
||||
assert.equal(options.allowPicking, true);
|
||||
assert.equal(options.customShader, undefined, 'lit by default');
|
||||
assert.equal(options.asynchronous, false, 'built at once');
|
||||
// The glTF's own axes: no Cesium axis correction (Y_UP_TO_Z_UP ×
|
||||
// Z_UP_TO_X_UP), so an orientation draws the same on every engine.
|
||||
assert.equal(options.upAxis, Cesium.Axis.Z);
|
||||
assert.equal(options.forwardAxis, Cesium.Axis.X);
|
||||
assert.ok(
|
||||
Cesium.Matrix4.equals(
|
||||
Cesium.ModelUtility.getAxisCorrectionMatrix(
|
||||
options.upAxis,
|
||||
options.forwardAxis,
|
||||
new Cesium.Matrix4(),
|
||||
),
|
||||
Cesium.Matrix4.IDENTITY,
|
||||
),
|
||||
);
|
||||
assert.deepEqual(options.environmentMapOptions, { enabled: false });
|
||||
const [first, second] = items(collection);
|
||||
assert.notEqual(first.modelMatrix, second.modelMatrix);
|
||||
const translation = Cesium.Matrix4.getTranslation(
|
||||
@@ -316,8 +332,12 @@ test('models load per instance with the set options and follow position, orienta
|
||||
assert.equal(second.id, 'second');
|
||||
assert.equal(set.ready(), false, 'loaded models not yet ready');
|
||||
first.ready = true;
|
||||
assert.equal(set.ready(0), true, 'an instance is ready with its model');
|
||||
assert.equal(set.ready(1), false);
|
||||
assert.equal(set.ready(), false);
|
||||
second.ready = true;
|
||||
assert.equal(set.ready(), true);
|
||||
assert.equal(set.ready(2), false, 'past the count');
|
||||
// Shrinking hides the instance past the count; a later write moves it.
|
||||
set.setCount(1);
|
||||
set.commit();
|
||||
|
||||
Reference in new issue
Block a user