mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Follow aircraft and satellites through the camera port
Flights and military follow their tracked aircraft with an entityFollowTarget: framed in ENU from viewFrom, never closer than 150 m, presentation read from the drawn entity's record. Satellites follow in Cesium's autodetect frame. The layers' own framing (applyTrackedCameraFrame) goes; the port's follow has the same close-range rules, and trackedCamera.js no longer imports Cesium. The port's helper entity draws nothing: its point's outline is transparent too, and click and voice picks of it count as picks of the target's drawn entity. The fake camera binder follows when the fake has Cesium's entity tracking.
This commit is contained in:
1 parent
99f9a701d9
commit
e3a850bc9c
22 files changed
+291
-332
No files matched your search
@@ -23,6 +23,21 @@ import { trackedEntityViewEntity } from './internals.js';
|
||||
const MAX_FRAME_ATTEMPTS = 120;
|
||||
const TRANSPARENT = new Cesium.Color(0, 0, 0, 0);
|
||||
const ZOOM_STATES = new WeakMap();
|
||||
/** Each helper entity's FollowTarget. */
|
||||
const HELPER_TARGETS = new WeakMap();
|
||||
|
||||
/**
|
||||
* A pick as the follow's helper entity should not make it: a hit on a helper
|
||||
* is a hit on its target's drawn `entity`, or no hit when it has none. Any
|
||||
* other pick comes back as it was.
|
||||
* @param {object|undefined} picked What `scene.pick` or `drillPick` gave.
|
||||
* @returns {object|undefined}
|
||||
*/
|
||||
export function pickThroughFollowHelper(picked) {
|
||||
const target = picked?.id && HELPER_TARGETS.get(picked.id);
|
||||
if (!target) return picked;
|
||||
return target.entity ? { ...picked, id: target.entity } : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn zoom coasting off and raise the zoom floor to `minRange` while any
|
||||
@@ -186,14 +201,20 @@ export function createCesiumFollow({ widget, scene, camera, onChanged }) {
|
||||
: target.viewFrom;
|
||||
|
||||
function helperFor(target) {
|
||||
return widget.entities.add({
|
||||
const helper = widget.entities.add({
|
||||
position: new Cesium.CallbackProperty((time, result) => {
|
||||
const p = target.position(msOf(time));
|
||||
return p ? Cesium.Cartesian3.fromElements(p.x, p.y, p.z, result) : p;
|
||||
}, false),
|
||||
// EntityView tracks an entity only once its bounding sphere is
|
||||
// ready, and an entity without graphics has none.
|
||||
point: { pixelSize: 1, color: TRANSPARENT },
|
||||
// Outline too: Cesium blends an opaque default outline into the edge.
|
||||
point: {
|
||||
pixelSize: 1,
|
||||
color: TRANSPARENT,
|
||||
outlineColor: TRANSPARENT,
|
||||
outlineWidth: 0,
|
||||
},
|
||||
viewFrom: new Cesium.CallbackProperty((time, result) => {
|
||||
const v = viewFromAt(target, time);
|
||||
return v ? startOffset(target, v, result) : v;
|
||||
@@ -203,6 +224,8 @@ export function createCesiumFollow({ widget, scene, camera, onChanged }) {
|
||||
? Cesium.TrackingReferenceFrame.AUTODETECT
|
||||
: Cesium.TrackingReferenceFrame.ENU,
|
||||
});
|
||||
HELPER_TARGETS.set(helper, target);
|
||||
return helper;
|
||||
}
|
||||
|
||||
// preUpdate on purpose: in preRender the target's drawing is already
|
||||
|
||||
@@ -9,7 +9,7 @@ import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { headlessCamera } from './cameraGoldens.js';
|
||||
import { createCesiumCamera } from './camera.js';
|
||||
import { holdFollowZoom } from './follow.js';
|
||||
import { holdFollowZoom, pickThroughFollowHelper } from './follow.js';
|
||||
|
||||
function trackingHost() {
|
||||
const { scene, camera } = headlessCamera();
|
||||
@@ -252,28 +252,21 @@ test('an autodetected follow is framed once Cesium tracks its helper', () => {
|
||||
h.dispose();
|
||||
});
|
||||
|
||||
test('a port follow and a layer frame hold one controller together', async () => {
|
||||
const { applyTrackedCameraFrame } =
|
||||
await import('../../data/trackedCamera.js');
|
||||
test('a pick of the helper is a pick of the target’s drawn entity', () => {
|
||||
const h = trackingHost();
|
||||
const controller = h.scene.screenSpaceCameraController;
|
||||
const viewer = {
|
||||
scene: h.scene,
|
||||
camera: h.camera,
|
||||
clock: h.widget.clock,
|
||||
isDestroyed: () => false,
|
||||
trackedEntity: {},
|
||||
};
|
||||
const stopLayer = applyTrackedCameraFrame(
|
||||
viewer,
|
||||
viewer.trackedEntity,
|
||||
new Cesium.Cartesian3(0, -800, 400),
|
||||
);
|
||||
h.port.follow(target('a', { minRange: 300 }));
|
||||
assert.equal(controller.minimumZoomDistance, 300);
|
||||
stopLayer();
|
||||
assert.equal(controller.minimumZoomDistance, 300, 'the port still holds');
|
||||
h.port.follow(null);
|
||||
assert.deepEqual(controller, { inertiaZoom: 0.8, minimumZoomDistance: 1 });
|
||||
const drawn = h.widget.entities.add({ position: AUSTIN });
|
||||
h.port.follow(target('a', { entity: drawn }));
|
||||
const helper = h.widget.entities.values.find((e) => e !== drawn);
|
||||
const primitive = {};
|
||||
assert.deepEqual(pickThroughFollowHelper({ id: helper, primitive }), {
|
||||
id: drawn,
|
||||
primitive,
|
||||
});
|
||||
h.port.follow(target('b'));
|
||||
const bare = h.widget.entities.values.find((e) => e !== drawn);
|
||||
assert.equal(pickThroughFollowHelper({ id: bare }), undefined);
|
||||
const other = { id: drawn };
|
||||
assert.equal(pickThroughFollowHelper(other), other);
|
||||
assert.equal(pickThroughFollowHelper(undefined), undefined);
|
||||
h.dispose();
|
||||
});
|
||||
Reference in new issue
Block a user