mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 03:32:19 +00:00
feat(aircraft): draw far-away aircraft as shaded sprites seen from the camera's angle
Aircraft on the map were flat, top-down SVG silhouettes turned along
their course: from an oblique camera they read as paper cut-outs lying
on the ground.
Each aircraft class (and each helicopter rotor frame) is now rendered in
Blender from a sphere of directions into one sheet of shaded sprites
(public/sprites/aircraft-views.webp: 302 views a class, 7.5 degrees
apart from straight above to 30 degrees below the horizon, 4096 x 3648,
grey, 3.1 MB). The renderer lays a contact flat on the ground along its
course, works out where the eye is in that frame and draws the nearest
view, mirrored for the port side. The view is a card standing at the
contact, square to the direction it was rendered from, so between views
the sprite is tilted (foreshortened and turned) as the aircraft would
be; views are not blended. Sprites are neutral, so the fleet, tracked
and military tints still apply.
Renderer: a new `viewSheets` capability, `DrawPort.views(id, sheet)` and
an image `{views, first, fallback}` for icon items (src/data/viewSheet.js
holds the layout and maths, in JS and GLSL). A view row draws from the
sheet's own texture, kept as luminance and alpha; until the sheet has
loaded, and if it cannot load, it draws its flat `fallback` along its
course as before. View sheets are offered on WebGL 2 only, and on
WebGL 1 the icon shader is as it was.
Layers: Flights, Military Flights (fleet and tracked contact) and Local
ADS-B draw views; the TR-3B, airport vehicles, ground stations and
Cockpit's far pips stay flat, as does any renderer without the
capability.
Tools: `npm run build:aircraft-views` bakes the sheet from the repo's
own fleet models (about 7 minutes); scripts/qa-aircraft-view-sheet.mjs
writes contact sheets of a bake and scripts/qa-aircraft-views.mjs
photographs a grid of every class in the app from above, tilted, from
below and round an orbit.
With 5,000 contacts on an M3 Max the frame takes 5.9-6.1 ms against
5.9 ms with the flat glyphs.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
d9d79ebc4d
commit
efdac0ba70
40 files changed
+3535
-109
No files matched your search
@@ -0,0 +1,175 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
aircraftViewRef,
|
||||
isAircraftViewRef,
|
||||
registerAircraftViews,
|
||||
VIEW_SHEETS_CAPABILITY,
|
||||
withAircraftView,
|
||||
} from './aircraftViews.js';
|
||||
import { AIRCRAFT_VIEWS } from './viewSheet.js';
|
||||
import { ROTOR_FRAMES, ROTOR_STILL_FRAME } from './rotorFrames.js';
|
||||
import { aircraftIcon, FLEET_ICON_PX } from './aircraftIcons.js';
|
||||
|
||||
const STILL_KINDS = [
|
||||
'airliner',
|
||||
'widebody',
|
||||
'quadjet',
|
||||
'turboprop',
|
||||
'light',
|
||||
'glider',
|
||||
'fastjet',
|
||||
'bizjet',
|
||||
'uav',
|
||||
];
|
||||
|
||||
test('every aircraft class draws its own block of the view sheet', () => {
|
||||
for (const kind of STILL_KINDS)
|
||||
assert.deepEqual(
|
||||
aircraftViewRef(kind),
|
||||
{
|
||||
views: AIRCRAFT_VIEWS.id,
|
||||
first: AIRCRAFT_VIEWS.subjects[kind],
|
||||
fallback: aircraftIcon(kind, FLEET_ICON_PX),
|
||||
},
|
||||
kind,
|
||||
);
|
||||
const firsts = STILL_KINDS.map((kind) => aircraftViewRef(kind).first);
|
||||
assert.equal(
|
||||
new Set(firsts).size,
|
||||
STILL_KINDS.length,
|
||||
'no two share a block',
|
||||
);
|
||||
assert.equal(
|
||||
aircraftViewRef('airliner'),
|
||||
aircraftViewRef('airliner'),
|
||||
'one ref per block, so an unchanged image writes nothing',
|
||||
);
|
||||
assert.ok(Object.isFrozen(aircraftViewRef('airliner')));
|
||||
});
|
||||
|
||||
test('a helicopter draws the block of its rotor frame, the still frame by default', () => {
|
||||
assert.equal(ROTOR_FRAMES, 3);
|
||||
for (let frame = 0; frame < ROTOR_FRAMES; frame++) {
|
||||
const ref = aircraftViewRef('helicopter', frame);
|
||||
assert.equal(
|
||||
ref.first,
|
||||
AIRCRAFT_VIEWS.subjects[`helicopter${frame}`],
|
||||
`frame ${frame}`,
|
||||
);
|
||||
assert.equal(
|
||||
ref.fallback,
|
||||
aircraftIcon('helicopter', FLEET_ICON_PX, frame),
|
||||
`its fallback is the glyph of rotor frame ${frame}`,
|
||||
);
|
||||
}
|
||||
assert.equal(
|
||||
aircraftViewRef('helicopter').fallback,
|
||||
aircraftIcon('helicopter', FLEET_ICON_PX, ROTOR_STILL_FRAME),
|
||||
);
|
||||
const still = AIRCRAFT_VIEWS.subjects[`helicopter${ROTOR_STILL_FRAME}`];
|
||||
for (const frame of [undefined, -1, 3, 1.5, NaN])
|
||||
assert.equal(aircraftViewRef('helicopter', frame).first, still, `${frame}`);
|
||||
});
|
||||
|
||||
test('the TR-3B, airport vehicles, ground stations and unknown kinds have no views', () => {
|
||||
for (const kind of [
|
||||
'tr3b',
|
||||
'tr3bHot',
|
||||
'vehicle',
|
||||
'station',
|
||||
'jet',
|
||||
'',
|
||||
undefined,
|
||||
])
|
||||
assert.equal(aircraftViewRef(kind), null, String(kind));
|
||||
assert.equal(
|
||||
aircraftViewRef('airliner', 1).first,
|
||||
0,
|
||||
'a frame means nothing to a fixed wing',
|
||||
);
|
||||
});
|
||||
|
||||
test('a view ref is told apart from flat images', () => {
|
||||
assert.equal(isAircraftViewRef(aircraftViewRef('glider')), true);
|
||||
for (const image of [
|
||||
'data:image/svg+xml;base64,AAA',
|
||||
null,
|
||||
undefined,
|
||||
{ atlas: 'a', slot: 's' },
|
||||
])
|
||||
assert.equal(isAircraftViewRef(image), false, String(image));
|
||||
});
|
||||
|
||||
test('the sheet is registered once per draw port, only with the capability', () => {
|
||||
const calls = [];
|
||||
const port = { views: (id, sheet) => calls.push([id, sheet]) };
|
||||
const caps = new Set([VIEW_SHEETS_CAPABILITY]);
|
||||
assert.equal(VIEW_SHEETS_CAPABILITY, 'viewSheets');
|
||||
assert.equal(registerAircraftViews(port, new Set()), false);
|
||||
assert.equal(registerAircraftViews(port, null), false);
|
||||
assert.equal(calls.length, 0, 'nothing registered without the capability');
|
||||
assert.equal(registerAircraftViews(port, caps), true);
|
||||
assert.equal(registerAircraftViews(port, caps), true);
|
||||
assert.deepEqual(calls, [[AIRCRAFT_VIEWS.id, AIRCRAFT_VIEWS.sheet]]);
|
||||
const other = { views: (id) => calls.push([id]) };
|
||||
assert.equal(registerAircraftViews(other, caps), true);
|
||||
assert.equal(calls.length, 2, 'a second port registers its own');
|
||||
assert.equal(
|
||||
registerAircraftViews({}, caps),
|
||||
false,
|
||||
'a port without views()',
|
||||
);
|
||||
assert.equal(registerAircraftViews(null, caps), false);
|
||||
});
|
||||
|
||||
test('a look takes the view only when views are on and it is drawn along its course', () => {
|
||||
const look = {
|
||||
image: 'flat',
|
||||
imageLod: { near: 'near', switchPx: 30 },
|
||||
size: [20, 20],
|
||||
scale: 1.5,
|
||||
};
|
||||
const on = { views: true, kind: 'airliner', rotationMode: 'course' };
|
||||
const viewed = withAircraftView(look, on);
|
||||
assert.deepEqual(viewed, {
|
||||
image: aircraftViewRef('airliner'),
|
||||
imageLod: undefined,
|
||||
size: [20, 20],
|
||||
scale: 1.5,
|
||||
});
|
||||
assert.ok('imageLod' in viewed, 'imageLod is cleared, so an update drops it');
|
||||
assert.equal(look.image, 'flat', 'the look given is left as it was');
|
||||
assert.equal(withAircraftView(look, { ...on, views: false }), look);
|
||||
assert.equal(withAircraftView(look, { ...on, rotationMode: 'screen' }), look);
|
||||
assert.equal(
|
||||
withAircraftView(look, { ...on, rotationMode: undefined }),
|
||||
look,
|
||||
);
|
||||
assert.equal(withAircraftView(look, { ...on, kind: 'tr3b' }), look);
|
||||
assert.equal(withAircraftView(look, { ...on, kind: 'station' }), look);
|
||||
assert.equal(
|
||||
withAircraftView(look, { ...on, kind: 'helicopter', frame: 2 }).image,
|
||||
aircraftViewRef('helicopter', 2),
|
||||
);
|
||||
});
|
||||
|
||||
test('the sheet is registered with its image resolved as the layer resolves its assets', () => {
|
||||
const calls = [];
|
||||
const port = { views: (id, sheet) => calls.push([id, sheet]) };
|
||||
const caps = new Set([VIEW_SHEETS_CAPABILITY]);
|
||||
registerAircraftViews(port, caps, (url) => `https://cdn.example/app${url}`);
|
||||
assert.equal(calls.length, 1);
|
||||
const [id, sheet] = calls[0];
|
||||
assert.equal(id, AIRCRAFT_VIEWS.id);
|
||||
assert.equal(
|
||||
sheet.image,
|
||||
'https://cdn.example/app/sprites/aircraft-views.webp',
|
||||
);
|
||||
assert.deepEqual(
|
||||
{ ...sheet, image: AIRCRAFT_VIEWS.sheet.image },
|
||||
{ ...AIRCRAFT_VIEWS.sheet },
|
||||
'the layout as it is',
|
||||
);
|
||||
assert.equal(AIRCRAFT_VIEWS.sheet.image, '/sprites/aircraft-views.webp');
|
||||
});
|
||||
Reference in new issue
Block a user