mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 03:32:19 +00:00
Vessels on the map were flat, top-down hulls turned along their course, drawn at one size at every range. Each hull shape (the ten vessel kinds, a dredger and a pilot boat) is now rendered in Blender into a view sheet like the aircraft's (public/sprites/vessel-views.webp: 208 views a shape, 7.5 degrees apart from straight above down to the horizon, 4096 x 2496, grey, 2.2 MB), cut at the waterline. On a renderer with `viewSheets` the Vessels layer draws a vessel as the view of its hull from where the eye is, with the flat hull as the fallback while the sheet loads or if it cannot load. A vessel keeps its kind's colour; aids to navigation keep their upright buoy; a renderer without view sheets draws the flat hulls as before. Every AIS ship type code 0-99 maps to a shape in the sheet (`vesselShape`, vesselTypes.js), pinned by a test. Type text such as "Search & Rescue" and "Anti Pollution" is now recognised, which also gives those vessels their right kind colour. Size: a vessel's icon now follows its range from the eye on the same range aircraft icons use (1.5 times its former size up close, its former size at about 1,000 km, a third from 8,000 km out), so it stays under an aircraft's icon at every range, and the vessel set recedes toward the horizon as the aircraft sets do. Tools: the bake script handles both sheets (scripts/bake-view-sheet.py; `npm run build:aircraft-views`, `npm run build:vessel-views`), and refuses a partial bake over a shipped sheet. scripts/qa-view-sheet.mjs writes contact sheets of a bake; scripts/qa-aircraft-views.mjs takes `--layer vessels`. The aircraft sheet is unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]>
383 lines
14 KiB
JavaScript
383 lines
14 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* qa-aircraft-views.mjs: screenshots of the aircraft view sheet in the app.
|
|
*
|
|
* Seeds a grid of synthetic military contacts (every icon class down the
|
|
* rows, eight courses across) through a fetch shim, then photographs it from
|
|
* straight above, tilted from several sides and from below, so a person can
|
|
* check that each sprite shows its aircraft from where the camera is: the
|
|
* nose along the course, the far wing foreshortened, the underside from
|
|
* below.
|
|
*
|
|
* Run: node scripts/qa-aircraft-views.mjs --url http://localhost:4173 [--out qa-shots/views]
|
|
* [--layer military|flights|vessels] [--block-sheet] [--headful]
|
|
* [--orbit [--orbit-step 2] [--orbit-pitch -35]]
|
|
* Needs the dev server (`npm run dev`).
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import puppeteer from 'puppeteer';
|
|
import { stubPlanespotters } from './qa-photo-stub.mjs';
|
|
|
|
const argv = process.argv.slice(2);
|
|
const opt = (name, fallback) => {
|
|
const i = argv.indexOf(name);
|
|
return i >= 0 && argv[i + 1] ? argv[i + 1] : fallback;
|
|
};
|
|
const APP_URL = opt('--url', 'http://localhost:4173');
|
|
const OUT = path.resolve(opt('--out', 'qa-shots/views'));
|
|
const HEADFUL = argv.includes('--headful');
|
|
// `military` (amber, every class by type code), `flights` (white, the
|
|
// classes an ADS-B emitter category gives) or `vessels` (every hull kind by
|
|
// AIS ship type, at sea level).
|
|
const LAYER = opt('--layer', 'military');
|
|
const VESSELS = LAYER === 'vessels';
|
|
// The app's id of the layer.
|
|
const LAYER_ID = VESSELS ? 'ais-live-vessels' : LAYER;
|
|
// Fail the sheet's request: the contacts should draw their flat glyphs.
|
|
const BLOCK_SHEET = argv.includes('--block-sheet');
|
|
const GPU = argv.includes('--gpu');
|
|
|
|
// A type code for each icon class (aircraftClass.js).
|
|
const CLASSES = [
|
|
['airliner', 'A320'],
|
|
['widebody', 'C17'],
|
|
['quadjet', 'B744'],
|
|
['turboprop', 'C130'],
|
|
['light', 'C172'],
|
|
['glider', 'DISC'],
|
|
['fastjet', 'F16'],
|
|
['bizjet', 'GLF4'],
|
|
['uav', 'Q9'],
|
|
['helicopter', 'H60'],
|
|
];
|
|
// The classes a flight's emitter category gives (OpenSky has no type code).
|
|
const CATEGORIES = [
|
|
['airliner', 4],
|
|
['widebody', 6],
|
|
['light', 2],
|
|
['fastjet', 7],
|
|
['glider', 9],
|
|
['helicopter', 8],
|
|
];
|
|
// An AIS ship type for each hull kind (vesselTypes.js).
|
|
const HULLS = [
|
|
['cargo', 70],
|
|
['tanker', 80],
|
|
['passenger', 60],
|
|
['highspeed', 40],
|
|
['fishing', 30],
|
|
['tug', 52],
|
|
['sailing', 36],
|
|
['pleasure', 37],
|
|
['military', 35],
|
|
['other', 90],
|
|
['dredger', 33],
|
|
['pilot', 50],
|
|
];
|
|
const ROWS = VESSELS ? HULLS : LAYER === 'flights' ? CATEGORIES : CLASSES;
|
|
const COURSES = [0, 45, 90, 135, 180, 225, 270, 315];
|
|
// Aircraft over Austin; vessels on open water in the North Sea.
|
|
const CENTRE = VESSELS ? { lon: 3.2, lat: 52.6 } : { lon: -97.74, lat: 30.3 };
|
|
const STEP_DEG = 0.03;
|
|
const ALT_FT = VESSELS ? 0 : 12000;
|
|
|
|
const contacts = [];
|
|
ROWS.forEach(([klass, type], row) =>
|
|
COURSES.forEach((courseDeg, column) =>
|
|
contacts.push({
|
|
hex: `ee${row.toString(16)}${column.toString(16)}00`.slice(0, 6),
|
|
flight: `${klass.slice(0, 4).toUpperCase()}${courseDeg}`,
|
|
t: type,
|
|
klass,
|
|
courseDeg,
|
|
lon: CENTRE.lon + (column - (COURSES.length - 1) / 2) * STEP_DEG,
|
|
lat: CENTRE.lat - (row - (ROWS.length - 1) / 2) * STEP_DEG,
|
|
altFt: ALT_FT,
|
|
}),
|
|
),
|
|
);
|
|
|
|
// Each shot: where the camera looks from. `heading` is the way it looks
|
|
// (degrees clockwise from north), `pitch` down from level, `rangeKm` from
|
|
// the grid's centre at the contacts' height.
|
|
const SHOTS = [
|
|
{ name: '1-above', heading: 0, pitch: -90, rangeKm: 44 },
|
|
{ name: '2-tilt30-north', heading: 0, pitch: -60, rangeKm: 46 },
|
|
{ name: '3-tilt55-north', heading: 0, pitch: -35, rangeKm: 50 },
|
|
{ name: '4-tilt55-east', heading: 90, pitch: -35, rangeKm: 50 },
|
|
{ name: '5-tilt55-southwest', heading: 225, pitch: -35, rangeKm: 50 },
|
|
{ name: '6-tilt75-north', heading: 0, pitch: -15, rangeKm: 52 },
|
|
// From below, looking up at the grid; a vessel is never seen from there,
|
|
// so vessels get a shot from just above the water in its place.
|
|
VESSELS
|
|
? { name: '7-horizon-north', heading: 0, pitch: -5, rangeKm: 30 }
|
|
: { name: '7-below-north', heading: 0, pitch: 12, rangeKm: 15.5 },
|
|
];
|
|
|
|
// `--orbit`: the camera swung round the grid a little at a time, a frame
|
|
// each step, to watch the sprites turn from one view to the next.
|
|
const ORBIT_STEP_DEG = Number(opt('--orbit-step', 2));
|
|
const ORBIT_SHOTS = Array.from(
|
|
{ length: Math.floor(90 / ORBIT_STEP_DEG) + 1 },
|
|
(_, i) => ({
|
|
name: `orbit-${String(i).padStart(3, '0')}`,
|
|
heading: i * ORBIT_STEP_DEG,
|
|
pitch: Number(opt('--orbit-pitch', -35)),
|
|
rangeKm: 50,
|
|
settleMs: i === 0 ? 6000 : 900,
|
|
}),
|
|
);
|
|
|
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
async function main() {
|
|
fs.mkdirSync(OUT, { recursive: true });
|
|
const browser = await puppeteer.launch({
|
|
headless: HEADFUL ? false : 'new',
|
|
args: [
|
|
'--no-sandbox',
|
|
'--disable-setuid-sandbox',
|
|
...(GPU ? [] : ['--use-gl=angle', '--use-angle=swiftshader']),
|
|
'--disable-web-security',
|
|
'--disable-background-timer-throttling',
|
|
'--disable-renderer-backgrounding',
|
|
'--window-size=1500,1000',
|
|
],
|
|
});
|
|
const errors = [];
|
|
try {
|
|
const page = await browser.newPage();
|
|
await stubPlanespotters(page);
|
|
await page.setViewport({ width: 1500, height: 1000, deviceScaleFactor: 2 });
|
|
page.on('console', (msg) => {
|
|
if (
|
|
msg.type() === 'error' &&
|
|
!/Failed to load resource/i.test(msg.text())
|
|
)
|
|
errors.push(msg.text());
|
|
});
|
|
page.on('pageerror', (error) => errors.push(`pageerror: ${error.message}`));
|
|
|
|
if (BLOCK_SHEET) {
|
|
await page.setRequestInterception(true);
|
|
page.on('request', (request) => {
|
|
if (request.isInterceptResolutionHandled()) return;
|
|
if (/\/sprites\/[a-z]+-views\./.test(request.url())) request.abort();
|
|
else request.continue();
|
|
});
|
|
}
|
|
await page.evaluateOnNewDocument(
|
|
(seed) => {
|
|
const realFetch = window.fetch.bind(window);
|
|
// Each contact flies its course, slowly: a feed whose fixes stand
|
|
// still while claiming a track makes the layers work a heading out
|
|
// of no movement, and the contacts turn north over a run.
|
|
const SPEED_MPS = 6;
|
|
const started = Date.now();
|
|
const at = (c) => {
|
|
const flown = (SPEED_MPS * (Date.now() - started)) / 1000;
|
|
const course = (c.courseDeg * Math.PI) / 180;
|
|
return {
|
|
lat: c.lat + (flown * Math.cos(course)) / 111320,
|
|
lon:
|
|
c.lon +
|
|
(flown * Math.sin(course)) /
|
|
(111320 * Math.cos((c.lat * Math.PI) / 180)),
|
|
};
|
|
};
|
|
const json = (body) =>
|
|
new Response(JSON.stringify(body), {
|
|
status: 200,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
window.fetch = (input, init) => {
|
|
const url =
|
|
typeof input === 'string' ? input : (input && input.url) || '';
|
|
if (url.includes('/api/openai/hud-summary'))
|
|
return Promise.resolve(json({ summary: 'view QA' }));
|
|
if (url.includes('/api/military/track'))
|
|
return Promise.resolve(
|
|
json({ timestamp: Math.floor(Date.now() / 1000), trace: [] }),
|
|
);
|
|
if (url.includes('/api/military'))
|
|
return Promise.resolve(
|
|
json({
|
|
msg: 'No error',
|
|
now: Date.now(),
|
|
ac: (seed.layer === 'military' ? seed.contacts : []).map(
|
|
(c) => ({
|
|
hex: c.hex,
|
|
flight: c.flight,
|
|
...at(c),
|
|
alt_baro: c.altFt,
|
|
track: c.courseDeg,
|
|
gs: SPEED_MPS * 1.9438,
|
|
t: c.t,
|
|
r: `QA-${c.hex.slice(-3)}`,
|
|
ownOp: 'QA',
|
|
seen_pos: 0,
|
|
}),
|
|
),
|
|
}),
|
|
);
|
|
if (url.includes('/api/vessels') && seed.layer === 'vessels') {
|
|
const now = Date.now();
|
|
return Promise.resolve(
|
|
json({
|
|
rows: seed.contacts.map((c, i) => ({
|
|
...at(c),
|
|
name: c.flight,
|
|
mmsi: String(235000000 + i),
|
|
imo: '0',
|
|
type: String(c.t),
|
|
destination: 'QA',
|
|
length: 120,
|
|
beam: 20,
|
|
speed: SPEED_MPS * 1.9438,
|
|
course: c.courseDeg,
|
|
heading: c.courseDeg,
|
|
last_position_UTC: new Date(now).toISOString(),
|
|
last_position_epoch: Math.floor(now / 1000),
|
|
})),
|
|
source: 'AISStream',
|
|
status: 'live',
|
|
error: null,
|
|
refreshing: false,
|
|
newestPositionAt: now,
|
|
lastMessageAt: now,
|
|
silentForMs: 0,
|
|
reconnectAttempt: 0,
|
|
nextAttemptAt: null,
|
|
staleAfterMs: 120000,
|
|
watchdog: 'armed',
|
|
}),
|
|
);
|
|
}
|
|
if (url.includes('/api/flights/track'))
|
|
return Promise.resolve(json({ path: [] }));
|
|
if (url.includes('/api/flights') && seed.layer === 'flights') {
|
|
const now = Math.floor(Date.now() / 1000);
|
|
return Promise.resolve(
|
|
json({
|
|
time: now,
|
|
states: seed.contacts.map((c) => [
|
|
c.hex,
|
|
c.flight,
|
|
'QA',
|
|
now,
|
|
now,
|
|
at(c).lon,
|
|
at(c).lat,
|
|
c.altFt * 0.3048,
|
|
false,
|
|
SPEED_MPS,
|
|
c.courseDeg,
|
|
0,
|
|
null,
|
|
null,
|
|
null,
|
|
false,
|
|
0,
|
|
c.t,
|
|
]),
|
|
}),
|
|
);
|
|
}
|
|
if (url.includes('/api/adsbdb/'))
|
|
return Promise.resolve(json({ found: false }));
|
|
return realFetch(input, init);
|
|
};
|
|
},
|
|
{ layer: LAYER, contacts },
|
|
);
|
|
|
|
console.log(`Loading ${APP_URL} ...`);
|
|
await page.goto(APP_URL, { waitUntil: 'domcontentloaded', timeout: 60000 });
|
|
await page.waitForFunction(
|
|
() => window.__godsEyeView?.viewer && window.__godsEyeView?.dataManager,
|
|
{ timeout: 60000, polling: 200 },
|
|
);
|
|
const seeded = await page.evaluate(
|
|
async (name, centre) => {
|
|
const { dataManager, viewer } = window.__godsEyeView;
|
|
// Over the grid first: a layer may ask only for what is in view.
|
|
const Cartesian3 = viewer.camera.position.constructor;
|
|
viewer.camera.setView({
|
|
destination: Cartesian3.fromDegrees(centre.lon, centre.lat, 60000),
|
|
});
|
|
await dataManager.setEnabled(name, true);
|
|
const layer = dataManager.layers.get(name).module;
|
|
for (let i = 0; i < 4; i++) {
|
|
await layer.update(viewer);
|
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
}
|
|
window.__viewQaDriver = setInterval(() => layer.update(viewer), 8000);
|
|
return layer.getStats().count;
|
|
},
|
|
LAYER_ID,
|
|
CENTRE,
|
|
);
|
|
console.log(` ${LAYER} contacts: ${seeded}/${contacts.length}`);
|
|
if (seeded !== contacts.length)
|
|
throw new Error(
|
|
`the ${LAYER} layer took ${seeded} of ${contacts.length} contacts`,
|
|
);
|
|
// Past the layer's render delay, so every contact is drawn.
|
|
await sleep(20000);
|
|
|
|
for (const shot of argv.includes('--orbit') ? ORBIT_SHOTS : SHOTS) {
|
|
await page.evaluate(
|
|
({ shot, centre, altM }) => {
|
|
const { viewer } = window.__godsEyeView;
|
|
const Cartesian3 = viewer.camera.position.constructor;
|
|
const heading = (shot.heading * Math.PI) / 180;
|
|
const pitch = (shot.pitch * Math.PI) / 180;
|
|
const range = shot.rangeKm * 1000;
|
|
// The eye sits `range` back along the way it looks.
|
|
const east = -range * Math.sin(heading) * Math.cos(pitch);
|
|
const north = -range * Math.cos(heading) * Math.cos(pitch);
|
|
const up = -range * Math.sin(pitch);
|
|
const lat = centre.lat + north / 111320;
|
|
const lon =
|
|
centre.lon +
|
|
east / (111320 * Math.cos((centre.lat * Math.PI) / 180));
|
|
viewer.camera.setView({
|
|
destination: Cartesian3.fromDegrees(
|
|
lon,
|
|
lat,
|
|
Math.max(50, altM + up),
|
|
),
|
|
orientation: { heading, pitch, roll: 0 },
|
|
});
|
|
viewer.scene.requestRender();
|
|
},
|
|
{ shot, centre: CENTRE, altM: ALT_FT * 0.3048 },
|
|
);
|
|
await sleep(shot.settleMs ?? 6000);
|
|
// The globe's own canvas, read right after a render: no HUD, dialogs
|
|
// or label overlays in the way.
|
|
const png = await page.evaluate(() => {
|
|
const { viewer } = window.__godsEyeView;
|
|
viewer.scene.render();
|
|
return viewer.scene.canvas.toDataURL('image/png');
|
|
});
|
|
const file = path.join(OUT, `${shot.name}.png`);
|
|
fs.writeFileSync(file, Buffer.from(png.split(',')[1], 'base64'));
|
|
console.log(` wrote ${file}`);
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
if (errors.length) {
|
|
console.log(`\nConsole errors (${errors.length}):`);
|
|
for (const error of errors.slice(0, 20)) console.log(` ${error}`);
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|