diff --git a/CHANGES.md b/CHANGES.md index 7ecf92712eb..4f82087bb93 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ - Billboards using `imageSubRegion` now render as expected. [#12585](https://github.com/CesiumGS/cesium/issues/12585) - Improved scaling of SVGs in billboards [#13020](https://github.com/CesiumGS/cesium/issues/13020) - Fixed unexpected outline artifacts around billboards [#13038](https://github.com/CesiumGS/cesium/issues/13038) +- Improved rendering performance when a 3D tileset is loaded [#12974](https://github.com/CesiumGS/cesium/pull/12974) #### Additions :tada: diff --git a/packages/engine/Source/Scene/Cesium3DTileset.js b/packages/engine/Source/Scene/Cesium3DTileset.js index 4a72983b483..fd2b6483ed4 100644 --- a/packages/engine/Source/Scene/Cesium3DTileset.js +++ b/packages/engine/Source/Scene/Cesium3DTileset.js @@ -3285,7 +3285,7 @@ function raiseLoadProgressEvent(tileset, frameState) { const lastNumberOfPendingRequest = statisticsLast.numberOfPendingRequests; const lastNumberOfTilesProcessing = statisticsLast.numberOfTilesProcessing; - Cesium3DTilesetStatistics.clone(statistics, statisticsLast); + Cesium3DTilesetStatistics.shallowClone(statistics, statisticsLast); const progressChanged = numberOfPendingRequests !== lastNumberOfPendingRequest || @@ -3408,7 +3408,7 @@ function update(tileset, frameState, passStatistics, passOptions) { updateTiles(tileset, frameState, passOptions); // Update pass statistics - Cesium3DTilesetStatistics.clone(statistics, passStatistics); + Cesium3DTilesetStatistics.shallowClone(statistics, passStatistics); if (passOptions.isRender) { const credits = tileset._credits; diff --git a/packages/engine/Source/Scene/Cesium3DTilesetStatistics.js b/packages/engine/Source/Scene/Cesium3DTilesetStatistics.js index 17b094f33ad..5b38e92a736 100644 --- a/packages/engine/Source/Scene/Cesium3DTilesetStatistics.js +++ b/packages/engine/Source/Scene/Cesium3DTilesetStatistics.js @@ -1,3 +1,4 @@ +import Check from "../Core/Check.js"; import defined from "../Core/defined.js"; import Model3DTileContent from "./Model/Model3DTileContent.js"; @@ -30,7 +31,7 @@ function Cesium3DTilesetStatistics() { // Memory statistics this.geometryByteLength = 0; this.texturesByteLength = 0; - this.texturesReferenceCounterById = {}; + this.texturesReferenceCounterById = new Map(); this.batchTableByteLength = 0; // batch textures and any binary metadata properties not otherwise accounted for } @@ -59,6 +60,10 @@ Cesium3DTilesetStatistics.prototype.clear = function () { Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function ( content, ) { + Check.defined( + "texturesReferenceCounterById", + this.texturesReferenceCounterById, + ); this.numberOfFeaturesSelected += content.featuresLength; this.numberOfPointsSelected += content.pointsLength; this.numberOfTrianglesSelected += content.trianglesLength; @@ -84,6 +89,10 @@ Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function ( * @param {Cesium3DTileContent} content */ Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) { + Check.defined( + "texturesReferenceCounterById", + this.texturesReferenceCounterById, + ); this.numberOfFeaturesLoaded += content.featuresLength; this.numberOfPointsLoaded += content.pointsLength; this.geometryByteLength += content.geometryByteLength; @@ -100,12 +109,12 @@ Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) { const textureIds = content.getTextureIds(); for (const textureId of textureIds) { const referenceCounter = - this.texturesReferenceCounterById[textureId] ?? 0; + this.texturesReferenceCounterById.get(textureId) ?? 0; if (referenceCounter === 0) { const textureByteLength = content.getTextureByteLengthById(textureId); this.texturesByteLength += textureByteLength; } - this.texturesReferenceCounterById[textureId] = referenceCounter + 1; + this.texturesReferenceCounterById.set(textureId, referenceCounter + 1); } } @@ -130,6 +139,10 @@ Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) { * @param {Cesium3DTileContent} content */ Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) { + Check.defined( + "texturesReferenceCounterById", + this.texturesReferenceCounterById, + ); this.numberOfFeaturesLoaded -= content.featuresLength; this.numberOfPointsLoaded -= content.pointsLength; this.geometryByteLength -= content.geometryByteLength; @@ -146,13 +159,13 @@ Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) { // total textures byte length const textureIds = content.getTextureIds(); for (const textureId of textureIds) { - const referenceCounter = this.texturesReferenceCounterById[textureId]; + const referenceCounter = this.texturesReferenceCounterById.get(textureId); if (referenceCounter === 1) { - delete this.texturesReferenceCounterById[textureId]; + this.texturesReferenceCounterById.delete(textureId); const textureByteLength = content.getTextureByteLengthById(textureId); this.texturesByteLength -= textureByteLength; } else { - this.texturesReferenceCounterById[textureId] = referenceCounter - 1; + this.texturesReferenceCounterById.set(textureId, referenceCounter - 1); } } } @@ -166,7 +179,12 @@ Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) { } }; -Cesium3DTilesetStatistics.clone = function (statistics, result) { +/** + * Shallow copies the given statistics object into the resulting statistics object. + * + * The result cannot be used to increment/decrement load counts. + */ +Cesium3DTilesetStatistics.shallowClone = function (statistics, result) { result.selected = statistics.selected; result.visited = statistics.visited; result.numberOfCommands = statistics.numberOfCommands; @@ -187,9 +205,7 @@ Cesium3DTilesetStatistics.clone = function (statistics, result) { statistics.numberOfTilesCulledWithChildrenUnion; result.geometryByteLength = statistics.geometryByteLength; result.texturesByteLength = statistics.texturesByteLength; - result.texturesReferenceCounterById = { - ...statistics.texturesReferenceCounterById, - }; result.batchTableByteLength = statistics.batchTableByteLength; + result.texturesReferenceCounterById = undefined; }; export default Cesium3DTilesetStatistics;