mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +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
@@ -1,3 +1,9 @@
|
||||
import { cameraOf } from '../../render/cesium/camera.js';
|
||||
import {
|
||||
entityFollowTarget,
|
||||
onFollowChanged,
|
||||
stopFollowing,
|
||||
} from '../../data/followed.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { formatNumber, t } from '../../i18n/index.js';
|
||||
import { unitLabel } from '../../ui/unitLabels.js';
|
||||
@@ -26,7 +32,7 @@ import {
|
||||
TRACKED_BILLBOARD_SCALE_BY_DISTANCE,
|
||||
} from './policy.js';
|
||||
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
|
||||
export function createTracking({
|
||||
flightState,
|
||||
@@ -49,7 +55,7 @@ export function createTracking({
|
||||
const { clearFocusTarget } = services.focus;
|
||||
const { isMilitaryLayerActive, isMilitaryIcao } = services.militaryRegistry;
|
||||
const { trackedLabelModelFromText, refreshTrackedReadout } = services.readout;
|
||||
const { applyTrackedCameraFrame } = services.camera;
|
||||
const { FOLLOW_MIN_RANGE_M } = services.camera;
|
||||
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
|
||||
const flightsLayer = layer;
|
||||
|
||||
@@ -615,7 +621,7 @@ export function createTracking({
|
||||
* aged-out plane, layer disable, and voice stopTracking.
|
||||
*
|
||||
* @param {boolean} [skipViewerUntrack=false] - ANOTHER layer just grabbed the
|
||||
* follow-camera: tear down our own state but leave viewer.trackedEntity
|
||||
* follow-camera: tear down our own state but leave the camera's follow
|
||||
* alone (the new owner controls it).
|
||||
* @param {object} [options] - Clear origin.
|
||||
* @param {boolean} [options.evicted=false] - The contact aged out of the feed
|
||||
@@ -628,8 +634,7 @@ export function createTracking({
|
||||
skipViewerUntrack = false,
|
||||
{ evicted = false, origin = 'programmatic' } = {},
|
||||
) {
|
||||
flightState._trackedCameraFrameStop?.();
|
||||
flightState._trackedCameraFrameStop = null;
|
||||
flightState._followTarget = null;
|
||||
if (!flightState._trackedIcao) {
|
||||
clearFocusTarget('flights');
|
||||
return;
|
||||
@@ -642,12 +647,12 @@ export function createTracking({
|
||||
const trackedCourseDeg = flightState._displayCourse.get(clearedIcao);
|
||||
|
||||
// Stop tracking and remove the entity. skipViewerUntrack: when ANOTHER layer just grabbed the
|
||||
// follow-camera, we tear down our own state but must NOT clear viewer.trackedEntity (the new owner
|
||||
// follow-camera, we tear down our own state but must NOT clear the camera's follow (the new owner
|
||||
// controls it now — clearing it would yank the camera off their plane). Releasing trackedEntity
|
||||
// does NOT move the camera: Cesium resets the lookAt transform in place, so the view stays where
|
||||
// the follow left it and the user can immediately orbit/zoom.
|
||||
if (flightState._viewer && !skipViewerUntrack) {
|
||||
flightState._viewer.trackedEntity = undefined;
|
||||
stopFollowing(flightState._viewer);
|
||||
}
|
||||
if (flightState._trackedEntity) {
|
||||
flightState._viewer.entities.remove(flightState._trackedEntity);
|
||||
@@ -933,15 +938,11 @@ export function createTracking({
|
||||
// resolves into an aircraft.
|
||||
//
|
||||
// The billboard stays SHOWN at all times and is hidden by going TRANSPARENT (alpha 0), not by
|
||||
// show=false. This is deliberate: viewer.trackedEntity derives the follow-camera framing from
|
||||
// the entity's bounding sphere, and a 3D model graphic reports a PENDING sphere until its glTF
|
||||
// finishes loading. If we hid the billboard outright, tracking a plane while already zoomed in
|
||||
// would stall the centering until the model loaded. A shown-but-transparent billboard always
|
||||
// supplies a ready sphere, so framing is instant; we only drop its alpha once the model GLB is
|
||||
// preloaded (_planeModelLoaded), so there's neither a billboard+model double-image nor a gap.
|
||||
// show=false: it drops its alpha only once the model GLB is preloaded (_planeModelLoaded), so
|
||||
// there's neither a billboard+model double-image nor a gap. The camera follows its own target
|
||||
// through the camera port, so nothing here frames the camera.
|
||||
// The tracked entity is a PURE BILLBOARD — no label or model graphic. The 3D model for the
|
||||
// tracked plane is a standalone primitive driven by _updateTrackedModel(); keeping it off the
|
||||
// entity is what makes the follow-camera's bounding sphere always ready (see _trackedModel).
|
||||
// tracked plane is a standalone primitive driven by _updateTrackedModel(); it stays off the entity (see _trackedModel).
|
||||
// Keep Cesium's generated entity ID: re-init without destroy can temporarily
|
||||
// overlap collections, and an explicit ICAO ID would throw on that duplicate.
|
||||
// What the tracked billboard is drawn at, kept in its entity record so the
|
||||
@@ -957,11 +958,6 @@ export function createTracking({
|
||||
};
|
||||
flightState._trackedEntity = flightState._viewer.entities.add({
|
||||
position: positionProperty,
|
||||
// Force Cesium's built-in EntityView and our close-range camera guard to
|
||||
// use the same local frame. AUTO can select a velocity frame while the
|
||||
// model matrix uses aircraft orientation; alternating between those
|
||||
// frames makes the target oscillate forward/back on screen.
|
||||
trackingReferenceFrame: Cesium.TrackingReferenceFrame.ENU,
|
||||
billboard: {
|
||||
image: aircraftIcon(
|
||||
parts.rendering._iconKind(
|
||||
@@ -1028,7 +1024,7 @@ export function createTracking({
|
||||
Math.max((info.altitude || 1500) * 1.1 + 2500, 3000),
|
||||
30000,
|
||||
);
|
||||
flightState._trackedEntity.viewFrom = new Cesium.Cartesian3(
|
||||
const viewFrom = new Cesium.Cartesian3(
|
||||
0,
|
||||
-followRange * 0.8,
|
||||
followRange * 0.55,
|
||||
@@ -1049,15 +1045,18 @@ export function createTracking({
|
||||
entityRecord(flightState._trackedEntity).visualPosition =
|
||||
parts.motion._trackedVisualCached;
|
||||
refreshTrackedReadout(flightState._trackedEntity);
|
||||
flightState._viewer.camera.cancelFlight();
|
||||
// Camera follows the tracked entity
|
||||
flightState._viewer.trackedEntity = flightState._trackedEntity;
|
||||
flightState._trackedCameraFrameStop =
|
||||
applyTrackedCameraFrame(
|
||||
flightState._viewer,
|
||||
flightState._trackedEntity,
|
||||
flightState._trackedEntity.viewFrom,
|
||||
) || null;
|
||||
// The camera follows through its port: a target framed from viewFrom in
|
||||
// ENU, never closer than the readable minimum, whose presentation (key,
|
||||
// label, sprite, display position) reads the tracked entity's record.
|
||||
const camera = cameraOf(flightState._viewer);
|
||||
camera.cancelFlight();
|
||||
flightState._followTarget = entityFollowTarget(flightState._trackedEntity, {
|
||||
position: getTrackedPosition,
|
||||
frame: 'enu',
|
||||
viewFrom,
|
||||
minRange: FOLLOW_MIN_RANGE_M,
|
||||
});
|
||||
camera.follow(flightState._followTarget);
|
||||
|
||||
// Track-history trail (PRD F1): seed from local history + async backfill.
|
||||
// Ground traffic draws NO trail (a taxi path is noise, not a track) — if the
|
||||
@@ -1143,25 +1142,25 @@ export function createTracking({
|
||||
if (flightState._clickSubscription) return; // already installed
|
||||
|
||||
// Cross-layer untrack: if ANOTHER layer (military, vessels, …) grabs the follow-camera, drop our
|
||||
// tracking so its model/entity/update-loop don't orphan — without touching viewer.trackedEntity
|
||||
// tracking so its model/entity/update-loop don't orphan — without touching the camera's follow
|
||||
// (the new owner controls it). Guarded so the intermediate untrack→retrack of OUR OWN switch
|
||||
// (viewer.trackedEntity briefly undefined) doesn't self-clear.
|
||||
// (the follow briefly ended) doesn't self-clear.
|
||||
if (!flightState._trackedEntityChangedRemove) {
|
||||
flightState._trackedEntityChangedRemove =
|
||||
viewer.trackedEntityChanged.addEventListener(() => {
|
||||
flightState._trackedEntityChangedRemove = onFollowChanged(
|
||||
viewer,
|
||||
(followed) => {
|
||||
if (
|
||||
flightState._trackedIcao &&
|
||||
flightState._viewer &&
|
||||
flightState._viewer.trackedEntity &&
|
||||
flightState._viewer.trackedEntity !== flightState._trackedEntity
|
||||
followed &&
|
||||
followed !== flightState._followTarget
|
||||
) {
|
||||
_clearTracking(true, {
|
||||
origin:
|
||||
readEntityRecord(flightState._viewer.trackedEntity)
|
||||
?.selectionOrigin || 'programmatic',
|
||||
origin: followed.selectionOrigin || 'programmatic',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
flightState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
|
||||
Reference in new issue
Block a user