Follow on the Cesium camera port

The Cesium camera port follows a target with Cesium's own entity
tracking, on a hidden helper entity per target, and gains followed,
followFramed, followOffset and followChanged. A target with a minimum
range gets GEV's close-range rules, moved here from trackedCamera.js:
an exact first framing, no zoom coasting, a zoom floor, and an eye that
never crosses through the target. followChanged now fires only when
what is followed changes, on the stub too. No layer follows through the
port yet.
This commit is contained in:
Sameh Khamis committed 2026-11-06 11:49:09 -08:00
1 parent 21d23034ec
commit 6c215f93a9
13 files changed
+690 -66

No files matched your search

+1
View File
@@ -193,6 +193,7 @@ test('consumer build includes only infrastructure code and resolves assets under
'ctrlWheelZoom.js',
'dispatcher.js',
'events.js',
'follow.js',
'heights.js',
'infrastructure.js',
'infrastructureData.js',
+3 -54
View File
@@ -1,9 +1,9 @@
import * as Cesium from 'cesium';
import { readEntityRecord } from './entityRecords.js';
import { clampFollowEye, holdFollowZoom } from '../render/cesium/follow.js';
const MAX_FRAME_ATTEMPTS = 120;
const MIN_TRACKED_RANGE_M = 150;
const ZOOM_INERTIA_STATES = new WeakMap();
/**
* Preserve real-world model scale except when a very close tracked camera
@@ -65,31 +65,7 @@ export function trackedDisplayPositionForCamera(entity, time, result) {
}
function acquireStableTrackedZoom(controller, entity) {
if (!controller) return () => {};
let state = ZOOM_INERTIA_STATES.get(controller);
if (!state) {
state = {
originalInertiaZoom: controller.inertiaZoom,
originalMinimumZoomDistance: controller.minimumZoomDistance,
owners: new Set(),
};
ZOOM_INERTIA_STATES.set(controller, state);
}
state.owners.add(entity);
controller.inertiaZoom = 0;
controller.minimumZoomDistance = Math.max(
state.originalMinimumZoomDistance,
MIN_TRACKED_RANGE_M,
);
return () => {
const current = ZOOM_INERTIA_STATES.get(controller);
if (!current) return;
current.owners.delete(entity);
if (current.owners.size > 0) return;
controller.inertiaZoom = current.originalInertiaZoom;
controller.minimumZoomDistance = current.originalMinimumZoomDistance;
ZOOM_INERTIA_STATES.delete(controller);
};
return holdFollowZoom(controller, entity, MIN_TRACKED_RANGE_M);
}
/**
@@ -106,34 +82,7 @@ export function clampTrackedCameraPosition(
previousPosition,
minimumRangeM = MIN_TRACKED_RANGE_M,
) {
const crossedOrigin =
Cesium.Cartesian3.dot(camera.position, previousPosition) <= 0;
const forwardDistance = -Cesium.Cartesian3.dot(
camera.position,
camera.direction,
);
const rangeSquared = Cesium.Cartesian3.magnitudeSquared(camera.position);
if (crossedOrigin) {
Cesium.Cartesian3.normalize(previousPosition, camera.position);
Cesium.Cartesian3.multiplyByScalar(
camera.position,
minimumRangeM,
camera.position,
);
return true;
}
if (
forwardDistance < minimumRangeM ||
rangeSquared < minimumRangeM * minimumRangeM
) {
Cesium.Cartesian3.multiplyByScalar(
camera.direction,
-minimumRangeM,
camera.position,
);
return true;
}
return false;
return clampFollowEye(camera, previousPosition, minimumRangeM);
}
/**