Skip to content

Commit

Permalink
refactor(potree1and2): change linked with multisource
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Sep 6, 2024
1 parent 4aa157e commit e8c9d54
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 58 deletions.
13 changes: 9 additions & 4 deletions examples/potree2_25d_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@
var lookAt = new itowns.THREE.Vector3();
var size = new itowns.THREE.Vector3();

potreeLayer.root.bbox.getSize(size);
potreeLayer.root.bbox.getCenter(lookAt);
const bboxes = potreeLayer.root.map(root => root.bbox);
let bbox = bboxes[0];
for (let i = 1; i < bboxes.length; i++) {
bbox = bbox.union(bboxes[i]);
}
bbox.getSize(size);
bbox.getCenter(lookAt);

debug.PointCloudDebug.initTools(view, potreeLayer, debugGui);

view.camera.camera3D.far = 2.0 * size.length();

ratio = size.x / size.z;
position = potreeLayer.root.bbox.min.clone().add(
position = bbox.min.clone().add(
size.multiply({ x: 0, y: 0, z: ratio * 0.5 }));
lookAt.z = potreeLayer.root.bbox.min.z;
lookAt.z = bbox.min.z;
placeCamera(position, lookAt);
controls.moveSpeed = size.length() / 3;

Expand Down
13 changes: 9 additions & 4 deletions examples/potree_25d_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@
var lookAt = new itowns.THREE.Vector3();
var size = new itowns.THREE.Vector3();

potreeLayer.root.bbox.getSize(size);
potreeLayer.root.bbox.getCenter(lookAt);
const bboxes = potreeLayer.root.map(root => root.bbox);
let bbox = bboxes[0];
for (let i = 1; i < bboxes.length; i++) {
bbox = bbox.union(bboxes[i]);
}
bbox.getSize(size);
bbox.getCenter(lookAt);

debug.PointCloudDebug.initTools(view, potreeLayer, debugGui);

view.camera3D.far = 2.0 * size.length();

ratio = size.x / size.z;
position = potreeLayer.root.bbox.min.clone().add(
position = bbox.min.clone().add(
size.multiply({ x: 0, y: 0, z: ratio * 0.5 }));
lookAt.z = potreeLayer.root.bbox.min.z;
lookAt.z = bbox.min.z;
placeCamera(position, lookAt);
controls.moveSpeed = size.length() / 3;

Expand Down
67 changes: 34 additions & 33 deletions src/Layer/Potree2Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,40 @@ class Potree2Layer extends PointCloudLayer {

const resolve = this.addInitializationStep();

this.source.whenReady.then((metadata) => {
this.scale = new THREE.Vector3(1, 1, 1);
this.metadata = metadata;
this.pointAttributes = parseAttributes(metadata.attributes);
this.spacing = metadata.spacing;

const normal = Array.isArray(this.pointAttributes.attributes) &&
this.pointAttributes.attributes.find(elem => elem.name.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal.name] = 1;
}

const min = new THREE.Vector3(...metadata.boundingBox.min);
const max = new THREE.Vector3(...metadata.boundingBox.max);
const boundingBox = new THREE.Box3(min, max);

const root = new Potree2Node(0, 0, this);

root.bbox = boundingBox;
root.boundingSphere = boundingBox.getBoundingSphere(new THREE.Sphere());

root.id = 'r';
root.depth = 0;
root.nodeType = 2;
root.hierarchyByteOffset = 0n;
root.hierarchyByteSize = BigInt(metadata.hierarchy.firstChunkSize);

root.byteOffset = 0;

this.root = root;

return this.root.loadOctree().then(resolve);
});
this.root = [];
this.source.whenReady
.then((metadata) => {
this.scale = new THREE.Vector3(1, 1, 1);
this.metadata = metadata;
this.pointAttributes = parseAttributes(metadata.attributes);
this.spacing = metadata.spacing;

const normal = Array.isArray(this.pointAttributes.attributes) &&
this.pointAttributes.attributes.find(elem => elem.name.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal.name] = 1;
}

const min = new THREE.Vector3(...metadata.boundingBox.min);
const max = new THREE.Vector3(...metadata.boundingBox.max);
const boundingBox = new THREE.Box3(min, max);

const root = new Potree2Node(0, 0, this);
root.bbox = boundingBox;
root.boundingSphere = boundingBox.getBoundingSphere(new THREE.Sphere());

root.id = 'r';
root.depth = 0;
root.nodeType = 2;
root.hierarchyByteOffset = 0n;
root.hierarchyByteSize = BigInt(metadata.hierarchy.firstChunkSize);

root.byteOffset = 0;

this.root.push(root);

return root.loadOctree().then(resolve);
});
}
}

Expand Down
34 changes: 19 additions & 15 deletions src/Layer/PotreeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,29 @@ class PotreeLayer extends PointCloudLayer {

const resolve = this.addInitializationStep();

this.source.whenReady.then((cloud) => {
this.scale = new THREE.Vector3().addScalar(cloud.scale);
this.spacing = cloud.spacing;
this.hierarchyStepSize = cloud.hierarchyStepSize;
this.root = [];
this.source.whenReady
.then((cloud) => {
this.scale = new THREE.Vector3().addScalar(cloud.scale);
this.spacing = cloud.spacing;
this.hierarchyStepSize = cloud.hierarchyStepSize;

const normal = Array.isArray(cloud.pointAttributes) &&
cloud.pointAttributes.find(elem => elem.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal] = 1;
}
const normal = Array.isArray(cloud.pointAttributes) &&
cloud.pointAttributes.find(elem => elem.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal] = 1;
}

this.supportsProgressiveDisplay = (this.source.extension === 'cin');
this.supportsProgressiveDisplay = (this.source.extension === 'cin');

this.root = new PotreeNode(0, 0, this);
this.root.bbox.min.set(cloud.boundingBox.lx, cloud.boundingBox.ly, cloud.boundingBox.lz);
this.root.bbox.max.set(cloud.boundingBox.ux, cloud.boundingBox.uy, cloud.boundingBox.uz);
const root = new PotreeNode(0, 0, this);
root.bbox.min.set(cloud.boundingBox.lx, cloud.boundingBox.ly, cloud.boundingBox.lz);
root.bbox.max.set(cloud.boundingBox.ux, cloud.boundingBox.uy, cloud.boundingBox.uz);

return this.root.loadOctree().then(resolve);
});
this.root.push(root);

return root.loadOctree().then(resolve);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/potree.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Potree', function () {
View.prototype.addLayer.call(viewer, potreeLayer)
.then((layer) => {
context.camera.camera3D.updateMatrixWorld();
assert.equal(layer.root.children.length, 6);
assert.equal(layer.root[0].children.length, 6);
layer.bboxes.visible = true;
done();
}).catch(done);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/potree2.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Potree2', function () {
View.prototype.addLayer.call(viewer, potreeLayer)
.then((layer) => {
context.camera.camera3D.updateMatrixWorld();
assert.equal(layer.root.children.length, 6);
assert.equal(layer.root[0].children.length, 6);
layer.bboxes.visible = true;
done();
}).catch(done);
Expand Down

0 comments on commit e8c9d54

Please sign in to comment.