diff --git a/src/Converter/convertToTile.js b/src/Converter/convertToTile.js index 6800a19557..255eeb9153 100644 --- a/src/Converter/convertToTile.js +++ b/src/Converter/convertToTile.js @@ -80,7 +80,7 @@ export default { setTileFromTiledLayer(tile, layer); if (parent) { - tile.setBBoxZ(parent.obb.z.min, parent.obb.z.max); + tile.setBBoxZ({ min: parent.obb.z.min, max: parent.obb.z.max }); } return tile; diff --git a/src/Core/3DTiles/C3DTBoundingVolume.js b/src/Core/3DTiles/C3DTBoundingVolume.js index 6802cba3ca..4150600167 100644 --- a/src/Core/3DTiles/C3DTBoundingVolume.js +++ b/src/Core/3DTiles/C3DTBoundingVolume.js @@ -54,7 +54,7 @@ class C3DTBoundingVolume { THREE.MathUtils.radToDeg(region[3])); const regionBox = new OBB(); regionBox.setFromExtent(extent); - regionBox.updateZ(region[4], region[5]); + regionBox.updateZ({ min: region[4], max: region[5] }); // at this point box.matrix = box.epsg4978_from_local, so // we transform it in parent_from_local by using parent's // epsg4978_from_local which from our point of view is diff --git a/src/Core/TileMesh.js b/src/Core/TileMesh.js index 290ce86b2c..b56d5f653f 100644 --- a/src/Core/TileMesh.js +++ b/src/Core/TileMesh.js @@ -49,23 +49,17 @@ class TileMesh extends THREE.Mesh { * If specified, update the min and max elevation of the OBB * and updates accordingly the bounding sphere and the geometric error * - * @param {?number} min - * @param {?number} max - * @param {?number} scale + * @param {Object} elevation + * @param {number} [elevation.min] + * @param {number} [elevation.max] + * @param {number} [elevation.scale] */ - setBBoxZ(min, max, scale) { - if (min == null && max == null) { - return; - } - // update bbox if min or max have changed by at least one decimal - // or if scale changed - if (min.toFixed(1) !== this.obb.z.min.toFixed(1) || max.toFixed(1) !== this.obb.z.max.toFixed(1) || scale != this.obb.z.scale) { - this.obb.updateZ(min, max, scale); - if (this.horizonCullingPointElevationScaled) { - this.horizonCullingPointElevationScaled.setLength(this.obb.z.delta + this.horizonCullingPoint.length()); - } - this.obb.box3D.getBoundingSphere(this.boundingSphere); + setBBoxZ(elevation) { + this.obb.updateZ(elevation); + if (this.horizonCullingPointElevationScaled) { + this.horizonCullingPointElevationScaled.setLength(this.obb.z.delta + this.horizonCullingPoint.length()); } + this.obb.box3D.getBoundingSphere(this.boundingSphere); } getExtentsByProjection(crs) { diff --git a/src/Layer/ElevationLayer.js b/src/Layer/ElevationLayer.js index 72f14c098a..408fa3c779 100644 --- a/src/Layer/ElevationLayer.js +++ b/src/Layer/ElevationLayer.js @@ -71,7 +71,9 @@ class ElevationLayer extends RasterLayer { node.material.addLayer(rasterElevationNode); node.material.setSequenceElevation(this.id); // bounding box initialisation - const updateBBox = () => node.setBBoxZ(rasterElevationNode.min, rasterElevationNode.max, this.scale); + const updateBBox = () => node.setBBoxZ({ + min: rasterElevationNode.min, max: rasterElevationNode.max, scale: this.scale, + }); updateBBox(); // listen elevation updating diff --git a/src/Process/LayeredMaterialNodeProcessing.js b/src/Process/LayeredMaterialNodeProcessing.js index 1b56088fa3..6ae8408709 100644 --- a/src/Process/LayeredMaterialNodeProcessing.js +++ b/src/Process/LayeredMaterialNodeProcessing.js @@ -240,7 +240,7 @@ export function removeLayeredMaterialNodeLayer(layerId) { if (node.material && node.material.removeLayer) { node.material.removeLayer(layerId); if (node.material.elevationLayerIds[0] == layerId) { - node.setBBoxZ(0, 0); + node.setBBoxZ({ min: 0, max: 0 }); } } if (node.layerUpdateState && node.layerUpdateState[layerId]) { diff --git a/src/Renderer/OBB.js b/src/Renderer/OBB.js index 53d38246a9..64e91cbfa3 100644 --- a/src/Renderer/OBB.js +++ b/src/Renderer/OBB.js @@ -62,22 +62,22 @@ class OBB extends THREE.Object3D { } /** - * Update z min and z max of oriented bounding box + * Update z min, z max and z scale of oriented bounding box * - * @param {number} min The minimum of oriented bounding box - * @param {number} max The maximum of oriented bounding box - * @param {number} scale + * @param {Object} [elevation={}] + * @param {number} [elevation.min] The minimum of oriented bounding box + * @param {number} [elevation.max] The maximum of oriented bounding box + * @param {number} [elevation.scale] The scale of oriented bounding box Z axis */ - updateZ(min, max, scale = this.z.scale) { - this.z = { min, max, scale, delta: Math.abs(max - min) * scale }; - this.box3D.min.z = this.natBox.min.z + min * scale; - this.box3D.max.z = this.natBox.max.z + max * scale; - } + updateZ(elevation = {}) { + this.z.min = elevation.min !== undefined && elevation.min !== null ? elevation.min : this.z.min; + this.z.max = elevation.max !== undefined && elevation.max !== null ? elevation.max : this.z.max; - updateScaleZ(scale) { - if (scale > 0) { - this.updateZ(this.z.min, this.z.max, scale); - } + this.z.scale = elevation.scale > 0 ? elevation.scale : this.z.scale; + this.z.delta = Math.abs(this.z.max - this.z.min) * this.z.scale; + + this.box3D.min.z = this.natBox.min.z + this.z.min * this.z.scale; + this.box3D.max.z = this.natBox.max.z + this.z.max * this.z.scale; } /** @@ -126,7 +126,7 @@ class OBB extends THREE.Object3D { obb.natBox.copy(geometry.boundingBox); this.copy(obb); - this.updateZ(minHeight, maxHeight); + this.updateZ({ min: minHeight, max: maxHeight }); this.position.copy(position); this.quaternion.copy(quaternion); this.updateMatrixWorld(true); diff --git a/test/unit/obb.js b/test/unit/obb.js index 8562ff5c59..b2428cd907 100644 --- a/test/unit/obb.js +++ b/test/unit/obb.js @@ -33,7 +33,7 @@ describe('OBB', function () { const o1 = new OBB(min, max); o1.z.min = -3; o1.z.max = 5; - o1.updateScaleZ(2); + o1.updateZ({ scale: 2 }); assert.equal(o1.z.min, -3); assert.equal(o1.z.max, 5); assert.equal(o1.z.scale, 2);