fix picking (by fixing computeVisibilityTextureData)

This commit is contained in:
m-schuetz 2018-06-20 18:08:40 +02:00
parent db16dd68a0
commit 2f2e9d14a1
2 changed files with 55 additions and 91 deletions

View File

@ -324,106 +324,34 @@ export class PointCloudOctree extends PointCloudTree {
let worldDir = new THREE.Vector3(); let worldDir = new THREE.Vector3();
let cameraRay = new THREE.Ray(camera.position, camera.getWorldDirection(worldDir)); let cameraRay = new THREE.Ray(camera.position, camera.getWorldDirection(worldDir));
for (let i = 0; i < nodes.length; i++) { let nodeMap = new Map();
let offsetsToChild = new Array(nodes.length).fill(Infinity);
for(let i = 0; i < nodes.length; i++){
let node = nodes[i]; let node = nodes[i];
nodeMap.set(node.name, node);
visibleNodeTextureOffsets.set(node, i); visibleNodeTextureOffsets.set(node, i);
data[i * 4 + 0] = 0; if(i > 0){
data[i * 4 + 1] = 0; let index = parseInt(node.name.slice(-1));
data[i * 4 + 2] = 0; let parentName = node.name.slice(0, -1);
//data[i * 4 + 3] = node.name.length - 1; let parent = nodeMap.get(parentName);
data[i * 4 + 3] = node.getLevel(); let parentOffset = visibleNodeTextureOffsets.get(parent);
for (let j = 0, k = 0; j < 8; j++) { let parentOffsetToChild = (i - parentOffset);
let child = node.children[j]; offsetsToChild[parentOffset] = Math.min(offsetsToChild[parentOffset], parentOffsetToChild);
if( child && child.constructor === PointCloudOctreeNode && child.sceneNode.visible){ data[parentOffset * 4 + 0] = data[parentOffset * 4 + 0] | (1 << index);
//children.push(child); data[parentOffset * 4 + 1] = (offsetsToChild[parentOffset] >> 8);
data[parentOffset * 4 + 2] = (offsetsToChild[parentOffset] % 256);
let index = parseInt(child.geometryNode.name.substr(-1));
data[i * 4 + 0] += Math.pow(2, index);
if (k === 0) {
let vArrayIndex = nodes.indexOf(child, i);
data[i * 4 + 1] = (vArrayIndex - i) >> 8;
data[i * 4 + 2] = (vArrayIndex - i) % 256;
}
k++;
}
} }
//{ data[i * 4 + 3] = node.name.length - 1;
// bBox.copy(node.getBoundingBox());
// bBox.getBoundingSphere(bSphere);
// bSphere.applyMatrix4(node.sceneNode.matrixWorld);
// bSphere.applyMatrix4(camera.matrixWorldInverse);
// let distance = intersectSphereBack(cameraRay, bSphere);
// let distance2 = bSphere.center.distanceTo(camera.position) + bSphere.radius;
// if(distance === null){
// distance = distance2;
// }
// distance = Math.max(distance, distance2);
// if(!lodRanges.has(node.getLevel())){
// lodRanges.set(node.getLevel(), distance);
// }else{
// let prevDistance = lodRanges.get(node.getLevel());
// let newDistance = Math.max(prevDistance, distance);
// lodRanges.set(node.getLevel(), newDistance);
// }
// if(!node.geometryNode.hasChildren){
// let value = {
// distance: distance,
// i: i
// };
// leafNodeLodRanges.set(node, value);
// }
//
//}
} }
//for(let [node, value] of leafNodeLodRanges){ var a = 10;
// let level = node.getLevel();
// let distance = value.distance;
// let i = value.i;
// if(level < 4){
// continue;
// }
// //if(node.name === "r6646"){
// // var a = 10;
// // a = 10 * 10;
// //}
// for(let [lod, range] of lodRanges){
// if(distance < range * 1.2){
// data[i * 4 + 3] = lod;
// }
// }
//}
//{
// if(!window.debugSizes){
// let msg = viewer.postMessage("abc");
// window.debugSizes = { msg: msg};
// }
// let msg = window.debugSizes.msg;
// let txt = ``;
// for(let entry of lodRanges){
// txt += `${entry[0]}: ${entry[1]}<br>`;
// }
// msg.setMessage(txt);
//}
if(Potree.measureTimings){ if(Potree.measureTimings){
performance.mark("computeVisibilityTextureData-end"); performance.mark("computeVisibilityTextureData-end");
@ -686,6 +614,8 @@ export class PointCloudOctree extends PointCloudTree {
let pickWindowSize = getVal(params.pickWindowSize, 17); let pickWindowSize = getVal(params.pickWindowSize, 17);
let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false); let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
pickWindowSize = 65;
let size = renderer.getSize(); let size = renderer.getSize();
let width = Math.ceil(getVal(params.width, size.width)); let width = Math.ceil(getVal(params.width, size.width));
@ -745,6 +675,8 @@ export class PointCloudOctree extends PointCloudTree {
this.updateMaterial(pickMaterial, nodes, camera, renderer); this.updateMaterial(pickMaterial, nodes, camera, renderer);
} }
//pickMaterial.pointColorType = Potree.PointColorType.LOD;
pickState.renderTarget.setSize(width, height); pickState.renderTarget.setSize(width, height);
let pixelPos = new THREE.Vector2(params.x, params.y); let pixelPos = new THREE.Vector2(params.x, params.y);
@ -830,8 +762,8 @@ export class PointCloudOctree extends PointCloudTree {
} }
} }
// DEBUG: show panel with pick image
//{ // open window with image //{
// let img = Utils.pixelsArrayToImage(buffer, w, h); // let img = Utils.pixelsArrayToImage(buffer, w, h);
// let screenshot = img.src; // let screenshot = img.src;
// //

View File

@ -1286,6 +1286,38 @@ export class Viewer extends EventDispatcher{
if (!this.freeze) { if (!this.freeze) {
let result = Potree.updatePointClouds(scene.pointclouds, camera, this.renderer); let result = Potree.updatePointClouds(scene.pointclouds, camera, this.renderer);
// DEBUG - ONLY DISPLAY NODES THAT INTERSECT MOUSE
//if(false){
// let renderer = viewer.renderer;
// let mouse = viewer.inputHandler.mouse;
// let nmouse = {
// x: (mouse.x / renderer.domElement.clientWidth) * 2 - 1,
// y: -(mouse.y / renderer.domElement.clientHeight) * 2 + 1
// };
// let pickParams = {};
// //if(params.pickClipped){
// // pickParams.pickClipped = params.pickClipped;
// //}
// pickParams.x = mouse.x;
// pickParams.y = renderer.domElement.clientHeight - mouse.y;
// let raycaster = new THREE.Raycaster();
// raycaster.setFromCamera(nmouse, camera);
// let ray = raycaster.ray;
// for(let pointcloud of scene.pointclouds){
// let nodes = pointcloud.nodesOnRay(pointcloud.visibleNodes, ray);
// pointcloud.visibleNodes = nodes;
// }
//}
if(result.lowestSpacing !== Infinity){ if(result.lowestSpacing !== Infinity){
let near = result.lowestSpacing * 10.0; let near = result.lowestSpacing * 10.0;
let far = -this.getBoundingBox().applyMatrix4(camera.matrixWorldInverse).min.z; let far = -this.getBoundingBox().applyMatrix4(camera.matrixWorldInverse).min.z;