diff --git a/examples/potree2_25d_map.html b/examples/potree2_25d_map.html
index 7ecb9533d9..32167d2e17 100644
--- a/examples/potree2_25d_map.html
+++ b/examples/potree2_25d_map.html
@@ -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;
diff --git a/examples/potree_25d_map.html b/examples/potree_25d_map.html
index 74efbfc34e..74ed0040d1 100644
--- a/examples/potree_25d_map.html
+++ b/examples/potree_25d_map.html
@@ -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;
diff --git a/src/Layer/Potree2Layer.js b/src/Layer/Potree2Layer.js
index b54258c5f3..84a11806a0 100644
--- a/src/Layer/Potree2Layer.js
+++ b/src/Layer/Potree2Layer.js
@@ -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);
+ });
}
}
diff --git a/src/Layer/PotreeLayer.js b/src/Layer/PotreeLayer.js
index 371c01f7a6..d8aa098989 100644
--- a/src/Layer/PotreeLayer.js
+++ b/src/Layer/PotreeLayer.js
@@ -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);
+ });
}
}
diff --git a/test/unit/potree.js b/test/unit/potree.js
index 2d1f3bee10..0413c3bfa0 100644
--- a/test/unit/potree.js
+++ b/test/unit/potree.js
@@ -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);
diff --git a/test/unit/potree2.js b/test/unit/potree2.js
index ca5ff065cd..3d342cfe40 100644
--- a/test/unit/potree2.js
+++ b/test/unit/potree2.js
@@ -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);