mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Load the default renderer as the page starts, and follow through the camera port in tests
- The standalone page starts loading the default renderer as it starts (loadDefaultRenderer), so Cesium arrives beside the page's own setup, not after it; the scene takes a plugin or a promise of one. - Where a follow target's layer has no display position yet, the followed position is the target's own position at the frame port's scene time. - The globe engine's photoreal base that fails to come back is off again and the globe shown; a later switch tries again. The draped-imagery host asks the map engine whether the globe is shown where the renderer cannot say. The scene resizes the renderer with its container. - Cockpit and voice tests follow through the camera port (followEntity), not by setting the viewer's tracked entity; the fake frame port has a scene time.
This commit is contained in:
1 parent
6daf63d90c
commit
ae4fbb5053
21 files changed
+328
-87
No files matched your search
@@ -7,6 +7,8 @@ import { toDegrees } from '../geo/index.js';
|
||||
import { bindRenderer, rendererOf } from '../render/rendererOf.js';
|
||||
import { createCesiumCamera } from '../render/cesium/camera.js';
|
||||
import { fakeCesiumCredits } from './fakeCreditsPort.mjs';
|
||||
import { entityFollowTarget, followedOf } from '../data/followed.js';
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
const DEFAULT_POSE = Object.freeze({
|
||||
lon: 0,
|
||||
@@ -65,6 +67,62 @@ export function fakeCameraPort({ pose = {}, viewRectangle = null } = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cesium's entity tracking for a fake viewer without entities of its own:
|
||||
* the follow's helper entity is tracked here, at the fake clock's time.
|
||||
* @param {object} viewer
|
||||
*/
|
||||
function trackingWidget(viewer) {
|
||||
const entities = new Cesium.EntityCollection();
|
||||
const trackedEntityChanged = new Cesium.Event();
|
||||
let tracked;
|
||||
return {
|
||||
entities,
|
||||
clock: {
|
||||
get currentTime() {
|
||||
return viewer.clock?.currentTime ?? Cesium.JulianDate.now();
|
||||
},
|
||||
},
|
||||
get trackedEntity() {
|
||||
return tracked;
|
||||
},
|
||||
set trackedEntity(entity) {
|
||||
if (entity === tracked) return;
|
||||
tracked = entity;
|
||||
trackedEntityChanged.raiseEvent(entity);
|
||||
},
|
||||
trackedEntityChanged,
|
||||
isDestroyed: () => false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow `entity` through `viewer`'s camera port as a layer does
|
||||
* (`entityFollowTarget`), at its own position; null stops following.
|
||||
* Returns the target followed.
|
||||
* @param {object} viewer
|
||||
* @param {object|null} entity
|
||||
*/
|
||||
export function followEntity(viewer, entity) {
|
||||
const camera = rendererOf(viewer).camera;
|
||||
if (!entity) {
|
||||
camera.follow(null);
|
||||
return null;
|
||||
}
|
||||
const target = entityFollowTarget(entity, {
|
||||
position: () => entity.position?.getValue?.() ?? null,
|
||||
frame: 'enu',
|
||||
viewFrom: { x: 0, y: -1000, z: 500 },
|
||||
});
|
||||
camera.follow(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
/** The entity `viewer`'s camera follows (`followEntity`), if any. */
|
||||
export function followedEntity(viewer) {
|
||||
return followedOf(viewer)?.entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind to a fake viewer the Cesium renderer's own camera port over its
|
||||
* Cesium-shaped fake camera, for tests whose code is half on the port: the
|
||||
@@ -140,12 +198,18 @@ export function bindFakeCesiumCamera(viewer, ports = {}) {
|
||||
},
|
||||
requestRender: () => viewer.scene?.requestRender?.(),
|
||||
};
|
||||
// A fake with Cesium's entity tracking follows as the renderer does.
|
||||
// A fake with Cesium's entity tracking follows as the renderer does: on
|
||||
// its own entities, or, where it only answers `contains`, on a tracking
|
||||
// widget of its own over the fake's clock.
|
||||
const tracks = Boolean(viewer.trackedEntityChanged && viewer.entities);
|
||||
const widget =
|
||||
tracks && typeof viewer.entities.add !== 'function'
|
||||
? trackingWidget(viewer)
|
||||
: viewer;
|
||||
const real = createCesiumCamera({
|
||||
scene,
|
||||
camera,
|
||||
...(tracks ? { widget: viewer } : {}),
|
||||
...(tracks ? { widget } : {}),
|
||||
report: (error) => {
|
||||
throw error;
|
||||
},
|
||||
|
||||
@@ -180,6 +180,13 @@ export function fakeSceneFrame(viewer) {
|
||||
return {
|
||||
on: (phase, cb) => listen(viewer.scene?.[phase], cb),
|
||||
requestRender: () => viewer.scene?.requestRender?.(),
|
||||
/** Scene time: the fake clock's, else now. */
|
||||
time() {
|
||||
const time = viewer.clock?.currentTime;
|
||||
return time instanceof Cesium.JulianDate
|
||||
? Cesium.JulianDate.toDate(time).getTime()
|
||||
: Date.now();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user