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

Remove deprecated ways of setting terrain exaggeration and a bugfix #9766

Merged
merged 6 commits into from
Aug 30, 2021
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### 1.85 - 2021-09-01

##### Breaking Changes :mega:

- Removed `Scene.terrainExaggeration` and `options.terrainExaggeration` for `CesiumWidget`, `Viewer`, and `Scene`, which were deprecated in CesiumJS 1.83. Use `Globe.terrainExaggeration` instead.

##### Additions :tada:

- Added `CloudCollection` and `CumulusCloud` for adding procedurally generated clouds to a scene. [#9737](https://github.com/CesiumGS/cesium/pull/9737)
Expand Down
57 changes: 57 additions & 0 deletions Source/Scene/GlobeSurfaceTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ GlobeSurfaceTile.processStateMachine = function (
frameState,
terrainProvider,
imageryLayerCollection,
quadtree,
vertexArraysToDestroy,
terrainOnly
) {
Expand All @@ -264,6 +265,7 @@ GlobeSurfaceTile.processStateMachine = function (
frameState,
terrainProvider,
imageryLayerCollection,
quadtree,
vertexArraysToDestroy
);
}
Expand Down Expand Up @@ -450,6 +452,56 @@ GlobeSurfaceTile.prototype.removeGeodeticSurfaceNormals = function (
toggleGeodeticSurfaceNormals(this, false, undefined, frameState);
};

GlobeSurfaceTile.prototype.updateExaggeration = function (
tile,
frameState,
quadtree
) {
var surfaceTile = this;
var mesh = surfaceTile.renderedMesh;
if (mesh === undefined) {
return;
}

// Check the tile's terrain encoding to see if it has been exaggerated yet
var exaggeration = frameState.terrainExaggeration;
var exaggerationRelativeHeight = frameState.terrainExaggerationRelativeHeight;
var hasExaggerationScale = exaggeration !== 1.0;

var encoding = mesh.encoding;
var encodingExaggerationScaleChanged = encoding.exaggeration !== exaggeration;
var encodingRelativeHeightChanged =
encoding.exaggerationRelativeHeight !== exaggerationRelativeHeight;

if (encodingExaggerationScaleChanged || encodingRelativeHeightChanged) {
// Turning exaggeration scale on/off requires adding or removing geodetic surface normals
// Relative height only translates, so it has no effect on normals
if (encodingExaggerationScaleChanged) {
if (hasExaggerationScale && !encoding.hasGeodeticSurfaceNormals) {
var ellipsoid = tile.tilingScheme.ellipsoid;
surfaceTile.addGeodeticSurfaceNormals(ellipsoid, frameState);
} else if (!hasExaggerationScale && encoding.hasGeodeticSurfaceNormals) {
surfaceTile.removeGeodeticSurfaceNormals(frameState);
}
}

encoding.exaggeration = exaggeration;
encoding.exaggerationRelativeHeight = exaggerationRelativeHeight;

// Notify the quadtree that this tile's height has changed
if (quadtree !== undefined) {
quadtree._tileToUpdateHeights.push(tile);
var customData = tile.customData;
var customDataLength = customData.length;
for (var i = 0; i < customDataLength; i++) {
// Restart the level so that a height update is triggered
var data = customData[i];
data.level = -1;
}
}
}
};

Comment on lines +455 to +504
Copy link
Contributor Author

@IanLilleyT IanLilleyT Aug 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly the same as before. It was moved because it's now called from GlobeSurfaceTile.processStateMachine

function prepareNewTile(tile, terrainProvider, imageryLayerCollection) {
var available = terrainProvider.getTileDataAvailable(
tile.x,
Expand Down Expand Up @@ -490,6 +542,7 @@ function processTerrainStateMachine(
frameState,
terrainProvider,
imageryLayerCollection,
quadtree,
vertexArraysToDestroy
) {
var surfaceTile = tile.data;
Expand All @@ -511,6 +564,7 @@ function processTerrainStateMachine(
frameState,
terrainProvider,
imageryLayerCollection,
quadtree,
vertexArraysToDestroy,
true
);
Expand Down Expand Up @@ -560,6 +614,9 @@ function processTerrainStateMachine(
tile.level,
vertexArraysToDestroy
);

// Update the tile's exaggeration in case the globe's exaggeration changed while the tile was being processed
surfaceTile.updateExaggeration(tile, frameState, quadtree);
}

if (
Expand Down
56 changes: 5 additions & 51 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ function GlobeSurfaceTileProvider(options) {

this._oldTerrainExaggeration = undefined;
this._oldTerrainExaggerationRelativeHeight = undefined;
this._processingTerrainExaggerationChange = false;
}

Object.defineProperties(GlobeSurfaceTileProvider.prototype, {
Expand Down Expand Up @@ -480,7 +479,6 @@ GlobeSurfaceTileProvider.prototype.endUpdate = function (frameState) {
var quadtree = this.quadtree;
var exaggeration = frameState.terrainExaggeration;
var exaggerationRelativeHeight = frameState.terrainExaggerationRelativeHeight;
var hasExaggerationScale = exaggeration !== 1.0;
var exaggerationChanged =
this._oldTerrainExaggeration !== exaggeration ||
this._oldTerrainExaggerationRelativeHeight !== exaggerationRelativeHeight;
Expand All @@ -489,59 +487,13 @@ GlobeSurfaceTileProvider.prototype.endUpdate = function (frameState) {
this._oldTerrainExaggeration = exaggeration;
this._oldTerrainExaggerationRelativeHeight = exaggerationRelativeHeight;

var processingChange =
exaggerationChanged || this._processingTerrainExaggerationChange;
var continueProcessing = false;

if (processingChange) {
quadtree.forEachRenderedTile(function (tile) {
if (exaggerationChanged) {
quadtree.forEachLoadedTile(function (tile) {
var surfaceTile = tile.data;
var mesh = surfaceTile.renderedMesh;
if (mesh !== undefined) {
// Check the tile's terrain encoding to see if it has been exaggerated yet
var encoding = mesh.encoding;
var encodingExaggerationScaleChanged =
encoding.exaggeration !== exaggeration;
var encodingRelativeHeightChanged =
encoding.exaggerationRelativeHeight !== exaggerationRelativeHeight;

if (encodingExaggerationScaleChanged || encodingRelativeHeightChanged) {
// Turning exaggeration scale on/off requires adding or removing geodetic surface normals
// Relative height only translates, so it has no effect on normals
if (encodingExaggerationScaleChanged) {
if (hasExaggerationScale && !encoding.hasGeodeticSurfaceNormals) {
var ellipsoid = tile.tilingScheme.ellipsoid;
surfaceTile.addGeodeticSurfaceNormals(ellipsoid, frameState);
} else if (
!hasExaggerationScale &&
encoding.hasGeodeticSurfaceNormals
) {
surfaceTile.removeGeodeticSurfaceNormals(frameState);
}
}

encoding.exaggeration = exaggeration;
encoding.exaggerationRelativeHeight = exaggerationRelativeHeight;

// Notify the quadtree that this tile's height has changed
quadtree._tileToUpdateHeights.push(tile);
var customData = tile.customData;
var customDataLength = customData.length;
for (var i = 0; i < customDataLength; i++) {
// Restart the level so that a height update is triggered
var data = customData[i];
data.level = -1;
}
}
} else {
// this tile may come into view at a later time so keep the loop active
continueProcessing = true;
}
surfaceTile.updateExaggeration(tile, frameState, quadtree);
});
}

this._processingTerrainExaggerationChange = continueProcessing;

// Add the tile render commands to the command list, sorted by texture count.
var tilesToRenderByTextureCount = this._tilesToRenderByTextureCount;
for (
Expand Down Expand Up @@ -650,6 +602,7 @@ GlobeSurfaceTileProvider.prototype.loadTile = function (frameState, tile) {
frameState,
this.terrainProvider,
this._imageryLayers,
this.quadtree,
this._vertexArraysToDestroy,
terrainOnly
);
Expand All @@ -671,6 +624,7 @@ GlobeSurfaceTileProvider.prototype.loadTile = function (frameState, tile) {
frameState,
this.terrainProvider,
this._imageryLayers,
this.quadtree,
this._vertexArraysToDestroy,
terrainOnly
);
Expand Down
37 changes: 0 additions & 37 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import createGuid from "../Core/createGuid.js";
import CullingVolume from "../Core/CullingVolume.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import deprecationWarning from "../Core/deprecationWarning.js";
import destroyObject from "../Core/destroyObject.js";
import DeveloperError from "../Core/DeveloperError.js";
import EllipsoidGeometry from "../Core/EllipsoidGeometry.js";
Expand Down Expand Up @@ -613,14 +612,6 @@ function Scene(options) {

this._brdfLutGenerator = new BrdfLutGenerator();

if (defined(options.terrainExaggeration)) {
deprecationWarning(
"terrainExaggeration-removed",
"terrainExaggeration is now a property of Globe"
);
}
this._terrainExaggeration = defaultValue(options.terrainExaggeration, 1.0);

this._performanceDisplay = undefined;
this._debugVolume = undefined;

Expand Down Expand Up @@ -1437,34 +1428,6 @@ Object.defineProperties(Scene.prototype, {
},
},

/**
* Gets or sets the scalar used to exaggerate the terrain.
* @memberof Scene.prototype
* @type {Number}
*/
terrainExaggeration: {
get: function () {
deprecationWarning(
"terrainExaggeration-removed",
"terrainExaggeration is now a property of Globe"
);
if (defined(this.globe)) {
return this.globe.terrainExaggeration;
}
return this._terrainExaggeration;
},
set: function (value) {
deprecationWarning(
"terrainExaggeration-removed",
"terrainExaggeration is now a property of Globe"
);
if (defined(this.globe)) {
this.globe.terrainExaggeration = value;
}
this._terrainExaggeration = value;
},
},

/**
* When <code>true</code>, splits the scene into two viewports with steroscopic views for the left and right eyes.
* Used for cardboard and WebVR.
Expand Down
9 changes: 0 additions & 9 deletions Source/Widgets/CesiumWidget/CesiumWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Cartesian3 from "../../Core/Cartesian3.js";
import Clock from "../../Core/Clock.js";
import defaultValue from "../../Core/defaultValue.js";
import defined from "../../Core/defined.js";
import deprecationWarning from "../../Core/deprecationWarning.js";
import destroyObject from "../../Core/destroyObject.js";
import DeveloperError from "../../Core/DeveloperError.js";
import Ellipsoid from "../../Core/Ellipsoid.js";
Expand Down Expand Up @@ -271,7 +270,6 @@ function CesiumWidget(container, options) {
mapProjection: options.mapProjection,
orderIndependentTranslucency: options.orderIndependentTranslucency,
scene3DOnly: defaultValue(options.scene3DOnly, false),
terrainExaggeration: options.terrainExaggeration,
shadows: options.shadows,
mapMode2D: options.mapMode2D,
requestRenderMode: options.requestRenderMode,
Expand All @@ -293,13 +291,6 @@ function CesiumWidget(container, options) {
if (!defined(globe)) {
globe = new Globe(ellipsoid);
}
if (defined(options.terrainExaggeration)) {
deprecationWarning(
"terrainExaggeration-removed",
"terrainExaggeration is now a property of Globe"
);
globe.terrainExaggeration = options.terrainExaggeration;
}
if (globe !== false) {
scene.globe = globe;
scene.globe.shadows = defaultValue(
Expand Down
1 change: 0 additions & 1 deletion Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
: bottomContainer,
creditViewport: options.creditViewport,
scene3DOnly: scene3DOnly,
terrainExaggeration: options.terrainExaggeration,
shadows: options.shadows,
terrainShadows: options.terrainShadows,
mapMode2D: options.mapMode2D,
Expand Down