mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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:
1 parent
20e9d4a0fa
commit
b14bf7e013
10 files changed
+1530
-3
No files matched your search
@@ -261,6 +261,10 @@ const TRACKED_RASTER_PX = 192;
|
||||
* Default size serves the fleet; pass `aircraftIcon(kind, TRACKED_ICON_PX)`
|
||||
* (re-exported below) for the tracked billboard. */
|
||||
export const TRACKED_ICON_PX = TRACKED_RASTER_PX;
|
||||
/** The fleet raster size (aircraftIcon's default). */
|
||||
export const FLEET_ICON_PX = FLEET_RASTER_PX;
|
||||
/** Every silhouette kind aircraftIcon draws (an engine's sprite atlas). */
|
||||
export const AIRCRAFT_ICON_KINDS = Object.freeze(Object.keys(BODIES));
|
||||
export function aircraftIcon(kind, px = FLEET_RASTER_PX) {
|
||||
const k = BODIES[kind] ? kind : 'airliner';
|
||||
const key = `${k}@${px}`;
|
||||
@@ -272,3 +276,65 @@ export function aircraftIcon(kind, px = FLEET_RASTER_PX) {
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The glyph atlas (engines that draw sprites from one texture: Navara)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const ATLAS_PAD = 2;
|
||||
const atlasCellKey = (kind, px) => `${kind}@${px}`;
|
||||
|
||||
/** Every aircraftIcon() data URI → its atlas cell key (`${kind}@${px}`). */
|
||||
export function aircraftIconCells() {
|
||||
const cells = new Map();
|
||||
for (const kind of AIRCRAFT_ICON_KINDS)
|
||||
for (const px of [FLEET_RASTER_PX, TRACKED_RASTER_PX])
|
||||
cells.set(aircraftIcon(kind, px), atlasCellKey(kind, px));
|
||||
return cells;
|
||||
}
|
||||
|
||||
/**
|
||||
* The atlas layout (pure): the tracked raster in row 0, the fleet raster in
|
||||
* row 1, one column per kind, ATLAS_PAD px around each cell; cells are
|
||||
* [u0, v0, u1, v1] in 0..1.
|
||||
*/
|
||||
export function aircraftIconAtlasLayout(kinds = AIRCRAFT_ICON_KINDS) {
|
||||
const big = TRACKED_RASTER_PX + 2 * ATLAS_PAD;
|
||||
const small = FLEET_RASTER_PX + 2 * ATLAS_PAD;
|
||||
const width = kinds.length * big;
|
||||
const height = big + small;
|
||||
const rects = new Map();
|
||||
const cells = {};
|
||||
kinds.forEach((kind, column) => {
|
||||
for (const [px, row] of [
|
||||
[TRACKED_RASTER_PX, 0],
|
||||
[FLEET_RASTER_PX, big],
|
||||
]) {
|
||||
const x = column * big + ATLAS_PAD;
|
||||
const y = row + ATLAS_PAD;
|
||||
const key = atlasCellKey(kind, px);
|
||||
rects.set(key, { x, y, size: px });
|
||||
cells[key] = [x / width, y / height, (x + px) / width, (y + px) / height];
|
||||
}
|
||||
});
|
||||
return { width, height, rects, cells };
|
||||
}
|
||||
|
||||
/** Draws the atlas (browser): a canvas and its cells, once the SVGs decode. */
|
||||
export async function drawAircraftIconAtlas() {
|
||||
const layout = aircraftIconAtlasLayout();
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = layout.width;
|
||||
canvas.height = layout.height;
|
||||
const context = canvas.getContext('2d');
|
||||
await Promise.all(
|
||||
[...aircraftIconCells()].map(async ([uri, key]) => {
|
||||
const image = new Image();
|
||||
image.src = uri;
|
||||
await image.decode();
|
||||
const { x, y, size } = layout.rects.get(key);
|
||||
context.drawImage(image, x, y, size, size);
|
||||
}),
|
||||
);
|
||||
return { canvas, cells: layout.cells };
|
||||
}
|
||||
Reference in new issue
Block a user