Skip to content

Commit

Permalink
docs(#9): add some explanatory comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Solberg committed Oct 5, 2025
1 parent c3bfa54 commit 2b8f6b6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/potreeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ export async function createPotreeViewer(containerId, pointcloudUrl, settings) {
pc.material.gradient = Potree.Gradients['VIRIDIS']

e.pointcloud.projection = '+proj=geocent +datum=WGS84 +units=m +no_defs'

// Initialize camera position and target point (manually chosen)
viewer.scene.view.setView(
[1993552.9, 87954.487, 7134018.721],
[1184471.63, 63828.49, 6243615.52]
[1993552.9, 87954.487, 7134018.721], // Initial camera position
[1184471.63, 63828.49, 6243615.52] // Initial target point
)

return viewer
Expand Down Expand Up @@ -96,20 +98,30 @@ function overrideShaderForGradient(pc) {
/vec3 getElevation\(\)[\s\S]*?\}/,
`
vec3 getElevation(){
// Transform the vertex position into world coordinates
vec4 world = modelMatrix * vec4(position, 1.0);
// Compute distance from Earth's center and latitude
float radius = length(world.xyz);
float latitude = asin(world.z / radius);
const float a = 6378137.0;
const float b = 6356752.3;
const float a = 6378137.0; // Equatorial radius
const float b = 6356752.3; // Polar radius
// Compute distance from Earth's center to the surface at the given latitude
float cosLat = cos(latitude);
float sinLat = sin(latitude);
float numerator = (a*a * cosLat) * (a*a * cosLat) + (b*b * sinLat) * (b*b * sinLat);
float denominator = (a * cosLat) * (a * cosLat) + (b * sinLat) * (b * sinLat);
float radiusAtLatitude = sqrt(numerator / denominator);
float w = (radius - radiusAtLatitude - elevationRange.x) / (elevationRange.y - elevationRange.x);
// Compute depth below the ellipsoid (sea level)
float depth = radius - radiusAtLatitude;
// Normalize depth to a [0, 1] range for coloring
float w = (depth - elevationRange.x) / (elevationRange.y - elevationRange.x);
// Sample color from gradient texture based on normalized depth
return texture2D(gradient, vec2(w, 1.0-w)).rgb;
}
`
Expand Down

0 comments on commit 2b8f6b6

Please sign in to comment.