From 58151097a9333c7aab1b947b9fa081e1172a41af Mon Sep 17 00:00:00 2001 From: AdrianSolberg Date: Wed, 5 Nov 2025 14:02:10 +0100 Subject: [PATCH] fix(#50): fix globe hiding for navigation controls --- src/cameraSync.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cameraSync.js b/src/cameraSync.js index cead992..4b40b76 100644 --- a/src/cameraSync.js +++ b/src/cameraSync.js @@ -58,11 +58,7 @@ export function syncCameras(potreeViewer, cesiumViewer) { } /** - * Determines whether the globe should be visible based on the camera position. - * - * Returns false if the camera is below the globe surface, if the pivot - * point would be blocked by the curvature of the Earth or if the camera - * is looking almost straight down at the pivot. + * Determines whether the globe should be visible based on the camera position and controls. * * @param cameraPos - The camera position in Cesium.Cartesian3 coordinates * @param pivot - The pivot point in Cesium.Cartesian3 coordinates @@ -99,7 +95,17 @@ function shouldShowGlobe(cameraPos, pivot, direction) { const targetNormal = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(pivot) const dotProduct = Math.abs(Cesium.Cartesian3.dot(direction, targetNormal)) - // If camera is "above" pivot on the axis, and not looking nearly straight down, the globe should be visible - // Otherwise, the globe should not be visible - return camProj >= pivotProj && dotProduct < 0.99 + // Get the camera's elevation based on ellipsoid + const cameraCarto = Cesium.Cartographic.fromCartesian(cameraPos, ellipsoid) + const elevation = cameraCarto.height + + // Determine globe visibility based on camera controls + if (window.potreeViewer.getControls() === window.potreeViewer.orbitControls) { + // If camera is "above" pivot on the axis, and not looking nearly straight down, the globe should be visible + // Otherwise, the globe should not be visible + return camProj >= pivotProj && dotProduct < 0.99 + } else { + // If the camera is inside the globe, or looking nearly straight down, hide the globe + return elevation > 0 && dotProduct < 0.99 + } }