Skip to content

Commit

Permalink
sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schuetz committed Feb 18, 2018
1 parent 6e168ef commit 06309cd
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"*.fs": "cpp"
},
"files.trimTrailingWhitespace": false,
"editor.fontSize": 16,
"editor.fontSize": 18,
"editor.autoIndent": false,
"editor.detectIndentation": false,
"editor.renderWhitespace": "all",
Expand Down
105 changes: 100 additions & 5 deletions src/PointCloudOctree.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
material.uniforms.octreeSize.value = this.pcoGeometry.boundingBox.getSize().x;
}

computeVisibilityTextureData (nodes) {
computeVisibilityTextureData(nodes, camera){

if(Potree.measureTimings) performance.mark("computeVisibilityTextureData-start");

Expand All @@ -281,6 +281,33 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
};
nodes.sort(sort);

// code sample taken from three.js src/math/Ray.js
let v1 = new THREE.Vector3();
let intersectSphereBack = (ray, sphere) => {
v1.subVectors( sphere.center, ray.origin );
let tca = v1.dot( ray.direction );
let d2 = v1.dot( v1 ) - tca * tca;
let radius2 = sphere.radius * sphere.radius;

if(d2 > radius2){
return null;
}

let thc = Math.sqrt( radius2 - d2 );

// t1 = second intersect point - exit point on back of sphere
let t1 = tca + thc;

if(t1 < 0 ){
return null;
}

return t1;
};

let lodRanges = new Map();
let leafNodeLodRanges = new Map();

for (let i = 0; i < nodes.length; i++) {
let node = nodes[i];

Expand All @@ -296,26 +323,94 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
}

let spacing = node.geometryNode.estimatedSpacing;
let parentSpacing = node.geometryNode.parent ? node.geometryNode.parent.estimatedSpacing : spacing;
let spacingFactor = parentSpacing / spacing;
let isLeafNode;

data[i * 4 + 0] = 0;
data[i * 4 + 1] = 0;
data[i * 4 + 2] = 0;
data[i * 4 + 3] = Math.max(0, Math.min(255, Math.round(spacingFactor)));
data[i * 4 + 3] = node.getLevel();
for (let j = 0; j < children.length; j++) {
let child = children[j];
let index = parseInt(child.geometryNode.name.substr(-1));
data[i * 4 + 0] += Math.pow(2, index);

if (j === 0) {
let vArrayIndex = nodes.indexOf(child, i);
//let vArrayIndex = child._index;

data[i * 4 + 1] = (vArrayIndex - i) >> 8;
data[i * 4 + 2] = (vArrayIndex - i) % 256;
}
}

{
let bBox = node.getBoundingBox().clone();
bBox.applyMatrix4(camera.matrixWorldInverse);

let bSphere = bBox.getBoundingSphere();

//let distance = center.distanceTo(camera.position);
let ray = new THREE.Ray(camera.position, camera.getWorldDirection());
let distance = intersectSphereBack(ray, 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){
let level = node.getLevel();
let distance = value.distance;
let i = value.i;


//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){
performance.mark("computeVisibilityTextureData-end");
Expand Down
1 change: 1 addition & 0 deletions src/PointCloudOctreeGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Potree.PointCloudOctreeGeometryNode = class PointCloudOctreeGeometryNode extends
callback(node, hbuffer);
} else {
console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + hurl);
Potree.numNodesLoading--;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/Potree.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){
let child = children[i];

let weight = 0;
if(camera.isPerspectiveCamera) {
if(camera.isPerspectiveCamera){
let sphere = child.getBoundingSphere();
let center = sphere.center;
//let distance = sphere.center.distanceTo(camObjPos);
Expand Down
50 changes: 43 additions & 7 deletions src/PotreeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,21 +802,36 @@ Potree.Renderer = class Renderer {
// }

//nodes = nodes.filter(node => {
// //return ["r",
// // "r3", "r1", "r0", "r2",
// // "r30", "r21", "r03", "r02", "r01", "r12", "r20", "r15", "r05", "r14", "r00", "r10", "r04"].includes(node.name)
// return ["r", "r6", "r66", "r664", "r6646", "r6644", "r64", "r646", "r4", "r66446", "r6642", "r660", "r62", "r2", "r6640"].includes(node.name)});

// return ["r",
// "r06", "r07"].includes(node.name)
//});
//nodes = nodes.filter(node => {
// return [
// //"r",
// "r6",
// "r2",
// "r4",
// "r64",
// "r66",
// "r62",
// "r664",
// "r646",
// "r660",
// "r6646",
// //"r6644",
// //"r6642",
// //"r6640",
// //"r66446",
// ].includes(node.name)});




if (material.pointSizeType >= 0) {
if (material.pointSizeType === Potree.PointSizeType.ADAPTIVE ||
material.pointColorType === Potree.PointColorType.LOD) {

let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
visibilityTextureData = octree.computeVisibilityTextureData(vnNodes);
visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);

const vnt = material.visibleNodesTexture;
const data = vnt.image.data;
Expand All @@ -826,6 +841,27 @@ Potree.Renderer = class Renderer {
}
}

//nodes = nodes.filter(node => {
// return [
// "r",
// "r6",
// "r2",
// "r4",
// "r64",
// "r66",
// "r62",
// "r664",
// "r646",
// "r660",

// "r6646",

// "r6644",
// "r6642",
// "r6640",
// "r66446",
// ].includes(node.name)});

{ // UPDATE SHADER AND TEXTURES
if (!this.shaders.has(material)) {
let [vs, fs] = [material.vertexShader, material.fragmentShader];
Expand Down
3 changes: 2 additions & 1 deletion src/materials/shaders/pointcloud.vs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ float getLOD(){
depth++;
}else{
// no more visible child nodes at this position
return depth;
return value.a * 255.0;
//return depth;
}

offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;
Expand Down

0 comments on commit 06309cd

Please sign in to comment.