Files
gods-eye-view/src/render/cesium/sceneRenderer.js
T
Sameh Khamis 0ab31d4fb8 The renderer seam: clicks go to the newest tool, recession and display groups through the contract, drawing at parity with Cesium
- Clicks: when two tools want the globe's clicks, the newest takes them and the older is told and turns itself off; a click is decided when it arrives, and ambient selection fires only when no tool holds the pointer. The "map is busy" paths and their strings are removed.
- Recession: the limb fade is shared (src/render/recession.js) and reaches icon and model sets through SetSpec.recede; tuning applies on the next frame.
- Display panel groups are published through src/ui/displayGroups.js; the Weather group and src/viewWeather.js are removed.
- Draw port: a set whose icons only move is moved in place, and models that did not change are not restyled each frame, so moving fleets cost what they did when drawn directly; an untinted, fully opaque model is drawn without a colour.
- Conformance: input.lease.lost checks the new lease inside onLost and reports a throwing onLost; draw.sets.recede covers model sets.
- QA scripts read the renderer host instead of internals the seam replaced.
2026-11-15 17:03:09 -08:00

132 lines
4.5 KiB
JavaScript

/**
* @module render/cesium/sceneRenderer
* @description The part of the Cesium renderer the reference scenes need,
* through the contract's own members: the globe and sky, icons, points,
* lines, shapes and models, `setView`, picks and projection, the frame
* phases, pointer input, credits, effects, settling, capture, pixel reads
* and cache release. The
* `/dev/conformance/` page draws the scenes with it to make and check the
* visual references.
*
* Its ports are `ports.js`'s, which the application's renderer shares;
* this factory adds the conformance widget, its fixed settings, the input
* port (`input.js`) and a bare starting globe and sky: no imagery or
* terrain, every sky part off.
*
* It is not yet the whole Cesium renderer: each later migration adds the
* members its layer family needs, until it passes the whole suite.
* Members it does not have are absent, never stubbed.
*/
import * as Cesium from 'cesium';
import { createCesiumInput } from './input.js';
import { cesiumCapabilities, createCesiumPorts } from './ports.js';
export { toCartesian, toColor, toImage } from './ports.js';
/** Each renderer's pointer feed, for the conformance harness. */
const feeds = new WeakMap();
/**
* Delivers one pointer event to a renderer this made, as its handler would.
* @param {object} renderer
* @returns {((type: string, x: number, y: number, extra?: object) => void) | null}
*/
export const pointerFeedOf = (renderer) => feeds.get(renderer) ?? null;
/**
* @param {{container: HTMLElement, msaa?: number, capabilities?: Iterable<string>,
* cameraController?: import('../contract/camera').CameraControllerFactory,
* now?: () => number}} options
* `capabilities` limits the renderer to those it lists; `cameraController`
* puts the camera port on that controller (`controlledCamera.js`); `now`
* is the clock its ticks and pointer events read (`performance.now` by
* default).
* @returns {Promise<object>} A renderer with the members listed above.
*/
export async function createCesiumSceneRenderer({
container,
msaa = 4,
capabilities: only,
cameraController,
now,
}) {
const credits = document.createElement('div');
const widget = new Cesium.CesiumWidget(container, {
baseLayer: false,
terrainProvider: new Cesium.EllipsoidTerrainProvider(),
skyBox: false,
skyAtmosphere: false,
requestRenderMode: true,
maximumRenderTimeChange: Infinity,
msaaSamples: msaa,
creditContainer: credits,
contextOptions: { webgl: { preserveDrawingBuffer: true } },
});
const scene = widget.scene;
// A fixed time, so lighting is the same in every capture; `setTime`
// moves it and it stays there.
widget.clock.shouldAnimate = false;
widget.clock.currentTime = Cesium.JulianDate.fromIso8601(
'2026-06-21T18:00:00Z',
);
scene.globe.baseColor = Cesium.Color.fromCssColorString('#1c2a36');
scene.backgroundColor = Cesium.Color.BLACK;
scene.globe.showGroundAtmosphere = false;
scene.fog.enabled = false;
if (scene.sun) scene.sun.show = false;
if (scene.moon) scene.moon.show = false;
scene.globe.enableLighting = false;
const capabilities = new Set(cesiumCapabilities(scene, only));
const ports = createCesiumPorts(widget, {
capabilities,
...(cameraController ? { cameraController } : {}),
...(now ? { now } : {}),
});
const input = createCesiumInput(widget, {
query: ports.query,
report: ports.report,
...(ports.suspendCamera ? { suspendCamera: ports.suspendCamera } : {}),
// Its events' times on the ticks' clock.
...(now ? { now } : {}),
});
ports.attachInput?.(input.port);
// --- Renderer --------------------------------------------------------------
const renderer = {
id: 'cesium',
contractVersion: '0',
capabilities,
canvas: scene.canvas,
frame: ports.frame,
globe: ports.globe,
// A member of a capability left out is absent, not stubbed.
draw: capabilities.has('models')
? ports.draw
: Object.fromEntries(
Object.entries(ports.draw).filter(([kind]) => kind !== 'models'),
),
camera: ports.camera,
query: ports.query,
input: input.port,
effects: ports.effects,
quality: ports.quality,
capture: ports.capture,
readPixels: ports.readPixels,
releaseUnused: ports.releaseUnused,
credits: ports.credits,
whenSettled: ports.whenSettled,
resize: () => widget.resize(),
on: ports.on,
destroy() {
input.dispose();
ports.dispose();
widget.destroy();
},
};
feeds.set(renderer, input.feed);
return renderer;
}