Merge remote-tracking branch 'origin/main' into fix/models-black

# Conflicts:
#	docs/CURRENT-STATE.md
This commit is contained in:
Sameh Khamis committed 2026-11-17 16:54:43 -08:00
commit 39f2d0b165
31 files changed
+643 -239

No files matched your search

+125 -46
View File
@@ -226,10 +226,10 @@ export function createAircraftModels({
return sets ? [sets.fleet.id, sets.tracked.id] : [];
}
/** The FLEET's 3D-model regime: models3d enabled AND the camera zoomed in past the altitude
* ceiling. Since 2026-08-22 the toggle DEFAULTS ON in `proximity`, which is itself the
* 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
/** The FLEET's 3D-model regime: models3d enabled AND the camera below the altitude ceiling,
* above which no contact can be within the model radius. Since 2026-08-22 the toggle DEFAULTS
* ON in `proximity`, which is itself the budget: models only appear within MODEL_ADD_M of the
* camera and only for the nearest MODEL_MAX. 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 routes through here too (`_trackedModelRegimeActive`), with its place in the
* fleet's cap, so selecting a contact never changes its form. */
@@ -255,20 +255,17 @@ export function createAircraftModels({
: mapCap;
}
/** Active ADD radius (m) — new planes inside this range get a model. Mode-aware: 'all' reaches far. */
/** ADD radius (m) — new planes inside this range get a model. Both modes
* share it; they differ by their caps. */
function _modelAddDistM() {
return state._models3dMode === 'all'
? policy.MODEL_ALL_ADD_M
: policy.MODEL_PROX_ADD_M;
return policy.MODEL_ADD_M;
}
/** Active KEEP radius (m) — a modeled plane keeps its model out to here (hysteresis vs ADD). */
/** KEEP radius (m) — a modeled plane keeps its model out to here (hysteresis vs ADD). */
function _modelKeepDistM() {
return state._models3dMode === 'all'
? policy.MODEL_ALL_KEEP_M
: policy.MODEL_PROX_KEEP_M;
return policy.MODEL_KEEP_M;
}
/** What a grounded model's ground sample sees through: the vertical sample
@@ -616,12 +613,11 @@ export function createAircraftModels({
state._lastFleetTickMs = 0;
}
/** Admit a fleet model for an aircraft; the icon shows until it is ready. */
/** Admit a fleet model for an aircraft; the icon shows until it is ready.
* The selected aircraft's is admitted too, and kept loaded but hidden
* while its tracked model draws it (`_keepTrackedFleetModel`). */
function _ensureModel(icao24) {
// Never model the TRACKED aircraft — it owns a separate entity billboard, and the fleet
// tick skips it, so a model here would be orphaned + double-rendered.
if (icao24 === state._trackedIcao) return;
onModelEligible(icao24);
if (state._models.has(icao24)) return;
// Without model sets (the renderer draws none) the icon stays.
@@ -636,7 +632,6 @@ export function createAircraftModels({
specKey: _specKeyFor(meta), // type-change sync compares against this
bellyM: spec.bellyM,
scale: spec.scale,
minPixelSize: policy.MODEL_MIN_PX,
});
record.url = resolveAsset(spec.url);
record.gltf = _gltfOf(spec);
@@ -727,21 +722,113 @@ 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. */
/** The tracked contact's fleet model lets go once the contact is no
* longer drawn as a model at all (out of range, 3D off, cockpit). */
function _releaseTrackedFleetModel() {
if (state._trackedIcao && state._models.has(state._trackedIcao))
_releaseModel(state._trackedIcao);
}
/** The tracked contact's fleet model (it was a model when it was
* selected, or was admitted since) stops drawing once the tracked model
* draws, or while the tracked icon carries the contact, but stays loaded:
* deselecting hands the contact straight back to it
* (`_handBackDeselected`), with no load and no icon in between. */
function _hideTrackedFleetModel() {
const icao24 = state._trackedIcao;
const record = icao24 ? state._models.get(icao24) : null;
if (!record?.show) return;
showModel(record, false);
_send(state._modelSets?.fleet, icao24, record, _modelSpec(_metaOf(icao24)));
}
/** Keep the tracked contact's fleet model loaded and placed where its icon
* is, one fleet tick at a time, so it is ready to take the contact back
* the moment it is deselected. It never shows here: it draws the contact
* only while the tracked model loads, as it did before the selection. */
function _keepTrackedFleetModel(icao24, position, course, out) {
_ensureModel(icao24);
const record = state._models.get(icao24);
if (!record) return;
const meta = _metaOf(icao24);
const set = state._modelSets?.fleet ?? null;
_retryFailedFleetModel(set, icao24, record);
const displayPos = _modelDisplayPosition(icao24, position);
if (displayPos) placeModel(record, displayPos, _modelHeading(course, meta));
else showModel(record, false); // nowhere safe to draw it
_send(set, icao24, record, _modelSpec(meta), out);
}
/**
* Hand a contact just deselected back to the fleet in the same frame: to
* its fleet model when one is loaded (kept while it was selected), placed
* where its icon is and shown, else to its icon. Runs once the contact no
* longer reads as tracked.
* @param {string} icao24
*/
function _handBackDeselected(icao24) {
const icons = state._icons;
const record = state._models.get(icao24);
if (!icons?.has(icao24)) {
if (record) _releaseModel(icao24);
return;
}
if (!record) {
icons.setShown(icao24, true);
return;
}
const pose = _pose();
if (!pose || !_modelRegimeActive(pose) || isTr3b(icao24)) {
_releaseModel(icao24); // the icon takes it back
return;
}
const t = parts.icons._displayMs();
const position = icons.position(icao24, t);
_driveFleetModelHandoff(
icao24,
record,
position,
icons.course(icao24, t),
() =>
_treatFleetModel(
icao24,
record,
distance(pose.position, position),
pose,
),
);
}
/** A fleet model's tint and alpha this tick: the contact's colour, faded
* as its icon is (focus, recession), or the IR boost's full-strength
* white. */
function _treatFleetModel(icao24, record, cameraDistanceM, pose) {
const icons = state._icons;
_treat(record, {
// IR boost must survive the per-tick treatment write — otherwise
// any alpha change would repaint the ordinary tint over the hot
// white. Boosted models also skip the recession fade: hot targets
// stay full-strength at any range (icons keep their normal
// fade — full-opacity glyph walls read as overwhelming).
base: state._irBoost ? WHITE : rgba(_modelColor(icao24)),
alpha: state._irBoost
? 1
: aircraftTreatmentAlpha({
baseAlpha: icons.alpha(icao24),
focusFactor: icons.focus(icao24),
cameraDistanceM,
cameraHeightM: pose.height,
}),
});
}
/** 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).
*
* 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
* asset at the same scale (its true size), 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. */
@@ -768,7 +855,7 @@ export function createAircraftModels({
parts.icons._iconPosition(state._trackedIcao);
if (!pos) {
_hideTrackedModel();
_releaseTrackedFleetModel();
_hideTrackedFleetModel();
return;
}
const icao24 = state._trackedIcao;
@@ -780,14 +867,13 @@ export function createAircraftModels({
// The icon carries it: after the load budget is spent, or until the
// fleet model set has loaded.
if (!_trackedModelLoadAllowed() || !spec.url) {
_releaseTrackedFleetModel();
_hideTrackedFleetModel();
return;
}
const record = createModelRecord({
specKey: _specKeyFor(meta), // type-change sync compares against this
bellyM: spec.bellyM,
scale: spec.scale,
minPixelSize: policy.MODEL_MIN_PX,
});
record.id = icao24;
record.url = resolveAsset(spec.url);
@@ -809,7 +895,7 @@ export function createAircraftModels({
const displayPos = _modelDisplayPosition(icao24, pos);
if (!displayPos) {
_hideTrackedModel(); // no ground evidence → the icon carries it
_releaseTrackedFleetModel();
_hideTrackedFleetModel();
return;
}
placeModel(
@@ -820,7 +906,7 @@ export function createAircraftModels({
_poseParts(record, meta, spec);
showModel(record, record.ready);
_send(state._modelSets.tracked, icao24, record, spec);
if (record.ready) _releaseTrackedFleetModel();
if (record.ready) _hideTrackedFleetModel();
}
/**
@@ -979,8 +1065,6 @@ 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 (
@@ -1003,6 +1087,17 @@ export function createAircraftModels({
}
continue;
}
// The tracked contact draws as `_updateTrackedModel` says; its fleet
// model is only kept ready for when it is deselected.
if (icao24 === state._trackedIcao) {
_keepTrackedFleetModel(
icao24,
position,
icons.course(icao24, t),
items,
);
continue;
}
_ensureModel(icao24);
const record = state._models.get(icao24);
const cameraDistanceM = distance(camPos, position);
@@ -1011,24 +1106,7 @@ export function createAircraftModels({
record,
position,
icons.course(icao24, t),
() => {
_treat(record, {
// IR boost must survive the per-tick treatment write — otherwise
// any alpha change would repaint the ordinary tint over the hot
// white. Boosted models also skip the recession fade: hot targets
// stay full-strength at any range (icons keep their normal
// fade — full-opacity glyph walls read as overwhelming).
base: state._irBoost ? WHITE : rgba(_modelColor(icao24)),
alpha: state._irBoost
? 1
: aircraftTreatmentAlpha({
baseAlpha: icons.alpha(icao24),
focusFactor: icons.focus(icao24),
cameraDistanceM,
cameraHeightM: pose.height,
}),
});
},
() => _treatFleetModel(icao24, record, cameraDistanceM, pose),
items,
);
}
@@ -1056,6 +1134,7 @@ export function createAircraftModels({
_releaseModels,
_showReleasedIcon,
_releaseTrackedModel,
_handBackDeselected,
_updateTrackedModel,
_fleetTick,
};
+107 -20
View File
@@ -4,25 +4,18 @@ import { createAircraftModels } from './aircraftModelLayer.js';
import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
import { bindRenderer } from '../render/rendererOf.js';
import { fromDegrees } from '../geo/ellipsoid.js';
import * as flightsPolicy from '../layers/flights/policy.js';
// The flights layer's own model policy: its radii, ceiling and caps.
const POLICY = {
MODEL_ALT_CEIL_M: 800_000,
...flightsPolicy,
MODEL_MAX: 40,
MODEL_MAX_ALL: 350,
COCKPIT_MODEL_MAX: 60,
MODEL_PROX_ADD_M: 150_000,
MODEL_PROX_KEEP_M: 185_000,
MODEL_ALL_ADD_M: 400_000,
MODEL_ALL_KEEP_M: 450_000,
MODEL_MIN_PX: 24,
TRACKED_MODEL_MIN_PX: 48,
TRACKED_MODEL_MAX_PX: 600,
MODEL_HEADING_OFFSET_DEG: 0,
FLEET_DR_INTERVAL_MS: 80,
TRACKED_MODEL_MAX_LOAD_FAILS: 3,
TRACKED_MODEL_RETRY_BACKOFF_MS: 1500,
};
/** The eye's height (m): 1 km above the contacts. */
const EYE_M = 11_000;
const SPEC = {
url: 'plane.glb',
scale: 1,
@@ -34,9 +27,9 @@ const SPEC = {
/**
* A fleet of airborne contacts at `positions` (icao → ECEF), drawn by a
* models layer over a fake draw port whose fleet set can be told to fail a
* write. The eye sits above them at 30 km.
* write. The eye sits at `eyeM`, by default 1 km above them (`EYE_M`).
*/
function fleetFixture(positions) {
function fleetFixture(positions, { eyeM = EYE_M } = {}) {
const base = fakeDrawPort();
const removes = [];
let failNextUpsert = false;
@@ -67,7 +60,7 @@ function fleetFixture(positions) {
};
},
};
const eye = fromDegrees(-97.71, 30.21, 30_000);
const eye = fromDegrees(-97.71, 30.21, eyeM);
const viewer = {};
bindRenderer(viewer, {
draw,
@@ -79,7 +72,7 @@ function fleetFixture(positions) {
right: { x: 1, y: 0, z: 0 },
fovy: Math.PI / 3,
aspectRatio: 1,
height: 30_000,
height: eyeM,
}),
},
});
@@ -185,7 +178,10 @@ function fleetFixture(positions) {
};
}
const near = (k) => fromDegrees(-97.71 + k * 0.01, 30.21, 10_000);
// About 0.5 km apart, within 2 km of the eye.
const near = (k) => fromDegrees(-97.71 + k * 0.005, 30.21, 10_000);
/** A contact at the eye's height, `m` metres north of it. */
const north = (m) => fromDegrees(-97.71, 30.21 + m / 110_850, EYE_M);
const far = (k) => fromDegrees(-90 + k * 0.01, 30.21, 10_000);
test('the fleet tick hands contacts to ready models and back without a gap', () => {
@@ -326,7 +322,7 @@ test('fleet model alpha is worked out once a fleet tick from the camera then, as
const position = near(1);
const f = fleetFixture(new Map([['a1', position]]));
assert.equal(f.fleet().spec.recede ?? null, null, 'the set does not recede');
const eye = fromDegrees(-97.71, 30.21, 30_000);
const eye = fromDegrees(-97.71, 30.21, EYE_M);
const expected = (focusFactor) =>
aircraftTreatmentAlpha({
baseAlpha: 0.8,
@@ -336,7 +332,7 @@ test('fleet model alpha is worked out once a fleet tick from the camera then, as
eye.y - position.y,
eye.z - position.z,
),
cameraHeightM: 30_000,
cameraHeightM: EYE_M,
});
try {
// Recede from the eye on, so the haze is not 1 here.
@@ -389,3 +385,94 @@ test('a contact not there yet at the time drawn has its fleet model hidden, as o
f.tick();
assert.equal(f.fleet().items.get('a1').show, true, 'drawn again');
});
test('aircraft draw as models only within 3 km of the camera, in either mode', () => {
for (const mode of ['proximity', 'all']) {
const positions = new Map([
['inside', north(2_900)],
['outside', north(3_100)],
]);
const f = fleetFixture(positions);
f.state._models3dMode = mode;
f.tick();
for (const id of positions.keys())
if (f.fleet().items.has(id)) f.draw.ready(f.fleetId, id);
f.tick();
assert.equal(f.shown.get('inside'), false, `${mode}: a model at 2.9 km`);
assert.equal(f.fleet().items.get('inside').show, true);
assert.equal(f.shown.get('outside'), true, `${mode}: an icon at 3.1 km`);
assert.equal(f.fleet().items.has('outside'), false);
}
});
test('a model is kept out to about 3.6 km, then its icon takes over', () => {
const positions = new Map([['a1', north(2_000)]]);
const f = fleetFixture(positions);
f.tick();
f.draw.ready(f.fleetId, 'a1');
f.tick();
assert.equal(f.shown.get('a1'), false, 'a model at 2 km');
positions.set('a1', north(3_500));
f.tick();
assert.equal(f.shown.get('a1'), false, 'kept at 3.5 km');
assert.equal(f.fleet().items.get('a1').show, true);
positions.set('a1', north(3_700));
f.tick();
assert.equal(f.shown.get('a1'), true, 'released at 3.7 km');
assert.equal(f.fleet().items.has('a1'), false);
positions.set('a1', north(3_300));
f.tick();
assert.equal(
f.fleet().items.has('a1'),
false,
'not taken again until it is back within 3 km',
);
});
test('a camera high above the ground still models an aircraft within 3 km of it', () => {
// A plane at 30 km with the camera 2 km above it: the altitude ceiling
// sits above every contact's height plus the keep radius.
const plane = fromDegrees(-97.71, 30.21, 30_000);
const f = fleetFixture(new Map([['high', plane]]), { eyeM: 32_000 });
f.tick();
f.draw.ready(f.fleetId, 'high');
f.tick();
assert.equal(f.shown.get('high'), false, 'its model draws it');
assert.equal(
POLICY.MODEL_ALT_CEIL_M,
POLICY.MODEL_HIGHEST_CONTACT_M + POLICY.MODEL_KEEP_M,
);
});
test('models are drawn at their true size, with no minimum pixel size', () => {
const f = fleetFixture(new Map([['a1', near(1)]]));
f.tick();
assert.equal(f.fleet().items.get('a1').minPixelSize ?? 0, 0);
});
test('the selected contact keeps a loaded, hidden fleet model that takes it back on deselect', () => {
const positions = new Map([['a1', near(1)]]);
const f = fleetFixture(positions);
// Selected while an icon: the fleet pass admits its model all the same.
f.state._trackedIcao = 'a1';
f.shown.set('a1', false); // selecting it hides its icon
f.tick();
assert.ok(f.fleet().items.has('a1'), 'admitted and loading while selected');
f.draw.ready(f.fleetId, 'a1');
positions.set('a1', near(2));
f.tick();
const item = f.fleet().items.get('a1');
assert.equal(item.show, false, 'never drawn while selected');
assert.deepEqual(
item.pos,
{ x: near(2).x, y: near(2).y, z: near(2).z },
'placed where its icon is',
);
assert.equal(f.shown.get('a1'), false, 'the icon stays hidden');
// Deselected: its model draws it in the same frame, its icon never shows.
f.state._trackedIcao = null;
f.models._handBackDeselected('a1');
assert.equal(f.fleet().items.get('a1').show, true);
assert.equal(f.shown.get('a1'), false);
});
+14 -9
View File
@@ -70,19 +70,24 @@ for (const layer of LAYERS) {
'the tracked-model driver uses the cockpit-aware predicate');
});
test(`${layer.name}: Cockpit uses standard Proximity and All radii with a lower cap`, () => {
assert.equal(numericConstant(source, 'MODEL_PROX_ADD_M'), 150_000);
assert.equal(numericConstant(source, 'MODEL_PROX_KEEP_M'), 185_000);
assert.equal(numericConstant(source, 'MODEL_ALL_ADD_M'), 400_000);
assert.equal(numericConstant(source, 'MODEL_ALL_KEEP_M'), 450_000);
test(`${layer.name}: models draw within 3 km in both modes; Cockpit's AIR band keeps its own radii`, () => {
assert.equal(numericConstant(source, 'MODEL_ADD_M'), 3000);
assert.equal(numericConstant(source, 'MODEL_KEEP_M'), 3600);
assert.equal(numericConstant(source, 'COCKPIT_MODEL_MAX'), 60);
const add = /^([ \t]*)function _modelAddDistM\b[\s\S]*?\n\1\}/m.exec(source)?.[0];
const keep = /^([ \t]*)function _modelKeepDistM\b[\s\S]*?\n\1\}/m.exec(source)?.[0];
assert.match(add, /(?:(?:flightState|state)\.)?_models3dMode\s*===\s*'all'\s*\?\s*(?:policy\.)?MODEL_ALL_ADD_M\s*:\s*(?:policy\.)?MODEL_PROX_ADD_M/);
assert.match(keep, /(?:(?:flightState|state)\.)?_models3dMode\s*===\s*'all'\s*\?\s*(?:policy\.)?MODEL_ALL_KEEP_M\s*:\s*(?:policy\.)?MODEL_PROX_KEEP_M/);
assert.doesNotMatch(add, /COCKPIT_MODEL_ADD_M/);
assert.doesNotMatch(keep, /COCKPIT_MODEL_KEEP_M/);
assert.match(add, /return\s+(?:policy\.)?MODEL_ADD_M;/, 'Proximity and All share the add radius');
assert.match(keep, /return\s+(?:policy\.)?MODEL_KEEP_M;/, 'Proximity and All share the keep radius');
// The AIR silhouettes are icons, not models: their band stays mode-aware.
assert.equal(numericConstant(source, 'COCKPIT_AIR_PROX_ADD_M'), 150_000);
assert.equal(numericConstant(source, 'COCKPIT_AIR_PROX_KEEP_M'), 185_000);
assert.equal(numericConstant(source, 'COCKPIT_AIR_ALL_ADD_M'), 400_000);
assert.equal(numericConstant(source, 'COCKPIT_AIR_ALL_KEEP_M'), 450_000);
const near = /^([ \t]*)function _refreshCockpitNearContacts\b[\s\S]*?\n\1\}/m.exec(source)?.[0];
assert.match(near, /all\s*\?\s*COCKPIT_AIR_ALL_ADD_M\s*:\s*COCKPIT_AIR_PROX_ADD_M/);
assert.match(near, /all\s*\?\s*COCKPIT_AIR_ALL_KEEP_M\s*:\s*COCKPIT_AIR_PROX_KEEP_M/);
const cap = /^([ \t]*)function _modelCap\b[\s\S]*?\n\1\}/m.exec(source)?.[0];
assert.match(cap, /Math\.min\(\s*(?:policy\.)?COCKPIT_MODEL_MAX/,
+2 -3
View File
@@ -19,9 +19,8 @@
* marker the scene itself hides behind geometry. Everything else keeps its
* label exactly as before, which covers contacts high above the ground
* (aircraft, satellites): their markers are drawn on top of the scene by
* design, their 3D models can be scaled up to a minimum pixel size and so fill
* the very pixel being read, and a label that hid while its marker stayed on
* screen would be the worse mismatch.
* design, their 3D models can fill the very pixel being read, and a label
* that hid while its marker stayed on screen would be the worse mismatch.
*
* This file is plain arithmetic; it never touches the renderer.
*/
+4 -5
View File
@@ -111,8 +111,9 @@ let instances = 0;
* @param {object} options.viewer The scene host.
* @param {() => object|null} [options.display] `{models3d, models3dMode,
* irBoost}`.
* @param {object} options.policy `{altitudeCeilingM, minimumPixelSize,
* cap, capAll, addM, addAllM, keepM, keepAllM, intervalMs}`.
* @param {object} options.policy `{altitudeCeilingM, cap, capAll, addM,
* keepM, intervalMs}`: both 3D modes share the add/keep radii and differ
* by their caps. Models are drawn at their true size.
* @param {(url: string) => string} [options.resolveAsset]
* @param {boolean} [options.waterline] Clip each model at its waterline.
* @param {(item: object, table: object) => object|undefined} [options.partState]
@@ -207,8 +208,7 @@ export function createFleetModelLayer({
function refreshEligibility(items, prefs, eye) {
const all = prefs.models3dMode === 'all';
const cap = all ? policy.capAll : policy.cap;
const addM = all ? policy.addAllM : policy.addM;
const keepM = all ? policy.keepAllM : policy.keepM;
const { addM, keepM } = policy;
const candidates = [];
for (const [id, item] of items) {
if (!item.position || item.show === false || !item.spec?.url) continue;
@@ -261,7 +261,6 @@ export function createFleetModelLayer({
...(fleetAxisScale(item.spec)
? { axisScale: fleetAxisScale(item.spec) }
: {}),
minPixelSize: policy.minimumPixelSize,
environmentMap: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS.enabled,
...(boost
? {
+36 -7
View File
@@ -19,6 +19,7 @@ import {
vesselModelSpec,
} from './fleetModels.js';
import { fetchPublicFile } from '../testSupport/fleetGlb.mjs';
import { FLEET_MODEL_POLICY } from '../layers/flights/policy.js';
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
import { eastNorthUp } from '../geo/frames.js';
import { fromDegrees, toLonLatH } from '../geo/ellipsoid.js';
@@ -29,15 +30,11 @@ console.info = () => {};
const set = await loadFleetModelSet({ fetchImpl: fetchPublicFile });
console.info = realInfo;
// The layers' own policy (3 km add, about 3.6 km keep), with small caps.
const POLICY = Object.freeze({
altitudeCeilingM: 800_000,
minimumPixelSize: 16,
...FLEET_MODEL_POLICY,
cap: 2,
capAll: 4,
addM: 5_000,
addAllM: 20_000,
keepM: 6_000,
keepAllM: 24_000,
intervalMs: 80,
});
@@ -117,7 +114,7 @@ test('the icon stays the visual until the model is ready; only the nearest are d
);
const near = models.items.get('near');
assert.equal(near.scale, spec.scale, 'drawn life size');
assert.equal(near.minPixelSize, POLICY.minimumPixelSize);
assert.equal(near.minPixelSize ?? 0, 0, 'at its true size: no pixel floor');
assert.equal(near.meta, 'near', 'picked as its vehicle');
assert.equal(near.show, false, 'hidden until ready');
@@ -158,6 +155,38 @@ test('the icon stays the visual until the model is ready; only the nearest are d
assert.equal(models.disposed, true);
});
test('vehicles draw as models within 3 km in either mode, and keep them to about 3.6 km', () => {
// The camera 1 km up: a vehicle `metres` east is sqrt(1 km² + metres²) away.
const at = (km) => Math.sqrt(km * km - 1) * 1_000;
for (const mode of ['proximity', 'all']) {
const { viewer, draw } = fakeViewer();
const layer = createFleetModelLayer({
viewer,
display: () => ({ models3d: true, models3dMode: mode }),
policy: POLICY,
});
const spec = transitModelSpec(set, { mode: 'tram' });
const items = new Map([
['in', itemAt(at(2.9), spec, { pickId: 'in' })],
['out', itemAt(at(3.1), spec, { pickId: 'out' })],
]);
layer.frame(items, 0);
const models = modelSet(draw);
assert.deepEqual(
[...models.items.keys()],
['in'],
`${mode}: 2.9 km, not 3.1 km`,
);
items.set('in', itemAt(at(3.5), spec, { pickId: 'in' }));
layer.frame(items, 100);
assert.ok(models.items.has('in'), `${mode}: kept at 3.5 km`);
items.set('in', itemAt(at(3.7), spec, { pickId: 'in' }));
layer.frame(items, 200);
assert.equal(models.items.size, 0, `${mode}: released at 3.7 km`);
layer.destroy();
}
});
test('models stay off above the altitude ceiling', () => {
const { viewer, draw } = fakeViewer(POLICY.altitudeCeilingM + 1);
const layer = createFleetModelLayer({
+13 -5
View File
@@ -127,19 +127,27 @@ export function courseSlewCapDps(speedMps, maxDps, minDps = COURSE_MIN_DPS) {
* fixes still describe clear movement. The delayed renderer already derives a
* matching segment speed and course from those fixes, so tracking and cockpit
* consumers should prefer that pair over stale poll fields.
*
* A host-supplied placement's speed (`derivedFromPlacement`) is how fast the
* marker is drawn, not how fast the aircraft goes: a placement waiting for its
* fixes to catch up stands still at 0. The reported ground speed is shown
* then, and the placement's only when nothing is reported.
*/
export function displayedKinematics({
derivedSpeedMps,
derivedTrackDeg,
reportedSpeedMps,
reportedTrackDeg,
derivedFromPlacement = false,
} = {}) {
const reported = Number.isFinite(reportedSpeedMps);
return {
speedMps: Number.isFinite(derivedSpeedMps)
? Math.max(0, derivedSpeedMps)
: Number.isFinite(reportedSpeedMps)
? Math.max(0, reportedSpeedMps)
: null,
speedMps:
Number.isFinite(derivedSpeedMps) && !(derivedFromPlacement && reported)
? Math.max(0, derivedSpeedMps)
: reported
? Math.max(0, reportedSpeedMps)
: null,
trackDeg: Number.isFinite(derivedTrackDeg)
? derivedTrackDeg
: Number.isFinite(reportedTrackDeg)
+7
View File
@@ -43,6 +43,13 @@ test('displayedKinematics preserves a derived stop and falls back when unavailab
}), { speedMps: 80, trackDeg: 180 });
});
test('displayedKinematics shows the reported speed over a placement standing still', () => {
const placed = { derivedSpeedMps: 0, derivedTrackDeg: 90, derivedFromPlacement: true };
assert.deepEqual(displayedKinematics({ ...placed, reportedSpeedMps: 230, reportedTrackDeg: 88 }),
{ speedMps: 230, trackDeg: 90 });
assert.deepEqual(displayedKinematics(placed), { speedMps: 0, trackDeg: 90 });
});
test('stale coasting follows last source contact without allowing indefinite drift', () => {
const fix = 1_000_000;
assert.equal(staleCoastLimitSeconds({ fixEpochMs: fix }), 60);
+97 -5
View File
@@ -1176,11 +1176,10 @@ for (const fixture of LAYERS) {
viewer.draw.ready(modelSet(fixture, viewer, 'tracked').spec.id, ICAO);
fixture.driveTrackedModel();
assert.equal(
fixture.ensureFleetModel(ICAO),
null,
'once the tracked model draws, the fleet model lets go',
);
const kept = fixture.ensureFleetModel(ICAO);
assert.ok(kept, 'once the tracked model draws, the fleet model is kept');
assert.equal(kept.ready, true, 'loaded');
assert.equal(kept.show, false, 'but hidden: one model draws the contact');
assert.equal(
fixture.trackedBillboardColor()[3],
0,
@@ -1192,6 +1191,99 @@ for (const fixture of LAYERS) {
}
});
test(`${fixture.name}: deselecting hands the contact straight back to its loaded fleet model, with no icon flash`, () => {
clearTr3bRegistry();
try {
fixture.layer.setParams({ models3d: true });
const viewer = viewerAtHeight(30_000);
const position = Cesium.Cartesian3.fromDegrees(-97.71, 30.21, 10_668);
const icon = fixture.seed({
viewer,
models: [
[
ICAO,
{
ready: true,
show: true,
modelMatrix: Cesium.Matrix4.fromTranslation(position),
},
],
],
trackedModelEligible: null,
});
fixture.driveTrackedModel();
viewer.draw.ready(modelSet(fixture, viewer, 'tracked').spec.id, ICAO);
fixture.driveTrackedModel();
assert.equal(
fixture.trackedModel().ready,
true,
'the tracked model draws',
);
icon.show = false; // as selecting it hides it
fixture.layer.stopTracking();
const fleetItem = modelSet(fixture, viewer, 'fleet').items.get(ICAO);
assert.equal(
fleetItem?.show,
true,
'the kept fleet model draws the contact in the same frame',
);
assert.equal(icon.show, false, 'and its icon never shows');
assert.equal(
modelSet(fixture, viewer, 'tracked').items.has(ICAO),
false,
'the tracked model is gone',
);
} finally {
fixture.layer.setParams({ models3d: false });
fixture.layer.stopTracking();
}
});
test(`${fixture.name}: deselecting shows the icon only when no fleet model is loaded`, () => {
clearTr3bRegistry();
try {
fixture.layer.setParams({ models3d: true });
const viewer = viewerAtHeight(30_000);
// Selected as an icon: no fleet model at all.
let icon = fixture.seed({
viewer,
models: [],
trackedModelEligible: null,
});
fixture.layer.stopTracking();
assert.equal(icon.show, true, 'no fleet model: the icon');
// A fleet model still loading when it is deselected.
icon = fixture.seed({
viewer,
models: [[ICAO, { ready: false, show: false }]],
trackedModelEligible: null,
});
fixture.layer.stopTracking();
assert.equal(icon.show, true, 'a fleet model not loaded yet: the icon');
assert.notEqual(
modelSet(fixture, viewer, 'fleet').items.get(ICAO)?.show,
true,
'and the model stays hidden until it loads',
);
// 3D turned off meanwhile: the icon, and the fleet model goes.
icon = fixture.seed({
viewer,
models: [[ICAO, { ready: true, show: false }]],
trackedModelEligible: null,
});
fixture.layer.setParams({ models3d: false });
fixture.layer.stopTracking();
assert.equal(icon.show, true, '3D off: the icon');
assert.equal(fixture.ensureFleetModel(ICAO), null, 'no fleet model kept');
} finally {
fixture.layer.setParams({ models3d: false });
fixture.layer.stopTracking();
}
});
test(`${fixture.name}: the tracked model draws at the fleet's scale and minimum pixel size, even up close`, () => {
clearTr3bRegistry();
try {