Files
gods-eye-view/src/data/modelRecord.test.mjs
T
Sameh Khamis abe9f97768 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.
2026-11-07 17:10:38 -08:00

56 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import {
createModelRecord,
headingFrame,
modelIsRendering,
placeModel,
showModel,
} from './modelRecord.js';
test('a placed model has the frame the Cesium renderer poses it in', () => {
for (const [lon, lat, height] of [
[-97.7, 30.2, 300],
[10, -60, 1000],
[179, 89.9, 0],
])
for (const heading of [0, 0.5, 2, 4, -1]) {
const at = Cesium.Cartesian3.fromDegrees(lon, lat, height);
const expected = Cesium.Transforms.headingPitchRollToFixedFrame(
at,
new Cesium.HeadingPitchRoll(heading, 0, 0),
Cesium.Ellipsoid.WGS84,
undefined,
new Cesium.Matrix4(),
);
const frame = headingFrame(
{ x: at.x, y: at.y, z: at.z },
heading,
new Float64Array(16),
);
for (let i = 0; i < 16; i++)
assert.ok(
Math.abs(frame[i] - expected[i]) < (i >= 12 ? 1e-6 : 1e-12),
`${lon},${lat} @ ${heading}: element ${i}`,
);
}
});
test('a record renders only once ready and shown', () => {
const record = createModelRecord({ specKey: 'a@1', bellyM: 2 });
assert.equal(record.ready, false);
assert.equal(modelIsRendering(record), false);
showModel(record, true);
assert.equal(modelIsRendering(record), false);
record.ready = true;
assert.equal(modelIsRendering(record), true);
const at = { x: 1, y: 2, z: 6_400_000 };
placeModel(record, at, 0.3);
at.x = 99;
assert.equal(record.position.x, 1, 'the position is copied');
assert.equal(record.matrix[12], 1);
assert.equal(record.heading, 0.3);
assert.equal(modelIsRendering(null), false);
});