Skip to content

Commit

Permalink
refactor(#9): change coordinate system to EPSG:4978
Browse files Browse the repository at this point in the history
Makes pointclouds follow the curvature of the globe.
  • Loading branch information
adriahso committed Oct 4, 2025
1 parent 4c69a04 commit d882dc2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
11 changes: 4 additions & 7 deletions src/cameraSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ export function syncCameras(potreeViewer, cesiumViewer) {
const pUp = new THREE.Vector3(0, 600, 0).applyMatrix4(camera.matrixWorld)
const pTarget = potreeViewer.scene.view.getPivot()

const toCes = (pos) => {
const xy = [pos.x, pos.y]
const height = pos.z
const deg = toMap.forward(xy)
return Cesium.Cartesian3.fromDegrees(...deg, height)
}

const toCes = (v) =>
new Cesium.Cartesian3(v.x, v.y, v.z)


const cPos = toCes(pPos)
const cUpTarget = toCes(pUp)
const cTarget = toCes(pTarget)
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function init() {
requestAnimationFrame(loop)
potreeViewer.update(potreeViewer.clock.getDelta(), timestamp)
potreeViewer.render()
if (window.toMap) syncCameras(potreeViewer, cesiumViewer)
syncCameras(potreeViewer, cesiumViewer)
cesiumViewer.render()
}

Expand Down
12 changes: 3 additions & 9 deletions src/potreeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ export async function createPotreeViewer(containerId, pointcloudUrl, settings) {
pc.material.activeAttributeName = 'elevation'
pc.material.gradient = Potree.Gradients['RAINBOW']

e.pointcloud.projection =
'+proj=utm +zone=32 +ellps=GRS80 +datum=ETRS89 +units=m +no_defs'
const pointcloudProjection = e.pointcloud.projection
const mapProjection = proj4.defs('WGS84')
window.toMap = proj4(pointcloudProjection, mapProjection)
window.toScene = proj4(mapProjection, pointcloudProjection)

e.pointcloud.projection = '+proj=geocent +datum=WGS84 +units=m +no_defs'
viewer.scene.view.setView(
[401603.85, 8860821.54, 1000000],
[401603.85, 8860821.54, -2650.47]
[1993552.900, 87954.487, 7134018.721],
[1184471.630, 63828.490, 6243615.520]
)

return viewer
Expand Down

0 comments on commit d882dc2

Please sign in to comment.