mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Merge origin/main into the renderer-contract branch: the procedural fleet models drawn through the renderer's model sets
Aircraft, military, local ADS-B, vessel, transit and rail models come from the fleet model set, loaded up front and drawn life size through the draw port's models sets; no layer touches the viewer or Cesium outside src/render/cesium/. The models capability gains glTF bytes (gltf), a per-axis stretch (axisScale), a colour for tinted parts (maskColor) and a cut below the origin (clip: 'belowOrigin'), with conformance checks. Main's rail layer and Data Library are ported to the ports; the CCTV footprint probe keeps the globe-terrain clamp through the query port.
This commit is contained in:
commit
e3865f462f
533 files changed
+55738
-2518
No files matched your search
@@ -280,6 +280,9 @@ export function createLocalAdsbLayer({
|
||||
);
|
||||
marker.evidence = evidence;
|
||||
marker.klass = klass;
|
||||
// What picks its fleet model: the adsbdb type, else the emitter category.
|
||||
marker.typeCode = enrichment.get(marker.record.icao)?.typeCode || null;
|
||||
marker.category = marker.record.category || null;
|
||||
if (!marker.carrier) return;
|
||||
marker.iconKind = klass;
|
||||
const scale = billboardScale(marker);
|
||||
|
||||
@@ -39,6 +39,15 @@ const iconOf = (draw, id) => layerSet(draw, ':markers')?.items.get(id);
|
||||
const ringOf = (draw, id) => layerSet(draw, ':rings')?.items.get(id);
|
||||
/** Degrees of latitude where an aircraft's icon now is. */
|
||||
const latitudeOf = (draw, id) => toLonLatH(iconOf(draw, id).pos).lat;
|
||||
import { loadFleetModelSet } from '../../data/fleetModels.js';
|
||||
import { aircraftLayerModelSpec } from '../flights/modelSpec.js';
|
||||
import { fetchPublicFile } from '../../testSupport/fleetGlb.mjs';
|
||||
|
||||
// The layer draws models only once the fleet model set has loaded; load it from disk.
|
||||
const realInfo = console.info;
|
||||
console.info = () => {};
|
||||
await loadFleetModelSet({ fetchImpl: fetchPublicFile });
|
||||
console.info = realInfo;
|
||||
|
||||
function fakeReceiver(initial = {}) {
|
||||
const state = {
|
||||
@@ -572,8 +581,14 @@ test('the DISPLAY 3D toggle gives local aircraft magenta class models', async (t
|
||||
const models = layerSet(draw, ':models');
|
||||
const model = () => models.items.get('local-adsb:a0b702');
|
||||
assert.ok(model(), 'admitted');
|
||||
assert.equal(model().url, '/models/bell206.glb', 'the Flights helicopter');
|
||||
assert.equal(model().scale, 1);
|
||||
const spec = aircraftLayerModelSpec({ category: 'A7' });
|
||||
assert.equal(
|
||||
model().url,
|
||||
'/models/fleet/helicopters/generic_heli.glb',
|
||||
'the Flights rotorcraft model',
|
||||
);
|
||||
assert.ok(model().gltf instanceof Uint8Array, 'built from the loaded set');
|
||||
assert.equal(model().scale, spec.scale, 'drawn life size');
|
||||
assert.deepEqual(model().tint, MAGENTA);
|
||||
assert.deepEqual(model().colorBlend, { mode: 'mix', amount: 0.94 });
|
||||
assert.equal(model().environmentMap, false);
|
||||
@@ -1196,7 +1211,7 @@ test('a click on a local aircraft under an unowned or trail pick still selects i
|
||||
assert.equal(calls.selected.length, 2, 'the Flights contact is not taken');
|
||||
});
|
||||
|
||||
test('a grounded aircraft changing class keeps its drawn model on its own belly offset until the new one is ready', () => {
|
||||
test('a grounded aircraft changing type keeps its drawn model on its own belly offset until the new one is ready', () => {
|
||||
const { draw, viewer, camera } = modelViewer();
|
||||
const models = createLocalAdsbModels({
|
||||
viewer,
|
||||
@@ -1210,31 +1225,33 @@ test('a grounded aircraft changing class keeps its drawn model on its own belly
|
||||
const marker = {
|
||||
position: fromDegrees(0, 0, 0),
|
||||
courseDeg: 0,
|
||||
klass: 'light',
|
||||
typeCode: 'C172',
|
||||
onGround: true,
|
||||
};
|
||||
const markers = new Map([['a', marker]]);
|
||||
const display = { models3d: true, models3dMode: 'proximity' };
|
||||
const light = 100 + aircraftLayerModelSpec({ typeCode: 'C172' }).bellyM;
|
||||
const widebody = 100 + aircraftLayerModelSpec({ typeCode: 'B789' }).bellyM;
|
||||
const height = () =>
|
||||
toLonLatH(draw.sets.get('test:models').items.get('a').pos).height;
|
||||
models.frame(markers, display, 100_000);
|
||||
draw.ready('test:models', 'a');
|
||||
models.frame(markers, display, 100_001);
|
||||
assert.ok(Math.abs(height() - 101.36) < 0.01, 'light: its belly offset');
|
||||
marker.klass = 'widebody';
|
||||
assert.ok(Math.abs(height() - light) < 0.01, 'light: its belly offset');
|
||||
marker.typeCode = 'B789';
|
||||
models.frame(markers, display, 200_000);
|
||||
assert.equal(
|
||||
draw.sets.get('test:models').items.get('a').url,
|
||||
'/models/b789.glb',
|
||||
'/models/fleet/aircraft/b789.glb',
|
||||
);
|
||||
assert.ok(Math.abs(height() - 101.36) < 0.01, 'the light model still draws');
|
||||
assert.ok(Math.abs(height() - light) < 0.01, 'the light model still draws');
|
||||
draw.ready('test:models', 'a');
|
||||
models.frame(markers, display, 200_001);
|
||||
assert.ok(Math.abs(height() - 107.81) < 0.01, 'the widebody, on its own');
|
||||
assert.ok(Math.abs(height() - widebody) < 0.01, 'the widebody, on its own');
|
||||
models.destroy();
|
||||
});
|
||||
|
||||
test('a class change takes its belly offset with the new model, however soon it is ready; a scale-only change at once', () => {
|
||||
test('a type change takes its belly offset with the new model, however soon it is ready; a scale-only change at once', () => {
|
||||
const { draw, viewer, camera } = modelViewer();
|
||||
const models = createLocalAdsbModels({
|
||||
viewer,
|
||||
@@ -1248,29 +1265,37 @@ test('a class change takes its belly offset with the new model, however soon it
|
||||
const marker = {
|
||||
position: fromDegrees(0, 0, 0),
|
||||
courseDeg: 0,
|
||||
klass: 'narrowbody',
|
||||
typeCode: 'A320',
|
||||
onGround: true,
|
||||
};
|
||||
const markers = new Map([['a', marker]]);
|
||||
const display = { models3d: true, models3dMode: 'proximity' };
|
||||
const bellyOf = (typeCode) =>
|
||||
100 + aircraftLayerModelSpec({ typeCode }).bellyM;
|
||||
const item = () => draw.sets.get('test:models').items.get('a');
|
||||
const height = () => toLonLatH(item().pos).height;
|
||||
models.frame(markers, display, 100_000);
|
||||
draw.ready('test:models', 'a');
|
||||
models.frame(markers, display, 100_001);
|
||||
assert.ok(Math.abs(height() - 106.719) < 0.01, 'narrowbody');
|
||||
// The same asset at another scale: no load, no ready.
|
||||
marker.klass = 'glider';
|
||||
assert.ok(Math.abs(height() - bellyOf('A320')) < 0.01, 'A320');
|
||||
// The same model at another length: no load, no ready.
|
||||
marker.typeCode = 'A321';
|
||||
models.frame(markers, display, 100_002);
|
||||
assert.equal(item().url, '/models/airplane.glb');
|
||||
assert.equal(item().scale, 0.75);
|
||||
assert.ok(Math.abs(height() - 105.03925) < 0.01, 'at once');
|
||||
// Another asset, ready before the next eligibility pass.
|
||||
marker.klass = 'widebody';
|
||||
assert.equal(item().url, '/models/fleet/aircraft/a320.glb');
|
||||
assert.equal(
|
||||
item().scale,
|
||||
aircraftLayerModelSpec({ typeCode: 'A321' }).scale,
|
||||
);
|
||||
assert.ok(Math.abs(height() - bellyOf('A321')) < 0.01, 'at once');
|
||||
// Another model, ready before the next eligibility pass.
|
||||
marker.typeCode = 'B789';
|
||||
models.frame(markers, display, 100_003);
|
||||
assert.ok(Math.abs(height() - 105.03925) < 0.01, 'the old model draws');
|
||||
assert.ok(Math.abs(height() - bellyOf('A321')) < 0.01, 'the old model draws');
|
||||
draw.ready('test:models', 'a');
|
||||
models.frame(markers, display, 100_004);
|
||||
assert.ok(Math.abs(height() - 107.81) < 0.01, 'the widebody, on its own');
|
||||
assert.ok(
|
||||
Math.abs(height() - bellyOf('B789')) < 0.01,
|
||||
'the widebody, on its own',
|
||||
);
|
||||
models.destroy();
|
||||
});
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
sub,
|
||||
} from '../../geo/vector.js';
|
||||
import { cssColor } from '../../render/color.js';
|
||||
import { civilAircraftModelSpec } from '../flights/modelSpec.js';
|
||||
import { aircraftLayerModelSpec } from '../flights/modelSpec.js';
|
||||
import { fleetModelSet, loadFleetModelSet } from '../../data/fleetModels.js';
|
||||
import {
|
||||
FLEET_DR_INTERVAL_MS,
|
||||
MODEL_ALL_ADD_M,
|
||||
@@ -36,19 +37,28 @@ function inView(pose, point) {
|
||||
);
|
||||
}
|
||||
|
||||
/** The fleet model an aircraft draws with: its adsbdb type, else its emitter category. */
|
||||
const specOf = (marker) =>
|
||||
aircraftLayerModelSpec({
|
||||
typeCode: marker?.typeCode,
|
||||
category: marker?.category,
|
||||
});
|
||||
|
||||
/**
|
||||
* 3D models for Local ADS-B aircraft under the DISPLAY rail's 3D toggle,
|
||||
* drawn as one `models` set of the renderer's draw port.
|
||||
*
|
||||
* Mirrors the public Flights fleet: models only below the altitude ceiling,
|
||||
* the same proximity/all caps and add/keep radii, the same visible-first
|
||||
* eligibility (`selectModelEligible`), the same per-class asset and scale
|
||||
* (`civilAircraftModelSpec`) and the same tint path (a MIX colour blend, here
|
||||
* magenta, as Flights tints military amber). A billboard stays the visual
|
||||
* until its model is ready (the set's `ready`) AND placed; a grounded
|
||||
* aircraft's model rides the one-shot ground snap plus the class belly
|
||||
* offset, and without a resolved ground it stays a billboard. Models move
|
||||
* and turn in place each frame; only a class change loads another asset.
|
||||
* eligibility (`selectModelEligible`), the same fleet model per type, life
|
||||
* size (`aircraftLayerModelSpec`) and the same tint path (a MIX colour blend,
|
||||
* here magenta, as Flights tints military amber). A billboard stays the
|
||||
* visual until its model is ready (the set's `ready`) AND placed; a grounded
|
||||
* aircraft's model rides the one-shot ground snap plus the model's clearance,
|
||||
* and without a resolved ground it stays a billboard. Models move and turn in
|
||||
* place each frame; only a type change loads another model. Every fleet
|
||||
* model loads once, up front, when the layer starts (`loadFleetModelSet`),
|
||||
* and models are drawn from those bytes.
|
||||
* @param {object} options
|
||||
* @param {object} options.viewer The viewer the layer draws on; the ground
|
||||
* snap samples through it.
|
||||
@@ -74,6 +84,9 @@ export function createLocalAdsbModels({
|
||||
}) {
|
||||
if (typeof draw?.models !== 'function' || !camera) return null;
|
||||
const tint = cssColor(color) ?? color;
|
||||
void loadFleetModelSet({ resolveAsset }).catch(() => {
|
||||
/* aircraft stay billboards */
|
||||
});
|
||||
const set = draw.models({ id: setId, show: false });
|
||||
/** What ground samples see through, by set id (with every set not drawn as ground). */
|
||||
const groundSets = [setId, ...seeThrough];
|
||||
@@ -118,13 +131,16 @@ export function createLocalAdsbModels({
|
||||
}
|
||||
|
||||
/**
|
||||
* Admit a model for `id`. One admitted keeps its slot through a class
|
||||
* change: the frame pass asks for the new asset, loaded in place.
|
||||
* Admit a model for `id`. One admitted keeps its slot through a type
|
||||
* change: the frame pass asks for the new model, loaded in place. Until
|
||||
* the fleet model set has loaded the aircraft stays a billboard.
|
||||
*/
|
||||
function admit(id, marker, cap) {
|
||||
if (models.has(id) || models.size >= cap) return;
|
||||
const spec = specOf(marker);
|
||||
if (!spec.url) return;
|
||||
models.set(id, {
|
||||
bellyM: civilAircraftModelSpec(marker.klass).bellyM,
|
||||
bellyM: spec.bellyM,
|
||||
nextBellyM: null,
|
||||
sentUrl: null,
|
||||
drawnUrl: null,
|
||||
@@ -199,7 +215,7 @@ export function createLocalAdsbModels({
|
||||
* every admitted model and hand each marker's visual to its model only
|
||||
* once the model is ready and placed.
|
||||
* @param {Map<string, object>} markers Layer markers (position, courseDeg,
|
||||
* klass, onGround); `modelOwnsVisual` is written back.
|
||||
* typeCode, category, onGround); `modelOwnsVisual` is written back.
|
||||
* @param {object} preferences `{ models3d, models3dMode }`.
|
||||
* @param {number} nowMs
|
||||
*/
|
||||
@@ -222,8 +238,10 @@ export function createLocalAdsbModels({
|
||||
const record = models.get(id);
|
||||
marker.modelOwnsVisual = false;
|
||||
if (!record || !marker.position) continue;
|
||||
const spec = civilAircraftModelSpec(marker.klass);
|
||||
const spec = specOf(marker);
|
||||
if (!spec.url) continue;
|
||||
const url = resolveAsset(spec.url);
|
||||
const gltf = fleetModelSet()?.bytes?.get(spec.model);
|
||||
noteAsset(record, url, spec.bellyM);
|
||||
const position = placement(id, marker);
|
||||
const shown =
|
||||
@@ -233,6 +251,8 @@ export function createLocalAdsbModels({
|
||||
// Unplaced, it waits hidden where it last was (or at the marker).
|
||||
pos: position ?? marker.position,
|
||||
url,
|
||||
// Built from the bytes loaded up front: never fetched mid-session.
|
||||
...(gltf ? { gltf } : {}),
|
||||
orientation: {
|
||||
heading:
|
||||
((marker.courseDeg || 0) + MODEL_HEADING_OFFSET_DEG) *
|
||||
|
||||
Reference in new issue
Block a user