diff --git a/src/layers/cctv/frames.js b/src/layers/cctv/frames.js index 8048b0e31a..7040d242ed 100644 --- a/src/layers/cctv/frames.js +++ b/src/layers/cctv/frames.js @@ -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, diff --git a/src/layers/cctv/frames.test.mjs b/src/layers/cctv/frames.test.mjs index 7beea0c03a..c297311af4 100644 --- a/src/layers/cctv/frames.test.mjs +++ b/src/layers/cctv/frames.test.mjs @@ -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(