Give a viewer with no renderer an effects port, as cameras get

The renderer bridge builds and keeps an effects port over a viewer no
renderer is bound to, with a factory the Cesium effects module provides,
so visual settings on a caller's own viewer draw their styles, bloom
and sharpen as before and give the scene's bloom back when destroyed.
The application shell loads the factory; a test checks every export
that reaches the effects lookup loads it.
This commit is contained in:
Sameh Khamis committed 2026-11-06 16:33:40 -08:00
1 parent 6a7905fc49
commit 94b8b0bd30
8 files changed
+333 -64

No files matched your search

+35
View File
@@ -5,8 +5,10 @@ import {
cameraOf,
findCamera,
findCredits,
findEffects,
provideUnboundCamera,
provideUnboundCredits,
provideUnboundEffects,
rendererOf,
} from './rendererOf.js';
@@ -130,3 +132,36 @@ test('with no renderer bound, findCredits builds one port per scene and keeps it
assert.equal(findCredits(gone), null);
assert.equal(built.find((entry) => entry.port === port).disposed, 1);
});
test('with no renderer bound, findEffects builds one effects port per scene until a renderer is bound', (t) => {
t.after(() => provideUnboundEffects(null));
const built = [];
provideUnboundEffects((host) => {
if (!host.scene) return null;
const entry = { port: { id: built.length }, disposed: 0 };
entry.dispose = () => (entry.disposed += 1);
built.push(entry);
return entry;
});
const viewer = { scene: {} };
assert.equal(findEffects(viewer), built[0].port);
assert.equal(findEffects(viewer), built[0].port, 'kept, not rebuilt');
assert.equal(findEffects({}), null, 'nothing to build over');
assert.equal(findEffects(null), null);
const effects = { styles() {} };
const unbind = bindRenderer(viewer, { effects });
assert.equal(built[0].disposed, 1, 'the renderer supersedes the built port');
assert.equal(findEffects(viewer), effects);
unbind();
assert.equal(
findEffects(viewer),
built[1].port,
'unbound again: a fresh one',
);
let destroyed = false;
const gone = { scene: {}, isDestroyed: () => destroyed };
findEffects(gone);
destroyed = true;
assert.equal(findEffects(gone), null);
assert.equal(built[2].disposed, 1, 'let go with its scene');
});