fix(cctv): keep below-ellipsoid planes refreshing

This commit is contained in:
brandonabyrd committed 2026-11-18 17:13:06 -06:00
1 parent 9a3fc84935
commit b1b66e9717
2 files changed
+68 -3

No files matched your search

+29 -3
View File
@@ -45,6 +45,9 @@ export function fitToProjection(sourceW, sourceH) {
const _scratchPoints = [];
const _scratchSphere = new Cesium.BoundingSphere();
const _scratchCartographic = new Cesium.Cartographic();
// Close to the reference ellipsoid, it is not a reliable terrain horizon.
const LOW_VIEWER_HEIGHT_M = 1000;
export function createFrames({ state: layerState, services, parts, source }) {
/**
@@ -244,7 +247,8 @@ export function createFrames({ state: layerState, services, parts, source }) {
/**
* Whether a camera's monitor plane can be on screen: the mount, the far cap
* and its corners are bounded by one sphere that is tested against the view
* frustum, and at least one of those points must be above the horizon.
* frustum, and at least one of those points must be above the horizon when
* the reference ellipsoid is a reliable occluder for this view.
* Anything this cannot judge (no viewer, a 2D or Columbus scene, no geometry
* yet) counts as visible, so a missing input never blocks a picture.
* @param {Object} record - Camera record.
@@ -277,8 +281,30 @@ export function createFrames({ state: layerState, services, parts, source }) {
typeof camera.frustum?.computeCullingVolume !== 'function'
)
return true;
const occluder = horizonOccluder(camera);
if (!points.some((point) => occluder.isPointVisible(point))) return false;
// The reference ellipsoid can lie above the actual street. Near the
// surface its horizon would incorrectly hide nearby below-ellipsoid planes;
// let the frustum alone decide at low altitude or when height is unknown.
const height = Cesium.Cartographic.fromCartesian(
camera.positionWC,
Cesium.Ellipsoid.WGS84,
_scratchCartographic,
)?.height;
const pointsAboveEllipsoid = points.every((point) => {
const h = Cesium.Cartographic.fromCartesian(
point,
Cesium.Ellipsoid.WGS84,
_scratchCartographic,
)?.height;
return Number.isFinite(h) && h >= 0;
});
if (
Number.isFinite(height) &&
height >= LOW_VIEWER_HEIGHT_M &&
pointsAboveEllipsoid
) {
const occluder = horizonOccluder(camera);
if (!points.some((point) => occluder.isPointVisible(point))) return false;
}
const culling = camera.frustum.computeCullingVolume(
camera.positionWC,
camera.directionWC,
+39
View File
@@ -251,6 +251,45 @@ test('a plane behind the camera is not fetched, but a forced refresh is', () =>
assert.match(record.projection.image.src, /projTs=/);
});
test('a nearby plane below the ellipsoid still fetches for a low viewer', () => {
const record = planeRecord();
const mount = point(0, 0, -18);
const cap = point(0.00054, 0, -18);
const position = point(0.00135, 0, 4);
record.billboard.position = mount;
record.frustumPositions = { mount, capCenter: cap };
const direction = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.subtract(cap, position, new Cesium.Cartesian3()),
new Cesium.Cartesian3(),
);
const viewer = viewerAt(position, direction, Cesium.Cartesian3.UNIT_Z);
const sphere = Cesium.BoundingSphere.fromPoints([mount, cap]);
const culling = viewer.camera.frustum.computeCullingVolume(
position,
direction,
viewer.camera.upWC,
);
assert.notEqual(culling.computeVisibility(sphere), Cesium.Intersect.OUTSIDE);
const frames = framesFor(viewer);
assert.equal(frames.projectionInView(record), true);
frames.refreshProjectionImage(record);
assert.match(record.projection.image.src, /projTs=/);
// An above-threshold viewer still needs a conservative result when the
// entire plane itself is below the reference ellipsoid.
const high = point(0.00135, 0, 1200);
const highDirection = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.subtract(cap, high, new Cesium.Cartesian3()),
new Cesium.Cartesian3(),
);
assert.equal(
framesFor(
viewerAt(high, highDirection, Cesium.Cartesian3.UNIT_Z),
).projectionInView(record),
true,
);
});
test('a plane below the horizon is not fetched', () => {
const far = point(180, 0, 30000);
const viewer = viewerAt(