Skip to content
Open
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 @@ -17,6 +17,7 @@
- Improved performance of `scene.drillPick`. [#12916](https://github.com/CesiumGS/cesium/pull/12916)
- Improved performance when removing primitives. [#3018](https://github.com/CesiumGS/cesium/pull/3018)
- Improved performance of terrain Quadtree handling of custom data [#12907](https://github.com/CesiumGS/cesium/pull/12907)
- Improved rendering performance when a 3D tileset is loaded [#12974](https://github.com/CesiumGS/cesium/pull/12974)

## 1.134.1 - 2025-10-10

Expand Down
12 changes: 7 additions & 5 deletions packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,13 @@ function Cesium3DTileset(options) {
this._addHeightCallbacks = [];

this._statistics = new Cesium3DTilesetStatistics();
this._statisticsLast = new Cesium3DTilesetStatistics();
this._statisticsLast = Cesium3DTilesetStatistics.snapshot(this._statistics);
this._statisticsPerPass = new Array(Cesium3DTilePass.NUMBER_OF_PASSES);

for (let i = 0; i < Cesium3DTilePass.NUMBER_OF_PASSES; ++i) {
this._statisticsPerPass[i] = new Cesium3DTilesetStatistics();
this._statisticsPerPass[i] = Cesium3DTilesetStatistics.snapshot(
this._statistics,
);
}

this._requestedTilesInFlight = [];
Expand Down Expand Up @@ -3285,7 +3287,7 @@ function raiseLoadProgressEvent(tileset, frameState) {
const lastNumberOfPendingRequest = statisticsLast.numberOfPendingRequests;
const lastNumberOfTilesProcessing = statisticsLast.numberOfTilesProcessing;

Cesium3DTilesetStatistics.clone(statistics, statisticsLast);
Cesium3DTilesetStatistics.snapshot(statistics, statisticsLast);

const progressChanged =
numberOfPendingRequests !== lastNumberOfPendingRequest ||
Expand Down Expand Up @@ -3371,7 +3373,7 @@ function detectModelMatrixChanged(tileset, frameState) {
* @private
* @param {Cesium3DTileset} tileset
* @param {FrameState} frameState
* @param {Cesium3DTilesetStatistics} passStatistics
* @param {Cesium3DTilesetStatisticsSnapshot} passStatistics
* @param {object} passOptions
* @returns {boolean}
*/
Expand Down Expand Up @@ -3408,7 +3410,7 @@ function update(tileset, frameState, passStatistics, passOptions) {
updateTiles(tileset, frameState, passOptions);

// Update pass statistics
Cesium3DTilesetStatistics.clone(statistics, passStatistics);
Cesium3DTilesetStatistics.snapshot(statistics, passStatistics);

if (passOptions.isRender) {
const credits = tileset._credits;
Expand Down
46 changes: 35 additions & 11 deletions packages/engine/Source/Scene/Cesium3DTilesetStatistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Model3DTileContent from "./Model/Model3DTileContent.js";
/**
* @private
*/
function Cesium3DTilesetStatistics() {
function Cesium3DTilesetStatisticsSnapshot() {
// Rendering statistics
this.selected = 0;
this.visited = 0;
Expand All @@ -30,10 +30,17 @@ function Cesium3DTilesetStatistics() {
// Memory statistics
this.geometryByteLength = 0;
this.texturesByteLength = 0;
this.texturesReferenceCounterById = {};
this.batchTableByteLength = 0; // batch textures and any binary metadata properties not otherwise accounted for
}

/**
* @private
*/
function Cesium3DTilesetStatistics() {
Cesium3DTilesetStatisticsSnapshot.call(this);
this.texturesReferenceCounterById = new Map();
}

Cesium3DTilesetStatistics.prototype.clear = function () {
this.selected = 0;
this.visited = 0;
Expand Down Expand Up @@ -100,12 +107,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);
}
}

Expand Down Expand Up @@ -146,13 +153,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);
}
}
}
Expand All @@ -166,7 +173,15 @@ Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) {
}
};

Cesium3DTilesetStatistics.clone = function (statistics, result) {
/**
* @param {Cesium3DTilesetStatistics} statistics
* @param {Cesium3DTilesetStatisticsSnapshot} result
* @returns {Cesium3DTilesetStatisticsSnapshot}
*/
Cesium3DTilesetStatistics.snapshot = function (
statistics,
result = new Cesium3DTilesetStatisticsSnapshot(),
) {
result.selected = statistics.selected;
result.visited = statistics.visited;
result.numberOfCommands = statistics.numberOfCommands;
Expand All @@ -187,9 +202,18 @@ Cesium3DTilesetStatistics.clone = function (statistics, result) {
statistics.numberOfTilesCulledWithChildrenUnion;
result.geometryByteLength = statistics.geometryByteLength;
result.texturesByteLength = statistics.texturesByteLength;
result.texturesReferenceCounterById = {
...statistics.texturesReferenceCounterById,
};
result.batchTableByteLength = statistics.batchTableByteLength;

return result;
};

Cesium3DTilesetStatistics.clone = function (
statistics,
result = new Cesium3DTilesetStatistics(),
) {
Cesium3DTilesetStatistics.snapshot(statistics, result);
result.texturesReferenceCounterById = new Map(
statistics.texturesReferenceCounterById,
);
};
export default Cesium3DTilesetStatistics;
Loading