Skip to content

Commit

Permalink
fix(#50): fix globe hiding for navigation controls
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSolberg committed Nov 5, 2025
1 parent 5e34abd commit 5815109
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/cameraSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

0 comments on commit 5815109

Please sign in to comment.