Skip to content

Commit

Permalink
style(#9): prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
adriahso committed Sep 27, 2025
1 parent 1b3a9d8 commit 5767ca1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
47 changes: 28 additions & 19 deletions src/cameraSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export function syncCameras(potreeViewer, cesiumViewer) {
const cUp = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.subtract(cUpTarget, cPos, new Cesium.Cartesian3()),
new Cesium.Cartesian3()
)
)

// Hide globe when the camera is below the surface or blocked by the curvature of the Earth
const showGlobe = shouldShowGlobe(cPos, cTarget);
cesiumViewer.scene.globe.show = showGlobe;
cesiumViewer.scene.skyAtmosphere.show = showGlobe;
const showGlobe = shouldShowGlobe(cPos, cTarget)
cesiumViewer.scene.globe.show = showGlobe
cesiumViewer.scene.skyAtmosphere.show = showGlobe

cesiumViewer.camera.setView({
destination: cPos,
Expand All @@ -52,32 +52,41 @@ 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 or if the pivot
* point would be blocked by the curvature of the Earth. This is handled
* in a unified way by projecting the pivot to the globe surface and
* comparing the camera and pivot positions along the axis from the Earth's
* point would be blocked by the curvature of the Earth. This is handled
* in a unified way by projecting the pivot to the globe surface and
* comparing the camera and pivot positions along the axis from the Earth's
* center through the pivot.
*
*
* @param cameraPos - The camera position in Cesium Cartesian3 coordinates
* @param pivot - The pivot point in the point cloud (Cartesian3)
* @returns true if the globe should be visible, false if it should be hidden
*/
function shouldShowGlobe(cameraPos, pivot) {
const ellipsoid = Cesium.Ellipsoid.WGS84;
const earthCenter = Cesium.Cartesian3.ZERO;
const ellipsoid = Cesium.Ellipsoid.WGS84
const earthCenter = Cesium.Cartesian3.ZERO

// Get point on globe surface directly above the pivot
const carto = Cesium.Cartographic.fromCartesian(pivot);
const pivotSurface = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, 0, ellipsoid);
const carto = Cesium.Cartographic.fromCartesian(pivot)
const pivotSurface = Cesium.Cartesian3.fromRadians(
carto.longitude,
carto.latitude,
0,
ellipsoid
)

// Axis vector from Earth center through pivot
const axis = Cesium.Cartesian3.subtract(pivotSurface, earthCenter, new Cesium.Cartesian3());
Cesium.Cartesian3.normalize(axis, axis);
const axis = Cesium.Cartesian3.subtract(
pivotSurface,
earthCenter,
new Cesium.Cartesian3()
)
Cesium.Cartesian3.normalize(axis, axis)

// Project camera and pivot onto this axis
const camProj = Cesium.Cartesian3.dot(cameraPos, axis);
const pivotProj = Cesium.Cartesian3.dot(pivotSurface, axis);
const camProj = Cesium.Cartesian3.dot(cameraPos, axis)
const pivotProj = Cesium.Cartesian3.dot(pivotSurface, axis)

// If camera is "above" pivot on this axis, the globe should be visible
// If camera is "below" pivot on this axis, the globe should be not be visible
return camProj >= pivotProj;
}
return camProj >= pivotProj
}
18 changes: 9 additions & 9 deletions src/potreeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export async function createPotreeViewer(containerId, pointcloudUrl, settings) {
})

// Remove original scroll listener and add new one
const oc = viewer.orbitControls;
oc.removeEventListener('mousewheel', oc._listeners?.mousewheel?.[0]);
oc.addEventListener('mousewheel', clampScrollRadius);
const oc = viewer.orbitControls
oc.removeEventListener('mousewheel', oc._listeners?.mousewheel?.[0])
oc.addEventListener('mousewheel', clampScrollRadius)

if (settings.edl) viewer.setEDLEnabled(true)
if (settings.fov) viewer.setFOV(settings.fov)
Expand Down Expand Up @@ -50,12 +50,12 @@ export async function createPotreeViewer(containerId, pointcloudUrl, settings) {
}

function clampScrollRadius(e) {
let resolvedRadius = this.scene.view.radius + this.radiusDelta;
let newRadius = resolvedRadius - e.delta * resolvedRadius * 0.1;
let resolvedRadius = this.scene.view.radius + this.radiusDelta
let newRadius = resolvedRadius - e.delta * resolvedRadius * 0.1

const maxRadius = 10000000;
if (newRadius > maxRadius) newRadius = maxRadius;
const maxRadius = 10000000
if (newRadius > maxRadius) newRadius = maxRadius

this.radiusDelta = newRadius - this.scene.view.radius;
this.stopTweens();
this.radiusDelta = newRadius - this.scene.view.radius
this.stopTweens()
}

0 comments on commit 5767ca1

Please sign in to comment.