Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply root tile scale to tileset geometric error #11047

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Fixed an edge case in `viewer.flyTo` when flying to a imagery layer with certain terrain providers. [#10937](https:/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:/CesiumGS/cesium/pull/10931)
- Fixed label background rendering. [#11040](https:/CesiumGS/cesium/issues/11040)
- Fixed a bug where scale was not being applied to the top-level tileset geometric error. [#11047](https:/CesiumGS/cesium/pull/11047)

### 1.101 - 2023-01-02

Expand Down
10 changes: 8 additions & 2 deletions packages/engine/Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions packages/engine/Specs/Scene/Cesium3DTileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe(
debugShowViewerRequestVolume: true,
modelMatrix: Matrix4.IDENTITY,
_geometricError: 2,
_scaledGeometricError: 2,
_heatmap: new Cesium3DTilesetHeatmap(),
};

Expand Down Expand Up @@ -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"
);