mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Segment colours and shows were drawn on draped solid lines only. Any other segmented line (3D, geodesic or draped; glow, dash, arrow, flow, pattern or an outlined solid) now draws a primitive a segment, each with its style's material in the segment's colour under a pick id that reads as the line's, recoloured and shown in place; an arrow's head is on its last segment, and a revealed line shows each segment by its share of the length. Draped pieces swap in with the set's other ground primitives. Pattern lines drape on a ground polyline of their own, and an inertial line with a depth-fail style is a primitive turned with the sky each frame. The new conformance check draw.lines.segmentStyles picks shown and hidden segments of five mode and style pairs before and after an in-place change; Cesium runs it.
190 lines
5.8 KiB
JavaScript
190 lines
5.8 KiB
JavaScript
/**
|
||
* @module render/cesium/harness
|
||
* @description The Cesium renderer as the conformance suite's renderer under
|
||
* test, in the `/dev/conformance/` page.
|
||
*
|
||
* `CESIUM_CHECKS` lists the checks of the ports the Cesium renderer has.
|
||
* Each migration adds the checks of the members it brings, so the suite
|
||
* shows how far the renderer is through the contract; every other check is
|
||
* left out of the run rather than failed. Camera flights are checked in
|
||
* Node instead (`cameraPort.test.mjs`): a page's frames come on the real
|
||
* clock at the display's rate, where the reference traces step 1/60 s.
|
||
*/
|
||
import { DEFAULT_TOLERANCE } from '../conformance/index.js';
|
||
import { toEcef } from '../stub/math.js';
|
||
import { createCesiumSceneRenderer, pointerFeedOf } from './sceneRenderer.js';
|
||
|
||
/** @type {ReadonlySet<string>} */
|
||
export const CESIUM_CHECKS = new Set([
|
||
'camera.trace.setView angles',
|
||
'camera.trace.setView keeps the position when only orientation is given',
|
||
'camera.trace.lookAt sweep and release',
|
||
'camera.trace.move, look, rotate and zoom',
|
||
'camera.trace.commands inside a lookAt frame',
|
||
'camera.trace.changed fires by each listener’s threshold',
|
||
'camera.moveEnd',
|
||
'camera.controls.holds',
|
||
'camera.controls.settings',
|
||
'camera.follow',
|
||
'camera.follow.autodetect',
|
||
'camera.followFrame',
|
||
'camera.trace.flyTo with a duration of 0 completes inside the call',
|
||
'camera.trace.flyTo where the camera already is completes inside the call',
|
||
'camera.setView.exact',
|
||
'camera.viewRectangle',
|
||
'camera.fov',
|
||
'camera.trace.view and projection matrices',
|
||
'credits',
|
||
'credits.listenerRules',
|
||
'draw.atlas',
|
||
'draw.clampState',
|
||
'draw.columns',
|
||
'draw.columns.shown',
|
||
'draw.drawOrder',
|
||
'draw.drillPick',
|
||
'draw.field.rasterShell',
|
||
'draw.field.windStreamlines',
|
||
'draw.icons.distance',
|
||
'draw.icons.images',
|
||
'draw.icons.update',
|
||
'draw.lines.depthFail',
|
||
'draw.lines.settled',
|
||
'draw.lines.styles',
|
||
'draw.lines.outline',
|
||
'draw.lines.drape',
|
||
'draw.lines.segments',
|
||
'draw.lines.segmentStyles',
|
||
'draw.ids',
|
||
'draw.models',
|
||
'draw.models.loadFailed',
|
||
'draw.models.tint',
|
||
'draw.models.update',
|
||
'draw.motion',
|
||
'draw.motion.arc',
|
||
'draw.motion.climb',
|
||
'draw.motion.live',
|
||
'draw.motion.shared',
|
||
'draw.pick',
|
||
'draw.points.update',
|
||
'draw.points.population',
|
||
'draw.displayRange',
|
||
'draw.sets',
|
||
'draw.shapes.drapedRotation',
|
||
'draw.shapes.resize',
|
||
'effects.crossfade',
|
||
'effects.defineStyle',
|
||
'effects.screenModulation',
|
||
'effects.screenModulation.pixels',
|
||
'effects.styles',
|
||
'effects.withoutScreenModulation',
|
||
'effects.withoutStyles',
|
||
'frame.demand',
|
||
'frame.order',
|
||
'frame.prediction',
|
||
'frame.renderOnce',
|
||
'frame.suspend',
|
||
'frame.time',
|
||
'globe.imagery',
|
||
'globe.sky',
|
||
'globe.split',
|
||
'globe.surfaceShading',
|
||
'globe.surfaceVersion',
|
||
'globe.visible',
|
||
'globe.withoutImageHooks',
|
||
'input.behaviours',
|
||
'input.clickPick',
|
||
'input.lease',
|
||
'input.lease.grab',
|
||
'input.lease.press',
|
||
'query.heights',
|
||
'query.pickBeforeStyles',
|
||
'query.heights.sets',
|
||
'query.projectMany',
|
||
'query.rays',
|
||
'query.withoutCapability',
|
||
'quality',
|
||
'quality.signals',
|
||
'quality.signals.gpuTiming',
|
||
'renderer.listeners',
|
||
'renderer.readPixels',
|
||
'renderer.releaseUnused',
|
||
'renderer.whenSettled',
|
||
]);
|
||
|
||
/** A frame fails the check rather than hang it when frames stop. */
|
||
const FRAME_TIMEOUT_MS = 5000;
|
||
|
||
/**
|
||
* One frame of the page: it resolves once the render loop's tick for the
|
||
* next animation frame (drawn or not, or none while suspended) has run, so
|
||
* loads and timers progress between frames. Cesium's loop asks for its
|
||
* animation frame before this does, so its tick runs first. It asks for no
|
||
* render itself: a check's own `requestRender` is what makes a tick draw.
|
||
*/
|
||
function nextFrame() {
|
||
return new Promise((resolve, reject) => {
|
||
const timer = setTimeout(
|
||
() => reject(new Error('no animation frame came')),
|
||
FRAME_TIMEOUT_MS,
|
||
);
|
||
requestAnimationFrame(() => {
|
||
clearTimeout(timer);
|
||
setTimeout(resolve, 0);
|
||
});
|
||
});
|
||
}
|
||
|
||
/**
|
||
* @param {{name?: string, model?: string, missingModel?: string}} [options]
|
||
* `model`: a glTF URL for the model checks; `missingModel`: one that
|
||
* fails to load, for the failure check.
|
||
* @returns {import('../conformance/index.js').ConformanceHarness}
|
||
*/
|
||
export function createCesiumHarness({
|
||
name = 'cesium',
|
||
model,
|
||
missingModel,
|
||
} = {}) {
|
||
return {
|
||
name,
|
||
async create({ viewport, capabilities }) {
|
||
const container = document.createElement('div');
|
||
container.style.cssText = `position:fixed;left:0;top:0;width:${viewport.width}px;height:${viewport.height}px`;
|
||
document.body.append(container);
|
||
let renderer;
|
||
try {
|
||
renderer = await createCesiumSceneRenderer({ container, capabilities });
|
||
} catch (error) {
|
||
container.remove();
|
||
throw error;
|
||
}
|
||
const destroy = renderer.destroy;
|
||
const { canvas } = renderer;
|
||
renderer.destroy = () => {
|
||
try {
|
||
destroy();
|
||
} finally {
|
||
// Free the context now: a full run makes more widgets than the
|
||
// browser keeps contexts for.
|
||
(canvas.getContext('webgl2') ?? canvas.getContext('webgl'))
|
||
?.getExtension('WEBGL_lose_context')
|
||
?.loseContext();
|
||
container.remove();
|
||
}
|
||
};
|
||
return renderer;
|
||
},
|
||
frame: nextFrame,
|
||
// Events as the renderer's handler delivers them: the checks send ones
|
||
// no real pointer can (a click with no press), so not DOM events.
|
||
pointer: (r, type, x, y, extra) => pointerFeedOf(r)(type, x, y, extra),
|
||
now: () => performance.now(),
|
||
// What a live motion clock reads.
|
||
wallTime: () => Date.now(),
|
||
toEcef,
|
||
tolerance: DEFAULT_TOLERANCE,
|
||
flightPaths: 'endpoints',
|
||
...(model ? { assets: { model, missingModel } } : {}),
|
||
};
|
||
}
|