diff --git a/CHANGES.md b/CHANGES.md index 6af3ce06ff8b..cf3bf335d47a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Change Log +### 1.76 - 2020-12-01 + +##### Fixes :wrench: + +- Fixed an issue where tileset styles would be reapplied every frame when a tileset has a style and `tileset.preloadWhenHidden` is true and `tileset.show` is false. Also fixed a related issue where styles would be reapplied if the style being set is the same as the active style. [#9223](https://github.com/CesiumGS/cesium/pull/9223) + ### 1.75 - 2020-11-02 ##### Fixes :wrench: diff --git a/Source/Scene/Cesium3DTileStyleEngine.js b/Source/Scene/Cesium3DTileStyleEngine.js index a2af20e55390..54d001ce78ea 100644 --- a/Source/Scene/Cesium3DTileStyleEngine.js +++ b/Source/Scene/Cesium3DTileStyleEngine.js @@ -15,6 +15,9 @@ Object.defineProperties(Cesium3DTileStyleEngine.prototype, { return this._style; }, set: function (value) { + if (value === this._style) { + return; + } this._style = value; this._styleDirty = true; }, @@ -25,7 +28,11 @@ Cesium3DTileStyleEngine.prototype.makeDirty = function () { this._styleDirty = true; }; -Cesium3DTileStyleEngine.prototype.applyStyle = function (tileset, passOptions) { +Cesium3DTileStyleEngine.prototype.resetDirty = function () { + this._styleDirty = false; +}; + +Cesium3DTileStyleEngine.prototype.applyStyle = function (tileset) { if (!tileset.ready) { return; } @@ -36,11 +43,6 @@ Cesium3DTileStyleEngine.prototype.applyStyle = function (tileset, passOptions) { var styleDirty = this._styleDirty; - if (passOptions.isRender) { - // Don't reset until the render pass - this._styleDirty = false; - } - if (styleDirty) { // Increase "time", so the style is applied to all visible tiles ++this._lastStyleTime; diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index b03ca969c1fd..1ab1b8f91b7e 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -1892,6 +1892,7 @@ Cesium3DTileset.prototype.postPassesUpdate = function (frameState) { cancelOutOfViewRequests(this, frameState); raiseLoadProgressEvent(this, frameState); this._cache.unloadTiles(this, unloadTile); + this._styleEngine.resetDirty(); }; /** @@ -2173,7 +2174,7 @@ function updateTileDebugLabels(tileset, frameState) { } function updateTiles(tileset, frameState, passOptions) { - tileset._styleEngine.applyStyle(tileset, passOptions); + tileset._styleEngine.applyStyle(tileset); var isRender = passOptions.isRender; var statistics = tileset._statistics; diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index 9586e39c8165..2a95c2149d83 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -2866,6 +2866,40 @@ describe( ); }); + it("doesn't re-evaluate style during the next update", function () { + return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then( + function (tileset) { + tileset.show = false; + tileset.preloadWhenHidden = true; + tileset.style = new Cesium3DTileStyle({ color: 'color("red")' }); + scene.renderForSpecs(); + + var statistics = tileset._statisticsPerPass[Cesium3DTilePass.PRELOAD]; + expect(statistics.numberOfTilesStyled).toBe(1); + + scene.renderForSpecs(); + expect(statistics.numberOfTilesStyled).toBe(0); + } + ); + }); + + it("doesn't re-evaluate style if the style being set is the same as the active style", function () { + return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then( + function (tileset) { + var style = new Cesium3DTileStyle({ color: 'color("red")' }); + tileset.style = style; + scene.renderForSpecs(); + + var statistics = tileset._statisticsPerPass[Cesium3DTilePass.RENDER]; + expect(statistics.numberOfTilesStyled).toBe(1); + + tileset.style = style; + scene.renderForSpecs(); + expect(statistics.numberOfTilesStyled).toBe(0); + } + ); + }); + function testColorBlendMode(url) { return Cesium3DTilesTester.loadTileset(scene, url).then(function ( tileset