feat(flights): render on Navara

Task 10b. src/layers/aircraft/render/navara.js implements the aircraft
renderer contract on the engine contract alone (no three, no Cesium):
- Fleet glyphs: banks of engine.movers sprite sets (one per distance scale
  and depth mode the handles ask for; flights: one, 'always', Cesium's
  NearFarScalar), growing by doubling, from a glyph atlas of every
  aircraftIcon() kind at the fleet (64 px) and tracked (192 px) rasters
  (data/aircraftIcons: AIRCRAFT_ICON_KINDS, aircraftIconCells,
  aircraftIconAtlasLayout, drawAircraftIconAtlas). Sprite handles keep the
  Billboard field vocabulary as setters; a frame's writes commit once at
  the end of the frame listener that made them (a microtask outside one).
- Models: banks of model mover sets per glTF and look; handles report
  ready from MoverSet.ready() and computedScale from minimumPixelSize kept
  on the CPU (radiusM in the spec, the class's nativeRadiusM); poses are
  Cesium's HPR frame (modelMatrix) turned by Navara's glTF axes
  (Z_UP_TO_X_UP: its loader is already Z-up; chosen side by side with
  Cesium among six candidates).
- Tracked glyph: a sprite whose position/colour/rotation callbacks are read
  every frame in preRender; follow = engine.camera.follow with the tracked
  readout's card as its label (gevFollowHandle); current() maps the follow
  back to the tracked handle, also while follow() raises followChanged.
- Trail and live head: engine.lines (alpha 0.85, depth-fail 0.4, geodesic)
  in the gev-trail pick namespace.
- View: camera/scene adapters over engine.camera.pose() (registered with
  the engine so shared helpers project through it), frustum and horizon
  tests, frame number, engine frame events.
flights/render/navara.js registers it for 'navara' from the Navara mode's
import(); the Navara catalog now offers Live Flights.

Also: tracking a contact that is selected but no longer followed follows it
again (a camera command ends a Navara follow; on Cesium a search flight
releases trackedEntity): trackById/select re-follows instead of only
re-publishing. Behaviour change on Cesium only in that case.

Tests: the renderer on the fake engine (contract, atlas, banks, per-frame
commits, growth, tracked callbacks, follow label, model pose, trails) and
the flights logic over it (fleet, click-select, follow, re-follow after a
camera command, release, no set left behind).
This commit is contained in:
German Khokhlov committed 2026-10-17 02:15:04 +04:00
1 parent 20e9d4a0fa
commit b14bf7e013
10 files changed
+1530 -3

No files matched your search

+11 -1
View File
@@ -718,8 +718,18 @@ export function createQueries({
if (!flightState._billboards.has(id)) return false;
if (parts.tracking._isExplicitTrackingOrigin(origin))
parts.tracking._cancelPendingTrackingRestore();
if (flightState._trackedIcao === id)
if (flightState._trackedIcao === id) {
// Selected but no longer followed (a camera command took the camera:
// a search flight, the startup view; on Navara any command ends a
// follow): asking to track it again follows it again.
const entity = flightState._trackedEntity;
if (entity && !flightState._renderer?.follow.isFollowing(entity)) {
flightState._trackedCameraFrameStop?.();
flightState._trackedCameraFrameStop =
flightState._renderer.follow.refocus(entity);
}
return parts.tracking._publishTrackedSelection(id, origin);
}
parts.tracking._trackFlight(id, { origin });
return true;
},
+22
View File
@@ -0,0 +1,22 @@
// The civil flights layer's renderer on the Navara engine: the shared
// aircraft renderer (src/layers/aircraft/render/navara.js) with the flights'
// sprite slot (drawn over the other contact layers, as data/spriteOrder
// orders them on Cesium) and airplane.glb's nose offset. Registered for
// 'navara' by the Navara mode after its import() (src/app/navaraMode.js).
import { createAircraftNavaraRenderer } from '../../aircraft/render/navara.js';
import { SPRITE_LAYER_ORDER } from '../../../data/spriteOrder.js';
import { MODEL_HEADING_OFFSET_DEG } from '../policy.js';
/**
* Registry factory (src/app/layers/renderers.js): `(engine, options)`.
* @param {import('../../../globe/contract.js').GlobeEngine} engine
*/
export function createFlightsNavaraRenderer(engine) {
return createAircraftNavaraRenderer({
engine,
layerId: 'flights',
order: SPRITE_LAYER_ORDER.indexOf('flights'),
headingOffsetDeg: MODEL_HEADING_OFFSET_DEG,
});
}
+82
View File
@@ -247,3 +247,85 @@ test('the flights logic draws, selects and follows only through its renderer', a
}
assert.ok(renderer.calls.some(([name]) => name === 'destroy'));
});
test('the flights logic draws and follows on the Navara renderer (fake engine)', async () => {
const { createAircraftNavaraRenderer, aircraftAtlasLayout } =
await import('../aircraft/render/navara.js');
const layout = aircraftAtlasLayout();
const engine = createFakeEngine();
let renderer = null;
const layer = createApplicationFlights({
surface: defaultSurface,
source: {
label: 'Fixture aircraft',
getSnapshot: async () => snapshotOf(['abc123', 'def456']),
},
militaryRegistry,
renderer: {
create: ({ engine: given }) =>
(renderer = createAircraftNavaraRenderer({
engine: given,
layerId: 'flights',
order: 8,
headingOffsetDeg: 180,
drawAtlas: async () => ({
canvas: { width: layout.width, height: layout.height },
cells: layout.cells,
}),
})),
},
});
layer.init(null, { engine });
layer.enable();
try {
await renderer.whenReady();
await layer.update(null);
await Promise.resolve();
const sprites = engine.movers
.list()
.filter(({ id }) => id.startsWith('flights-sprites'));
assert.equal(sprites.length, 1);
assert.equal(sprites[0].count, 2);
const { store } = engine.fake.moverSet(sprites[0].id);
assert.deepEqual([...store.pickIds.slice(0, 2)].sort(), [
'abc123',
'def456',
]);
// A click on a contact selects it; the engine follows with its label.
engine.fake.script('pick', () => ({ id: 'def456' }));
engine.fake.script('drillPick', () => [{ id: 'def456' }]);
engine.fake.input('down', { position: { x: 10, y: 10 } });
engine.fake.input('up', { position: { x: 10, y: 10 } });
engine.fake.input('click', { position: { x: 10, y: 10 } });
assert.equal(layer.getTrackedInfo()?.icao24, 'def456');
const following = engine.camera.following();
assert.equal(following?.label?.id, 'flights:def456');
engine.fake.frame();
const tracked = engine.movers
.list()
.find(({ id }) => id.startsWith('flights-tracked'));
assert.equal(tracked.count, 1);
assert.equal(layer.getAllPositions().length, 2);
// A camera command ends the engine's follow; the contact stays selected
// (as on Cesium after a search flight), and tracking it again follows.
engine.camera.setView({
destination: geo.cartesian3.fromDegrees(-97.7, 30.2, 50_000),
});
assert.equal(engine.camera.following(), null);
assert.equal(layer.getTrackedInfo()?.icao24, 'def456');
assert.equal(layer.trackById('def456', { origin: 'voice' }), true);
assert.equal(engine.camera.following()?.label?.id, 'flights:def456');
assert.equal(layer.stopTracking(), true);
assert.equal(engine.camera.following(), null);
assert.equal(
engine.movers.list().find(({ id }) => id.startsWith('flights-tracked'))
.count,
0,
);
} finally {
layer.disable();
layer.destroy(null);
}
assert.equal(engine.movers.list().length, 0, 'no mover set left behind');
engine.destroy();
});
+4
View File
@@ -467,6 +467,9 @@ export function createRendering({
url: resolveAsset(spec.url),
minimumPixelSize: MODEL_MIN_PX,
scale: spec.scale,
// Bounding radius per scale unit (an engine that keeps
// minimumPixelSize on the CPU reports the drawn scale with it).
radiusM: spec.nativeRadiusM,
color: flightState._irBoost ? WHITE : _modelColor(icao24),
// Launch presentation keeps the code-side tint dominant for every approved
// model; IR boost removes the remaining diffuse hint with flat UNLIT white.
@@ -635,6 +638,7 @@ export function createRendering({
url: resolveAsset(trackedSpec.url),
minimumPixelSize: TRACKED_MODEL_MIN_PX,
scale: trackedSpec.scale,
radiusM: trackedSpec.nativeRadiusM,
color: flightState._irBoost ? WHITE : CYAN,
// The tracked aircraft uses the same dominant light tint as the fleet;
// IR boost removes the remaining diffuse hint with flat UNLIT white.