mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(selection): selecting a contact keeps its size and the camera's view: aircraft, vessels, trains and transit vehicles keep their form and size when selected (colour only); a click follows from the camera's own distance and angle, the contact gliding to the centre over one second (FollowTarget transitionS, shared rule render/camera/followTransition, conformance camera.follow.transition)
This commit is contained in:
1 parent
e3865f462f
commit
7a61bf04a0
52 files changed
+1648
-891
No files matched your search
@@ -31,6 +31,8 @@ import { cockpitContactDotImage } from './cockpitContactDot.js';
|
||||
/** Raster size of the cockpit contact pip (cockpitContactDot.js draws 16 px). */
|
||||
const COCKPIT_DOT_PX = 16;
|
||||
/** Fleet glyphs keep the established close-range 3× scale. */
|
||||
/** A contact icon's size before its scale, CSS px. */
|
||||
const FLEET_ICON_SIZE_PX = 20;
|
||||
const NORMAL_SCALE_BY_DISTANCE = Object.freeze({
|
||||
near: 1000,
|
||||
nearValue: 3.0,
|
||||
@@ -670,6 +672,36 @@ export function createAircraftIcons({
|
||||
state._iconFocusActive = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* How a contact's icon is drawn outside Cockpit: its image (and the sharper
|
||||
* one it switches to up close), size, scale and scale by distance. The
|
||||
* tracked contact's own icon is drawn with this too, so selecting a contact
|
||||
* changes its colour and nothing else.
|
||||
* @param {string} icao24
|
||||
* @param {object} [info] Its record.
|
||||
* @returns {{image: string, imageLod: {near: string, switchPx: number},
|
||||
* size: [number, number], scale: number, scaleByDistance: object}}
|
||||
*/
|
||||
function _fleetLook(icao24, info = state.records.data.get(icao24)) {
|
||||
const rendering = parts.rendering;
|
||||
return {
|
||||
image: aircraftIcon(
|
||||
rendering._iconKind(icao24, info?.klass),
|
||||
FLEET_ICON_PX,
|
||||
),
|
||||
imageLod: {
|
||||
near: aircraftIcon(
|
||||
rendering._iconKind(icao24, info?.klass),
|
||||
TRACKED_ICON_PX,
|
||||
),
|
||||
switchPx,
|
||||
},
|
||||
size: [FLEET_ICON_SIZE_PX, FLEET_ICON_SIZE_PX],
|
||||
scale: rendering._fleetBillboardScale(icao24, info?.klass),
|
||||
scaleByDistance: NORMAL_SCALE_BY_DISTANCE,
|
||||
};
|
||||
}
|
||||
|
||||
/** Image, size, scale, tint and freshness for one row under the current
|
||||
* normal/cockpit contract. Motion and course stay with `_planIcon`. */
|
||||
function _applyIconPresentation(icao24) {
|
||||
@@ -693,20 +725,7 @@ export function createAircraftIcons({
|
||||
rotationMode: 'screen',
|
||||
}
|
||||
: {
|
||||
image: aircraftIcon(
|
||||
rendering._iconKind(icao24, info?.klass),
|
||||
FLEET_ICON_PX,
|
||||
),
|
||||
imageLod: {
|
||||
near: aircraftIcon(
|
||||
rendering._iconKind(icao24, info?.klass),
|
||||
TRACKED_ICON_PX,
|
||||
),
|
||||
switchPx,
|
||||
},
|
||||
size: tracked ? [24, 24] : [20, 20],
|
||||
scale: rendering._fleetBillboardScale(icao24, info?.klass),
|
||||
scaleByDistance: NORMAL_SCALE_BY_DISTANCE,
|
||||
..._fleetLook(icao24, info),
|
||||
color: rgba(rendering._fleetBillboardColor(icao24, info)),
|
||||
rotationMode: 'course',
|
||||
};
|
||||
@@ -777,6 +796,7 @@ export function createAircraftIcons({
|
||||
_replanExpired,
|
||||
_focusIcons,
|
||||
_applyIconPresentation,
|
||||
_fleetLook,
|
||||
_addIcon,
|
||||
_forgetContact,
|
||||
_iconIds,
|
||||
@@ -795,7 +815,7 @@ function baseContactItem(layerId, icao24, show) {
|
||||
pos: { x: 0, y: 0, z: 0 },
|
||||
motion: { kind: 'hold', courseDeg: 0 },
|
||||
course: 0,
|
||||
size: [20, 20],
|
||||
size: [FLEET_ICON_SIZE_PX, FLEET_ICON_SIZE_PX],
|
||||
rotationMode: 'course',
|
||||
recede: true,
|
||||
disableDepthTest: Infinity,
|
||||
|
||||
@@ -110,7 +110,6 @@ export function createAircraftModels({
|
||||
afterReplan = () => {},
|
||||
}) {
|
||||
const { isTr3b } = services.aircraftPresentation;
|
||||
const { trackedModelScaleForPixelCap } = services.camera;
|
||||
const { focusNowMs, getFocusTarget } = services.focus;
|
||||
const writeEpsilon = DEFAULT_AIRCRAFT_RECESSION_PARAMS.writeEpsilon;
|
||||
let instances = 0;
|
||||
@@ -228,9 +227,8 @@ export function createAircraftModels({
|
||||
* budget: models only appear below MODEL_ALT_CEIL_M and only for the nearest MODEL_MAX in
|
||||
* view. The toggle still OWNS the fleet — an operator who wants every in-view plane arms
|
||||
* `all`, and one who wants none turns 3D off — this predicate is unchanged. The TRACKED
|
||||
* contact does not route through here: it is one model, it is what the camera is aimed at,
|
||||
* and it takes its own default-on, hysteretic zoom regime
|
||||
* (`_trackedModelRegimeActive`). */
|
||||
* contact routes through here too (`_trackedModelRegimeActive`), with its place in the
|
||||
* fleet's cap, so selecting a contact never changes its form. */
|
||||
|
||||
function _modelRegimeActive(pose = _pose()) {
|
||||
if (!state._models3dEnabled) return false;
|
||||
@@ -467,7 +465,8 @@ export function createAircraftModels({
|
||||
* flip take effect on the same frame rather than waiting for
|
||||
* `_updateTrackedModel` to clear `show`; the rendering test is what keeps a
|
||||
* null or still-loading tracked model from claiming a visual it is not
|
||||
* drawing yet.
|
||||
* drawing yet. Until the tracked model draws, the fleet model the contact
|
||||
* had when it was selected still draws it, and owns the visual.
|
||||
* @param {string} icao24
|
||||
* @param {import('./modelRecord.js').ModelRecord|null} [record] Resolved
|
||||
* fleet model record; null means absent.
|
||||
@@ -476,9 +475,11 @@ export function createAircraftModels({
|
||||
|
||||
function _modelOwnsVisual(icao24, record) {
|
||||
if (icao24 === state._trackedIcao) {
|
||||
// Its fleet model draws it until the tracked model takes over.
|
||||
return (
|
||||
parts.tracking._trackedModelRegimeActive() &&
|
||||
modelIsRendering(state._trackedModel)
|
||||
(modelIsRendering(state._trackedModel) ||
|
||||
modelIsRendering(state._models.get(icao24)))
|
||||
);
|
||||
}
|
||||
return modelIsRendering(
|
||||
@@ -673,10 +674,24 @@ export function createAircraftModels({
|
||||
);
|
||||
}
|
||||
|
||||
/** A fleet model still drawing the tracked contact (it was a model when
|
||||
* it was selected) lets go once the tracked model draws, or once the
|
||||
* contact is no longer drawn as a model at all. */
|
||||
function _releaseTrackedFleetModel() {
|
||||
if (state._trackedIcao && state._models.has(state._trackedIcao))
|
||||
_releaseModel(state._trackedIcao);
|
||||
}
|
||||
|
||||
/** Per-frame driver for the standalone tracked model. Runs every preUpdate (not the 80 ms fleet
|
||||
* cadence) so the centered plane moves smoothly. The tracked entity stays a pure billboard, so the
|
||||
* follow-camera's bounding sphere is ALWAYS ready — toggling 3D, or tracking while already zoomed
|
||||
* in, can never stall or freeze the centering (the old model-graphic-on-entity failure mode). */
|
||||
* in, can never stall or freeze the centering (the old model-graphic-on-entity failure mode).
|
||||
*
|
||||
* The model draws exactly as the fleet would draw this contact: the same
|
||||
* asset at the same scale and `minPixelSize` (`MODEL_MIN_PX`), only its
|
||||
* tint the tracked colour; whether it draws at all is the fleet's rule too
|
||||
* (`_trackedModelRegimeActive`). Selecting a contact changes its colour,
|
||||
* never its size or form. */
|
||||
|
||||
function _updateTrackedModel() {
|
||||
// A failed load is let go (the icon carries the contact); the budget
|
||||
@@ -688,6 +703,7 @@ export function createAircraftModels({
|
||||
state._modelSets;
|
||||
if (!active) {
|
||||
_hideTrackedModel();
|
||||
_releaseTrackedFleetModel();
|
||||
return;
|
||||
}
|
||||
// Ask the frame-cached source directly. If the entity callback already ran,
|
||||
@@ -699,6 +715,7 @@ export function createAircraftModels({
|
||||
parts.icons._iconPosition(state._trackedIcao);
|
||||
if (!pos) {
|
||||
_hideTrackedModel();
|
||||
_releaseTrackedFleetModel();
|
||||
return;
|
||||
}
|
||||
const icao24 = state._trackedIcao;
|
||||
@@ -707,14 +724,17 @@ export function createAircraftModels({
|
||||
if (state._trackedModel && state._trackedModel.id !== icao24)
|
||||
_releaseTrackedModel();
|
||||
if (!state._trackedModel) {
|
||||
if (!_trackedModelLoadAllowed()) return; // the icon carries it
|
||||
// Until the fleet model set has loaded the icon carries it.
|
||||
if (!spec.url) return;
|
||||
// The icon carries it: after the load budget is spent, or until the
|
||||
// fleet model set has loaded.
|
||||
if (!_trackedModelLoadAllowed() || !spec.url) {
|
||||
_releaseTrackedFleetModel();
|
||||
return;
|
||||
}
|
||||
const record = createModelRecord({
|
||||
specKey: _specKeyFor(meta), // type-change sync compares against this
|
||||
bellyM: spec.bellyM,
|
||||
scale: spec.scale,
|
||||
minPixelSize: policy.TRACKED_MODEL_MIN_PX,
|
||||
minPixelSize: policy.MODEL_MIN_PX,
|
||||
});
|
||||
record.id = icao24;
|
||||
record.url = resolveAsset(spec.url);
|
||||
@@ -736,6 +756,7 @@ export function createAircraftModels({
|
||||
const displayPos = _modelDisplayPosition(icao24, pos);
|
||||
if (!displayPos) {
|
||||
_hideTrackedModel(); // no ground evidence → the icon carries it
|
||||
_releaseTrackedFleetModel();
|
||||
return;
|
||||
}
|
||||
placeModel(
|
||||
@@ -743,19 +764,9 @@ export function createAircraftModels({
|
||||
displayPos,
|
||||
_modelHeading(parts.motion._trackedDisplayCourse(), meta),
|
||||
);
|
||||
if (record.ready) {
|
||||
const pose = _pose();
|
||||
record.scale = trackedModelScaleForPixelCap({
|
||||
baseScale: spec.scale,
|
||||
nativeRadiusM: spec.nativeRadiusM,
|
||||
rangeM: pose?.position ? distance(pose.position, displayPos) : NaN,
|
||||
viewportHeightPx: _viewport().height,
|
||||
fovyRad: pose?.fovy,
|
||||
maximumPixelSize: policy.TRACKED_MODEL_MAX_PX,
|
||||
});
|
||||
}
|
||||
showModel(record, record.ready);
|
||||
_send(state._modelSets.tracked, icao24, record, spec);
|
||||
if (record.ready) _releaseTrackedFleetModel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -830,7 +841,10 @@ export function createAircraftModels({
|
||||
// Drop all models the moment we leave it (toggled off / zoomed out) so icons resume.
|
||||
const useModels = _modelRegimeActive(pose);
|
||||
if (!useModels && state._models.size) _releaseModels();
|
||||
if (!useModels) return;
|
||||
if (!useModels) {
|
||||
state._trackedModelEligible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 3D-model eligibility: by DISTANCE (the mode's add/keep band), with ON-SCREEN PRIORITY under the
|
||||
// cap. FOUR passes, visible-first, so the slots are spent on what you can see: (1) KEEP on-screen
|
||||
@@ -850,7 +864,10 @@ export function createAircraftModels({
|
||||
// Candidates = planes within the KEEP radius, nearest first, each tagged with on-screen-ness.
|
||||
const cand = [];
|
||||
for (const icao of icons.ids()) {
|
||||
if (icao === state._trackedIcao) continue;
|
||||
// The tracked contact competes like any other (its model is drawn by
|
||||
// `_updateTrackedModel`), so selecting it never changes its form; in
|
||||
// cockpit it is the airframe you sit in, and takes no slot.
|
||||
if (icao === state._trackedIcao && state._cockpitContactMode) continue;
|
||||
// A converted TR-3B renders as an icon and can never take a model, so
|
||||
// it must not occupy a CAP SLOT either — excluded here at selection time,
|
||||
// not just at the handoff below, or accumulated conversions would starve
|
||||
@@ -876,8 +893,12 @@ export function createAircraftModels({
|
||||
const modelEligible = selectModelEligible(cand, {
|
||||
cap,
|
||||
addDistSq,
|
||||
isModeled: (icao) => state._models.has(icao),
|
||||
isModeled: (icao) =>
|
||||
state._models.has(icao) ||
|
||||
(icao === state._trackedIcao && state._trackedModelEligible),
|
||||
});
|
||||
state._trackedModelEligible =
|
||||
Boolean(state._trackedIcao) && modelEligible.has(state._trackedIcao);
|
||||
const toRelease = [];
|
||||
for (const icao of state._models.keys()) {
|
||||
if (icao !== state._trackedIcao && !modelEligible.has(icao))
|
||||
@@ -894,6 +915,8 @@ export function createAircraftModels({
|
||||
const items = pendingItems;
|
||||
for (const icao24 of modelEligible) {
|
||||
if (isTr3b(icao24)) continue;
|
||||
// The tracked contact's model is `_updateTrackedModel`'s.
|
||||
if (icao24 === state._trackedIcao) continue;
|
||||
if (!icons.has(icao24)) continue;
|
||||
const position = icons.position(icao24, t);
|
||||
if (!parts.icons._aboveHorizon(position, occluder)) {
|
||||
|
||||
+2
-1
@@ -9,7 +9,6 @@ const flightsLayer = createApplicationFlights({
|
||||
source: createFlightSource(),
|
||||
militaryRegistry,
|
||||
});
|
||||
export { TRACKED_MODEL_MAX_PX } from '../layers/flights/policy.js';
|
||||
export const _floorGroundedDisplayPositionForTest =
|
||||
flightsLayer.testing._floorGroundedDisplayPositionForTest;
|
||||
export const _clearDisplayFloorStateForTest =
|
||||
@@ -41,6 +40,8 @@ export const _driveFleetModelHandoffForTest =
|
||||
export const _ensureFleetModelForTest =
|
||||
flightsLayer.testing._ensureFleetModelForTest;
|
||||
export const _trackedModelForTest = flightsLayer.testing._trackedModelForTest;
|
||||
export const _trackedIconLookForTest =
|
||||
flightsLayer.testing._trackedIconLookForTest;
|
||||
export const _modelSetIdsForTest = flightsLayer.testing._modelSetIdsForTest;
|
||||
export const _iconForTest = flightsLayer.testing._iconForTest;
|
||||
export const _setIconForTest = flightsLayer.testing._setIconForTest;
|
||||
|
||||
@@ -9,7 +9,6 @@ const militaryFlightsLayer = createApplicationMilitary({
|
||||
source: createMilitarySource(),
|
||||
militaryRegistry,
|
||||
});
|
||||
export { TRACKED_MODEL_MAX_PX } from '../layers/military/policy.js';
|
||||
export const _setTrackedMilitaryRefreshStateForTest =
|
||||
militaryFlightsLayer.testing._setTrackedMilitaryRefreshStateForTest;
|
||||
export const _setMilitaryTrackingRefreshOutcomeForTest =
|
||||
@@ -34,6 +33,8 @@ export const _ensureFleetModelForTest =
|
||||
militaryFlightsLayer.testing._ensureFleetModelForTest;
|
||||
export const _trackedModelForTest =
|
||||
militaryFlightsLayer.testing._trackedModelForTest;
|
||||
export const _trackedIconLookForTest =
|
||||
militaryFlightsLayer.testing._trackedIconLookForTest;
|
||||
export const _modelSetIdsForTest =
|
||||
militaryFlightsLayer.testing._modelSetIdsForTest;
|
||||
export const _iconForTest = militaryFlightsLayer.testing._iconForTest;
|
||||
|
||||
@@ -235,11 +235,9 @@ test('both flight layers keep a converted contact 2D and visible (render invaria
|
||||
// no TR-3B GLB, so the triangle icon stays the visual.
|
||||
assert.match(source, /for \(const icao24 of modelEligible\) \{\s*if \(isTr3b\(icao24\)\) continue;/,
|
||||
`${name}: fleet model handoff skips converted contacts`);
|
||||
// The tracked regime became default-on and camera-distance driven
|
||||
// (2026-08-19), so the suppression moved from a conjunct on
|
||||
// `_modelRegimeActive()` to an explicit early return. The invariant is
|
||||
// unchanged: a converted contact never reaches the model handoff.
|
||||
assert.match(source, /if\s*\(\s*!(?:flightState\.)?_trackedIcao\s*\|\|\s*(?:flightState\.)?_cockpitContactMode\s*\|\|\s*isTr3b\(\s*(?:flightState\.)?_trackedIcao,?\s*\),?\s*\)\s*\{/,
|
||||
// The tracked regime's suppression is an explicit early return: a
|
||||
// converted contact never reaches the model handoff.
|
||||
assert.match(source, /if\s*\(\s*!(?:flightState\.)?_trackedIcao\s*\|\|\s*(?:flightState\.)?_cockpitContactMode\s*\|\|\s*isTr3b\(\s*(?:flightState\.)?_trackedIcao,?\s*\),?\s*\)\s*(?:\{|return false;)/,
|
||||
`${name}: the standalone tracked model is suppressed for a converted contact`);
|
||||
|
||||
// 2. The icon is never hidden by that suppression — it must keep
|
||||
|
||||
@@ -83,6 +83,7 @@ export function createTrackedAircraftIcon({ viewer, setPrefix }) {
|
||||
pos: pos ? { x: pos.x, y: pos.y, z: pos.z } : { x: 0, y: 0, z: 0 },
|
||||
show: Boolean(pos) && visible,
|
||||
image: shown.image,
|
||||
...(shown.imageLod ? { imageLod: shown.imageLod } : {}),
|
||||
size: [shown.sprite.width, shown.sprite.height],
|
||||
scale: shown.sprite.scale,
|
||||
scaleByDistance: shown.sprite.scaleByDistance,
|
||||
@@ -99,6 +100,10 @@ export function createTrackedAircraftIcon({ viewer, setPrefix }) {
|
||||
written.pos.y === item.pos.y &&
|
||||
written.pos.z === item.pos.z &&
|
||||
written.image === item.image &&
|
||||
written.imageLod?.near === item.imageLod?.near &&
|
||||
written.imageLod?.switchPx === item.imageLod?.switchPx &&
|
||||
written.size[0] === item.size[0] &&
|
||||
written.size[1] === item.size[1] &&
|
||||
written.scale === item.scale &&
|
||||
written.rotation === item.rotation &&
|
||||
sameColor(written.color, item.color)
|
||||
@@ -115,8 +120,10 @@ export function createTrackedAircraftIcon({ viewer, setPrefix }) {
|
||||
* @param {object} target
|
||||
* @param {string} target.id The contact's id.
|
||||
* @param {string} target.image
|
||||
* @param {{near: string, switchPx: number}} [target.imageLod] The
|
||||
* sharper image it switches to once drawn larger than `switchPx`.
|
||||
* @param {{width: number, height: number, scale: number,
|
||||
* scaleByDistance: object}} target.sprite
|
||||
* scaleByDistance: object}} target.sprite Read each frame.
|
||||
* @param {() => object|null} target.position ECEF this frame; none hides it.
|
||||
* @param {() => number} target.rotation Screen radians, counter-clockwise.
|
||||
* @param {() => object} target.color The tint this frame.
|
||||
@@ -131,9 +138,10 @@ export function createTrackedAircraftIcon({ viewer, setPrefix }) {
|
||||
},
|
||||
|
||||
/** Draw it from a new image (the class or conversion changed) next frame. */
|
||||
setImage(image) {
|
||||
setImage(image, imageLod) {
|
||||
if (!shown) return;
|
||||
shown.image = image;
|
||||
shown.imageLod = imageLod;
|
||||
requestFrame('tracked icon image');
|
||||
},
|
||||
|
||||
|
||||
+29
-39
@@ -1,3 +1,11 @@
|
||||
import {
|
||||
distance,
|
||||
eastNorthUp,
|
||||
inverseFrameVector,
|
||||
normalize,
|
||||
scale,
|
||||
} from '../geo/index.js';
|
||||
|
||||
/**
|
||||
* Closest a follow camera comes to a tracked aircraft, metres: the camera
|
||||
* port's `minRange` for the aircraft layers' FollowTargets.
|
||||
@@ -5,44 +13,26 @@
|
||||
export const FOLLOW_MIN_RANGE_M = 150;
|
||||
|
||||
/**
|
||||
* Preserve real-world model scale except when a very close tracked camera
|
||||
* would make the selected aircraft dominate the viewport.
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {number} options.baseScale Asset's calibrated real-world scale.
|
||||
* @param {number} options.nativeRadiusM Asset bounding radius before scale.
|
||||
* @param {number} options.rangeM Camera-to-aircraft range.
|
||||
* @param {number} options.viewportHeightPx Rendered viewport height.
|
||||
* @param {number} options.fovyRad Vertical field of view.
|
||||
* @param {number} options.maximumPixelSize Maximum selected-model diameter.
|
||||
* @returns {number} Scale to apply to the model.
|
||||
* Seconds a follow started by a click on a target takes to slide the target
|
||||
* to the centre: the FollowTarget's `transitionS`.
|
||||
*/
|
||||
export function trackedModelScaleForPixelCap({
|
||||
baseScale,
|
||||
nativeRadiusM,
|
||||
rangeM,
|
||||
viewportHeightPx,
|
||||
fovyRad,
|
||||
maximumPixelSize,
|
||||
}) {
|
||||
if (
|
||||
!Number.isFinite(baseScale) ||
|
||||
baseScale <= 0 ||
|
||||
!Number.isFinite(nativeRadiusM) ||
|
||||
nativeRadiusM <= 0 ||
|
||||
!Number.isFinite(rangeM) ||
|
||||
rangeM <= 0 ||
|
||||
!Number.isFinite(viewportHeightPx) ||
|
||||
viewportHeightPx <= 0 ||
|
||||
!Number.isFinite(fovyRad) ||
|
||||
fovyRad <= 0 ||
|
||||
!Number.isFinite(maximumPixelSize) ||
|
||||
maximumPixelSize <= 0
|
||||
)
|
||||
return baseScale;
|
||||
const focalLengthPx = viewportHeightPx / (2 * Math.tan(fovyRad / 2));
|
||||
const projectedDiameterPx =
|
||||
(2 * nativeRadiusM * baseScale * focalLengthPx) / rangeM;
|
||||
if (projectedDiameterPx <= maximumPixelSize) return baseScale;
|
||||
return baseScale * (maximumPixelSize / projectedDiameterPx);
|
||||
export const SELECTION_FOLLOW_TRANSITION_S = 1;
|
||||
|
||||
/**
|
||||
* A follow offset that keeps the camera's view of a target it starts
|
||||
* following: the eye's own view direction, at its own distance from `at`, in
|
||||
* `at`'s east-north-up frame (an `enu` FollowTarget's `viewFrom`). Followed
|
||||
* from there, the camera neither zooms nor turns; only the eye moves, so the
|
||||
* target comes to the centre. Null without an eye, or with the eye at `at`.
|
||||
* @param {{position: object, direction: object}|null|undefined} pose The
|
||||
* camera port's pose.
|
||||
* @param {{x: number, y: number, z: number}|null|undefined} at The target.
|
||||
* @returns {{x: number, y: number, z: number}|null}
|
||||
*/
|
||||
export function keptViewFrom(pose, at) {
|
||||
if (!pose?.position || !pose?.direction || !at) return null;
|
||||
const range = distance(pose.position, at);
|
||||
if (!(range > 0) || !Number.isFinite(range)) return null;
|
||||
const look = normalize(inverseFrameVector(eastNorthUp(at), pose.direction));
|
||||
return scale(look, -range);
|
||||
}
|
||||
@@ -1,7 +1,17 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { trackedModelScaleForPixelCap } from './trackedCamera.js';
|
||||
import { keptViewFrom } from './trackedCamera.js';
|
||||
import {
|
||||
distance,
|
||||
eastNorthUp,
|
||||
framePoint,
|
||||
frameVector,
|
||||
fromDegrees,
|
||||
magnitude,
|
||||
normalize,
|
||||
scale,
|
||||
} from '../geo/index.js';
|
||||
import { clampFollowEye as clampTrackedCameraPosition } from '../render/cesium/follow.js';
|
||||
|
||||
test('tracked camera origin crossing returns to the prior side at the minimum range', () => {
|
||||
@@ -12,7 +22,9 @@ test('tracked camera origin crossing returns to the prior side at the minimum ra
|
||||
const previous = new Cesium.Cartesian3(0, -1000, 600);
|
||||
assert.equal(clampTrackedCameraPosition(camera, previous, 150), true);
|
||||
assert.ok(Cesium.Cartesian3.dot(camera.position, previous) > 0);
|
||||
assert.ok(Math.abs(Cesium.Cartesian3.magnitude(camera.position) - 150) < 1e-9);
|
||||
assert.ok(
|
||||
Math.abs(Cesium.Cartesian3.magnitude(camera.position) - 150) < 1e-9,
|
||||
);
|
||||
});
|
||||
|
||||
test('tracked camera clamps a too-close approach along the current sight line', () => {
|
||||
@@ -41,29 +53,24 @@ test('tracked camera leaves a safe approach unchanged', () => {
|
||||
assert.deepEqual(camera.position, before);
|
||||
});
|
||||
|
||||
test('tracked model keeps calibrated scale when it projects below the pixel cap', () => {
|
||||
const scale = trackedModelScaleForPixelCap({
|
||||
baseScale: 24,
|
||||
nativeRadiusM: 1.43,
|
||||
rangeM: 1000,
|
||||
viewportHeightPx: 800,
|
||||
fovyRad: Math.PI / 3,
|
||||
maximumPixelSize: 104,
|
||||
});
|
||||
assert.equal(scale, 24);
|
||||
test('a kept view follows from the eye: its own view direction at its own range', () => {
|
||||
const at = fromDegrees(-122.2, 37.7, 600);
|
||||
const enu = eastNorthUp(at);
|
||||
// An eye 2 km off, looking a little beside the target.
|
||||
const eye = framePoint(enu, { x: 300, y: -1600, z: 1100 });
|
||||
const direction = normalize(frameVector(enu, { x: -250, y: 1600, z: -1150 }));
|
||||
const viewFrom = keptViewFrom({ position: eye, direction }, at);
|
||||
assert.ok(Math.abs(magnitude(viewFrom) - distance(eye, at)) < 1e-6);
|
||||
// Followed from there, the eye looks the way it looked.
|
||||
const followedLook = normalize(frameVector(enu, scale(viewFrom, -1)));
|
||||
assert.ok(distance(followedLook, direction) < 1e-12);
|
||||
});
|
||||
|
||||
test('tracked model shrinks smoothly when close enough to exceed the pixel cap', () => {
|
||||
const scale = trackedModelScaleForPixelCap({
|
||||
baseScale: 24,
|
||||
nativeRadiusM: 1.43,
|
||||
rangeM: 150,
|
||||
viewportHeightPx: 800,
|
||||
fovyRad: Math.PI / 3,
|
||||
maximumPixelSize: 104,
|
||||
});
|
||||
const focalLengthPx = 800 / (2 * Math.tan(Math.PI / 6));
|
||||
const projectedDiameterPx = (2 * 1.43 * scale * focalLengthPx) / 150;
|
||||
assert.ok(scale < 24);
|
||||
assert.ok(Math.abs(projectedDiameterPx - 104) < 1e-9);
|
||||
test('a kept view needs an eye apart from the target', () => {
|
||||
const at = fromDegrees(-122.2, 37.7, 600);
|
||||
assert.equal(keptViewFrom(null, at), null);
|
||||
assert.equal(
|
||||
keptViewFrom({ position: at, direction: { x: 0, y: 0, z: -1 } }, at),
|
||||
null,
|
||||
);
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,83 +0,0 @@
|
||||
/**
|
||||
* Zoom-driven 2D↔3D policy for the TRACKED contact (both flight layers).
|
||||
*
|
||||
* The fleet's 3D models stay behind the DISPLAY-rail "3D" toggle (`models3d`)
|
||||
* — hundreds of GLBs are a draw-call budget decision the operator owns. Since
|
||||
* 2026-08-22 that toggle DEFAULTS ON in `proximity` (owner directive), so the
|
||||
* fleet is armed on a fresh boot; proximity is itself the budget, admitting only
|
||||
* the nearest MODEL_MAX in view below the fleet ceiling. The contact you have
|
||||
* SELECTED is still a separate case: it is exactly one model, it is what the
|
||||
* camera is pointed at, and the operator's expectation is that zooming in on a
|
||||
* target resolves it into an aircraft. So the tracked contact's handoff is
|
||||
* DEFAULT behaviour, driven purely by camera distance and never consulting the
|
||||
* toggle at all (owner directive, 2026-08-19).
|
||||
*
|
||||
* Threshold history — the tracked contact used to inherit the fleet ceiling
|
||||
* `MODEL_ALT_CEIL_M = 800_000` m, and a first pass raised it to 1_000_000 m to
|
||||
* make the airframe arrive sooner. Owner playtest 2026-08-20 rejected that: the
|
||||
* model "pops to 3D far too early" — a 26 m airframe held at its minimum pixel
|
||||
* size from ~1 Mm out reads as a floating toy, not an aircraft. The ruling is a
|
||||
* MUCH closer swap: 2D is correct at ~600_000 m, and the handoff belongs at
|
||||
* ~150_000 m. That is the constant below.
|
||||
*
|
||||
* NOTE — the tracked contact now enters 3D *later* (nearer) than the FLEET does.
|
||||
* Cruise altitudes between 150_000 m and the fleet's 800_000 m ceiling draw the
|
||||
* surrounding contacts as models while the SELECTED one is still a billboard
|
||||
* (the fleet pass skips the tracked icao, so nothing double-draws — it is purely
|
||||
* an ordering difference). As of the 2026-08-22 default flip this is what an
|
||||
* operator sees WITHOUT arming anything, where before it needed the toggle on;
|
||||
* the inversion itself is unchanged and is still a consequence of the owner's
|
||||
* number, not an accident. It is pinned in trackedModelRegime.test.mjs so a
|
||||
* later "cleanup" cannot erase it without reading this note. Aligning the two is
|
||||
* a fleet-side decision and is explicitly out of scope here (fleet-wide auto-3D
|
||||
* is a separate post-launch change).
|
||||
*
|
||||
* HYSTERESIS — the enter and exit thresholds are deliberately asymmetric. A
|
||||
* single threshold makes an orbit AT the boundary flap billboard↔model every
|
||||
* time the camera's altitude wobbles across it (the tracked orbit is a real
|
||||
* camera motion, not a static pose), which is the same flicker the fleet's
|
||||
* ADD/KEEP radii exist to prevent. Once the model owns the visual it keeps it
|
||||
* until the camera climbs 15% past the enter ceiling.
|
||||
*
|
||||
* Pure functions + constants so the policy is unit-testable without a viewer;
|
||||
* the layers own the latch (one per selection) and the Cesium plumbing.
|
||||
*/
|
||||
|
||||
/** The FLEET's ceiling (`MODEL_ALT_CEIL_M` in both layers), duplicated here only
|
||||
* so the relationship in the note above is assertable. The fleet's own constant
|
||||
* is unchanged and remains the single source for fleet behaviour. */
|
||||
export const FLEET_MODEL_ALT_CEIL_M = 800_000;
|
||||
|
||||
/** Camera altitude (m) at or below which the TRACKED contact takes its 3D model.
|
||||
* Owner playtest ruling 2026-08-20: 2D still reads correctly at ~600_000 m, and
|
||||
* the swap belongs at ~150_000 m. */
|
||||
export const TRACKED_MODEL_ENTER_ALT_M = 150_000;
|
||||
|
||||
/** Exit is 15% looser than enter — the anti-flap band for a boundary orbit. */
|
||||
export const TRACKED_MODEL_EXIT_RATIO = 1.15;
|
||||
|
||||
/** Camera altitude (m) the camera must climb past before the model hands back to the billboard. */
|
||||
export const TRACKED_MODEL_EXIT_ALT_M =
|
||||
TRACKED_MODEL_ENTER_ALT_M * TRACKED_MODEL_EXIT_RATIO; // 172_500
|
||||
|
||||
/**
|
||||
* Whether the tracked contact's 3D model owns the visual at this camera altitude.
|
||||
*
|
||||
* Hysteretic: the caller feeds back the previous answer, and that selects which
|
||||
* threshold applies. Inside the band [enter, exit) the answer is simply "whatever
|
||||
* it already was", so a camera loitering on the boundary never toggles.
|
||||
*
|
||||
* A non-finite height (no viewer yet, camera not positioned) reads as "infinitely
|
||||
* far out" → inactive, matching the `?? Infinity` the layers used before.
|
||||
*
|
||||
* @param {number} cameraHeightM - Camera altitude above the ellipsoid, in metres.
|
||||
* @param {boolean} [wasActive=false] - The regime's answer on the previous evaluation.
|
||||
* @returns {boolean} True when the tracked 3D model should own the visual.
|
||||
*/
|
||||
export function trackedModelZoomActive(cameraHeightM, wasActive = false) {
|
||||
if (!Number.isFinite(cameraHeightM)) return false;
|
||||
return (
|
||||
cameraHeightM <
|
||||
(wasActive ? TRACKED_MODEL_EXIT_ALT_M : TRACKED_MODEL_ENTER_ALT_M)
|
||||
);
|
||||
}
|
||||
@@ -6,8 +6,6 @@ import {
|
||||
isTrackingSelectionGesture,
|
||||
} from './trackingClickGesture.js';
|
||||
import { FAKE_EVENT_TYPES as TYPES, fakeInput } from '../input/testDoubles.mjs';
|
||||
import { TRACKED_MODEL_MAX_PX as CIVIL_TRACKED_MODEL_MAX_PX } from './flights.js';
|
||||
import { TRACKED_MODEL_MAX_PX as MILITARY_TRACKED_MODEL_MAX_PX } from './militaryFlights.js';
|
||||
|
||||
/** A dispatcher on a fake handler, with `onClick(click, gesture)` as the layers read it. */
|
||||
function gestureInput(now, onClick) {
|
||||
@@ -111,7 +109,20 @@ test('civilian and military click handlers apply duration only at the deselect b
|
||||
);
|
||||
});
|
||||
|
||||
test('civilian and military tracked model caps both expose the owner-selected 200 px feel', () => {
|
||||
assert.equal(CIVIL_TRACKED_MODEL_MAX_PX, 200);
|
||||
assert.equal(MILITARY_TRACKED_MODEL_MAX_PX, 200);
|
||||
test('a click on an aircraft follows it keeping the camera’s view; other selections frame it', () => {
|
||||
const sources = [
|
||||
readLayerSource(new URL('./flights.js', import.meta.url)),
|
||||
readLayerSource(new URL('./militaryFlights.js', import.meta.url)),
|
||||
];
|
||||
for (const source of sources) {
|
||||
assert.match(
|
||||
source,
|
||||
/_trackFlight\(pickedIcao, \{ origin: 'user', keepView: true \}\)/,
|
||||
);
|
||||
assert.match(
|
||||
source,
|
||||
/keepView\s*\?\s*keptViewFrom\(camera\.pose\(\), getTrackedPosition\(\)\)/,
|
||||
);
|
||||
assert.match(source, /transitionS: SELECTION_FOLLOW_TRANSITION_S/);
|
||||
}
|
||||
});
|
||||
@@ -170,7 +170,10 @@ const _b64 = (s) =>
|
||||
* little minification.
|
||||
*/
|
||||
const FLEET_RASTER_PX = 48;
|
||||
/** The selected vehicle draws bigger and deserves a crisper source. */
|
||||
/**
|
||||
* Source size for the selected vehicle: drawn at the fleet's size, from a
|
||||
* crisper raster under its wider halo.
|
||||
*/
|
||||
export const SELECTED_ICON_PX = 96;
|
||||
|
||||
/**
|
||||
@@ -240,7 +243,8 @@ export function transitIcon(kind, px = FLEET_RASTER_PX, options = {}) {
|
||||
);
|
||||
const style =
|
||||
profile === 'mono' ? 'thermal' : profile === 'crt' ? 'retro' : 'normal';
|
||||
const displayPx = (selected ? 30 : 20) * presetSpriteScale(style, selected);
|
||||
// Selected or not, the glyph is drawn at the fleet's size.
|
||||
const displayPx = FLEET_SCREEN_PX * presetSpriteScale(style, selected);
|
||||
const frame = haloFrame(presetSpriteOutlinePx(style, selected), displayPx);
|
||||
const heading = options.heading !== false;
|
||||
const bodies = heading ? HEADING_BODIES : NEUTRAL_BODIES;
|
||||
|
||||
@@ -69,8 +69,7 @@ test('all 72 variants retain the specified final halo at both display sizes', as
|
||||
for (const selected of [false, true]) {
|
||||
for (const style of ['normal', 'thermal', 'retro'])
|
||||
for (const heading of [true, false]) {
|
||||
const display =
|
||||
(selected ? 30 : 20) * presetSpriteScale(style, selected);
|
||||
const display = 20 * presetSpriteScale(style, selected);
|
||||
const svg = decode(
|
||||
transitIcon(kind, selected ? 96 : 48, { style, heading }),
|
||||
);
|
||||
@@ -157,10 +156,8 @@ test('every mono raster preserves the normal silhouette mask and aspect at CRT d
|
||||
Math.abs(mono.aspect / normal.aspect - 1) <= 0.05,
|
||||
`${kind}/${style}: aspect`,
|
||||
);
|
||||
const display =
|
||||
(selected ? 30 : 20) * presetSpriteScale(style, selected);
|
||||
const crt =
|
||||
(selected ? 30 : 20) * presetSpriteScale('retro', selected);
|
||||
const display = 20 * presetSpriteScale(style, selected);
|
||||
const crt = 20 * presetSpriteScale('retro', selected);
|
||||
assert.equal(display, crt);
|
||||
const frame = haloFrame(
|
||||
presetSpriteOutlinePx(style, selected),
|
||||
@@ -202,8 +199,7 @@ test('sensor raster halo stays dark across its screen-space band on a white roof
|
||||
for (const selected of [false, true]) {
|
||||
const pixels = [];
|
||||
for (const kind of TRANSIT_ICON_KINDS) {
|
||||
const display =
|
||||
(selected ? 30 : 20) * presetSpriteScale('thermal', selected);
|
||||
const display = 20 * presetSpriteScale('thermal', selected);
|
||||
const frame = haloFrame(
|
||||
presetSpriteOutlinePx('thermal', selected),
|
||||
display,
|
||||
|
||||
Reference in new issue
Block a user