diff --git a/CHANGES.md b/CHANGES.md index 5242f7b26ed9..0a21096a2ff2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,7 @@ - Fixed an edge case in `viewer.flyTo` when flying to a imagery layer with certain terrain providers. [#10937](https://github.com/CesiumGS/cesium/issues/10937) - Fixed a crash in terrain sampling if any points have an indefined position due to being outside the rectangle. [#10931](https://github.com/CesiumGS/cesium/pull/10931) - Fixed label background rendering. [#11040](https://github.com/CesiumGS/cesium/issues/11040) +- Fixed a bug where scale was not being applied to the top-level tileset geometric error. [#11047](https://github.com/CesiumGS/cesium/pull/11047) ### 1.101 - 2023-01-02 diff --git a/packages/engine/Source/Scene/Cesium3DTile.js b/packages/engine/Source/Scene/Cesium3DTile.js index e82df6f0faad..4495909c9411 100644 --- a/packages/engine/Source/Scene/Cesium3DTile.js +++ b/packages/engine/Source/Scene/Cesium3DTile.js @@ -146,7 +146,7 @@ function Cesium3DTile(tileset, baseResource, header, parent) { if (!defined(this._geometricError)) { this._geometricError = defined(parent) - ? parent.geometricError + ? parent._geometricError : tileset._geometricError; Cesium3DTile._deprecationWarning( "geometricErrorUndefined", @@ -874,7 +874,7 @@ Cesium3DTile.prototype.getScreenSpaceError = function ( const heightFraction = defaultValue(progressiveResolutionHeightFraction, 1.0); const parentGeometricError = defined(this.parent) ? this.parent.geometricError - : tileset._geometricError; + : tileset._scaledGeometricError; const geometricError = useParentGeometricError ? parentGeometricError : this.geometricError; @@ -1791,6 +1791,12 @@ Cesium3DTile.prototype.updateGeometricErrorScale = function () { const scale = Matrix4.getScale(this.computedTransform, scratchScale); const uniformScale = Cartesian3.maximumComponent(scale); this.geometricError = this._geometricError * uniformScale; + + if (!defined(this.parent)) { + // Update the tileset's geometric error + const tileset = this._tileset; + tileset._scaledGeometricError = tileset._geometricError * uniformScale; + } }; function applyDebugSettings(tile, tileset, frameState, passOptions) { diff --git a/packages/engine/Source/Scene/Cesium3DTileset.js b/packages/engine/Source/Scene/Cesium3DTileset.js index d3f8209d05c8..1c2a9327103b 100644 --- a/packages/engine/Source/Scene/Cesium3DTileset.js +++ b/packages/engine/Source/Scene/Cesium3DTileset.js @@ -167,6 +167,7 @@ function Cesium3DTileset(options) { this._asset = undefined; // Metadata for the entire tileset this._properties = undefined; // Metadata for per-model/point/etc properties this._geometricError = undefined; // Geometric error when the tree is not rendered at all + this._scaledGeometricError = undefined; // Geometric error scaled by root tile scale this._extensionsUsed = undefined; this._extensions = undefined; this._modelUpAxis = undefined; @@ -1007,6 +1008,11 @@ function Cesium3DTileset(options) { return; } + // Set these before loading the tileset since _geometricError + // and _scaledGeometricError get accessed during tile creation + that._geometricError = tilesetJson.geometricError; + that._scaledGeometricError = tilesetJson.geometricError; + that._root = that.loadTileset(resource, tilesetJson); // Handle legacy gltfUpAxis option @@ -1019,7 +1025,6 @@ function Cesium3DTileset(options) { const asset = tilesetJson.asset; that._asset = asset; that._properties = tilesetJson.properties; - that._geometricError = tilesetJson.geometricError; that._extensionsUsed = tilesetJson.extensionsUsed; that._extensions = tilesetJson.extensions; that._modelUpAxis = modelUpAxis; diff --git a/packages/engine/Specs/Scene/Cesium3DTileSpec.js b/packages/engine/Specs/Scene/Cesium3DTileSpec.js index fd71214cf0c4..f94cc124f135 100644 --- a/packages/engine/Specs/Scene/Cesium3DTileSpec.js +++ b/packages/engine/Specs/Scene/Cesium3DTileSpec.js @@ -123,6 +123,7 @@ describe( debugShowViewerRequestVolume: true, modelMatrix: Matrix4.IDENTITY, _geometricError: 2, + _scaledGeometricError: 2, _heatmap: new Cesium3DTilesetHeatmap(), }; @@ -672,6 +673,28 @@ describe( expect(tile2._priority).toBeGreaterThanOrEqual(foveatedDeferralPenalty); tile2._priorityDeferred = false; }); + + it("tile transform scales geometric error", function () { + const header = clone(tileWithContentBoundingSphere, true); + header.transform = Matrix4.pack( + Matrix4.fromUniformScale(2.0), + new Array(16) + ); + + const mockTilesetScaled = clone(mockTileset, true); + + const tile = new Cesium3DTile( + mockTilesetScaled, + "/some_url", + header, + undefined + ); + + expect(tile._geometricError).toBe(1); + expect(tile.geometricError).toBe(2); + expect(mockTilesetScaled._geometricError).toBe(2); + expect(mockTilesetScaled._scaledGeometricError).toBe(4); + }); }, "WebGL" );