Stories: reach the globe through the renderer's ports

Main now keeps Cesium behind the renderer contract, so Stories stops
reaching Cesium and the viewer directly.

- Camera: flights, the -60 degree story framing, cancel, the pose saved
  on open and put back on Close go through the camera port; a follow is
  released with stopFollowing.
- Pins: placed in the frame port's postRender from the query port's
  projection and horizon test, still written straight to each pin's
  transform on every drawn frame.
- Tile settling: a continuous-render hold until the globe port reports
  the base settled, for at most 10 s.
- Clock: Close and Back to Explore put back the page's world clock (live,
  or the time it showed, playing on), and leave a clock that is still
  where it should be alone.
- Card images: drawn from Esri World Imagery's own Web Mercator tiles
  while the Esri map stack is active, read as images; no Cesium imagery
  provider is touched.
- THUMBNAIL: the director hands captureStoryThumb the frame port and the
  renderer's canvas, so the scene document's module stays renderer-free.
- Credits: Stories places and keeps visible the application's credit
  line (#gev-credits) and its list as well as the renderer's own display.
- Tests fake the ports instead of a Cesium viewer, and cover pins per
  frame, the flights, the settling bound and the clock restore; the
  share link tests Stories added build their manager over a camera port.
This commit is contained in:
Manjunath committed 2026-11-16 20:43:53 +05:30
1 parent 9e9ce1db22
commit b8e622aac8
15 files changed
+695 -376

No files matched your search

+10 -4
View File
@@ -22,7 +22,12 @@ import { createToast } from '../ui/toast.js';
import { buildPlaybackQueue, playSceneQueue } from '../director/playback.js';
import { createScenePlaybackAdapter } from './playbackAdapter.js';
import { toRadians } from '../geo/vector.js';
import { cameraOf, canvasOf, findCamera } from '../render/rendererOf.js';
import {
cameraOf,
canvasOf,
findCamera,
findFrame,
} from '../render/rendererOf.js';
import {
SCENE_APPEND_RECIPES,
SCENE_RECIPES,
@@ -634,9 +639,10 @@ export class SceneDirector {
if (!scene || this._destroyed) return false;
let thumb;
try {
thumb = await captureStoryThumb(this.viewer, {
createCanvas: () => document.createElement('canvas'),
});
thumb = await captureStoryThumb(
{ frame: findFrame(this.viewer), canvas: canvasOf(this.viewer) },
{ createCanvas: () => document.createElement('canvas') },
);
} catch (error) {
console.warn('[Scenes] Could not capture the thumbnail:', error);
if (!this._destroyed)
+11 -9
View File
@@ -1,4 +1,5 @@
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import { rendererOf } from '../render/rendererOf.js';
import { readShellSource } from '../testSupport/readShellSource.mjs';
import { useStatusStore } from '../ui/stores/status.js';
import { applicationPinia } from '../ui/vueRuntime.js';
@@ -2564,16 +2565,17 @@ test('THUMBNAIL stores the frame read in postRender on the selected scene', asyn
'no scene, no capture',
);
director.selectShot('scene-1');
// The renderer's frame port: postRender runs on the frame it is asked for.
const listeners = new Set();
viewer.scene = {
canvas: { width: 640, height: 360 },
postRender: {
addEventListener(listener) {
listeners.add(listener);
return () => listeners.delete(listener);
},
const renderer = rendererOf(viewer);
viewer.canvas = { width: 640, height: 360 };
renderer.frame = {
on(phase, listener) {
assert.equal(phase, 'postRender');
listeners.add(listener);
return () => listeners.delete(listener);
},
requestRender: () => [...listeners].forEach((listener) => listener()),
requestRender: () => [...listeners].forEach((listener) => listener({})),
};
document.createElement = () => ({
getContext: () => ({ drawImage() {} }),
@@ -2583,7 +2585,7 @@ test('THUMBNAIL stores the frame read in postRender on the selected scene', asyn
assert.equal(director._project.scenes[0].storyThumb, THUMB);
assert.equal(director._presentation.status, 'Thumbnail captured');
viewer.scene = null;
delete renderer.frame;
assert.equal(await director.captureSceneThumb(), false);
assert.equal(
director._presentation.status,
+16 -11
View File
@@ -1,7 +1,8 @@
/**
* A scene's Stories card thumbnail: captured from the globe, stored as a data
* URL. The scene document validates with this module, so it reaches no
* browser globals; callers hand it the viewer and a canvas factory.
* browser globals and no renderer; callers hand it the renderer's frame port,
* its canvas and a canvas factory.
*/
export const STORY_THUMB_WIDTH = 320;
@@ -107,25 +108,29 @@ export function encodeStoryThumb(source, createCanvas) {
/**
* Capture the globe as it is drawn now. The WebGL canvas has no
* preserveDrawingBuffer, so it is read inside the next postRender, while the
* frame is still in the drawing buffer; a render is requested for it.
* @param {object} viewer Cesium viewer (its `scene`).
* preserveDrawingBuffer, so it is read inside the next postRender of the
* renderer's frame port, while the frame is still in the drawing buffer; a
* render is requested for it.
* @param {{frame?: import('../render/contract/frame').FramePort | null,
* canvas?: HTMLCanvasElement | null}} globe The renderer's frame port and
* the canvas it draws in, as the caller found them for its scene.
* @param {object} options
* @param {() => HTMLCanvasElement} options.createCanvas Makes an empty canvas.
* @param {number} [options.timeoutMs] Give up when no frame is drawn.
* @returns {Promise<string>} JPEG data URL.
*/
export function captureStoryThumb(viewer, { createCanvas, timeoutMs = 3000 }) {
const scene = viewer?.scene;
if (!scene?.postRender || !scene.canvas)
return Promise.reject(new Error('Globe not ready'));
export function captureStoryThumb(
{ frame, canvas } = {},
{ createCanvas, timeoutMs = 3000 },
) {
if (!frame || !canvas) return Promise.reject(new Error('Globe not ready'));
return new Promise((resolve, reject) => {
let timer = null;
const remove = scene.postRender.addEventListener(() => {
const remove = frame.on('postRender', () => {
remove();
clearTimeout(timer);
try {
resolve(encodeStoryThumb(scene.canvas, createCanvas));
resolve(encodeStoryThumb(canvas, createCanvas));
} catch (error) {
reject(error);
}
@@ -134,6 +139,6 @@ export function captureStoryThumb(viewer, { createCanvas, timeoutMs = 3000 }) {
remove();
reject(new Error('No frame was drawn'));
}, timeoutMs);
scene.requestRender?.();
frame.requestRender('story-thumb');
});
}
+28 -21
View File
@@ -100,48 +100,55 @@ test('encodeStoryThumb lowers the quality until the image fits, then gives up',
);
});
/** A Cesium scene double: postRender listeners run on requestRender. */
function fakeViewer({ draws = true } = {}) {
/**
* The renderer's frame port double, running postRender listeners on
* requestRender, and the canvas it draws in.
*/
function fakeGlobe({ draws = true } = {}) {
const listeners = new Set();
const scene = {
canvas: { width: 640, height: 360 },
const frame = {
renders: 0,
postRender: {
addEventListener(listener) {
listeners.add(listener);
return () => listeners.delete(listener);
},
reasons: [],
on(phase, listener) {
assert.equal(phase, 'postRender');
listeners.add(listener);
return () => listeners.delete(listener);
},
requestRender() {
scene.renders++;
if (draws) for (const listener of [...listeners]) listener();
requestRender(reason) {
frame.renders++;
frame.reasons.push(reason);
if (draws) for (const listener of [...listeners]) listener({});
},
listeners,
};
return { scene };
return { globe: { frame, canvas: { width: 640, height: 360 } }, frame };
}
test('captureStoryThumb reads the canvas inside the postRender it requested', async () => {
const viewer = fakeViewer();
const { globe, frame } = fakeGlobe();
const { create } = fakeCanvases();
const url = await captureStoryThumb(viewer, { createCanvas: create });
const url = await captureStoryThumb(globe, { createCanvas: create });
assert.equal(url, 'data:image/jpeg;base64,AAAA');
assert.equal(viewer.scene.renders, 1);
assert.equal(viewer.scene.listeners.size, 0, 'the listener is removed');
assert.equal(frame.renders, 1);
assert.deepEqual(frame.reasons, ['story-thumb']);
assert.equal(frame.listeners.size, 0, 'the listener is removed');
});
test('captureStoryThumb gives up when no frame is drawn or there is no globe', async () => {
const viewer = fakeViewer({ draws: false });
const { globe, frame } = fakeGlobe({ draws: false });
await assert.rejects(
captureStoryThumb(viewer, {
captureStoryThumb(globe, {
createCanvas: fakeCanvases().create,
timeoutMs: 1,
}),
/No frame was drawn/,
);
assert.equal(viewer.scene.listeners.size, 0);
assert.equal(frame.listeners.size, 0);
await assert.rejects(
captureStoryThumb({}, { createCanvas: fakeCanvases().create }),
captureStoryThumb(
{ frame: null, canvas: null },
{ createCanvas: fakeCanvases().create },
),
/Globe not ready/,
);
});