mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(flights): aircraft draw life-size fleet models chosen by type
Flights, Military Flights and Local ADS-B draw each aircraft with the fleet model its ICAO type, class or emitter category selects, scaled to the type's length, built from the up-front loaded bytes. The eight third-party aircraft models and their attribution are removed; every shipped model is now the project's own.
This commit is contained in:
1 parent
f6760ad96c
commit
fcc44d0eaf
45 files changed
+970
-1371
No files matched your search
@@ -467,54 +467,3 @@ export const CLASS_SCALE_2D = {
|
||||
bizjet: 0.72,
|
||||
uav: 0.75,
|
||||
};
|
||||
|
||||
/** 3D model scale multipliers — clamped [0.75, 1.45] while every class shares
|
||||
* the single airplane.glb (a jet mesh at C172 scale reads wrong). Widen when
|
||||
* real per-class models land in CLASS_MODEL_URL. */
|
||||
export const CLASS_SCALE_3D = {
|
||||
light: 0.75,
|
||||
glider: 0.75,
|
||||
turboprop: 0.85,
|
||||
airliner: 1.0,
|
||||
widebody: 1.3,
|
||||
quadjet: 1.45,
|
||||
helicopter: 0.8,
|
||||
fastjet: 0.8,
|
||||
bizjet: 0.8,
|
||||
uav: 0.8,
|
||||
};
|
||||
|
||||
/** Per-class glTF — all the shared airplane today; drop real assets in here.
|
||||
* NOTE for future models: each asset may need its own heading offset (the
|
||||
* shared GLB uses MODEL_HEADING_OFFSET_DEG = 180 in both layers). */
|
||||
export const CLASS_MODEL_URL = {
|
||||
light: '/models/airplane.glb',
|
||||
glider: '/models/airplane.glb',
|
||||
turboprop: '/models/airplane.glb',
|
||||
airliner: '/models/airplane.glb',
|
||||
widebody: '/models/airplane.glb',
|
||||
quadjet: '/models/airplane.glb',
|
||||
helicopter: '/models/airplane.glb',
|
||||
fastjet: '/models/airplane.glb',
|
||||
bizjet: '/models/airplane.glb',
|
||||
uav: '/models/airplane.glb',
|
||||
};
|
||||
|
||||
/** Real per-class GLBs (2026-08-15 Hangar fleet, owner picks; CC-BY 4.0 —
|
||||
* provenance in public/models/README.md). Every asset is vertex-baked to the
|
||||
* airplane.glb convention: Y-up, X = length, Z = span, nose −X (so the layers'
|
||||
* MODEL_HEADING_OFFSET_DEG = 180 applies unchanged), origin at bbox centre,
|
||||
* REAL-WORLD METERS (render at scale 1 — no MODEL_SCALE, no CLASS_SCALE_3D).
|
||||
* bellyM = origin→lowest-vertex distance (grounded-model lift, replaces the
|
||||
* airplane.glb MODEL_BELLY_OFFSET_NATIVE formula); radiusM = bounding-sphere
|
||||
* radius in meters (pixel-size math). Values measured from the shipped GLBs —
|
||||
* pinned by modelScale.test.mjs. Classes NOT listed (airliner, quadjet,
|
||||
* glider, fastjet) still render the shared airplane.glb via CLASS_MODEL_URL. */
|
||||
export const CLASS_MODEL_REAL = {
|
||||
helicopter: { url: '/models/bell206.glb', bellyM: 1.66, radiusM: 8.24 },
|
||||
light: { url: '/models/c172.glb', bellyM: 1.36, radiusM: 7.0 },
|
||||
bizjet: { url: '/models/citation2.glb', bellyM: 2.86, radiusM: 11.24 },
|
||||
uav: { url: '/models/mq9.glb', bellyM: 2.02, radiusM: 12.0 },
|
||||
widebody: { url: '/models/b789.glb', bellyM: 7.81, radiusM: 44.08 },
|
||||
turboprop: { url: '/models/atr72.glb', bellyM: 3.81, radiusM: 19.49 },
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/data/aircraftClass.test.mjs
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { classifyAircraft, CLASS_SCALE_2D, CLASS_SCALE_3D, CLASS_MODEL_URL, CLASS_MODEL_REAL } from './aircraftClass.js';
|
||||
import { classifyAircraft, CLASS_SCALE_2D } from './aircraftClass.js';
|
||||
|
||||
test('type-code classification (military layer path)', () => {
|
||||
assert.equal(classifyAircraft({ typeCode: 'F16' }), 'fastjet');
|
||||
@@ -48,19 +48,8 @@ test('typeCode outranks category; unknown → airliner', () => {
|
||||
assert.equal(classifyAircraft({ typeCode: null, category: 0 }), 'airliner');
|
||||
});
|
||||
|
||||
test('scale/url tables cover every class', () => {
|
||||
test('the icon scale table covers every class', () => {
|
||||
for (const kind of ['light','glider','turboprop','airliner','widebody','quadjet','helicopter','fastjet','bizjet','uav']) {
|
||||
assert.ok(Number.isFinite(CLASS_SCALE_2D[kind]), kind);
|
||||
assert.ok(CLASS_SCALE_3D[kind] >= 0.75 && CLASS_SCALE_3D[kind] <= 1.45, kind);
|
||||
assert.ok(typeof CLASS_MODEL_URL[kind] === 'string', kind);
|
||||
}
|
||||
});
|
||||
|
||||
test('CLASS_MODEL_REAL entries carry the fields the layers consume', () => {
|
||||
for (const [kind, spec] of Object.entries(CLASS_MODEL_REAL)) {
|
||||
assert.ok(spec.url.startsWith('/models/') && spec.url.endsWith('.glb'), kind);
|
||||
assert.ok(spec.radiusM > 0 && spec.bellyM > 0, kind);
|
||||
// every real-model class must also exist in the classifier tables
|
||||
assert.ok(Number.isFinite(CLASS_SCALE_2D[kind]), kind);
|
||||
}
|
||||
});
|
||||
@@ -160,8 +160,8 @@ const BODIES = {
|
||||
L -3,31 L -8,34 L -8,30 L -6,16
|
||||
L -27,26 L -27,20 L -5,-8
|
||||
C -4.6,-16 -4,-24 -3.5,-30 Z" fill="white" ${STROKE}/>`,
|
||||
// 2026-08-15 Hangar additions: two NEW classes shipped with the real-model
|
||||
// fleet (CLASS_MODEL_REAL). Same contract as the set above: 96×96 nose-up,
|
||||
// 2026-08-15 additions: two NEW classes (bizjet, uav). Same contract as
|
||||
// the set above: 96×96 nose-up,
|
||||
// white fill, hairline stroke, tint-safe.
|
||||
// Business jet — slender fuselage, modest swept wing, aft engines, T-tail.
|
||||
bizjet: `
|
||||
|
||||
@@ -6,9 +6,8 @@ import { AIRCRAFT_ENVIRONMENT_MAP_OPTIONS } from './aircraftModelLighting.js';
|
||||
|
||||
/**
|
||||
* Every aircraft model drawn in the scene skips Cesium's dynamic environment
|
||||
* map (a sky render and GPU readback per model). The preload calls only warm
|
||||
* the glTF cache and are never added to the scene, so they are left out:
|
||||
* drawn models are the calls that set a minimum pixel size.
|
||||
* map (a sky render and GPU readback per model). Drawn models are the calls
|
||||
* that set a minimum pixel size.
|
||||
*/
|
||||
const SOURCES = [
|
||||
{
|
||||
@@ -36,7 +35,9 @@ test('the shared option turns the dynamic environment map off', () => {
|
||||
for (const { name, source } of SOURCES) {
|
||||
test(`${name}: every drawn aircraft model skips the dynamic environment map`, () => {
|
||||
const calls = [
|
||||
...source.matchAll(/(?:fromGltfAsync|loadModel)\(\{([\s\S]*?)\}\)/g),
|
||||
...source.matchAll(
|
||||
/(?:fromGltfAsync\(|loadModel\(|(?:_createModel|createFleetModel)\(\s*\w+,\s*)\{([\s\S]*?)\n\s*\}[,)]/g,
|
||||
),
|
||||
]
|
||||
.map((match) => match[1])
|
||||
.filter((options) => /\bminimumPixelSize:/.test(options));
|
||||
|
||||
@@ -28,11 +28,13 @@ for (const layer of LAYERS) {
|
||||
const source = readLayerSource(layer.path);
|
||||
|
||||
test(`${layer.name}: every GLB creation bypasses the tile-contended frame-spread queue`, () => {
|
||||
const calls = [...source.matchAll(/Cesium\.Model\.fromGltfAsync\(\{([\s\S]*?)\}\)/g)];
|
||||
assert.ok(calls.length >= 3, `expected fleet, tracked, and preload model calls; found ${calls.length}`);
|
||||
const calls = [...source.matchAll(/_createModel\(\s*\w+,\s*\{([\s\S]*?)\n\s*\}\)/g)];
|
||||
assert.ok(calls.length >= 2, `expected fleet and tracked model calls; found ${calls.length}`);
|
||||
assert.doesNotMatch(source, /Cesium\.Model\.fromGltfAsync\(/,
|
||||
'every model is built from the loaded fleet set through _createModel');
|
||||
for (const [index, call] of calls.entries()) {
|
||||
assert.match(call[1], /\basynchronous:\s*false\b/,
|
||||
`Model.fromGltfAsync call ${index + 1} must keep bounded GLB readiness independent of tile jobs`);
|
||||
`_createModel call ${index + 1} must keep bounded GLB readiness independent of tile jobs`);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,415 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { horizonOccluder } from './iconOrientation.js';
|
||||
import { selectModelEligible } from './modelEligibility.js';
|
||||
import { AIRCRAFT_ENVIRONMENT_MAP_OPTIONS } from './aircraftModelLighting.js';
|
||||
import { fleetModelSet } from './fleetModels.js';
|
||||
|
||||
/**
|
||||
* Cesium models of the procedural fleet set (`fleetModels.js`), and the
|
||||
* icon-to-model handoff the Vessels, Transit and Rail layers share.
|
||||
*/
|
||||
|
||||
/** Every fleet GLB is nose -X: opposite Cesium's heading 0. */
|
||||
export const FLEET_HEADING_OFFSET_DEG = 180;
|
||||
|
||||
/**
|
||||
* Create a Cesium Model of `spec` from the up-front loaded bytes, so no model
|
||||
* is fetched mid-session. Each model keeps its own URL as its base path: the
|
||||
* glTF cache keys by it, and two models sharing one would share geometry.
|
||||
* Rejects when the set is not loaded or the model's GLB failed to load.
|
||||
* @param {object} spec `fleetModelSpec`.
|
||||
* @param {object} options Cesium `Model.fromGltfAsync` options.
|
||||
* @param {{resolveAsset?: (url: string) => string, set?: object|null,
|
||||
* load?: (options: object) => Promise<object>}} [context]
|
||||
* @returns {Promise<object>} Cesium Model.
|
||||
*/
|
||||
export function createFleetModel(
|
||||
spec,
|
||||
options,
|
||||
{
|
||||
resolveAsset = (url) => url,
|
||||
set = fleetModelSet(),
|
||||
// Looked up when called, so a replaced `fromGltfAsync` (tests) is the one used.
|
||||
load = (o) => Cesium.Model.fromGltfAsync(o),
|
||||
} = {},
|
||||
) {
|
||||
const bytes = set?.bytes?.get(spec?.model);
|
||||
if (!bytes)
|
||||
return Promise.reject(new Error(`fleet model ${spec?.model} not loaded`));
|
||||
return load({
|
||||
environmentMapOptions: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS,
|
||||
...options,
|
||||
gltf: bytes,
|
||||
basePath: resolveAsset(spec.url),
|
||||
});
|
||||
}
|
||||
|
||||
const tintShaders = new Map();
|
||||
|
||||
/**
|
||||
* The custom shader that paints a route colour where a transit model's
|
||||
* `_TINT` vertex attribute marks it: drawn colour = vertex colour ×
|
||||
* mix(1, colour, _TINT). One shader per colour, shared by every model drawn in
|
||||
* it (Cesium compiles the program once; uniforms are per shader).
|
||||
* @param {Cesium.Color} color
|
||||
* @returns {Cesium.CustomShader}
|
||||
*/
|
||||
export function fleetTintShader(color) {
|
||||
const key = color.toCssHexString();
|
||||
let shader = tintShaders.get(key);
|
||||
if (!shader) {
|
||||
shader = new Cesium.CustomShader({
|
||||
mode: Cesium.CustomShaderMode.MODIFY_MATERIAL,
|
||||
uniforms: {
|
||||
u_routeColor: {
|
||||
type: Cesium.UniformType.VEC3,
|
||||
value: new Cesium.Cartesian3(color.red, color.green, color.blue),
|
||||
},
|
||||
},
|
||||
fragmentShaderText: `
|
||||
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
|
||||
vec3 route = czm_srgbToLinear(u_routeColor);
|
||||
material.diffuse *= mix(vec3(1.0), route, fsInput.attributes.tint);
|
||||
}
|
||||
`,
|
||||
});
|
||||
tintShaders.set(key, shader);
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the world matrix of a fleet model standing at `position` heading
|
||||
* `headingDeg` (clockwise from north) into `result`, stretched by the spec's
|
||||
* beam and height scales relative to its length scale (a Model's own `scale`
|
||||
* carries the length scale, so its minimum pixel size still applies).
|
||||
* @param {Cesium.Cartesian3} position
|
||||
* @param {number} headingDeg
|
||||
* @param {object} spec `fleetModelSpec`.
|
||||
* @param {Cesium.Matrix4} result
|
||||
* @param {Cesium.HeadingPitchRoll} scratchHpr
|
||||
* @returns {Cesium.Matrix4}
|
||||
*/
|
||||
export function fleetModelMatrix(
|
||||
position,
|
||||
headingDeg,
|
||||
spec,
|
||||
result,
|
||||
scratchHpr,
|
||||
) {
|
||||
scratchHpr.heading = Cesium.Math.toRadians(
|
||||
(headingDeg || 0) + FLEET_HEADING_OFFSET_DEG,
|
||||
);
|
||||
scratchHpr.pitch = 0;
|
||||
scratchHpr.roll = 0;
|
||||
Cesium.Transforms.headingPitchRollToFixedFrame(
|
||||
position,
|
||||
scratchHpr,
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
undefined,
|
||||
result,
|
||||
);
|
||||
const [sx, sy, sz] = spec.scaleXYZ;
|
||||
if (sx > 0 && (sy !== sx || sz !== sx)) {
|
||||
// Cesium's glTF axis correction puts the model's length on local Y, its
|
||||
// beam on local X and its height on local Z.
|
||||
scratchScale.x = sy / sx;
|
||||
scratchScale.y = 1;
|
||||
scratchScale.z = sz / sx;
|
||||
Cesium.Matrix4.multiplyByScale(result, scratchScale, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
const scratchScale = new Cesium.Cartesian3();
|
||||
|
||||
/**
|
||||
* 3D models for one layer's vehicles under the DISPLAY rail's 3D toggle (the
|
||||
* Flights layer's `models3d`/`models3dMode`), on the same rules the aircraft
|
||||
* layers follow: models only below the camera altitude ceiling, for the
|
||||
* nearest `cap` vehicles in the add/keep band, on-screen first. A vehicle's
|
||||
* icon stays the visual until its model is loaded and placed; the layer reads
|
||||
* `modelOwnsVisual` back from each item and hides that icon.
|
||||
*
|
||||
* Each frame the layer passes its vehicles as items:
|
||||
* `{position, headingDeg, spec, tint, pickId, show}`, `position` the point
|
||||
* the model's origin stands on (the waterline, the road or rail top; the
|
||||
* spec's `elevationM` is added here), `tint` a Cesium.Color for a tinted
|
||||
* model's route colour (or null), `show` false to keep it hidden.
|
||||
* @param {object} options
|
||||
* @param {object} options.viewer Cesium viewer.
|
||||
* @param {() => object|null} [options.display] `{models3d, models3dMode}`.
|
||||
* @param {object} options.policy `{altitudeCeilingM, minimumPixelSize,
|
||||
* cap, capAll, addM, addAllM, keepM, keepAllM, intervalMs}`.
|
||||
* @param {(url: string) => string} [options.resolveAsset]
|
||||
* @param {(spec: object, options: object) => Promise<object>} [options.createModel]
|
||||
* @returns {object}
|
||||
*/
|
||||
export function createFleetModelLayer({
|
||||
viewer,
|
||||
display = () => null,
|
||||
policy,
|
||||
resolveAsset = (url) => url,
|
||||
createModel = (spec, options) =>
|
||||
createFleetModel(spec, options, { resolveAsset }),
|
||||
}) {
|
||||
const collection = new Cesium.PrimitiveCollection();
|
||||
viewer.scene.primitives.add(collection);
|
||||
/** @type {Map<string, object>} id -> admitted model */
|
||||
const models = new Map();
|
||||
/** @type {Map<string, number>} id -> generation of an in-flight load */
|
||||
const pending = new Map();
|
||||
let generation = 0;
|
||||
let destroyed = false;
|
||||
let lastEligibilityAt = -Infinity;
|
||||
let eligible = new Set();
|
||||
let settling = 0;
|
||||
const scratchHpr = new Cesium.HeadingPitchRoll();
|
||||
const scratchSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.ZERO, 1);
|
||||
const scratchCarto = new Cesium.Cartographic();
|
||||
const scratchPosition = new Cesium.Cartesian3();
|
||||
|
||||
function release(id) {
|
||||
pending.delete(id);
|
||||
const model = models.get(id);
|
||||
if (!model) return;
|
||||
models.delete(id);
|
||||
if (!collection.isDestroyed()) collection.remove(model);
|
||||
}
|
||||
|
||||
function releaseAll() {
|
||||
for (const id of [...models.keys()]) release(id);
|
||||
pending.clear();
|
||||
generation += 1;
|
||||
}
|
||||
|
||||
function preferences() {
|
||||
return display?.() || null;
|
||||
}
|
||||
|
||||
function regime(prefs) {
|
||||
if (!prefs?.models3d || !fleetModelSet()) return false;
|
||||
const height = viewer.camera?.positionCartographic?.height ?? Infinity;
|
||||
return height < policy.altitudeCeilingM;
|
||||
}
|
||||
|
||||
function shaderFor(item) {
|
||||
return item.spec.tinted && item.tint
|
||||
? fleetTintShader(item.tint)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
async function ensure(id, item, cap) {
|
||||
const key = item.spec.key;
|
||||
const current = models.get(id);
|
||||
if (current && current._gevSpecKey === key) return;
|
||||
if (current) release(id);
|
||||
if (pending.has(id) || models.size + pending.size >= cap) return;
|
||||
const loadGeneration = generation;
|
||||
pending.set(id, loadGeneration);
|
||||
let model;
|
||||
try {
|
||||
model = await createModel(item.spec, {
|
||||
asynchronous: false,
|
||||
minimumPixelSize: policy.minimumPixelSize,
|
||||
scale: item.spec.scale,
|
||||
customShader: shaderFor(item),
|
||||
id: item.pickId ?? id,
|
||||
});
|
||||
} catch {
|
||||
if (pending.get(id) === loadGeneration) pending.delete(id);
|
||||
return;
|
||||
}
|
||||
const stale =
|
||||
destroyed ||
|
||||
pending.get(id) !== loadGeneration ||
|
||||
generation !== loadGeneration ||
|
||||
!eligible.has(id) ||
|
||||
models.has(id);
|
||||
if (pending.get(id) === loadGeneration) pending.delete(id);
|
||||
if (stale) {
|
||||
model.destroy?.();
|
||||
return;
|
||||
}
|
||||
model.id = item.pickId ?? id;
|
||||
model._gevSpecKey = key;
|
||||
model._gevTint = item.spec.tinted ? item.tint : null;
|
||||
// Admitted, not yet the visual: placement turns it on.
|
||||
model.show = false;
|
||||
collection.add(model);
|
||||
models.set(id, model);
|
||||
}
|
||||
|
||||
function refreshEligibility(items, prefs) {
|
||||
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 camera = viewer.camera;
|
||||
const cameraPosition = camera.positionWC;
|
||||
const cull = camera.frustum.computeCullingVolume(
|
||||
cameraPosition,
|
||||
camera.directionWC,
|
||||
camera.upWC,
|
||||
);
|
||||
const candidates = [];
|
||||
for (const [id, item] of items) {
|
||||
if (!item.position || item.show === false || !item.spec) continue;
|
||||
const distanceSq = Cesium.Cartesian3.distanceSquared(
|
||||
cameraPosition,
|
||||
item.position,
|
||||
);
|
||||
if (distanceSq > keepM * keepM) continue;
|
||||
Cesium.Cartesian3.clone(item.position, scratchSphere.center);
|
||||
candidates.push([
|
||||
id,
|
||||
distanceSq,
|
||||
cull.computeVisibility(scratchSphere) !== Cesium.Intersect.OUTSIDE,
|
||||
]);
|
||||
}
|
||||
candidates.sort((a, b) => a[1] - b[1]);
|
||||
eligible = selectModelEligible(candidates, {
|
||||
cap,
|
||||
addDistSq: addM * addM,
|
||||
isModeled: (id) => models.has(id),
|
||||
});
|
||||
for (const id of [...models.keys(), ...pending.keys()])
|
||||
if (!eligible.has(id)) release(id);
|
||||
for (const id of eligible) void ensure(id, items.get(id), cap);
|
||||
}
|
||||
|
||||
/** Where the model's origin stands: the item's point raised by the spec's elevation. */
|
||||
function placement(item) {
|
||||
const lift = item.spec.elevationM || 0;
|
||||
if (!lift) return item.position;
|
||||
const carto = Cesium.Cartographic.fromCartesian(
|
||||
item.position,
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
scratchCarto,
|
||||
);
|
||||
if (!carto) return item.position;
|
||||
return Cesium.Cartesian3.fromRadians(
|
||||
carto.longitude,
|
||||
carto.latitude,
|
||||
carto.height + lift,
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
scratchPosition,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
/** Ids whose model admission is current. */
|
||||
get eligible() {
|
||||
return eligible;
|
||||
},
|
||||
|
||||
/**
|
||||
* Per-frame pass: re-derive eligibility at the policy's cadence, then
|
||||
* place every admitted model and hand each item's visual to its model
|
||||
* only once the model is ready and placed (`item.modelOwnsVisual`).
|
||||
* @param {Map<string, object>} items
|
||||
* @param {number} nowMs
|
||||
* @returns {boolean} Whether any model is drawn.
|
||||
*/
|
||||
frame(items, nowMs) {
|
||||
if (destroyed) return false;
|
||||
const prefs = preferences();
|
||||
if (!regime(prefs)) {
|
||||
settling = 0;
|
||||
if (models.size || pending.size) releaseAll();
|
||||
eligible = new Set();
|
||||
for (const item of items.values()) item.modelOwnsVisual = false;
|
||||
return false;
|
||||
}
|
||||
if (nowMs - lastEligibilityAt >= policy.intervalMs) {
|
||||
lastEligibilityAt = nowMs;
|
||||
refreshEligibility(items, prefs);
|
||||
}
|
||||
const occluder = horizonOccluder(viewer.camera);
|
||||
let drawn = false;
|
||||
settling = pending.size;
|
||||
for (const [id, item] of items) {
|
||||
const model = models.get(id);
|
||||
item.modelOwnsVisual = false;
|
||||
if (!model) continue;
|
||||
if (
|
||||
!item.position ||
|
||||
item.show === false ||
|
||||
!occluder.isPointVisible(item.position)
|
||||
) {
|
||||
model.show = false;
|
||||
continue;
|
||||
}
|
||||
if (item.spec.key !== model._gevSpecKey) {
|
||||
// A new type or size: the next eligibility pass loads it.
|
||||
model.show = false;
|
||||
lastEligibilityAt = -Infinity;
|
||||
continue;
|
||||
}
|
||||
const tint = item.spec.tinted ? item.tint : null;
|
||||
if (tint && !Cesium.Color.equals(tint, model._gevTint)) {
|
||||
model.customShader = fleetTintShader(tint);
|
||||
model._gevTint = tint;
|
||||
}
|
||||
fleetModelMatrix(
|
||||
placement(item),
|
||||
item.headingDeg,
|
||||
item.spec,
|
||||
model.modelMatrix,
|
||||
scratchHpr,
|
||||
);
|
||||
if (!model.ready) {
|
||||
model.show = false;
|
||||
settling += 1;
|
||||
continue;
|
||||
}
|
||||
model.show = true;
|
||||
item.modelOwnsVisual = true;
|
||||
drawn = true;
|
||||
}
|
||||
for (const id of [...models.keys()]) if (!items.has(id)) release(id);
|
||||
return drawn;
|
||||
},
|
||||
|
||||
/**
|
||||
* Models loading or not yet ready after the last frame: the layer keeps
|
||||
* frames coming while any are, so each one takes over as soon as it can.
|
||||
*/
|
||||
get settling() {
|
||||
return settling;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether models are drawn now: 3D on, the set loaded and the camera
|
||||
* below the altitude ceiling. A layer skips building items while not.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
active() {
|
||||
return !destroyed && regime(preferences());
|
||||
},
|
||||
|
||||
/** The model drawing `id`, if one is admitted. */
|
||||
modelFor(id) {
|
||||
return models.get(id) || null;
|
||||
},
|
||||
|
||||
/** Show or hide every model (the layer's own visibility). */
|
||||
setVisible(show) {
|
||||
if (!collection.isDestroyed()) collection.show = show;
|
||||
},
|
||||
|
||||
/** Drop every model (3D off, layer disabled). */
|
||||
clear: releaseAll,
|
||||
|
||||
/** Number of admitted models (tests and diagnostics). */
|
||||
get size() {
|
||||
return models.size;
|
||||
},
|
||||
|
||||
destroy() {
|
||||
destroyed = true;
|
||||
releaseAll();
|
||||
if (!viewer.isDestroyed?.() && !collection.isDestroyed())
|
||||
viewer.scene.primitives.remove(collection);
|
||||
},
|
||||
};
|
||||
}
|
||||
+135
-773
File diff suppressed because it is too large.
Load diff
@@ -1,74 +1,15 @@
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
/**
|
||||
* Model-space visual centres measured from the shipped GLBs' scene-space AABBs.
|
||||
* Model-space anchors on the aircraft layers' fleet models: where brackets
|
||||
* and readouts sit (a model's visual centre) and where a tracked trail
|
||||
* attaches (its aft-belly point, measured per model in fleetTrailAnchors.js
|
||||
* and handed to the layers with each model's spec by fleetModels.js).
|
||||
*
|
||||
* glTF stores these assets Y-up. Cesium's model frame is Z-up, so a glTF
|
||||
* centre `[x, y, z]` becomes `[x, -z, y]` before the layer's ENU modelMatrix
|
||||
* is applied. Values remain in native model units; callers supply the Model's
|
||||
* Values are native model units in raw glTF axes; callers supply the Model's
|
||||
* effective rendered `computedScale` because Cesium does not bake it into
|
||||
* modelMatrix and may raise it above `scale` to satisfy minimumPixelSize.
|
||||
*/
|
||||
const CENTERED_MODEL = Object.freeze([0, 0, 0]);
|
||||
|
||||
export const MODEL_VISUAL_CENTER_NATIVE = Object.freeze({
|
||||
'/models/airplane.glb': CENTERED_MODEL,
|
||||
'/models/jet.glb': CENTERED_MODEL,
|
||||
});
|
||||
|
||||
/**
|
||||
* Aft-belly trail attachment points, measured on each approved model's actual
|
||||
* MESH SURFACE. Every bundled asset is baked to one convention (see
|
||||
* aircraftClass.js): origin at the bbox centre, X = length with the NOSE at
|
||||
* local −X, glTF Y = up (Cesium-local Z here).
|
||||
*
|
||||
* Each value is the point of the hull's CENTRELINE PROFILE (the y = 0 slice of
|
||||
* the mesh) closest to that model's aft-belly AABB corner. Three things follow
|
||||
* from that construction, and each is asserted rather than described in
|
||||
* modelScale.test.mjs:
|
||||
*
|
||||
* ON THE HULL. This is the correction that matters. The previous round put
|
||||
* the anchor ON the AABB corner itself, reasoning that an anchor aft of
|
||||
* every vertex makes non-intersection geometric. It does — but an AABB
|
||||
* corner is EMPTY SPACE, and on these airframes it is a long way from
|
||||
* any of them: 4.80 m out for airplane.glb and 6.14 m for jet.glb in
|
||||
* native units, which at the 450 m framing is a visible gap between the
|
||||
* aircraft and the end of its own trail. The trail must terminate on the
|
||||
* aeroplane, so the anchor is a surface point.
|
||||
*
|
||||
* AFT. The head segment is drawn from a point behind the aircraft to this
|
||||
* anchor, so an anchor near the middle makes the segment enter at the
|
||||
* tail and stop mid-fuselage — a line drawn through the airframe. These
|
||||
* sit at 83–96 % of each model's aft extreme, on the aft-most hull the
|
||||
* centreline has.
|
||||
*
|
||||
* BELOW. Nothing of the aircraft is lower than the anchor at or behind its
|
||||
* own station, so the trail leaves from underneath the way a wake does
|
||||
* rather than out of the roof. On most assets that is a frank belly
|
||||
* point; on jet.glb the aft centreline profile has swept up into the
|
||||
* tail cone by then, so the anchor sits just above the model's vertical
|
||||
* centre (+0.13 native on a 5.63 m half-height) at the exhaust — which
|
||||
* is where a fast jet's wake leaves it anyway.
|
||||
*
|
||||
* Y stays on the centreline — the profile is sliced at y = 0 rather than taking
|
||||
* the nearest surface point in the round — so the attachment cannot drift
|
||||
* screen-left or screen-right as the aircraft turns. (The unconstrained nearest
|
||||
* point would put jet.glb's anchor 1.29 m off-axis.) Values are native model
|
||||
* units; callers scale them by Cesium's effective `computedScale`.
|
||||
*
|
||||
* Locked against the shipped GLBs by modelScale.test.mjs, which re-reads the
|
||||
* POSITION buffers and re-derives every property above — re-measure, never
|
||||
* re-guess, when an asset changes.
|
||||
*/
|
||||
export const MODEL_TRAIL_ANCHOR_NATIVE = Object.freeze({
|
||||
'/models/airplane.glb': Object.freeze([24.0879, -2.2163, 0]),
|
||||
'/models/jet.glb': Object.freeze([18.9103, 0.1266, 0]),
|
||||
'/models/bell206.glb': Object.freeze([5.2077, -0.0005, 0]),
|
||||
'/models/c172.glb': Object.freeze([3.6816, -0.2425, 0]),
|
||||
'/models/citation2.glb': Object.freeze([6.8804, -0.6136, 0]),
|
||||
'/models/mq9.glb': Object.freeze([5.1951, -1.1516, 0]),
|
||||
'/models/b789.glb': Object.freeze([30.1007, -3.4814, 0]),
|
||||
'/models/atr72.glb': Object.freeze([12.9785, -1.2935, 0]),
|
||||
});
|
||||
|
||||
/** @constant Cesium's OWN axis correction for a glTF loaded with the
|
||||
* `Model.fromGltfAsync` defaults (upAxis Y, forwardAxis Z), assembled from its
|
||||
@@ -134,27 +75,6 @@ export function modelAnchorWorld(model, nativeAnchor, result) {
|
||||
return Cesium.Matrix4.multiplyByPoint(_chainScratch, _anchorScratch, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the model-local visual centre for an approved bundled GLB.
|
||||
* Assets absent from the table were audited as origin-centred.
|
||||
* @param {string} url Bundled model URL.
|
||||
* @returns {readonly number[]} Cesium-local `[x, y, z]` native-unit offset.
|
||||
*/
|
||||
export function visualCenterForModel(url) {
|
||||
return MODEL_VISUAL_CENTER_NATIVE[url] || CENTERED_MODEL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the model-local aft-belly attachment point for a tracked trail.
|
||||
* Unknown future assets safely fall back to their visual centre until their
|
||||
* geometry is measured and added to the table.
|
||||
* @param {string} url Bundled model URL.
|
||||
* @returns {readonly number[]} Cesium-local `[x, y, z]` native-unit offset.
|
||||
*/
|
||||
export function trailAnchorForModel(url) {
|
||||
return MODEL_TRAIL_ANCHOR_NATIVE[url] || visualCenterForModel(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a trail head segment should START being drawn: the whole segment, a
|
||||
* shortened piece of it, or nothing at all.
|
||||
@@ -171,7 +91,7 @@ export function trailAnchorForModel(url) {
|
||||
* mistake matters:
|
||||
*
|
||||
* - Testing segment LENGTH against the radius hid real trail. With
|
||||
* `airplane.glb`'s 34.41 m radius and 24.09 m tail anchor, a prior fix 58 m
|
||||
* an airliner model's 34.41 m radius and 24.09 m tail anchor, a prior fix 58 m
|
||||
* aft gives a 33.98 m segment — under the radius, so suppressed — even
|
||||
* though ~23.6 m of it is in open air behind the aircraft. It also made the
|
||||
* whole segment pop in at once on crossing ~58.4 m.
|
||||
|
||||
@@ -45,6 +45,18 @@ import militaryFlightsLayer, {
|
||||
} from './militaryFlights.js';
|
||||
import { clearTr3bRegistry, setTr3b } from './tr3bRegistry.js';
|
||||
import { reportMeshFloorCell, _clearMeshFloorCellsForTest } from './groundFloor.js';
|
||||
import { loadFleetModelSet } from './fleetModels.js';
|
||||
import { aircraftLayerModelSpec } from '../layers/flights/modelSpec.js';
|
||||
import { fetchPublicFile } from '../testSupport/fleetGlb.mjs';
|
||||
|
||||
// The layers draw only once the fleet model set has loaded; load it from disk.
|
||||
// Model creation itself is stubbed per test through Cesium.Model.fromGltfAsync.
|
||||
const _silentInfo = console.info;
|
||||
console.info = () => {};
|
||||
await loadFleetModelSet({ fetchImpl: fetchPublicFile });
|
||||
console.info = _silentInfo;
|
||||
const FLIGHTS_META = Object.freeze({ typeCode: 'A320', klass: 'airliner' });
|
||||
const MILITARY_META = Object.freeze({ typeCode: 'F16', klass: 'fastjet' });
|
||||
|
||||
// Sample altitudes are expressed RELATIVE to the band rather than as absolute
|
||||
// offsets. The thresholds have already been retuned once (1_000_000 → 150_000
|
||||
@@ -201,7 +213,8 @@ const LAYERS = [
|
||||
driveFleetModel: flightsDriveFleetModel,
|
||||
ensureFleetModel: flightsEnsureFleetModel,
|
||||
trackedBillboardColor: flightsTrackedBillboardColor,
|
||||
bellyM: 6.719,
|
||||
/** How far a grounded A320 stands its origin above the ground (scaled wheel clearance). */
|
||||
bellyM: aircraftLayerModelSpec(FLIGHTS_META).bellyM,
|
||||
seed({ viewer, tracked = true, icao24 = ICAO, modelCollection = null, onGround = false, models = [] }) {
|
||||
const billboard = contactBillboard();
|
||||
_setTrackedFlightRefreshStateForTest({
|
||||
@@ -213,7 +226,7 @@ const LAYERS = [
|
||||
tracked,
|
||||
models,
|
||||
modelCollection,
|
||||
meta: { callsign: 'TEST123 ', altitude: 10_668, klass: 'airliner', onGround },
|
||||
meta: { callsign: 'TEST123 ', altitude: 10_668, ...FLIGHTS_META, onGround },
|
||||
});
|
||||
return billboard;
|
||||
},
|
||||
@@ -226,7 +239,7 @@ const LAYERS = [
|
||||
driveFleetModel: militaryDriveFleetModel,
|
||||
ensureFleetModel: militaryEnsureFleetModel,
|
||||
trackedBillboardColor: militaryTrackedBillboardColor,
|
||||
bellyM: 5.631 * 0.8,
|
||||
bellyM: aircraftLayerModelSpec(MILITARY_META).bellyM,
|
||||
seed({ viewer, tracked = true, icao24 = ICAO, modelCollection = null, onGround = false, models = [] }) {
|
||||
const billboard = contactBillboard();
|
||||
_setTrackedMilitaryRefreshStateForTest({
|
||||
@@ -238,7 +251,7 @@ const LAYERS = [
|
||||
tracked,
|
||||
models,
|
||||
modelCollection,
|
||||
meta: { callsign: 'TEST123 ', altitudeFt: 35_000, klass: 'fastjet', onGround },
|
||||
meta: { callsign: 'TEST123 ', altitudeFt: 35_000, ...MILITARY_META, onGround },
|
||||
});
|
||||
return billboard;
|
||||
},
|
||||
@@ -841,8 +854,8 @@ for (const fixture of LAYERS) {
|
||||
Date.now = () => now;
|
||||
let attempts = 0;
|
||||
const requested = [];
|
||||
Cesium.Model.fromGltfAsync = ({ url }) => {
|
||||
attempts++; requested.push(url);
|
||||
Cesium.Model.fromGltfAsync = ({ basePath }) => {
|
||||
attempts++; requested.push(basePath);
|
||||
return Promise.reject(new Error('simulated missing GLB'));
|
||||
};
|
||||
// The give-up path warns once by design; keep the run's output clean.
|
||||
|
||||
Reference in new issue
Block a user