From 55cae7d8062d9a259e254d579ca2c6258dd5f5e1 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 2 Nov 2020 23:27:39 -0500 Subject: [PATCH 1/2] Prevent style recompilation happening every frame when tileset sets preloadWhenHidden to true --- CHANGES.md | 6 +++++ Source/Scene/Cesium3DTileStyleEngine.js | 14 +++++----- Source/Scene/Cesium3DTileset.js | 3 ++- Specs/Scene/Cesium3DTilesetSpec.js | 34 +++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6af3ce06ff8b..657c647e29b3 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. Also fixed a related issue were styles would be reapplied if the style being set is the same as the active style. + ### 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 From 662821bb36e88b57fd41413c01a06c7a8a4aa9d1 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 3 Nov 2020 08:39:39 -0500 Subject: [PATCH 2/2] Fix CHANGES.md [skip ci] --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 657c647e29b3..cf3bf335d47a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ ##### Fixes :wrench: -- Fixed an issue where tileset styles would be reapplied every frame when a tileset has a style and `tileset.preloadWhenHidden` is true. Also fixed a related issue were styles would be reapplied if the style being set is the same as the active style. +- 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