Draw Flights and Military 3D models through draw-port model sets

The two aircraft layers' fleet and tracked models are now draw-port
models sets made each layer lifetime, re-posed and restyled in place,
instead of Cesium models in a collection of their own. Model records are
plain data; picks name the set and the contact, readiness comes from the
set's ready event, the IR boost restyles in place (unlit, white tint,
full blend), and the drawn scale comes from the camera pose and pixel
floor. Fleet writes go out together at the end of each tick, before the
icons they replace, and a failed write hands the contacts back to their
icons. A model that has not loaded is rewritten every few seconds so the
renderer can retry it, which replaces the tracked model's load-failure
budget. Models load off the tile-contended job queue, as before.

aircraftModelLayer.js, modelRecord.js and the flights and military
lifecycle and testing files, plus flights rendering.js, come off the
Cesium allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-07 17:10:38 -08:00
1 parent eed3b83858
commit abe9f97768
28 files changed
+1310 -1255

No files matched your search

+59 -17
View File
@@ -1,5 +1,4 @@
import * as Cesium from 'cesium';
import { CYAN_TRANSPARENT } from './policy.js';
import { CYAN_TRANSPARENT, TRACKED_CYAN } from './policy.js';
import { createModelRecord } from '../../data/modelRecord.js';
import {
aircraftIconTestSeams,
@@ -15,7 +14,7 @@ export function createTesting({
}) {
const { _seedIconForTest, _iconForTest, _setIconForTest } =
aircraftIconTestSeams(flightState, parts, 'flights');
/** Test seam for the display-floor clamp (unit-tested against real Cesium math
/** Test seam for the display-floor clamp (unit-tested against real ellipsoid math
* with seeded mesh cells — the drift mechanism is otherwise only reachable
* through a live poll + render loop). */
@@ -46,21 +45,49 @@ export function createTesting({
/**
* Seed only the mutable state needed to exercise tracked-card refreshes through
* the production poll reconciler. Tests still call `flightsLayer.update()`;
* this seam avoids constructing the browser-only Cesium layer lifecycle.
* this seam avoids constructing the browser-only layer lifecycle.
* @param {object} state
* @param {string} state.icao24
* @param {object} state.entity
* @param {object} state.meta
* @param {{position?: Cesium.Cartesian3, show?: boolean}} [state.icon]
* @param {{position?: {x: number, y: number, z: number}, show?: boolean}} [state.icon]
* Where the contact's icon is held, and whether it is shown.
* @param {{show?: boolean}} [state.iconLayer] Layer visibility.
* @param {object} state.viewer
* @param {Array<Object>} [state.history=[]]
* @param {boolean} [state.tracked=true]
* @param {Iterable<[string, object]>} [state.models=[]] - Fleet 3D models keyed
* by icao24, for the icon-hidden/model-shown handoff state.
* by icao24, for the icon-hidden/model-shown handoff state: each object
* becomes the contact's model record (`ready`, `show`, and a placement
* `modelMatrix` when given), so the test reads what the layer writes back.
* @param {object|null} [state.draw] A draw port the layer's model sets are
* made on (a test double); none keeps the records only.
*/
/** Turn a test's model fields into the contact's model record, in place. */
function _modelRecordForTest(fields, klass) {
const spec = parts.rendering._modelSpec(klass);
const base = createModelRecord({
specKey: parts.rendering._specKeyFor(klass),
bellyM: spec.bellyM,
scale: spec.scale,
});
for (const key of Object.keys(base))
if (!(key in fields)) fields[key] = base[key];
fields.ready = fields.ready === true;
fields.show = fields.show ?? true;
if (fields.modelMatrix) {
fields.matrix = Float64Array.from(fields.modelMatrix);
fields.position = {
x: fields.matrix[12],
y: fields.matrix[13],
z: fields.matrix[14],
};
fields.placed = true;
}
return fields;
}
function _setTrackedFlightRefreshStateForTest({
icao24,
entity,
@@ -71,10 +98,11 @@ export function createTesting({
history = [],
tracked = true,
models = [],
modelCollection = null,
draw = null,
}) {
flightState._viewer = viewer;
flightState._modelCollection = modelCollection;
parts.rendering._disposeModelSets();
if (draw) parts.rendering._createModelSets(viewer, { draw });
flightState._icons = createContactIcons();
flightState._icons.show = iconLayer?.show ?? true;
flightState._grounded.clear();
@@ -82,7 +110,7 @@ export function createTesting({
_seedIconForTest(icao24, icon, tracked);
flightState._models.clear();
for (const [key, model] of models)
flightState._models.set(key, createModelRecord(model));
flightState._models.set(key, _modelRecordForTest(model, meta?.klass));
flightState._detectionObjects = new Map();
flightState.records.data = new Map([[icao24, meta]]);
flightState._positionHistory = new Map([[icao24, history]]);
@@ -93,7 +121,6 @@ export function createTesting({
flightState._trackedEntity = tracked ? entity : null;
flightState._trackedModel = null;
parts.tracking._cancelPendingTrackingRestore();
flightState._trackedModelLoading = false;
// NOTE: deliberately does NOT reset the per-selection latches. They are
// production state owned by the tracking lifecycle (_resetTrackedSelectionState),
// and clearing them here would mask exactly the deselect→re-track hole this
@@ -175,7 +202,7 @@ export function createTesting({
}
/** Run one frame of the production tracked-model driver (normally a
* `scene.preUpdate` listener) so tests can pin its bounded load retries. */
* `preUpdate` listener). */
function _updateTrackedModelForTest() {
return parts.rendering._updateTrackedModel();
@@ -186,7 +213,7 @@ export function createTesting({
function _trackedBillboardColorForTest() {
return parts.rendering._modelOwnsVisual(flightState._trackedIcao)
? CYAN_TRANSPARENT
: Cesium.Color.CYAN;
: TRACKED_CYAN;
}
/** Drive the exact fleet icon-to-model handoff used by `_fleetTick`. */
@@ -200,18 +227,31 @@ export function createTesting({
);
}
/** Exercise the exact asynchronous fleet loader and return its admitted model. */
/** Exercise the exact fleet admission and return the admitted model's record. */
async function _ensureFleetModelForTest(icao24) {
await parts.rendering._ensureModel(icao24);
return flightState._models.get(icao24)?.model ?? null;
function _ensureFleetModelForTest(icao24) {
parts.rendering._ensureModel(icao24);
return flightState._models.get(icao24) ?? null;
}
/** The tracked model's record, or null. */
function _trackedModelForTest() {
return flightState._trackedModel;
}
/** The fleet and tracked model sets' ids, or null without sets. */
function _modelSetIdsForTest() {
const [fleet, tracked] = parts.rendering._modelSetIds();
return fleet ? { fleet, tracked } : null;
}
/** Run the fleet tick's grounded floor pass once, at `renderTime`. */
function _floorGroundedIconsForTest(renderTime, cameraPosition) {
parts.icons._floorGroundedIcons(
renderTime,
Cesium.JulianDate.toDate(renderTime).getTime(),
parts.motion._fixEpochMs({ time: renderTime }),
Date.now(),
cameraPosition,
);
@@ -235,5 +275,7 @@ export function createTesting({
_driveFleetModelHandoffForTest,
_iconForTest,
_ensureFleetModelForTest,
_trackedModelForTest,
_modelSetIdsForTest,
};
}