From 8b1dfece505e19e842e5eda85a5b29ba5d3f1730 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Wed, 28 Jun 2017 20:40:00 +0200 Subject: [PATCH] add viewer.scene.estimateHeightAt --- src/viewer/viewer.js | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index ced6130d..140419a7 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -151,6 +151,58 @@ Potree.Scene = class extends THREE.EventDispatcher{ } + estimateHeightAt(position){ + + let height = null; + let fromSpacing = Infinity; + + + for(let pointcloud of this.pointclouds){ + + let pHeight = null; + let pFromSpacing = null; + + let lpos = position.clone().sub(pointcloud.position); + lpos.z = 0; + let ray = new THREE.Ray(lpos, new THREE.Vector3(0, 0, 1)); + + let stack = [pointcloud.root]; + while(stack.length > 0){ + let node = stack.pop(); + let box = node.getBoundingBox(); + + let inside = ray.intersectBox(box); + + if(!inside){ + continue; + } + + let h = node.geometryNode.mean.z + + pointcloud.position.z + + node.geometryNode.boundingBox.min.z; + + if(node.geometryNode.spacing <= pFromSpacing){ + pHeight = h; + pFromSpacing = node.geometryNode.spacing; + } + + for(let index of Object.keys(node.children)){ + let child = node.children[index]; + if(child.geometryNode){ + stack.push(node.children[index]); + } + } + } + + if(height === null || pFromSpacing < fromSpacing){ + height = pHeight; + fromSpacing = pFromSpacing; + } + } + + return height; + } + addPointCloud(pointcloud){ this.pointclouds.push(pointcloud); this.scenePointCloud.add(pointcloud);