mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
refactor(flights): Cesium rendering behind a renderer interface
Task 10a. The flights logic no longer imports Cesium: every Cesium object it
built moved one for one into the shared aircraft renderer
(src/layers/aircraft/render/cesium.js; contract in render/contract.js), with
the flights' parameters in src/layers/flights/render/cesium.js, registered
for 'cesium' in the renderer registry and created at init(viewer, {engine}).
- Fleet: BillboardCollection + sprite-order slot; sprites stay Billboard
handles (field vocabulary documented for the Navara renderer).
- Models: fleet/tracked/preload glTF loads (asynchronous:false, MIX tint, IR
boost as `unlit` → the UNLIT CustomShader), the model collection, setPose
(same HPR frame with airplane.glb's 180° offset).
- Tracked: the ENU billboard Entity with its position/colour/rotation
callbacks, viewFrom, followed through viewer.trackedEntity + the one exact
tracked frame (kept as is; engine.camera.follow on Cesium would also end
the follow on any camera command, a behaviour change).
- Trail: the entity trail (data/trailRenderer, unchanged: its Primitive
predecessor failed below the mesh) and the live head segment.
- View: camera/scene reads, frame number, frustum and horizon tests,
projection, render requests, frame events, evidence render-loop hold.
- Clicks and Escape go through the engine's selection dispatcher (the
ScreenSpaceEventHandler and keydown listener are gone); the cross-layer
untrack watches the renderer's follow.
- Colours are engine-neutral Rgba (src/layers/shared/color.js), bit-equal to
the Cesium.Color constants they replace; NearFarScalar → nearFarScale.
- Cesium math in the logic → src/geo.
- check-import-directions: cesium only in render/cesium*.js and three/Navara
only in render/navara*.js for flights, aircraft and shared; a layer's
Navara renderer only through navaraMode's import().
Source-text tests updated with the moved code, same meaning:
- readLayerSource reads a layer's render/*.js and, for the aircraft layers,
aircraft/render/*.js (GLB-load, tracked-entity, CallbackProperty checks).
- modelScale.test: _normalBillboardScaleByDistance reads nearFarScale(...).
- spriteOrder.test: flights' enable calls fleet.restoreOrderOnEnable(); the
renderer wires it to restoreSpriteOrderOnEnable('flights', viewer).
- trackingClickGesture.test: the flights gesture rules are the dispatcher's
(selection gesture before select, click classifier before the empty-space
clear); flights answers the empty click with a user-origin clear.
- militaryAwareness.test: flights' hasContact guard reads fleet.visible().
- ownership.test: the services fixture names selection and renderer.
New tests: color, the Cesium aircraft renderer (contract, collections, pose,
loads, frustum/horizon, tracked entity, follow, trail head, adopted
collections), the flights logic over a plain-data renderer and a fake engine
(fleet, click-select, no-op on the tracked visual, empty-click release), the
boundary rule.
W1 replay vs 7c7422e2: counts, known objects, screen points (0 px), tracking
poses (0 m), requests and shots (same sha256) identical. Main chunk
2,890,982 B (+6.2 KB, +0.21 %: the renderer indirection).
This commit is contained in:
1 parent
8e702f0c3b
commit
7f13ef4a87
33 files changed
+1974
-748
No files matched your search
@@ -1,10 +1,10 @@
|
||||
import { createCivilFlightLayer } from '../../layers/flights/index.js';
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
import * as sprites from '../../data/spriteOrder.js';
|
||||
import * as trails from '../../data/trailRenderer.js';
|
||||
import * as selection from '../../data/selectionDispatcher.js';
|
||||
import * as aircraftPresentation from '../../data/tr3bRegistry.js';
|
||||
import * as trackedCamera from '../../data/trackedCamera.js';
|
||||
import { applyTrackedCameraFrame } from '../../globe/cesium/follow.js';
|
||||
import { rendererFor } from './renderers.js';
|
||||
import { createFlightsCesiumRenderer } from '../../layers/flights/render/cesium.js';
|
||||
import * as labels from '../../data/detectionDraw.js';
|
||||
import * as geoid from '../../data/geoid.js';
|
||||
import * as focus from '../../data/focusDeemphasis.js';
|
||||
@@ -20,6 +20,13 @@ export function createApplicationFlights({
|
||||
militaryRegistry,
|
||||
resolveAsset = (url) =>
|
||||
`${import.meta.env?.BASE_URL || '/'}${url.replace(/^\//, '')}`,
|
||||
// Test seam: the renderer factory (default: the engine's, from the registry).
|
||||
renderer = {
|
||||
create: ({ viewer, engine = null, adopt }) =>
|
||||
engine
|
||||
? rendererFor('flights', engine, { viewer, adopt })
|
||||
: createFlightsCesiumRenderer(null, { viewer, adopt }),
|
||||
},
|
||||
}) {
|
||||
const { groundFloor, meshFloor, groundSnap } = surface;
|
||||
return createCivilFlightLayer({
|
||||
@@ -27,10 +34,12 @@ export function createApplicationFlights({
|
||||
resolveAsset,
|
||||
services: {
|
||||
picking,
|
||||
sprites,
|
||||
trails,
|
||||
selection,
|
||||
// The engine's flights renderer from the registry (render/cesium.js on
|
||||
// Cesium); a bare viewer without an engine (unit tests) draws on Cesium.
|
||||
renderer,
|
||||
aircraftPresentation,
|
||||
camera: { ...trackedCamera, applyTrackedCameraFrame },
|
||||
camera: trackedCamera,
|
||||
militaryRegistry,
|
||||
labels,
|
||||
groundFloor,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
// provider (`{ engine, unavailable() }` is the part it reads).
|
||||
|
||||
import { APPLICATION_LAYER_DIRECTORY } from './directory.js';
|
||||
import { createFlightsCesiumRenderer } from '../../layers/flights/render/cesium.js';
|
||||
|
||||
const ENGINE_KINDS = new Set(['cesium', 'navara']);
|
||||
|
||||
@@ -81,11 +82,19 @@ export const rendererFor = (layerId, engine, options) =>
|
||||
export const layerAvailableOn = (layerId, engineKind) =>
|
||||
defaultRegistry.layerAvailableOn(layerId, engineKind);
|
||||
|
||||
// Every application layer draws itself on Cesium today.
|
||||
/** Cesium renderers extracted from their layers (render/cesium.js). */
|
||||
export const CESIUM_LAYER_RENDERERS = Object.freeze({
|
||||
flights: createFlightsCesiumRenderer,
|
||||
});
|
||||
|
||||
// The other application layers still draw themselves on Cesium.
|
||||
registerLayerRenderers(
|
||||
'cesium',
|
||||
Object.fromEntries(
|
||||
APPLICATION_LAYER_DIRECTORY.map(({ id }) => [id, CESIUM_BUILTIN]),
|
||||
APPLICATION_LAYER_DIRECTORY.map(({ id }) => [
|
||||
id,
|
||||
CESIUM_LAYER_RENDERERS[id] ?? CESIUM_BUILTIN,
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
CESIUM_BUILTIN,
|
||||
CESIUM_LAYER_RENDERERS,
|
||||
rendererFor,
|
||||
createLayerAvailability,
|
||||
createRendererRegistry,
|
||||
layerAvailableOn,
|
||||
@@ -54,6 +56,15 @@ test('the default registry: every layer on Cesium, none yet on Navara', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('flights has an extracted Cesium renderer; the others still draw themselves', () => {
|
||||
assert.deepEqual(Object.keys(CESIUM_LAYER_RENDERERS), ['flights']);
|
||||
const viewer = { scene: {}, camera: {} };
|
||||
const renderer = rendererFor('flights', { kind: 'cesium' }, { viewer });
|
||||
assert.equal(renderer.kind, 'cesium');
|
||||
assert.equal(renderer.viewer, viewer);
|
||||
assert.equal(rendererFor('satellites', { kind: 'cesium' }), null);
|
||||
});
|
||||
|
||||
test('the layer availability API: engine, isAvailable, available, unavailable', () => {
|
||||
const registry = createRendererRegistry();
|
||||
registry.register('navara', { flights: () => ({}) });
|
||||
|
||||
Reference in new issue
Block a user