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

+97 -37
View File
@@ -1,47 +1,71 @@
/**
* @module modelRecord
* @description A layer's own record of one 3D model it draws, held in the
* layer's maps under the contact's id, so the layer reads what it pushed back
* from itself instead of from the renderer's object.
* @description A layer's own record of one 3D model it draws through a draw
* port `models` set, held in the layer's maps under the contact's id, so the
* layer reads what it pushed (and what the set told it) back from itself.
*
* Write `show` and the placement with {@link showModel} and {@link placeModel};
* read them from the record. What the renderer measures (`ready`,
* `computedScale`) is still read from `record.model`. Colour stays out: the
* cyber-sonar theme writes it too and reads the live value.
* Write `show` and the placement with {@link showModel} and
* {@link placeModel}; the set's `ready` event sets `ready`. The placement is
* kept as the column-major frame the model is posed in, the same frame a
* renderer builds from the item's position and heading, so anchors on the
* model can be read from it.
*/
import * as Cesium from 'cesium';
import { eastNorthUp } from '../geo/frames.js';
/**
* @typedef {object} ModelRecord
* @property {Cesium.Model} model
* @property {string|null} id The item's id in its set, where the record
* does not live under it in a map (the tracked model).
* @property {string|null} url The model asset the layer sends.
* @property {boolean} ready Whether the set reported the model loaded and
* posed (`ready`).
* @property {boolean} show Whether the layer last showed the model.
* @property {Cesium.Matrix4} matrix Where the layer last placed it.
* @property {string|null} specKey The model spec it was loaded for; a class
* change reloads.
* @property {boolean|null} irBoost The IR boost it was loaded with; a flip
* reloads.
* @property {boolean} placed Whether the layer has placed it yet.
* @property {Float64Array} matrix Where the layer last placed it: the
* east-north-up frame at its position turned by its heading, column-major.
* @property {{x:number,y:number,z:number}} position Where it is placed.
* @property {number} heading Radians, as the item's `orientation.heading`.
* @property {string|null} specKey The model spec it was admitted for; a
* class change readmits.
* @property {number} bellyM Metres from the model origin to its belly, to sit
* it on the ground.
* @property {number} scale The `scale` the layer last sent.
* @property {number} minPixelSize The `minPixelSize` the layer last sent.
* @property {number[]|null} tint The `tint` the layer last sent.
* @property {string|null} sent The item last sent, as a key, or null.
*/
/**
* A record for a model the layer just made, from the options it made it with
* (Cesium's defaults when none: shown, at the identity).
* @param {Cesium.Model} model
* @param {{specKey?: string, irBoost?: boolean, bellyM?: number}} [fields]
* A record for a model the layer just admitted.
* @param {{id?: string|null, url?: string|null, specKey?: string,
* bellyM?: number, scale?: number, minPixelSize?: number}} [fields]
* @returns {ModelRecord}
*/
export function createModelRecord(
model,
{ specKey = null, irBoost = null, bellyM = 0 } = {},
) {
export function createModelRecord({
id = null,
url = null,
specKey = null,
bellyM = 0,
scale = 1,
minPixelSize = 0,
} = {}) {
const matrix = new Float64Array(16);
matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1;
return {
model,
show: model.show ?? true,
matrix: Cesium.Matrix4.clone(model.modelMatrix ?? Cesium.Matrix4.IDENTITY),
id,
url,
ready: false,
show: false,
placed: false,
matrix,
position: { x: 0, y: 0, z: 0 },
heading: 0,
specKey,
irBoost,
bellyM,
scale,
minPixelSize,
tint: null,
sent: null,
};
}
@@ -52,21 +76,57 @@ export function createModelRecord(
*/
export function showModel(record, show) {
record.show = show;
record.model.show = show;
}
/**
* Place a model and record where. The matrix is copied into both, so a shared
* scratch can be passed and reused straight after.
* Place a model at `position` turned by `heading` (radians clockwise from
* north about the local up, as `orientation.heading`), and record its frame.
* @param {ModelRecord} record
* @param {Cesium.Matrix4} matrix
* @param {{x:number,y:number,z:number}} position ECEF; copied.
* @param {number} heading
*/
export function placeModel(record, matrix) {
Cesium.Matrix4.clone(matrix, record.matrix);
const model = record.model;
// Cesium clones the model's own matrix each frame, so write into it in place.
if (model.modelMatrix) Cesium.Matrix4.clone(matrix, model.modelMatrix);
else model.modelMatrix = Cesium.Matrix4.clone(matrix);
export function placeModel(record, position, heading) {
record.position.x = position.x;
record.position.y = position.y;
record.position.z = position.z;
record.heading = heading;
record.placed = true;
headingFrame(record.position, heading, record.matrix);
}
/**
* The east-north-up frame at `origin` turned by `heading` about its up axis,
* as a column-major 4x4: a heading of 0 keeps local x east, and a positive
* heading turns it clockwise seen from above.
* @param {{x:number,y:number,z:number}} origin
* @param {number} heading Radians.
* @param {Float64Array|number[]} out
* @returns {Float64Array|number[]} `out`.
*/
export function headingFrame(origin, heading, out) {
const enu = eastNorthUp(origin);
const c = Math.cos(heading);
const s = Math.sin(heading);
const e = enu.x;
const n = enu.y;
const u = enu.z;
out[0] = e.x * c - n.x * s;
out[1] = e.y * c - n.y * s;
out[2] = e.z * c - n.z * s;
out[3] = 0;
out[4] = e.x * s + n.x * c;
out[5] = e.y * s + n.y * c;
out[6] = e.z * s + n.z * c;
out[7] = 0;
out[8] = u.x;
out[9] = u.y;
out[10] = u.z;
out[11] = 0;
out[12] = origin.x;
out[13] = origin.y;
out[14] = origin.z;
out[15] = 1;
return out;
}
/**
@@ -75,5 +135,5 @@ export function placeModel(record, matrix) {
* @returns {boolean}
*/
export function modelIsRendering(record) {
return !!record && record.model.ready === true && record.show === true;
return !!record && record.ready === true && record.show === true;
}