Read the eye's follow frame through the camera port and take share-follow off the Cesium list

The camera port gains an optional followFrame() (capability followFrame):
the frame the eye is placed in now, as a column-major 4x4 matrix to ECEF.
Once a follow has framed the camera it is the follow's own frame
(east-north-up, or the orbit frame an autodetect follow chose), under
lookAt the target's east-north-up frame, otherwise the identity. setView
places a world pose and keeps that frame. The Cesium port reads it from
camera.transform, only when the capability is on; the stub from its own
eye frame. A conformance check covers the world, lookAt and enu-follow
frames, the offset in it, and setView keeping it.

src/ui/shareFollow.js now reads the pose, the frame and the follow offset
through the camera and frame ports: a shared offset is re-expressed in the
follow's own frame as before, satellites included, and the eye is placed
with setView at exact heading, pitch and roll, so a near-vertical view
keeps its roll. placeFollowEye returns false on a camera that cannot say
its frame. offsetFromHeadingPitchRange moves to src/geo/frames.js, shared
with the stub.
This commit is contained in:
Sameh Khamis committed 2026-11-07 21:49:25 -08:00
1 parent b0ed9d7e90
commit 90e73f2ef2
19 files changed
+596 -143

No files matched your search

+63 -20
View File
@@ -123,12 +123,53 @@ function fakeViewer() {
const flush = () => new Promise((resolve) => setImmediate(resolve));
/** A frame port whose preUpdate is the fake viewer's scene's, read when subscribed. */
const preUpdateFrame = (viewer) => ({
on: (phase, cb) =>
phase === 'preUpdate'
? (viewer.scene?.preUpdate?.addEventListener(cb) ?? (() => {}))
: () => {},
});
/**
* A Cesium-shaped camera in `transform` with its eye at `position` there:
* a view set on it (a world pose) lands in that frame, and each eye it is
* given is recorded in `looks`, in the frame.
*/
function cameraInFrame(transform, position, looks) {
return {
transform,
position,
get positionWC() {
return Cesium.Matrix4.multiplyByPoint(
this.transform,
this.position,
new Cesium.Cartesian3(),
);
},
setView({ destination }) {
const local = Cesium.Matrix4.multiplyByPoint(
Cesium.Matrix4.inverseTransformation(
this.transform,
new Cesium.Matrix4(),
),
destination,
new Cesium.Cartesian3(),
);
looks.push(local);
this.position = local;
},
};
}
/** A ShareRestoration over a real ShareLinkManager, as the shell wires them. */
function openPage(t, href, { managerOptions = {}, tracking = null } = {}) {
const page = installPage(t, href);
const clock = installManualTimers(t);
const viewer = fakeViewer();
const restores = [];
// Bound first with a frame port: the share follow runs on its preUpdate.
bindFakeCesiumCamera(viewer, { frame: preUpdateFrame(viewer) });
const manager = new ShareLinkManager(bindFakeCesiumCamera(viewer), {
onRestore: async (state) => restores.push(state),
isNavigationCurrent: () => true,
@@ -272,15 +313,16 @@ test('a thing view turns its layer on, follows by id and frames the shared offse
},
isDestroyed: () => false,
});
Object.assign(page.viewer.camera, {
transform: Cesium.Transforms.eastNorthUpToFixedFrame(target),
// The app's own follow framing: south of the aircraft and above it.
position: new Cesium.Cartesian3(0, -4800, 3300),
lookAtTransform(transform, offset) {
looks.push(offset);
this.position = Cesium.Cartesian3.clone(offset);
},
});
// The app's own follow framing: south of the aircraft and above it.
const followCamera = cameraInFrame(
Cesium.Transforms.eastNorthUpToFixedFrame(target),
new Cesium.Cartesian3(0, -4800, 3300),
looks,
);
Object.defineProperties(
page.viewer.camera,
Object.getOwnPropertyDescriptors(followCamera),
);
entity = withEntityRecord({}, { trackedId: 'flights:a1b2c3', displayPosition: () => target });
const parsed = page.manager._parseShareCode(aircraftCode());
@@ -302,7 +344,8 @@ test('a thing view turns its layer on, follows by id and frames the shared offse
Math.abs(Cesium.Math.toDegrees(destination.longitude) - camera.lon) < 1e-3,
);
// Once followed, the camera takes the shared offset after the follow's
// own first frame.
// own first frame. (The restore's own views do not count.)
looks.length = 0;
assert.equal(listeners.length, 1);
listeners[0]();
assert.equal(looks.length, 0);
@@ -449,11 +492,11 @@ test('the followed entity is read in the share format, and its offset round-trip
new Cesium.Cartesian3(local.east, local.north, local.up),
new Cesium.Cartesian3(),
);
const viewer = {
const viewer = bindFakeCesiumCamera({
camera: { positionWC: cameraPosition },
clock: { currentTime: Cesium.JulianDate.now() },
trackedEntity: withEntityRecord({}, { trackedId: 'military:ae1234', displayPosition: () => target }),
};
});
const subject = readShareFollowSubject({ viewer, nowMs: NOW_MS });
assert.equal(subject.kind, 'military_aircraft');
assert.equal(subject.id, 'ae1234');
@@ -484,15 +527,13 @@ test('a shared offset on the far side swings round, never jumping through the en
},
},
trackedEntity: entity,
camera: {
transform: Cesium.Transforms.eastNorthUpToFixedFrame(target),
position: new Cesium.Cartesian3(0, -4800, 3300),
lookAtTransform(transform, offset) {
looks.push(Cesium.Cartesian3.clone(offset));
this.position = Cesium.Cartesian3.clone(offset);
},
},
camera: cameraInFrame(
Cesium.Transforms.eastNorthUpToFixedFrame(target),
new Cesium.Cartesian3(0, -4800, 3300),
looks,
),
};
bindFakeCesiumCamera(viewer, { frame: preUpdateFrame(viewer) });
// Looking south at the nose: the opposite side of the app's framing.
const offset = { range: 5800, heading: 180, pitch: -35 };
applyShareFollowOffset(viewer, followedOf(viewer), offset);
@@ -525,7 +566,9 @@ test('applying a follow offset gives up when the follow ends', () => {
},
},
trackedEntity: null,
camera: {},
};
bindFakeCesiumCamera(viewer, { frame: preUpdateFrame(viewer) });
applyShareFollowOffset(viewer, {}, OFFSET);
listeners[0]();
assert.equal(listeners.length, 0);