Give a viewer of its own a frame port, and use it for the active fires layer

findFrame and frameOf find the bound renderer's frame port or, for a
caller's viewer with no renderer bound, one the Cesium adapter's factory
builds over it, as findQuery and findDraw do. Unlike the renderer's own,
it leaves the viewer's loop as its owner set it up: it listens to the
scene's phases, asks for frames, holds by asking again after each one
drawn, and maps suspend, the target rate and scene time onto the viewer.
Its preUpdate says whether the tick draws by the same test the renderer's
frame port makes, now shared by both.

The active fires layer's cards and LOD watcher take their query and frame
ports from findQuery and findFrame, in place of the layer's own copy of
projection, occlusion and preRender over the viewer's scene.
This commit is contained in:
Sameh Khamis committed 2026-11-06 22:25:07 -08:00
1 parent 784561a6ae
commit 4ed51930c2
12 files changed
+604 -132

No files matched your search

+2 -74
View File
@@ -18,14 +18,13 @@ import { listenerList, toCartesian, uncaught } from './common.js';
import { createCesiumCredits } from './credits.js';
import { createCesiumDraw } from './draw.js';
import { createCesiumEffects } from './effects.js';
import { willDraw } from './frame.js';
import { createCesiumGlobe } from './globe.js';
import { createCesiumQuery, queryCapabilities } from './query.js';
import { createCesiumQuality } from './quality.js';
import {
atEndOfTick,
billboardLoadError,
lastRenderTime,
lastSeenCamera,
onEngineWorkCompleted,
renderPending,
trimGlobeTiles,
@@ -34,52 +33,6 @@ import {
export { listenerList, toCartesian };
export { toColor, toImage } from './draw.js';
const scratchPosition0 = new Cesium.Cartesian3();
const scratchPosition1 = new Cesium.Cartesian3();
/** Cesium's own test (`View.js`) for whether the camera moved. */
function cameraEqual(camera0, camera1, epsilon) {
const maximumPositionComponent = Math.max(
Cesium.Cartesian3.maximumComponent(
Cesium.Cartesian3.abs(camera0.position, scratchPosition0),
),
Cesium.Cartesian3.maximumComponent(
Cesium.Cartesian3.abs(camera1.position, scratchPosition1),
),
);
const scalar = 1 / Math.max(1, maximumPositionComponent);
Cesium.Cartesian3.multiplyByScalar(
camera0.position,
scalar,
scratchPosition0,
);
Cesium.Cartesian3.multiplyByScalar(
camera1.position,
scalar,
scratchPosition1,
);
return (
Cesium.Cartesian3.equalsEpsilon(
scratchPosition0,
scratchPosition1,
epsilon,
) &&
Cesium.Cartesian3.equalsEpsilon(
camera0.direction,
camera1.direction,
epsilon,
) &&
Cesium.Cartesian3.equalsEpsilon(camera0.up, camera1.up, epsilon) &&
Cesium.Cartesian3.equalsEpsilon(camera0.right, camera1.right, epsilon) &&
Cesium.Matrix4.equalsEpsilon(
camera0.transform,
camera1.transform,
epsilon,
) &&
camera0.frustum.equalsEpsilon(camera1.frustum, epsilon)
);
}
/**
* What every Cesium globe does: photoreal tiles, terrain, imagery draped on
* tiles, the split and main-thread tile hooks.
@@ -192,7 +145,7 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
Object.defineProperty(t, 'rendering', {
enumerable: true,
configurable: true,
get: () => willDraw(time),
get: () => willDraw(scene, time),
});
liveTick = t;
}
@@ -224,31 +177,6 @@ export function createCesiumPorts(widget, { capabilities, credentials = {} }) {
scene.postRender.addEventListener(() => trimGlobeAfterDraw()),
];
/**
* Whether this tick draws: the test `Scene.render` makes just after
* `preUpdate`, made here so `preUpdate` can say. Not seen: a request made
* in between, by a `camera.moveEnd` listener (Cesium raises it there); no
* listener of the app's does that, and the answer is corrected at preRender.
*/
function willDraw(time) {
if (!scene.requestRenderMode || renderPending(scene)) return true;
if (scene.mode === Cesium.SceneMode.MORPHING) return true;
const seen = lastSeenCamera(scene);
if (!seen || !cameraEqual(camera, seen, Cesium.Math.EPSILON15)) return true;
const last = lastRenderTime(scene);
const max = scene.maximumRenderTimeChange;
return (
last !== undefined &&
max !== undefined &&
Math.abs(
Cesium.JulianDate.secondsDifference(
last,
time ?? Cesium.JulianDate.now(),
),
) > max
);
}
// Holds keep the loop drawing every frame; counted per reason.
const holds = new Map();
function applyHolds() {