mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Draw launch-pad zones as radial ground discs with the original fill, rim, transitions, emission and depth bias. Drape Transit history and its backing on ground corridors. Keep the current age bands and once-per-second updates; advance the active head with a reveal fraction and rebuild only at segment crossings. Its wider dark edge and colour core blend once, as on Cesium. Navara composes these looks after tone mapping. Build reveal corridors and dynamic Transit history synchronously once shared terrain bounds are loaded. Keep requesting frames until the visible globe tiles and committed primitives are ready: classification needs current surface depth after a camera move. Retain the reference radial material, its alpha envelope and the head's material-only reveal updates. Remove the empty Navara ground effect from the render chain when the last shown set is hidden or destroyed. It otherwise remains as the insertion anchor for later pulse effects after its packed textures have been disposed. Cover reveal, destruction and replacement with fresh-state comparisons for corridors, polygons, discs and cells. Cesium drawing is unchanged by this fix. Keep the radial pixel check at a 500 metre radius and 4 kilometre view, sample the brightest of six inner points around the native fill gap, and sample across the rim width. Restore its view during arrival flights and run it last among ground checks. Both suite launchers wait for the linked view to arrive before checking. Keep these checks with the radial look. Pass rectangular pick windows and drill limits through input subscriptions. Street Level uses its 9 pixel window and CCTV uses its 14 pixel window and six-result drill. Down picks stay synchronous, moves coalesce per frame and Navara clicks keep the GPU answer from their gesture. Add a projector ellipsoid option and use WGS84 radii reduced by 1,000 metres for Street Level. These changes restore the original Cesium pad fill and ground trail rather than the temporary ring and raised lines. Navara follows the same appearance and horizon policy, and now honours explicit CPU pick windows. Existing callers without these options retain their defaults. The four debts share the contract, suite and engine implementations, so keep them together. No coupling count grew or fell: renderer lines remain 0 and 189, external Cesium imports 3, external viewer lines 891, engine-kind checks 1, engine resolution calls 0, extension reads 3, ground passes 1, SDK loads 3, screen handler files 4 and engine-name lines 32. The contract and ground suites now wait until the camera has reached the view in their link before checking, because the app's restore flight could land in the middle of a check; that was also the cause of the intermittent camera-events failure. The radial check uses a launch pad's size and samples the fill at several inner points: Cesium's own old pad leaves the same gap in a small ground disc's fill. The pulse-band check takes its base frame once the surface has settled. Checked in the browser, keyless: the contract suite passes on both engines (84 and 85 checks), the ground suite passes on both, CCTV v2 passes 58 checks, and the space, transit, Street Level and CCTV engine switches pass. The transit and Street Level scripts fail as they do before this change.
356 lines
12 KiB
JavaScript
356 lines
12 KiB
JavaScript
/** Camera-jump regression against an existing server; never starts a server. */
|
|
import puppeteer from 'puppeteer';
|
|
import { chromeExecutablePath, captureQaScreenshot } from './qa-chrome.mjs';
|
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
import { reduceTrailPixels } from '../src/layers/transit/qaMetrics.js';
|
|
import { blockPaidQaMaps } from './qa-map-policy.mjs';
|
|
import { transitQaBase } from './qa-transit-browser.mjs';
|
|
|
|
const base = transitQaBase(process.env.QA_BASE_URL);
|
|
const shots = process.env.QA_SHOTS || 'qa-shots/transit-recovery';
|
|
await mkdir(shots, { recursive: true });
|
|
const browser = await puppeteer.launch({
|
|
headless: true,
|
|
executablePath:
|
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
args: [
|
|
'--use-angle=metal',
|
|
'--enable-gpu',
|
|
'--disable-background-timer-throttling',
|
|
'--disable-renderer-backgrounding',
|
|
],
|
|
});
|
|
try {
|
|
const page = await browser.newPage();
|
|
await blockPaidQaMaps(page);
|
|
await page.setViewport({ width: 1920, height: 1080 });
|
|
const errors = [];
|
|
page.on('pageerror', (error) => errors.push(error.message));
|
|
await page.goto(
|
|
`${base}/?welcome=0#lat=30.271&lon=-97.7431&alt=600&heading=0&pitch=-60`,
|
|
);
|
|
await page.waitForFunction(() =>
|
|
window.__godsEyeView?.dataManager?.layers.has('transit'),
|
|
);
|
|
await page.evaluate(async () => {
|
|
const app = window.__godsEyeView;
|
|
await app.dataManager.setEnabled('transit', true, { source: 'qa' });
|
|
});
|
|
await page.waitForFunction(
|
|
() => {
|
|
const scene = window.__godsEyeView.viewer.scene;
|
|
return scene.globe.tilesLoaded && scene.globe.show;
|
|
},
|
|
{ timeout: 60000 },
|
|
);
|
|
await page.waitForFunction(
|
|
() => {
|
|
const cover = document.getElementById('loading-screen');
|
|
return !cover || cover.classList.contains('hidden');
|
|
},
|
|
{ timeout: 60000 },
|
|
);
|
|
await page.evaluate(() => {
|
|
const app = window.__godsEyeView,
|
|
camera = app.viewer.camera;
|
|
const C = camera.positionCartographic.constructor,
|
|
lat = 30.267 + 90 / 111320;
|
|
const floor =
|
|
app.viewer.scene.globe.getHeight(C.fromDegrees(-97.7431, lat)) || 0;
|
|
camera.setView({
|
|
destination: C.toCartesian(
|
|
C.fromDegrees(
|
|
-97.7431,
|
|
lat - 600 / Math.tan(Math.PI / 3) / 111320,
|
|
floor + 600,
|
|
),
|
|
),
|
|
orientation: { heading: 0, pitch: -Math.PI / 3, roll: 0 },
|
|
});
|
|
});
|
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
await page.waitForFunction(
|
|
() => window.__godsEyeView.viewer.scene.globe.tilesLoaded,
|
|
{ timeout: 60000 },
|
|
);
|
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
const result = await page.evaluate(async () => {
|
|
const app = window.__godsEyeView,
|
|
scene = app.viewer.scene,
|
|
camera = app.viewer.camera;
|
|
const layer = app.dataManager.layers.get('transit').module;
|
|
const state = layer._transitStateForTest(),
|
|
parts = layer._transitPartsForTest();
|
|
const { getRegisteredTransitFeed } =
|
|
await import('/src/data/transitFeeds.js');
|
|
const { setRate } = await import('/src/data/contactPlayback.js');
|
|
const C = camera.positionCartographic.constructor;
|
|
const feed = {
|
|
...getRegisteredTransitFeed('capmetro-austin'),
|
|
id: 'qa-camera-recovery',
|
|
};
|
|
const aim = (lat, height = 600) =>
|
|
camera.setView({
|
|
destination: C.toCartesian(
|
|
C.fromDegrees(
|
|
-97.7431,
|
|
lat - 600 / Math.tan(Math.PI / 3) / 111320,
|
|
height,
|
|
),
|
|
),
|
|
orientation: { heading: 0, pitch: -Math.PI / 3, roll: 0 },
|
|
});
|
|
// The trail draws through engine.ground (render/display.js); its renderer
|
|
// is the handle that shows and hides the whole trail. Keep the one the
|
|
// selection below creates.
|
|
let trailRenderer = null;
|
|
const createTrailRenderer = parts.renderer.createTrailRenderer;
|
|
parts.renderer.createTrailRenderer = (...args) =>
|
|
(trailRenderer = createTrailRenderer.apply(parts.renderer, args));
|
|
parts.selection.clearSelection();
|
|
parts.ingestion.abortAllInFlight();
|
|
state._activeFeeds.clear();
|
|
for (const key of state._vehicles.keys())
|
|
parts.ingestion.removeVehicle(key);
|
|
// Model an outstanding floor lookup while reports arrive off screen.
|
|
// Only acquisition is controlled; selection, visibility, paths and rendering
|
|
// use their real owners. Release to the loaded terrain at the camera jump.
|
|
const requestHeight = parts.height.requestHeight;
|
|
parts.height.requestHeight = (lat, lon) => ({
|
|
cell: `${lat},${lon}`,
|
|
height: null,
|
|
prior: null,
|
|
});
|
|
aim(30.28);
|
|
const now = Date.now();
|
|
for (let i = 0; i < 9; i++) {
|
|
const timestamp = now - 135000 + i * 15000;
|
|
parts.ingestion.applySnapshot(
|
|
feed,
|
|
{
|
|
fetchedAt: timestamp,
|
|
vehicles: [
|
|
{
|
|
id: 'moving-bus',
|
|
routeId: '1',
|
|
tripId: 'qa',
|
|
lat: 30.267 + (i * 90) / 111320,
|
|
lon: -97.7431,
|
|
timestamp: timestamp / 1000,
|
|
timestampSource: 'vehicle',
|
|
bearing: 0,
|
|
},
|
|
],
|
|
},
|
|
{ stale: false },
|
|
);
|
|
}
|
|
const entry = state._vehicles.get(`${feed.id}:moving-bus`);
|
|
entry.qaFixture = true; // Protect this disclosed fixture from live feed eviction.
|
|
parts.rendering.sampleIdle(entry);
|
|
const before = {
|
|
shown: entry.marker.show,
|
|
heightPending: entry.heightPending,
|
|
phase: entry.sample.phase,
|
|
fixes: entry.track.count,
|
|
};
|
|
clearTimeout(state._floorTimer);
|
|
state._floorTimer = null;
|
|
const started = performance.now();
|
|
parts.selection.selectVehicle(entry.key);
|
|
parts.renderer.createTrailRenderer = createTrailRenderer;
|
|
const preparedAtSelection = !!parts.trails.diagnostics()?.body;
|
|
parts.height.requestHeight = requestHeight;
|
|
const floor =
|
|
scene.globe.getHeight(
|
|
C.fromDegrees(entry.sample.lon, entry.sample.lat),
|
|
) || 0;
|
|
aim(entry.sample.lat, floor + 600);
|
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
let trail;
|
|
while (performance.now() - started < 1400) {
|
|
trail = parts.trails.diagnostics();
|
|
if (entry.marker.show && trail?.body?.show && trail.body.ready) break;
|
|
scene.requestRender();
|
|
await wait(25);
|
|
}
|
|
const status = {
|
|
before,
|
|
preparedAtSelection,
|
|
markerShow: entry.marker.show,
|
|
body: !!trail?.body,
|
|
bodyShow: trail?.body?.show === true,
|
|
visibility: layer
|
|
._transitVisibilityForTest()
|
|
.find((e) => e.key === entry.key),
|
|
recoveryMs: performance.now() - started,
|
|
};
|
|
if (!trailRenderer)
|
|
return { ...status, reason: 'the selection created no trail renderer' };
|
|
if (!entry.marker.show || !trail?.body?.show || !trail.body.ready)
|
|
return {
|
|
...status,
|
|
reason: 'marker or body did not recover before pixel deadline',
|
|
};
|
|
setRate(entry.track, 0, {
|
|
wallNowMs: Date.now(),
|
|
monoNowMs: performance.now(),
|
|
});
|
|
parts.rendering.sampleIdle(entry);
|
|
parts.rendering.schedulePlayback(entry);
|
|
// Marker positions are plain { x, y, z } now (the display's handles), not
|
|
// Cesium Cartesian3 instances with static helpers.
|
|
const V = {
|
|
distance: (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z),
|
|
lerp: (a, b, t) => ({
|
|
x: a.x + (b.x - a.x) * t,
|
|
y: a.y + (b.y - a.y) * t,
|
|
z: a.z + (b.z - a.z) * t,
|
|
}),
|
|
};
|
|
const points = entry.trailSegments
|
|
.filter((s) => s.toT <= entry.sample.displayT)
|
|
.flatMap((s) => s.positions);
|
|
const lengths = [0];
|
|
for (let i = 1; i < points.length; i++)
|
|
lengths.push(lengths.at(-1) + V.distance(points[i - 1], points[i]));
|
|
const canvas = scene.canvas,
|
|
gl = scene.context._gl,
|
|
scale = canvas.width / canvas.clientWidth;
|
|
const mul = (m, v) =>
|
|
[0, 1, 2, 3].map(
|
|
(i) =>
|
|
m[i] * v[0] + m[i + 4] * v[1] + m[i + 8] * v[2] + m[i + 12] * v[3],
|
|
);
|
|
const project = (p) => {
|
|
const q = mul(
|
|
camera.frustum.projectionMatrix,
|
|
mul(camera.viewMatrix, [p.x, p.y, p.z, 1]),
|
|
);
|
|
return {
|
|
x: ((q[0] / q[3]) * 0.5 + 0.5) * canvas.clientWidth,
|
|
y: (0.5 - (q[1] / q[3]) * 0.5) * canvas.clientHeight,
|
|
inFront: q[3] > 0,
|
|
};
|
|
};
|
|
const samples = Array.from({ length: 8 }, (_, i) => {
|
|
const d = (lengths.at(-1) * (i + 1)) / 9;
|
|
let j = 1;
|
|
while (j < lengths.length - 1 && lengths[j] < d) j++;
|
|
const p = V.lerp(
|
|
points[j - 1],
|
|
points[j],
|
|
(d - lengths[j - 1]) / Math.max(0.001, lengths[j] - lengths[j - 1]),
|
|
);
|
|
const cart = C.fromCartesian(p);
|
|
cart.height = scene.globe.getHeight(cart) || 0;
|
|
return {
|
|
...project(C.toCartesian(cart)),
|
|
radius: (Math.SQRT2 * Math.ceil(3 * scale)) / scale,
|
|
};
|
|
});
|
|
const sprite = {
|
|
...project(entry.marker.position),
|
|
radius: Math.hypot(entry.marker.width, entry.marker.height) / 2 + 4,
|
|
};
|
|
const read = () =>
|
|
samples.map(({ x, y }) => {
|
|
const r = Math.ceil(3 * scale),
|
|
px = Math.round(x * scale),
|
|
py = Math.round(canvas.height - 1 - y * scale);
|
|
if (
|
|
px < r ||
|
|
py < r ||
|
|
px + r >= canvas.width ||
|
|
py + r >= canvas.height
|
|
)
|
|
return null;
|
|
const data = new Uint8Array((2 * r + 1) ** 2 * 4);
|
|
gl.readPixels(
|
|
px - r,
|
|
py - r,
|
|
2 * r + 1,
|
|
2 * r + 1,
|
|
gl.RGBA,
|
|
gl.UNSIGNED_BYTE,
|
|
data,
|
|
);
|
|
return Array.from(data);
|
|
});
|
|
const frame = () =>
|
|
new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => {
|
|
remove();
|
|
reject(new Error('No recovery frame'));
|
|
}, 500);
|
|
const remove = scene.postRender.addEventListener(() => {
|
|
remove();
|
|
clearTimeout(timer);
|
|
resolve(read());
|
|
});
|
|
scene.requestRender();
|
|
});
|
|
let visible = true;
|
|
// Body and head together, as the trail's own visibility switch does.
|
|
const remove = scene.preRender.addEventListener(() =>
|
|
trailRenderer.setVisible(visible),
|
|
);
|
|
const captures = [];
|
|
try {
|
|
for (const show of [false, true, false, true]) {
|
|
visible = show;
|
|
await frame();
|
|
captures.push(await frame());
|
|
}
|
|
} finally {
|
|
remove();
|
|
trailRenderer.setVisible(true);
|
|
parts.trails.update();
|
|
}
|
|
const [off, on, offAgain, onAgain] = captures;
|
|
return {
|
|
...status,
|
|
samples,
|
|
sprite,
|
|
off,
|
|
on,
|
|
offAgain,
|
|
onAgain,
|
|
tilesReady:
|
|
scene.globe.tilesLoaded &&
|
|
parts.trails.diagnostics().body === trail.body,
|
|
elapsedMs: performance.now() - started,
|
|
// The trail's ground corridors (age bands and head, each with a backing).
|
|
lines: app.engine.ground
|
|
.list()
|
|
.filter(({ id }) => id.startsWith('transit-trail-')),
|
|
};
|
|
});
|
|
const pixels = reduceTrailPixels(result.on, result.off, result);
|
|
result.present = pixels.present;
|
|
result.pixelPass = pixels.pass;
|
|
result.pixelDetails = pixels;
|
|
result.errors = errors;
|
|
await captureQaScreenshot(page, { path: `${shots}/recovery.png` });
|
|
await writeFile(`${shots}/recovery.json`, JSON.stringify(result, null, 2));
|
|
for (const key of ['on', 'off', 'onAgain', 'offAgain']) delete result[key];
|
|
const pass =
|
|
result.before?.shown === false &&
|
|
result.before?.phase === 'playing' &&
|
|
// Ground history is prepared even while marker floors are unresolved.
|
|
result.preparedAtSelection &&
|
|
result.markerShow &&
|
|
result.body &&
|
|
result.bodyShow &&
|
|
result.elapsedMs <= 2000 &&
|
|
pixels.pass &&
|
|
!errors.length;
|
|
console.log(
|
|
`${pass ? 'PASS' : 'FAIL'} select moving bus, setView, marker + body + >=6/8 trail pixels within 2 s`,
|
|
);
|
|
console.log(JSON.stringify(result));
|
|
process.exitCode = pass ? 0 : 1;
|
|
} finally {
|
|
await browser.close();
|
|
}
|