mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Application extras come from the renderer plugin; framing, occlusion and panel drawing are contract ports
A renderer plugin may supply applicationHooks(renderer) for what only its renderer has (map engine, own credits, stale commands, QA handles). What every renderer should do moves onto the contract: controls.keepEarthFramed (behind the keepEarthFramed capability), query.occlusionTest (behind occlusionTest), and panel drawing, which keepPanelRendering now does through resize and frame.renderNow through the contract. renderNow throws when the frame fails to draw. The Cesium port installs its zoom-out guard through keepEarthFramed (a setView no longer cancels its turn) and answers occlusionTest with the scene's probe; the stub answers it with a horizon test.
This commit is contained in:
1 parent
a755f63638
commit
619c19ea67
40 files changed
+737
-323
No files matched your search
@@ -11,21 +11,20 @@
|
||||
* (`src/maps/globeEngine.js`).
|
||||
* - `trimStaleCommands()`: drops the draw commands a renderer keeps for a
|
||||
* while after it stops drawing them; run after a layer turns off.
|
||||
* - `keepPanelRendering(options)`: keeps the globe drawing in an inline panel
|
||||
* whose host stops animation frames (embed mode); returns its disposer.
|
||||
* - `viewerDrawsEntity(entity)`: whether an entity is one the renderer draws
|
||||
* itself (Cockpit asks whether the aircraft it flies still draws).
|
||||
* - `installZoomOutGuard(options)`: keeps outward user zooms bounded and the
|
||||
* Earth framed; returns its disposer.
|
||||
* - `createOcclusionProbe()`: a probe that tests depth-tested contacts
|
||||
* (street vehicles) against what the frame drew, so the detection overlay
|
||||
* leaves out those something stands in front of (`SurfaceOcclusion` in
|
||||
* `src/data/detectionOcclusion.js` says what it answers); without one,
|
||||
* every such contact is drawn.
|
||||
* - `qaHandles`: values QA scripts read from `window.__godsEyeView`.
|
||||
* - `ownCreditDisplay`: true when the renderer shows its credits in a
|
||||
* display of its own; otherwise the application shows what its credits
|
||||
* port lists (`src/ui/creditsView.js`).
|
||||
*
|
||||
* A plugin hands them as its `applicationHooks(renderer)`
|
||||
* (`ApplicationHooks`, `contract/renderer.d.ts`); the application scene
|
||||
* records them here as it creates the renderer. What the renderer should
|
||||
* do is in the contract instead: keeping the Earth framed on zooming out is
|
||||
* `camera.controls.keepEarthFramed`, the detection overlay's depth test is
|
||||
* `query.occlusionTest`, and an inline panel keeps drawing through the frame
|
||||
* port (`src/app/panelRendering.js`).
|
||||
*/
|
||||
|
||||
const hooks = new WeakMap();
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
* and it has every member of the contract. The application's base (the
|
||||
* photoreal tiles, the map stack's imagery and terrain) is still loaded
|
||||
* through the Cesium map engine (`mapEngine.js`), which the plugin hands
|
||||
* the application with the renderer (`../applicationHooks.js`); the globe
|
||||
* the application with the renderer (its `applicationHooks`); the globe
|
||||
* port drapes its imagery on that base as drawn (see `globe.js`).
|
||||
* `whenSettled` waits for the globe, the scene's 3D tiles and what the draw
|
||||
* sets hold.
|
||||
*
|
||||
* What only this renderer needs at startup is set up here: the free-look
|
||||
* height limit, keyboard access to the credits' expand link (in the page's
|
||||
* language), and the hooks the application uses where a renderer has
|
||||
* them (stale command trimming, inline panel rendering, whether an entity
|
||||
* is the viewer's own, the zoom-out guard, the viewer QA scripts read).
|
||||
* language). The plugin's `applicationHooks` are what the application
|
||||
* uses where a renderer has them: the map engine, stale command trimming,
|
||||
* whether an entity is the viewer's own, and the viewer QA scripts read.
|
||||
* Adapter code reaches the viewer behind a renderer through
|
||||
* `cesiumViewerOf` (`viewers.js`), never through a renderer member, so no
|
||||
* engine type crosses the contract.
|
||||
@@ -26,16 +26,12 @@
|
||||
import { createApplicationViewer } from './applicationViewer.js';
|
||||
import { CONTRACT_VERSION } from '../contract/index.js';
|
||||
import { bindRenderer } from '../rendererOf.js';
|
||||
import { provideApplicationHooks } from '../applicationHooks.js';
|
||||
import { FREE_LOOK_MAX_HEIGHT_METERS } from '../../globeInView.js';
|
||||
import { createCesiumInput } from './input.js';
|
||||
import { cesiumCapabilities, createCesiumPorts } from './ports.js';
|
||||
import { cesiumMapEngine } from './mapEngine.js';
|
||||
import { installFreeLookHeightLimit } from './freeLookLimit.js';
|
||||
import { keepPanelRendering } from './panelRendering.js';
|
||||
import { trimStaleSceneCommands } from './sceneCommandRelease.js';
|
||||
import { installZoomOutGuard } from './zoomOutGuard.js';
|
||||
import { createViewerOcclusionProbe } from './sceneOcclusionProbe.js';
|
||||
import { configureCreditKeyboardAccess } from './creditKeyboard.js';
|
||||
import { onLocaleChange } from '../../i18n/index.js';
|
||||
import { cesiumViewerOf, recordViewer } from './viewers.js';
|
||||
@@ -168,29 +164,27 @@ export function createCesiumRendererPlugin({
|
||||
});
|
||||
recordViewer(renderer, viewer);
|
||||
unbind = bindRenderer(viewer, renderer);
|
||||
provideApplicationHooks(renderer, {
|
||||
return renderer;
|
||||
},
|
||||
/**
|
||||
* @param {TransitionalRenderer} renderer
|
||||
* @returns {import('../contract/renderer').ApplicationHooks}
|
||||
*/
|
||||
applicationHooks(renderer) {
|
||||
const viewer = cesiumViewerOf(renderer);
|
||||
return {
|
||||
mapEngine: cesiumMapEngine,
|
||||
// Cesium's credit display (#cesium-credits) shows the credits.
|
||||
ownCreditDisplay: true,
|
||||
// Drops the draw commands the scene keeps after it stops drawing
|
||||
// them; run after a drawn frame (see sceneCommandRelease.js).
|
||||
trimStaleCommands: () => trimStaleSceneCommands(viewer.scene),
|
||||
// Keeps the globe drawing in an inline panel whose host stops
|
||||
// animation frames (embed mode, src/app/embed.js).
|
||||
keepPanelRendering: (options) => keepPanelRendering(viewer, options),
|
||||
// Whether an entity is one of the viewer's own (Cockpit asks whether
|
||||
// the aircraft it flies still draws).
|
||||
viewerDrawsEntity: (entity) => viewer.entities.contains(entity),
|
||||
// Keeps outward user zooms bounded and the Earth framed; returns its
|
||||
// disposer (see zoomOutGuard.js).
|
||||
installZoomOutGuard: (options) => installZoomOutGuard(viewer, options),
|
||||
// Tests depth-tested contacts (street vehicles) against the frame's
|
||||
// own depth, for the detection overlay (see sceneOcclusionProbe.js).
|
||||
createOcclusionProbe: () => createViewerOcclusionProbe(viewer),
|
||||
// QA scripts drive and read the viewer itself.
|
||||
qaHandles: { viewer },
|
||||
});
|
||||
return renderer;
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { CONTRACT_VERSION, checkRendererShape } from '../contract/index.js';
|
||||
import { rendererOf } from '../rendererOf.js';
|
||||
import { applicationHooksOf } from '../applicationHooks.js';
|
||||
import { cesiumMapEngine } from './mapEngine.js';
|
||||
import {
|
||||
ReadonlySet,
|
||||
@@ -142,17 +141,13 @@ test('the plugin wraps the viewer it is given, behind the accessor only', async
|
||||
false,
|
||||
'free look is limited to low heights from the start',
|
||||
);
|
||||
const hooks = applicationHooksOf(renderer);
|
||||
const hooks = plugin.applicationHooks(renderer);
|
||||
assert.equal(hooks.mapEngine, cesiumMapEngine, 'the map stacks use Cesium');
|
||||
assert.equal(hooks.ownCreditDisplay, true, 'Cesium shows its own credits');
|
||||
assert.equal(hooks.qaHandles.viewer, viewer, 'QA scripts read the viewer');
|
||||
assert.equal(hooks.viewerDrawsEntity({ own: true }), true);
|
||||
assert.equal(hooks.viewerDrawsEntity({}), false);
|
||||
for (const name of [
|
||||
'trimStaleCommands',
|
||||
'keepPanelRendering',
|
||||
'installZoomOutGuard',
|
||||
])
|
||||
assert.equal(typeof hooks[name], 'function', name);
|
||||
assert.equal(typeof hooks.trimStaleCommands, 'function');
|
||||
|
||||
assert.ok(viewer.listeners.size > 0, 'the ports follow the frame phases');
|
||||
assert.equal(typeof renderer.draw.icons, 'function');
|
||||
|
||||
@@ -21,7 +21,10 @@ test("zooming out stops with the globe 30% of the screen's height across", () =>
|
||||
|
||||
test('a wide screen, whose view is narrower, may zoom out farther', () => {
|
||||
assert.ok(zoomOutLimit(0.4) > zoomOutLimit(Math.PI / 3));
|
||||
assert.ok(zoomOutLimit(Math.PI / 3) > 20_000_000, 'past the views a link opens');
|
||||
assert.ok(
|
||||
zoomOutLimit(Math.PI / 3) > 20_000_000,
|
||||
'past the views a link opens',
|
||||
);
|
||||
});
|
||||
|
||||
function fakeViewer({ fovy = Math.PI / 3, height = 10_000_000 } = {}) {
|
||||
|
||||
@@ -117,12 +117,16 @@ export function createCesiumCamera({
|
||||
})
|
||||
: null;
|
||||
|
||||
const controlsPart = createCesiumControls({ scene, widget });
|
||||
|
||||
// Camera commands: hooks run before each one, so an owner can yield.
|
||||
const commandHooks = listenerList(report);
|
||||
const command = (kind) => commandHooks.fire({ kind });
|
||||
|
||||
const controlsPart = createCesiumControls({
|
||||
scene,
|
||||
widget,
|
||||
onCommand: (cb) => commandHooks.on(cb),
|
||||
});
|
||||
|
||||
// The flight this port started, while it is in progress. Cesium cancels
|
||||
// a flight in progress when another starts, including one started on
|
||||
// its camera directly, and runs the callbacks inside the call or frame
|
||||
|
||||
@@ -26,11 +26,16 @@
|
||||
* contract has no name for is kept as it is when they are set. While
|
||||
* they hold `ctrlWheel`, trackpad pinches (small pixel-mode Ctrl+wheel
|
||||
* events) are relayed at a usable speed (`ctrlWheelZoom.js`).
|
||||
* - `keepEarthFramed` installs the zoom-out guard (`zoomOutGuard.js`) on
|
||||
* the widget, which reads the controller's own input; a camera command
|
||||
* (`onCommand`) ends its easing. Without a widget whose scene has a
|
||||
* controller, it only reads back.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { acquireCameraInput } from './cameraInput.js';
|
||||
import { installTrackpadPinchRelay } from './ctrlWheelZoom.js';
|
||||
import { followZoomBase, setFollowZoomBase } from './follow.js';
|
||||
import { installZoomOutGuard } from './zoomOutGuard.js';
|
||||
|
||||
const HALF_PI = Math.PI / 2;
|
||||
const { WHEEL, PINCH, RIGHT_DRAG } = Cesium.CameraEventType;
|
||||
@@ -88,9 +93,12 @@ export const controllerDefaults = () => ({
|
||||
|
||||
/**
|
||||
* @param {{scene: {screenSpaceCameraController?: object}, widget?: object,
|
||||
* pinchRelay?: typeof installTrackpadPinchRelay}} options `widget`, the
|
||||
* Viewer or CesiumWidget, takes the trackpad pinch relay; without one
|
||||
* `ctrlWheel` binds Ctrl+wheel alone.
|
||||
* pinchRelay?: typeof installTrackpadPinchRelay,
|
||||
* onCommand?: (cb: () => void) => () => void,
|
||||
* zoomOutGuard?: typeof installZoomOutGuard}} options `widget`, the
|
||||
* Viewer or CesiumWidget, takes the trackpad pinch relay and the zoom-out
|
||||
* guard; without one `ctrlWheel` binds Ctrl+wheel alone. `onCommand`
|
||||
* subscribes to the camera port's commands.
|
||||
* @returns {{controls: import('../contract/camera').CameraControls,
|
||||
* dispose: () => void}}
|
||||
*/
|
||||
@@ -98,6 +106,8 @@ export function createCesiumControls({
|
||||
scene,
|
||||
widget,
|
||||
pinchRelay = installTrackpadPinchRelay,
|
||||
onCommand,
|
||||
zoomOutGuard = installZoomOutGuard,
|
||||
}) {
|
||||
const ownController = scene.screenSpaceCameraController;
|
||||
const controller = ownController ?? controllerDefaults();
|
||||
@@ -125,6 +135,13 @@ export function createCesiumControls({
|
||||
// The pitch range as last set, read back while the controller still has
|
||||
// the tilt limit it was given.
|
||||
let pitchSet = null;
|
||||
// `keepEarthFramed`, and the guard's disposer while it is installed.
|
||||
let framed = false;
|
||||
let releaseGuard = null;
|
||||
const guardable = () =>
|
||||
Boolean(
|
||||
ownController && widget?.camera && widget?.canvas && scene.preRender,
|
||||
);
|
||||
|
||||
const controls = {
|
||||
// Read without taking over `enableInputs`: once any user holds input,
|
||||
@@ -249,6 +266,27 @@ export function createCesiumControls({
|
||||
];
|
||||
relayPinches(value.includes('ctrlWheel'));
|
||||
},
|
||||
get keepEarthFramed() {
|
||||
return framed;
|
||||
},
|
||||
set keepEarthFramed(value) {
|
||||
framed = Boolean(value);
|
||||
if (framed && !releaseGuard && !disposed && guardable())
|
||||
releaseGuard = zoomOutGuard(widget, {
|
||||
requestRender: () => scene.requestRender?.(),
|
||||
// A command that places the eye ends the guard's easing; the
|
||||
// step views a held key sends every frame do not (the guard
|
||||
// lets go of a pose it did not make on its own).
|
||||
subscribeCameraHandoff: (listener) =>
|
||||
onCommand?.((command) => {
|
||||
if (command?.kind !== 'setView') listener(command);
|
||||
}),
|
||||
});
|
||||
else if (!framed && releaseGuard) {
|
||||
releaseGuard();
|
||||
releaseGuard = null;
|
||||
}
|
||||
},
|
||||
};
|
||||
// A controller that already binds Ctrl+wheel relays pinches from the start.
|
||||
relayPinches(controls.zoomInputs.includes('ctrlWheel'));
|
||||
@@ -257,6 +295,8 @@ export function createCesiumControls({
|
||||
controls,
|
||||
dispose() {
|
||||
relayPinches(false);
|
||||
releaseGuard?.();
|
||||
releaseGuard = null;
|
||||
disposed = true;
|
||||
cameraInput?.release();
|
||||
cameraInput = null;
|
||||
|
||||
@@ -225,3 +225,46 @@ test('a scene without a controller still has settings', () => {
|
||||
assert.equal(controls.zoomFactor, 9);
|
||||
assert.deepEqual(controls.zoomInputs, ['rightDrag', 'wheel', 'pinch']);
|
||||
});
|
||||
|
||||
test('keepEarthFramed installs the zoom-out guard, which placing commands cancel', () => {
|
||||
const scene = { ...sceneWithController(), preRender: {}, requestRender() {} };
|
||||
const widget = { scene, camera: {}, canvas: {} };
|
||||
const commands = new Set();
|
||||
const installed = [];
|
||||
const { controls, dispose } = createCesiumControls({
|
||||
scene,
|
||||
widget,
|
||||
onCommand: (cb) => (commands.add(cb), () => commands.delete(cb)),
|
||||
zoomOutGuard(viewer, { subscribeCameraHandoff }) {
|
||||
const guard = { viewer, cancels: 0, released: false };
|
||||
const off = subscribeCameraHandoff(() => (guard.cancels += 1));
|
||||
installed.push(guard);
|
||||
return () => {
|
||||
guard.released = true;
|
||||
off();
|
||||
};
|
||||
},
|
||||
});
|
||||
assert.equal(controls.keepEarthFramed, false);
|
||||
controls.keepEarthFramed = true;
|
||||
controls.keepEarthFramed = true;
|
||||
assert.equal(installed.length, 1, 'installed once');
|
||||
assert.equal(installed[0].viewer, widget);
|
||||
// A held key's step views do not cancel it; a flight does.
|
||||
for (const cb of commands) cb({ kind: 'setView' });
|
||||
assert.equal(installed[0].cancels, 0);
|
||||
for (const cb of commands) cb({ kind: 'flyTo' });
|
||||
assert.equal(installed[0].cancels, 1);
|
||||
controls.keepEarthFramed = false;
|
||||
assert.equal(installed[0].released, true);
|
||||
assert.equal(commands.size, 0);
|
||||
controls.keepEarthFramed = true;
|
||||
dispose();
|
||||
assert.equal(installed[1].released, true, 'released on dispose');
|
||||
});
|
||||
|
||||
test('keepEarthFramed only reads back without a controller to guard', () => {
|
||||
const { controls } = createCesiumControls({ scene: {} });
|
||||
controls.keepEarthFramed = true;
|
||||
assert.equal(controls.keepEarthFramed, true);
|
||||
});
|
||||
@@ -10,8 +10,12 @@ function fakeElement() {
|
||||
dataset: {},
|
||||
focused: false,
|
||||
id: '',
|
||||
setAttribute(name, value) { attributes.set(name, String(value)); },
|
||||
getAttribute(name) { return attributes.get(name) ?? null; },
|
||||
setAttribute(name, value) {
|
||||
attributes.set(name, String(value));
|
||||
},
|
||||
getAttribute(name) {
|
||||
return attributes.get(name) ?? null;
|
||||
},
|
||||
addEventListener(type, listener) {
|
||||
if (!listeners.has(type)) listeners.set(type, []);
|
||||
listeners.get(type).push(listener);
|
||||
@@ -22,8 +26,12 @@ function fakeElement() {
|
||||
target: this,
|
||||
defaultPrevented: false,
|
||||
propagationStopped: false,
|
||||
preventDefault() { this.defaultPrevented = true; },
|
||||
stopPropagation() { this.propagationStopped = true; },
|
||||
preventDefault() {
|
||||
this.defaultPrevented = true;
|
||||
},
|
||||
stopPropagation() {
|
||||
this.propagationStopped = true;
|
||||
},
|
||||
...event,
|
||||
};
|
||||
for (const listener of listeners.get(type) || []) listener(dispatched);
|
||||
@@ -33,8 +41,12 @@ function fakeElement() {
|
||||
this.onclick?.();
|
||||
this.dispatch('click');
|
||||
},
|
||||
focus() { this.focused = true; },
|
||||
listenerCount(type) { return listeners.get(type)?.length || 0; },
|
||||
focus() {
|
||||
this.focused = true;
|
||||
},
|
||||
listenerCount(type) {
|
||||
return listeners.get(type)?.length || 0;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -48,7 +60,8 @@ function fixture() {
|
||||
lightbox.parentElement = overlay;
|
||||
const root = {
|
||||
querySelector(selector) {
|
||||
if (selector === '#cesium-credits .cesium-credit-expand-link') return expand;
|
||||
if (selector === '#cesium-credits .cesium-credit-expand-link')
|
||||
return expand;
|
||||
if (selector === '.cesium-credit-lightbox') return lightbox;
|
||||
return null;
|
||||
},
|
||||
@@ -72,8 +85,12 @@ test('Enter opens and closes attribution on initial keydown', () => {
|
||||
const f = fixture();
|
||||
let opened = 0;
|
||||
let closed = 0;
|
||||
f.expand.onclick = () => { opened++; };
|
||||
f.close.onclick = () => { closed++; };
|
||||
f.expand.onclick = () => {
|
||||
opened++;
|
||||
};
|
||||
f.close.onclick = () => {
|
||||
closed++;
|
||||
};
|
||||
configureCreditKeyboardAccess(f.root);
|
||||
const openEvent = f.expand.dispatch('keydown', { key: 'Enter' });
|
||||
assert.equal(openEvent.defaultPrevented, true);
|
||||
@@ -91,8 +108,12 @@ test('Space opens and closes attribution only on key release', () => {
|
||||
const f = fixture();
|
||||
let opened = 0;
|
||||
let closed = 0;
|
||||
f.expand.onclick = () => { opened++; };
|
||||
f.close.onclick = () => { closed++; };
|
||||
f.expand.onclick = () => {
|
||||
opened++;
|
||||
};
|
||||
f.close.onclick = () => {
|
||||
closed++;
|
||||
};
|
||||
configureCreditKeyboardAccess(f.root);
|
||||
|
||||
const openDown = f.expand.dispatch('keydown', { key: ' ' });
|
||||
@@ -118,7 +139,9 @@ test('Space opens and closes attribution only on key release', () => {
|
||||
test('held activation keys do not repeat open or close actions', () => {
|
||||
const f = fixture();
|
||||
let opened = 0;
|
||||
f.expand.onclick = () => { opened++; };
|
||||
f.expand.onclick = () => {
|
||||
opened++;
|
||||
};
|
||||
configureCreditKeyboardAccess(f.root);
|
||||
|
||||
f.expand.dispatch('keydown', { key: ' ' });
|
||||
@@ -132,7 +155,9 @@ test('held activation keys do not repeat open or close actions', () => {
|
||||
|
||||
const g = fixture();
|
||||
let enterOpened = 0;
|
||||
g.expand.onclick = () => { enterOpened++; };
|
||||
g.expand.onclick = () => {
|
||||
enterOpened++;
|
||||
};
|
||||
configureCreditKeyboardAccess(g.root);
|
||||
g.expand.dispatch('keydown', { key: 'Enter' });
|
||||
g.expand.dispatch('keydown', { key: 'Enter', repeat: true });
|
||||
@@ -142,7 +167,9 @@ test('held activation keys do not repeat open or close actions', () => {
|
||||
test('losing focus during a Space hold cancels release activation', () => {
|
||||
const f = fixture();
|
||||
let opened = 0;
|
||||
f.expand.onclick = () => { opened++; };
|
||||
f.expand.onclick = () => {
|
||||
opened++;
|
||||
};
|
||||
configureCreditKeyboardAccess(f.root);
|
||||
|
||||
f.expand.dispatch('keydown', { key: ' ' });
|
||||
@@ -156,10 +183,15 @@ test('losing focus during a Space hold cancels release activation', () => {
|
||||
test('Escape and backdrop dismissal close attribution and restore its disclosure', () => {
|
||||
const f = fixture();
|
||||
let closed = 0;
|
||||
f.close.onclick = () => { closed++; };
|
||||
f.close.onclick = () => {
|
||||
closed++;
|
||||
};
|
||||
configureCreditKeyboardAccess(f.root);
|
||||
f.expand.click();
|
||||
const escape = f.lightbox.dispatch('keydown', { key: 'Escape', target: f.close });
|
||||
const escape = f.lightbox.dispatch('keydown', {
|
||||
key: 'Escape',
|
||||
target: f.close,
|
||||
});
|
||||
assert.equal(escape.defaultPrevented, true);
|
||||
assert.equal(escape.propagationStopped, true);
|
||||
assert.equal(closed, 1);
|
||||
@@ -185,7 +217,10 @@ test('credit keyboard setup is idempotent and safely declines incomplete markup'
|
||||
assert.equal(f.close.listenerCount('blur'), 1);
|
||||
assert.equal(f.lightbox.listenerCount('keydown'), 1);
|
||||
assert.equal(f.overlay.listenerCount('click'), 1);
|
||||
assert.equal(configureCreditKeyboardAccess({ querySelector: () => null }), false);
|
||||
assert.equal(
|
||||
configureCreditKeyboardAccess({ querySelector: () => null }),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
function textFixture() {
|
||||
|
||||
@@ -102,6 +102,26 @@ export function willDraw(scene, time) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The contract's `renderNow` on `scene`: draw a frame at `time` even when
|
||||
* nothing asked for one, and throw the error Cesium caught and raised on
|
||||
* `renderError` when the frame failed.
|
||||
* @param {object} scene
|
||||
* @param {object} [time] A Cesium JulianDate.
|
||||
*/
|
||||
export function renderNow(scene, time) {
|
||||
let failure = null;
|
||||
const off = scene.renderError?.addEventListener((_scene, error) => {
|
||||
failure ??= { error };
|
||||
});
|
||||
try {
|
||||
scene.forceRender(time);
|
||||
} finally {
|
||||
off?.();
|
||||
}
|
||||
if (failure) throw failure.error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} viewer A Cesium `Viewer` or `CesiumWidget`.
|
||||
* @returns {{port: import('../contract/frame').FramePort,
|
||||
@@ -239,7 +259,7 @@ export function createSceneFrame(viewer) {
|
||||
viewer.useDefaultRenderLoop = suspended ? false : ownLoop;
|
||||
if (!suspended && !gone()) scene.requestRender();
|
||||
},
|
||||
renderNow: () => scene.forceRender(viewer.clock?.currentTime),
|
||||
renderNow: () => renderNow(scene, viewer.clock?.currentTime),
|
||||
renderOnce({ timeoutMs } = {}) {
|
||||
if (gone()) return Promise.resolve();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import test from 'node:test';
|
||||
import { bindRenderer, findFrame, frameOf } from '../rendererOf.js';
|
||||
import './frame.js';
|
||||
import { renderNow } from './frame.js';
|
||||
|
||||
/** A viewer whose scene raises its phases when `tick` is called. */
|
||||
function fakeViewer() {
|
||||
@@ -189,3 +189,21 @@ test('a built frame port counts holds per reason, times out a wait, and settles
|
||||
await waiting;
|
||||
unbind();
|
||||
});
|
||||
|
||||
test('renderNow throws the error Cesium raises on renderError', () => {
|
||||
const listeners = new Set();
|
||||
const failure = new Error('worker failed');
|
||||
let fail = false;
|
||||
const scene = {
|
||||
renderError: {
|
||||
addEventListener: (cb) => (listeners.add(cb), () => listeners.delete(cb)),
|
||||
},
|
||||
forceRender() {
|
||||
if (fail) for (const cb of listeners) cb(scene, failure);
|
||||
},
|
||||
};
|
||||
renderNow(scene);
|
||||
fail = true;
|
||||
assert.throws(() => renderNow(scene), failure);
|
||||
assert.equal(listeners.size, 0, 'it stops listening either way');
|
||||
});
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* @module render/cesium/panelRendering
|
||||
* @description Keeping the Cesium viewer drawing in an inline panel whose
|
||||
* host stops animation frames (`src/app/embed.js`, embed mode). The
|
||||
* application scene hands it to the embed views (`src/app/scene.js`).
|
||||
*/
|
||||
|
||||
// A panel keeps drawing at about this rate when its host stops animation
|
||||
// frames; see keepPanelRendering.
|
||||
const PANEL_FRAME_MS = 33;
|
||||
const MISSED_FRAMES_MS = 250;
|
||||
|
||||
/** A render error's details, including the plain objects workers report. */
|
||||
function describeError(error) {
|
||||
if (error instanceof Error)
|
||||
return `${error.name}: ${error.message}\n${error.stack}`;
|
||||
try {
|
||||
return JSON.stringify(error, Object.getOwnPropertyNames(error ?? {}));
|
||||
} catch {
|
||||
return String(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep the globe drawing in an inline panel. Some hosts report a panel on
|
||||
* screen as hidden, which stops the browser's animation frames and with them
|
||||
* Cesium's render loop; while frames stop arriving, draw from a timer.
|
||||
* Returns a function that stops it.
|
||||
*/
|
||||
export function keepPanelRendering(
|
||||
viewer,
|
||||
{ windowRef = globalThis.window, now = () => performance.now() } = {},
|
||||
) {
|
||||
let lastFrame = now();
|
||||
let frameRequest = null;
|
||||
const onFrame = () => {
|
||||
lastFrame = now();
|
||||
frameRequest = windowRef.requestAnimationFrame(onFrame);
|
||||
};
|
||||
frameRequest = windowRef.requestAnimationFrame(onFrame);
|
||||
// Cesium stops drawing after a render error, and so does the timer.
|
||||
// Report the error in full: workers report plain objects, which Cesium
|
||||
// prints as [object Object].
|
||||
let failed = false;
|
||||
const removeErrorListener = viewer.scene?.renderError?.addEventListener(
|
||||
(_scene, error) => {
|
||||
failed = true;
|
||||
console.error(
|
||||
"[God's Eye View panel] render error:",
|
||||
describeError(error),
|
||||
);
|
||||
},
|
||||
);
|
||||
const timer = windowRef.setInterval(() => {
|
||||
if (
|
||||
failed ||
|
||||
now() - lastFrame < MISSED_FRAMES_MS ||
|
||||
viewer.isDestroyed?.()
|
||||
)
|
||||
return;
|
||||
viewer.resize();
|
||||
viewer.render();
|
||||
}, PANEL_FRAME_MS);
|
||||
return () => {
|
||||
windowRef.clearInterval(timer);
|
||||
windowRef.cancelAnimationFrame(frameRequest);
|
||||
removeErrorListener?.();
|
||||
};
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { keepPanelRendering } from './panelRendering.js';
|
||||
|
||||
test('a panel keeps drawing from a timer while animation frames stop', () => {
|
||||
let clock = 0;
|
||||
let tick = null;
|
||||
let frame = null;
|
||||
const windowRef = {
|
||||
requestAnimationFrame: (fn) => ((frame = fn), 1),
|
||||
cancelAnimationFrame: () => (frame = null),
|
||||
setInterval: (fn) => ((tick = fn), 1),
|
||||
clearInterval: () => (tick = null),
|
||||
};
|
||||
const drawn = [];
|
||||
const viewer = {
|
||||
resize: () => drawn.push('resize'),
|
||||
render: () => drawn.push('render'),
|
||||
};
|
||||
const stop = keepPanelRendering(viewer, { windowRef, now: () => clock });
|
||||
// Frames arrive: the render loop draws, so the timer does nothing.
|
||||
clock = 100;
|
||||
frame();
|
||||
tick();
|
||||
assert.deepEqual(drawn, []);
|
||||
// Frames stop, as in a panel its host reports hidden: the timer draws.
|
||||
clock = 400;
|
||||
tick();
|
||||
assert.deepEqual(drawn, ['resize', 'render']);
|
||||
stop();
|
||||
assert.equal(tick, null);
|
||||
assert.equal(frame, null);
|
||||
});
|
||||
|
||||
test('a panel reports a render error in full and stops drawing', () => {
|
||||
let listener = null;
|
||||
let tick = null;
|
||||
const windowRef = {
|
||||
requestAnimationFrame: () => 1,
|
||||
cancelAnimationFrame() {},
|
||||
setInterval: (fn) => ((tick = fn), 1),
|
||||
clearInterval() {},
|
||||
};
|
||||
const drawn = [];
|
||||
const viewer = {
|
||||
resize() {},
|
||||
render: () => drawn.push('render'),
|
||||
scene: {
|
||||
renderError: {
|
||||
addEventListener: (fn) => ((listener = fn), () => (listener = null)),
|
||||
},
|
||||
},
|
||||
};
|
||||
const logged = [];
|
||||
const original = console.error;
|
||||
console.error = (...args) => logged.push(args.join(' '));
|
||||
try {
|
||||
let clock = 0;
|
||||
const stop = keepPanelRendering(viewer, { windowRef, now: () => clock });
|
||||
listener(viewer.scene, { name: 'RuntimeError', message: 'worker failed' });
|
||||
assert.match(logged[0], /render error: .*"message":"worker failed"/);
|
||||
clock = 1000;
|
||||
tick();
|
||||
assert.deepEqual(drawn, []);
|
||||
stop();
|
||||
assert.equal(listener, null);
|
||||
} finally {
|
||||
console.error = original;
|
||||
}
|
||||
});
|
||||
@@ -19,7 +19,7 @@ import { createCesiumCredits } from './credits.js';
|
||||
import { createCesiumDraw } from './draw.js';
|
||||
import { GPU_ICON_CAPABILITIES } from './gpuIcons.js';
|
||||
import { createCesiumEffects } from './effects.js';
|
||||
import { willDraw } from './frame.js';
|
||||
import { renderNow, willDraw } from './frame.js';
|
||||
import { createCesiumGlobe } from './globe.js';
|
||||
import { createCesiumQuery, queryCapabilities } from './query.js';
|
||||
import { createCesiumQuality } from './quality.js';
|
||||
@@ -70,6 +70,10 @@ export function cesiumCapabilities(scene, only) {
|
||||
'fields',
|
||||
'followFrame',
|
||||
'cameraChangeThreshold',
|
||||
// The zoom-out guard reads the scene's own controller and frame events.
|
||||
...(scene?.screenSpaceCameraController && scene?.preRender
|
||||
? ['keepEarthFramed']
|
||||
: []),
|
||||
...GPU_ICON_CAPABILITIES,
|
||||
'styles',
|
||||
'bloom',
|
||||
@@ -294,8 +298,8 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
|
||||
widget.useDefaultRenderLoop = !suspended;
|
||||
if (!suspended) scene.requestRender();
|
||||
},
|
||||
// Draws even when nothing asked for a frame.
|
||||
renderNow: () => scene.forceRender(widget.clock.currentTime),
|
||||
// Draws even when nothing asked for a frame; throws when it fails.
|
||||
renderNow: () => renderNow(scene, widget.clock.currentTime),
|
||||
renderOnce: (options) => nextPostRender(options),
|
||||
setTargetFps(fps) {
|
||||
targetFps = fps > 0 ? fps : 0;
|
||||
|
||||
@@ -41,6 +41,7 @@ test('capabilities follow what the scene supports', () => {
|
||||
...draw,
|
||||
...effects,
|
||||
'pickPosition',
|
||||
'occlusionTest',
|
||||
]);
|
||||
assert.deepEqual(
|
||||
cesiumCapabilities({
|
||||
@@ -53,6 +54,7 @@ test('capabilities follow what the scene supports', () => {
|
||||
...effects,
|
||||
'globeVisibility',
|
||||
'pickPosition',
|
||||
'occlusionTest',
|
||||
'sampleHeight',
|
||||
'finestHeights',
|
||||
'rayCast',
|
||||
@@ -67,6 +69,14 @@ test('a caller can ask for fewer capabilities, never more', () => {
|
||||
'rayCast',
|
||||
]);
|
||||
assert.deepEqual(cesiumCapabilities({}, new Set(['sampleHeight'])), []);
|
||||
// The zoom-out guard needs the scene's own controller and frame events.
|
||||
assert.ok(
|
||||
cesiumCapabilities({
|
||||
screenSpaceCameraController: {},
|
||||
preRender: {},
|
||||
}).includes('keepEarthFramed'),
|
||||
);
|
||||
assert.ok(!cesiumCapabilities({ preRender: {} }).includes('keepEarthFramed'));
|
||||
});
|
||||
|
||||
test('a listener list keeps the listener rules', () => {
|
||||
|
||||
@@ -18,6 +18,7 @@ import { toCartesian } from './common.js';
|
||||
import { unboundDrawPart } from './draw.js';
|
||||
import { drawHitOf } from './drawHit.js';
|
||||
import { rememberPick } from './pickMemo.js';
|
||||
import { createSceneOcclusionTest } from './sceneOcclusionProbe.js';
|
||||
|
||||
/** The fewest things a bounded drill looks through (`QueryPort.drillPick`). */
|
||||
const DRILL_DEPTH = 16;
|
||||
@@ -31,7 +32,8 @@ const DRILL_DEPTH = 16;
|
||||
*/
|
||||
export function queryCapabilities(scene) {
|
||||
const found = [];
|
||||
if (scene.pickPositionSupported) found.push('pickPosition');
|
||||
// The occlusion test reads the same depth a depth pick does.
|
||||
if (scene.pickPositionSupported) found.push('pickPosition', 'occlusionTest');
|
||||
if (scene.sampleHeightSupported)
|
||||
found.push('sampleHeight', 'finestHeights', 'rayCast');
|
||||
return found;
|
||||
@@ -460,6 +462,9 @@ export function createCesiumQuery({
|
||||
: null;
|
||||
},
|
||||
};
|
||||
// Only where the scene keeps the depth it tests against.
|
||||
if (can('occlusionTest'))
|
||||
query.occlusionTest = () => createSceneOcclusionTest(scene);
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
@@ -805,13 +805,13 @@ export class SceneOcclusionProbe {
|
||||
}
|
||||
|
||||
/**
|
||||
* A probe bound to `viewer`'s scene: what the application's detection
|
||||
* overlay is handed (the `createOcclusionProbe` application hook). Its
|
||||
* `beginFrame(now)` reads the scene itself; the rest is the probe's.
|
||||
* @param {Cesium.Viewer} viewer
|
||||
* @returns {object}
|
||||
* The query port's `occlusionTest()` on `scene`: a probe whose
|
||||
* `beginFrame(now)` reads the scene itself (none once it is destroyed); the
|
||||
* rest is the probe's.
|
||||
* @param {object} scene A Cesium scene.
|
||||
* @returns {import('../contract/query').OcclusionTest}
|
||||
*/
|
||||
export function createViewerOcclusionProbe(viewer) {
|
||||
export function createSceneOcclusionTest(scene) {
|
||||
const probe = new SceneOcclusionProbe();
|
||||
return {
|
||||
get mode() {
|
||||
@@ -827,9 +827,9 @@ export function createViewerOcclusionProbe(viewer) {
|
||||
return probe.lastFrameTests;
|
||||
},
|
||||
beginFrame(now) {
|
||||
probe.beginFrame(viewer.isDestroyed?.() ? null : viewer.scene, now);
|
||||
probe.beginFrame(scene.isDestroyed?.() ? null : scene, now);
|
||||
},
|
||||
add: (contact, position) => probe.add(contact, position),
|
||||
add: (point, position) => probe.add(point, position),
|
||||
endFrame: () => probe.endFrame(),
|
||||
reset: () => probe.reset(),
|
||||
destroy: () => probe.destroy(),
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
/**
|
||||
* @module render/cesium/zoomOutGuard
|
||||
* @description Keeps the user's outward zooms bounded and the Earth framed
|
||||
* on the Cesium camera controller. It reads that controller's own input, so
|
||||
* it lives in the adapter; the application installs it through the scene's
|
||||
* viewer hooks (`application.js`).
|
||||
* on the Cesium camera controller: the camera port's
|
||||
* `controls.keepEarthFramed` (`cameraControls.js`). It reads that
|
||||
* controller's own input, so it lives in the adapter.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { governorRequestRender } from '../../renderGovernor.js';
|
||||
import { cameraFlightActive } from './internals.js';
|
||||
|
||||
/** Whole-Earth input limit; explicit camera destinations can go farther. */
|
||||
@@ -87,7 +86,7 @@ function readInput(aggregator, bindings) {
|
||||
export function installZoomOutGuard(
|
||||
viewer,
|
||||
{
|
||||
requestRender = governorRequestRender,
|
||||
requestRender = () => viewer?.scene?.requestRender?.(),
|
||||
subscribeCameraHandoff,
|
||||
createAggregator = (canvas) => new Cesium.CameraEventAggregator(canvas),
|
||||
} = {},
|
||||
|
||||
@@ -335,6 +335,13 @@ export function cameraChecks() {
|
||||
['ctrlWheel', 'wheel'],
|
||||
'zoomInputs are settable',
|
||||
);
|
||||
if (r.capabilities.has('keepEarthFramed')) {
|
||||
equal(c.keepEarthFramed, false, 'keepEarthFramed is off at first');
|
||||
c.keepEarthFramed = true;
|
||||
equal(c.keepEarthFramed, true, 'keepEarthFramed is settable');
|
||||
c.keepEarthFramed = false;
|
||||
equal(c.keepEarthFramed, false, 'keepEarthFramed turns off');
|
||||
}
|
||||
r.destroy();
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2899,6 +2899,33 @@ export function portChecks() {
|
||||
}
|
||||
},
|
||||
),
|
||||
check(
|
||||
'query.occlusionTest',
|
||||
'an occlusion test takes points and leaves the unanswered pending',
|
||||
async (h) => {
|
||||
const r = await h.create({ viewport: SCRIPT_VIEWPORT });
|
||||
try {
|
||||
const test = r.query.occlusionTest();
|
||||
ok(
|
||||
['async', 'sync', 'off'].includes(test.mode),
|
||||
'mode is async, sync or off',
|
||||
);
|
||||
ok(test.maxPerFrame > 0, 'takes at least one point a frame');
|
||||
const point = { pending: false, answered: false, lastHiddenAt: 0 };
|
||||
test.beginFrame(0);
|
||||
const taken = test.add(point, h.toEcef({ ...AUSTIN, height: 10 }));
|
||||
equal(typeof taken, 'boolean', 'add says whether it took the point');
|
||||
if (taken && test.mode === 'async')
|
||||
ok(point.pending || point.answered, 'a point taken is under test');
|
||||
test.endFrame();
|
||||
test.reset();
|
||||
test.destroy();
|
||||
} finally {
|
||||
r.destroy();
|
||||
}
|
||||
},
|
||||
{ capability: 'occlusionTest' },
|
||||
),
|
||||
|
||||
// --- Input -------------------------------------------------------------
|
||||
check(
|
||||
|
||||
Vendored
+10
@@ -201,6 +201,16 @@ export interface CameraControls {
|
||||
* the page.
|
||||
*/
|
||||
zoomInputs: Array<'wheel' | 'pinch' | 'rightDrag' | 'ctrlWheel'>;
|
||||
/**
|
||||
* `keepEarthFramed`: keep the whole Earth in reach and in frame as the
|
||||
* user zooms out. An outward user zoom goes no farther than about
|
||||
* 40,000 km, or than the height a camera command left the eye at when
|
||||
* that is higher (the user then zooms in from there), and from high up
|
||||
* it turns the view down toward the globe so the whole Earth stays in
|
||||
* frame. A camera command, a follow and a flight are not held to it, and
|
||||
* a camera command ends any turn under way. Off by default.
|
||||
*/
|
||||
keepEarthFramed?: boolean;
|
||||
}
|
||||
|
||||
export type CameraEvent =
|
||||
|
||||
Vendored
+4
@@ -170,6 +170,10 @@ export type Capability =
|
||||
| 'gpuTiming'
|
||||
/** Depth picks against tiles and terrain. */
|
||||
| 'pickPosition'
|
||||
/** Points tested against the frame's depth (`query.occlusionTest`). */
|
||||
| 'occlusionTest'
|
||||
/** Outward user zooms that keep the Earth framed (`controls.keepEarthFramed`). */
|
||||
| 'keepEarthFramed'
|
||||
/** Height sampling against tiles and terrain. */
|
||||
| 'sampleHeight'
|
||||
/** Ray casts against tiles and terrain. */
|
||||
|
||||
Vendored
+1
-1
@@ -72,7 +72,7 @@ export interface FramePort {
|
||||
diagnostics(): FrameDiagnostics;
|
||||
/** Stop ticking while the page is hidden; resume on `false`. */
|
||||
suspend(hidden: boolean): void;
|
||||
/** Draw a frame now, synchronously. */
|
||||
/** Draw a frame now, synchronously; throws when the frame fails to draw. */
|
||||
renderNow(): void;
|
||||
/** Resolves after the next frame has been drawn and presented. */
|
||||
renderOnce(options?: { timeoutMs?: number }): Promise<void>;
|
||||
|
||||
@@ -45,6 +45,8 @@ export const CAPABILITIES = Object.freeze([
|
||||
'globeVisibility',
|
||||
'followFrame',
|
||||
'cameraChangeThreshold',
|
||||
'occlusionTest',
|
||||
'keepEarthFramed',
|
||||
]);
|
||||
|
||||
/** @type {readonly import('./frame').FrameStep[]} */
|
||||
@@ -199,9 +201,10 @@ export const PORTS = deepFreeze({
|
||||
'matrices',
|
||||
),
|
||||
['followFrame', 'followFrame'],
|
||||
['controls.keepEarthFramed', 'keepEarthFramed'],
|
||||
]),
|
||||
query: Object.fromEntries(
|
||||
required(
|
||||
query: Object.fromEntries([
|
||||
...required(
|
||||
'pick',
|
||||
'drillPick',
|
||||
'pickPosition',
|
||||
@@ -216,7 +219,8 @@ export const PORTS = deepFreeze({
|
||||
'clampToSurface',
|
||||
'rayCast',
|
||||
),
|
||||
),
|
||||
['occlusionTest', 'occlusionTest'],
|
||||
]),
|
||||
input: Object.fromEntries(
|
||||
required(
|
||||
'on',
|
||||
|
||||
Vendored
+50
@@ -92,6 +92,12 @@ export interface QueryPort {
|
||||
projectMany(source: Float64Array, out: Float32Array): void;
|
||||
/** Hidden by the ellipsoid's horizon from the current eye. */
|
||||
isOccluded(position: Ecef): boolean;
|
||||
/**
|
||||
* `occlusionTest`: a test of many points against the depth of the frames
|
||||
* drawn, for overlays that leave out what something stands in front of.
|
||||
* Each call makes a new one; its owner destroys it.
|
||||
*/
|
||||
occlusionTest?(): OcclusionTest;
|
||||
/** `sampleHeight`: cached height now, or null when not loaded. */
|
||||
sampleHeightNow(point: LonLat, options?: HeightOptions): number | null;
|
||||
/**
|
||||
@@ -113,3 +119,47 @@ export interface QueryPort {
|
||||
options?: HeightOptions & { maxDistance?: number },
|
||||
): Promise<Ecef | null>;
|
||||
}
|
||||
|
||||
/**
|
||||
* One point under test (`OcclusionTest.add`): the test's owner keeps it and
|
||||
* reads the answer from it. The test sets `pending` when it takes the point,
|
||||
* and when the answer comes clears `pending`, sets `answered` and, when
|
||||
* something drawn stood in front of the point, sets `lastHiddenAt` to
|
||||
* `OcclusionTest`'s clock as of the frame it was tested against.
|
||||
*/
|
||||
export interface OcclusionPoint {
|
||||
pending: boolean;
|
||||
answered: boolean;
|
||||
lastHiddenAt: number;
|
||||
/** When the owner queued it, on the same clock. */
|
||||
queuedAt: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests points against the depth of the frames as drawn, without waiting
|
||||
* for the GPU: an answer may come a frame or two after its test.
|
||||
*/
|
||||
export interface OcclusionTest {
|
||||
/**
|
||||
* `'async'` while answers come a frame or two after their test, `'sync'`
|
||||
* while they come at once, `'off'` while nothing can be tested (no depth
|
||||
* to test against): every point is then to be taken as seen.
|
||||
*/
|
||||
readonly mode: 'async' | 'sync' | 'off';
|
||||
/** How many points it takes in one frame; Infinity when unbounded. */
|
||||
readonly maxPerFrame: number;
|
||||
/** Open a frame, collecting the answers that have come; `now` dates them. */
|
||||
beginFrame(now: number): void;
|
||||
/**
|
||||
* Test `point`, at `position`, against this frame: hidden when a surface
|
||||
* drawn stands in front of it by more than a small margin, which grows as
|
||||
* the view looks along the ground rather than down on it. False when it
|
||||
* cannot take one more this frame.
|
||||
*/
|
||||
add(point: OcclusionPoint, position: Ecef): boolean;
|
||||
/** Close the frame: start the tests taken. */
|
||||
endFrame(): void;
|
||||
/** Drop every test under way. */
|
||||
reset(): void;
|
||||
destroy(): void;
|
||||
}
|
||||
Vendored
+33
@@ -25,6 +25,39 @@ export interface RendererPlugin {
|
||||
/** Stable id, recorded with each session (`'cesium'`, ...). */
|
||||
id: string;
|
||||
create(options: CreateOptions): Promise<Renderer>;
|
||||
/**
|
||||
* What the plugin hands the application beside the contract for a
|
||||
* renderer it made, asked once, right after `create` resolves. Omitted:
|
||||
* none.
|
||||
*/
|
||||
applicationHooks?(renderer: Renderer): ApplicationHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* What only some renderers have and the application uses where given, does
|
||||
* application uses each where given and does without where not. None is a
|
||||
* do is in the ports.
|
||||
*/
|
||||
export interface ApplicationHooks {
|
||||
/**
|
||||
* The renderer's own map engine, which the map stacks switch through in
|
||||
* place of the globe port (`src/maps/engine.js`).
|
||||
*/
|
||||
mapEngine?: unknown;
|
||||
/**
|
||||
* True when the renderer shows its credits in a display of its own;
|
||||
* otherwise the application shows what the credits port lists.
|
||||
*/
|
||||
ownCreditDisplay?: boolean;
|
||||
/**
|
||||
* Drop the draw commands the renderer keeps for a while after it stops
|
||||
* drawing them; run after a layer turns off.
|
||||
*/
|
||||
trimStaleCommands?(): void;
|
||||
/** Whether an entity is one the renderer draws itself. */
|
||||
viewerDrawsEntity?(entity: unknown): boolean;
|
||||
/** Values QA scripts read from the page's debug handle. */
|
||||
qaHandles?: Readonly<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export interface CreateOptions {
|
||||
|
||||
@@ -75,7 +75,8 @@ const ONE_DEGREE = Math.PI / 180;
|
||||
* @param {(reason: string) => void} options.requestRender
|
||||
* @param {(error: Error) => void} options.report
|
||||
* @param {boolean} [options.thresholds] `cameraChangeThreshold`: each
|
||||
* `changed` listener's own threshold (default true).
|
||||
* `changed` listener's own threshold (default true). `framing`: whether
|
||||
* the controls have `keepEarthFramed` (default false).
|
||||
*/
|
||||
export function createStubCamera({
|
||||
viewport,
|
||||
@@ -85,6 +86,7 @@ export function createStubCamera({
|
||||
report,
|
||||
drawnPosition = () => null,
|
||||
thresholds = true,
|
||||
framing = false,
|
||||
}) {
|
||||
// Local frame values; world values are `frame` applied to them.
|
||||
let frame = IDENTITY;
|
||||
@@ -147,6 +149,9 @@ export function createStubCamera({
|
||||
pitchRange: [-Math.PI / 2, 0],
|
||||
zoomInputs: ['wheel', 'pinch', 'rightDrag'],
|
||||
};
|
||||
// The stub takes no user input: there is nothing to keep framed, and the
|
||||
// setting only reads back.
|
||||
if (framing) controls.keepEarthFramed = false;
|
||||
|
||||
function aspectRatio() {
|
||||
const { width, height } = viewport();
|
||||
|
||||
@@ -234,6 +234,7 @@ export function createStubRenderer(options = {}) {
|
||||
report,
|
||||
drawnPosition: (ref, aheadMs) => drawnPosition(ref, aheadMs),
|
||||
thresholds: capabilities.has('cameraChangeThreshold'),
|
||||
framing: capabilities.has('keepEarthFramed'),
|
||||
});
|
||||
camera.setViewRectangle(viewRectangle);
|
||||
if (capabilities.has('followFrame'))
|
||||
@@ -1064,6 +1065,28 @@ export function createStubRenderer(options = {}) {
|
||||
return rayEllipsoid(ray);
|
||||
},
|
||||
};
|
||||
// The stub's only surface is the ellipsoid: a point is hidden behind its
|
||||
// horizon, answered at once.
|
||||
if (capabilities.has('occlusionTest'))
|
||||
query.occlusionTest = () => {
|
||||
let now = 0;
|
||||
return {
|
||||
mode: 'sync',
|
||||
maxPerFrame: Number.POSITIVE_INFINITY,
|
||||
beginFrame(t) {
|
||||
now = t;
|
||||
},
|
||||
add(point, position) {
|
||||
point.pending = false;
|
||||
point.answered = true;
|
||||
if (isOccluded(position)) point.lastHiddenAt = now;
|
||||
return true;
|
||||
},
|
||||
endFrame() {},
|
||||
reset() {},
|
||||
destroy() {},
|
||||
};
|
||||
};
|
||||
|
||||
// --- Input -----------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in new issue
Block a user