Skip to content

Commit 5fb5f91

Browse files
committed
Keep expired content while new content loads
1 parent 6aaff1b commit 5fb5f91

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

Source/Scene/Cesium3DTile.js

+34-4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ define([
212212
this._contentState = contentState;
213213
this._contentReadyToProcessPromise = undefined;
214214
this._contentReadyPromise = undefined;
215+
this._expiredContent = undefined;
215216

216217
this._requestServer = requestServer;
217218

@@ -445,6 +446,22 @@ define([
445446
}
446447
},
447448

449+
/**
450+
* Determines if the tile has available content to render. <code>true</code> if the tile's
451+
* content is ready or if it has expired content that renders while new content loads; otherwise,
452+
* <code>false</code>.
453+
*
454+
* @memberof Cesium3DTile.prototype
455+
*
456+
* @type {Boolean}
457+
* @readonly
458+
*/
459+
contentAvailable : {
460+
get : function() {
461+
return this.contentReady || defined(this._expiredContent);
462+
}
463+
},
464+
448465
/**
449466
* Determines if the tile is ready to render. <code>true</code> if the tile
450467
* is ready to render; otherwise, <code>false</code>.
@@ -538,6 +555,7 @@ define([
538555
var now = JulianDate.now(scratchJulianDate);
539556
if (JulianDate.lessThan(tile.expireDate, now)) {
540557
tile._contentState = Cesium3DTileContentState.EXPIRED;
558+
tile._expiredContent = tile._content;
541559
}
542560
}
543561
}
@@ -605,9 +623,6 @@ define([
605623
return when.reject('tileset is destroyed');
606624
}
607625

608-
// Destroy expired content to make way for the new content
609-
that._content = that._content && that._content.destroy();
610-
611626
var uint8Array = new Uint8Array(arrayBuffer);
612627
var magic = getMagic(uint8Array);
613628
var contentFactory = Cesium3DTileContentFactory[magic];
@@ -933,6 +948,20 @@ define([
933948
}
934949
}
935950

951+
function updateContent(tile, tileset, frameState) {
952+
var content = tile._content;
953+
var expiredContent = tile._expiredContent;
954+
955+
if (defined(expiredContent) && !tile.contentReady) {
956+
// Render the expired content while the content loads
957+
expiredContent.update(tileset, frameState);
958+
return;
959+
}
960+
961+
tile._expiredContent = tile._expiredContent && tile._expiredContent.destroy();
962+
content.update(tileset, frameState);
963+
}
964+
936965
/**
937966
* Get the draw commands needed to render this tile.
938967
*
@@ -941,7 +970,7 @@ define([
941970
Cesium3DTile.prototype.update = function(tileset, frameState) {
942971
applyDebugSettings(this, tileset, frameState);
943972
updateExpiration(this);
944-
this._content.update(tileset, frameState);
973+
updateContent(this, tileset, frameState);
945974
this._transformDirty = false;
946975
};
947976

@@ -977,6 +1006,7 @@ define([
9771006
*/
9781007
Cesium3DTile.prototype.destroy = function() {
9791008
this._content = this._content && this._content.destroy();
1009+
this._expiredContent = this._expiredContent && this._expiredContent.destroy();
9801010
this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy();
9811011
this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy();
9821012
this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();

Source/Scene/Cesium3DTileset.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ define([
12771277
function selectTile(tileset, tile, frameState) {
12781278
// There may also be a tight box around just the tile's contents, e.g., for a city, we may be
12791279
// zoomed into a neighborhood and can cull the skyscrapers in the root node.
1280-
if (tile.contentReady && (
1280+
if (tile.contentAvailable && (
12811281
(tile.visibilityPlaneMask === CullingVolume.MASK_INSIDE) ||
12821282
(tile.contentVisibility(frameState) !== Intersect.OUTSIDE)
12831283
)) {
@@ -1357,8 +1357,8 @@ define([
13571357
var tile = original;
13581358
// traverse up the tree to find a ready ancestor
13591359
if (!tile.hasEmptyContent) {
1360-
while (defined(tile) && !(tile.hasRenderableContent && tile.contentReady)) {
1361-
if (!tile.contentReady) {
1360+
while (defined(tile) && !(tile.hasRenderableContent && tile.contentAvailable)) {
1361+
if (!tile.contentAvailable) {
13621362
tileset._hasMixedContent = true;
13631363
}
13641364
tile = tile.parent;
@@ -1381,7 +1381,7 @@ define([
13811381
var childrenLength = children.length;
13821382
for (var j = 0; j < childrenLength; ++j) {
13831383
var child = children[j];
1384-
if (child.contentReady) {
1384+
if (child.contentAvailable) {
13851385
if (!child.selected) {
13861386
child._finalResolution = true;
13871387
child.selected = true;
@@ -1391,7 +1391,7 @@ define([
13911391
}
13921392
}
13931393
if (child._depth - original._depth < 2) { // prevent traversing too far
1394-
if (!child.contentReady || child.refine === Cesium3DTileRefine.ADD) {
1394+
if (!child.contentAvailable || child.refine === Cesium3DTileRefine.ADD) {
13951395
descendantStack.push(child);
13961396
}
13971397
}

0 commit comments

Comments
 (0)