Skip to content

Commit 808f4e5

Browse files
committed
Handle expiring subtrees
1 parent 5fb5f91 commit 808f4e5

File tree

3 files changed

+35
-40
lines changed

3 files changed

+35
-40
lines changed

Source/Scene/Cesium3DTile.js

+22-30
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ define([
120120
*/
121121
this.computedTransform = computedTransform;
122122

123-
this._transformDirty = true;
124-
125123
this._boundingVolume = this.createBoundingVolume(header.boundingVolume, computedTransform);
126124
this._boundingVolume2D = undefined;
127125

@@ -422,20 +420,6 @@ define([
422420
}
423421
},
424422

425-
/**
426-
* Whether the computedTransform has changed this frame.
427-
*
428-
* @memberof Cesium3DTile.prototype
429-
*
430-
* @type {Boolean}
431-
* @readonly
432-
*/
433-
transformDirty : {
434-
get : function() {
435-
return this._transformDirty;
436-
}
437-
},
438-
439423
/**
440424
* @readonly
441425
* @private
@@ -550,15 +534,20 @@ define([
550534

551535
var scratchJulianDate = new JulianDate();
552536

553-
function updateExpiration(tile) {
554-
if (defined(tile.expireDate) && tile.contentReady && !tile.hasEmptyContent) {
537+
/**
538+
* Update whether the tile has expired.
539+
*
540+
* @private
541+
*/
542+
Cesium3DTile.prototype.updateExpiration = function() {
543+
if (defined(this.expireDate) && this.contentReady && !this.hasEmptyContent) {
555544
var now = JulianDate.now(scratchJulianDate);
556-
if (JulianDate.lessThan(tile.expireDate, now)) {
557-
tile._contentState = Cesium3DTileContentState.EXPIRED;
558-
tile._expiredContent = tile._content;
545+
if (JulianDate.lessThan(this.expireDate, now)) {
546+
this._contentState = Cesium3DTileContentState.EXPIRED;
547+
this._expiredContent = this._content;
559548
}
560549
}
561-
}
550+
};
562551

563552
function updateExpireDate(tile) {
564553
if (defined(tile.expireDuration)) {
@@ -620,9 +609,9 @@ define([
620609

621610
promise.then(function(arrayBuffer) {
622611
if (that.isDestroyed()) {
623-
return when.reject('tileset is destroyed');
612+
// Tile is unloaded before the content finishes loading
613+
return when.reject('tile is destroyed');
624614
}
625-
626615
var uint8Array = new Uint8Array(arrayBuffer);
627616
var magic = getMagic(uint8Array);
628617
var contentFactory = Cesium3DTileContentFactory[magic];
@@ -642,6 +631,11 @@ define([
642631
that._contentReadyToProcessPromise.resolve(content);
643632

644633
content.readyPromise.then(function(content) {
634+
if (that.isDestroyed()) {
635+
// Tile is unloaded before the content finishes processing
636+
that._content.destroy();
637+
return when.reject('tile is destroyed');
638+
}
645639
updateExpireDate(that);
646640
that._contentState = Cesium3DTileContentState.READY;
647641
that._contentReadyPromise.resolve(content);
@@ -883,9 +877,8 @@ define([
883877
Cesium3DTile.prototype.updateTransform = function(parentTransform) {
884878
parentTransform = defaultValue(parentTransform, Matrix4.IDENTITY);
885879
var computedTransform = Matrix4.multiply(parentTransform, this.transform, scratchTransform);
886-
var transformDirty = !Matrix4.equals(computedTransform, this.computedTransform);
887-
if (transformDirty) {
888-
this._transformDirty = true;
880+
var transformChanged = !Matrix4.equals(computedTransform, this.computedTransform);
881+
if (transformChanged) {
889882
Matrix4.clone(computedTransform, this.computedTransform);
890883

891884
// Update the bounding volumes
@@ -969,9 +962,7 @@ define([
969962
*/
970963
Cesium3DTile.prototype.update = function(tileset, frameState) {
971964
applyDebugSettings(this, tileset, frameState);
972-
updateExpiration(this);
973965
updateContent(this, tileset, frameState);
974-
this._transformDirty = false;
975966
};
976967

977968
var scratchCommandList = [];
@@ -1006,10 +997,11 @@ define([
1006997
*/
1007998
Cesium3DTile.prototype.destroy = function() {
1008999
this._content = this._content && this._content.destroy();
1009-
this._expiredContent = this._expiredContent && this._expiredContent.destroy();
1000+
this._expiredContent = this._expiredContent && !this._expiredContent.isDestroyed() && this._expiredContent.destroy();
10101001
this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy();
10111002
this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy();
10121003
this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
1004+
10131005
return destroyObject(this);
10141006
};
10151007

Source/Scene/Cesium3DTileset.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1255,18 +1255,13 @@ define([
12551255
}
12561256

12571257
var stats = tileset._statistics;
1258-
var expired = tile.contentExpired;
12591258
var requested = tile.requestContent();
12601259

12611260
if (!requested) {
12621261
++stats.numberOfAttemptedRequests;
12631262
return;
12641263
}
12651264

1266-
if (expired && tile.hasTilesetContent) {
1267-
unloadSubtree(tileset, tile);
1268-
}
1269-
12701265
++stats.numberOfPendingRequests;
12711266

12721267
var removeFunction = removeFromProcessingQueue(tileset, tile);
@@ -1591,6 +1586,7 @@ define([
15911586
tile._sse = getScreenSpaceError(tileset, tile.geometricError, tile, frameState);
15921587
tile.selected = false;
15931588
tile._finalResolution = false;
1589+
tile.updateExpiration();
15941590
touch(tileset, tile, outOfCore);
15951591
}
15961592

@@ -1623,7 +1619,12 @@ define([
16231619
var loadSiblings = tileset.loadSiblings;
16241620

16251621
if (tile.hasTilesetContent) {
1626-
updateAndPushChildren(tileset, tile, frameState, stack, loadSiblings, outOfCore);
1622+
if (tile.contentExpired) {
1623+
loadTile(tile);
1624+
unloadSubtree(tileset, tile);
1625+
} else {
1626+
updateAndPushChildren(tileset, tile, frameState, stack, loadSiblings, outOfCore);
1627+
}
16271628
} else {
16281629
if (tile.refine === Cesium3DTileRefine.ADD) {
16291630
loadAndAddToQueue(tileset, tile, finalQueue);
@@ -1982,7 +1983,7 @@ define([
19821983
}
19831984

19841985
function unloadTile(tileset, tile) {
1985-
if (!tile.hasRenderableContent) {
1986+
if (!tile.hasRenderableContent || !tile.contentReady) {
19861987
return;
19871988
}
19881989

@@ -1997,7 +1998,7 @@ define([
19971998
tile.unloadContent();
19981999
}
19992000

2000-
function unloadTiles(tileset, frameState) {
2001+
function unloadTiles(tileset) {
20012002
var trimTiles = tileset._trimTiles;
20022003
tileset._trimTiles = false;
20032004

@@ -2100,7 +2101,7 @@ define([
21002101
updateTiles(this, frameState);
21012102

21022103
if (outOfCore) {
2103-
unloadTiles(this, frameState);
2104+
unloadTiles(this);
21042105
}
21052106

21062107
// Events are raised (added to the afterRender queue) here since promises

Source/Scene/PointCloud3DTileContent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ define([
115115
this._quantizedVolumeScale = undefined;
116116
this._quantizedVolumeOffset = undefined;
117117

118+
this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY);
118119
this._mode = undefined;
119120

120121
/**
@@ -1138,7 +1139,8 @@ define([
11381139
* Part of the {@link Cesium3DTileContent} interface.
11391140
*/
11401141
PointCloud3DTileContent.prototype.update = function(tileset, frameState) {
1141-
var updateModelMatrix = this._tile.transformDirty || this._mode !== frameState.mode;
1142+
var modelMatrixChanged = !Matrix4.equals(this._modelMatrix, this._tile.computedTransform);
1143+
var updateModelMatrix = modelMatrixChanged || this._mode !== frameState.mode;
11421144
this._mode = frameState.mode;
11431145

11441146
if (!defined(this._drawCommand)) {

0 commit comments

Comments
 (0)