Skip to content

Commit

Permalink
Handle expiring subtrees
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Apr 24, 2017
1 parent 5fb5f91 commit f0ea129
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 45 deletions.
52 changes: 22 additions & 30 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ define([
*/
this.computedTransform = computedTransform;

this._transformDirty = true;

this._boundingVolume = this.createBoundingVolume(header.boundingVolume, computedTransform);
this._boundingVolume2D = undefined;

Expand Down Expand Up @@ -422,20 +420,6 @@ define([
}
},

/**
* Whether the computedTransform has changed this frame.
*
* @memberof Cesium3DTile.prototype
*
* @type {Boolean}
* @readonly
*/
transformDirty : {
get : function() {
return this._transformDirty;
}
},

/**
* @readonly
* @private
Expand Down Expand Up @@ -550,15 +534,20 @@ define([

var scratchJulianDate = new JulianDate();

function updateExpiration(tile) {
if (defined(tile.expireDate) && tile.contentReady && !tile.hasEmptyContent) {
/**
* Update whether the tile has expired.
*
* @private
*/
Cesium3DTile.prototype.updateExpiration = function() {
if (defined(this.expireDate) && this.contentReady && !this.hasEmptyContent) {
var now = JulianDate.now(scratchJulianDate);
if (JulianDate.lessThan(tile.expireDate, now)) {
tile._contentState = Cesium3DTileContentState.EXPIRED;
tile._expiredContent = tile._content;
if (JulianDate.lessThan(this.expireDate, now)) {
this._contentState = Cesium3DTileContentState.EXPIRED;
this._expiredContent = this._content;
}
}
}
};

function updateExpireDate(tile) {
if (defined(tile.expireDuration)) {
Expand Down Expand Up @@ -620,9 +609,9 @@ define([

promise.then(function(arrayBuffer) {
if (that.isDestroyed()) {
return when.reject('tileset is destroyed');
// Tile is unloaded before the content finishes loading
return when.reject('tile is destroyed');
}

var uint8Array = new Uint8Array(arrayBuffer);
var magic = getMagic(uint8Array);
var contentFactory = Cesium3DTileContentFactory[magic];
Expand All @@ -642,6 +631,11 @@ define([
that._contentReadyToProcessPromise.resolve(content);

content.readyPromise.then(function(content) {
if (that.isDestroyed()) {
// Tile is unloaded before the content finishes processing
that._content.destroy();
return when.reject('tile is destroyed');
}
updateExpireDate(that);
that._contentState = Cesium3DTileContentState.READY;
that._contentReadyPromise.resolve(content);
Expand Down Expand Up @@ -883,9 +877,8 @@ define([
Cesium3DTile.prototype.updateTransform = function(parentTransform) {
parentTransform = defaultValue(parentTransform, Matrix4.IDENTITY);
var computedTransform = Matrix4.multiply(parentTransform, this.transform, scratchTransform);
var transformDirty = !Matrix4.equals(computedTransform, this.computedTransform);
if (transformDirty) {
this._transformDirty = true;
var transformChanged = !Matrix4.equals(computedTransform, this.computedTransform);
if (transformChanged) {
Matrix4.clone(computedTransform, this.computedTransform);

// Update the bounding volumes
Expand Down Expand Up @@ -969,9 +962,7 @@ define([
*/
Cesium3DTile.prototype.update = function(tileset, frameState) {
applyDebugSettings(this, tileset, frameState);
updateExpiration(this);
updateContent(this, tileset, frameState);
this._transformDirty = false;
};

var scratchCommandList = [];
Expand Down Expand Up @@ -1005,8 +996,9 @@ define([
* @private
*/
Cesium3DTile.prototype.destroy = function() {
// For the interval between new content being requested and downloaded, expiredContent === content, so don't destroy twice
this._content = this._content && this._content.destroy();
this._expiredContent = this._expiredContent && this._expiredContent.destroy();
this._expiredContent = this._expiredContent && !this._expiredContent.isDestroyed() && this._expiredContent.destroy();
this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
Expand Down
29 changes: 15 additions & 14 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,22 +1223,21 @@ define([
///////////////////////////////////////////////////////////////////////////

function unloadSubtree(tileset, tile) {
var subtreeRoot = tile;
var stats = tileset._statistics;
var stack = [];
var stack = scratchStack;
stack.push(tile);
while (stack.length > 0) {
tile = stack.pop();
unloadTile(tileset, tile);
var children = tile.children;
var length = children.length;
for (var i = 0; i < length; ++i) {
var child = children[i];
--stats.numberTotal;
stack.push(child);
stack.push(children[i]);
}
}

tile.children = [];
subtreeRoot.children = [];
}

function isVisible(visibilityPlaneMask) {
Expand All @@ -1255,18 +1254,14 @@ define([
}

var stats = tileset._statistics;
var expired = tile.contentExpired;

var requested = tile.requestContent();

if (!requested) {
++stats.numberOfAttemptedRequests;
return;
}

if (expired && tile.hasTilesetContent) {
unloadSubtree(tileset, tile);
}

++stats.numberOfPendingRequests;

var removeFunction = removeFromProcessingQueue(tileset, tile);
Expand Down Expand Up @@ -1591,6 +1586,7 @@ define([
tile._sse = getScreenSpaceError(tileset, tile.geometricError, tile, frameState);
tile.selected = false;
tile._finalResolution = false;
tile.updateExpiration();
touch(tileset, tile, outOfCore);
}

Expand Down Expand Up @@ -1623,7 +1619,12 @@ define([
var loadSiblings = tileset.loadSiblings;

if (tile.hasTilesetContent) {
updateAndPushChildren(tileset, tile, frameState, stack, loadSiblings, outOfCore);
if (tile.contentExpired) {
loadTile(tile);
unloadSubtree(tileset, tile);
} else {
updateAndPushChildren(tileset, tile, frameState, stack, loadSiblings, outOfCore);
}
} else {
if (tile.refine === Cesium3DTileRefine.ADD) {
loadAndAddToQueue(tileset, tile, finalQueue);
Expand Down Expand Up @@ -1982,7 +1983,7 @@ define([
}

function unloadTile(tileset, tile) {
if (!tile.hasRenderableContent) {
if (!tile.hasRenderableContent || !tile.contentReady) {
return;
}

Expand All @@ -1997,7 +1998,7 @@ define([
tile.unloadContent();
}

function unloadTiles(tileset, frameState) {
function unloadTiles(tileset) {
var trimTiles = tileset._trimTiles;
tileset._trimTiles = false;

Expand Down Expand Up @@ -2100,7 +2101,7 @@ define([
updateTiles(this, frameState);

if (outOfCore) {
unloadTiles(this, frameState);
unloadTiles(this);
}

// Events are raised (added to the afterRender queue) here since promises
Expand Down
4 changes: 3 additions & 1 deletion Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ define([
this._quantizedVolumeScale = undefined;
this._quantizedVolumeOffset = undefined;

this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY);
this._mode = undefined;

/**
Expand Down Expand Up @@ -1138,7 +1139,8 @@ define([
* Part of the {@link Cesium3DTileContent} interface.
*/
PointCloud3DTileContent.prototype.update = function(tileset, frameState) {
var updateModelMatrix = this._tile.transformDirty || this._mode !== frameState.mode;
var modelMatrixChanged = !Matrix4.equals(this._modelMatrix, this._tile.computedTransform);
var updateModelMatrix = modelMatrixChanged || this._mode !== frameState.mode;
this._mode = frameState.mode;

if (!defined(this._drawCommand)) {
Expand Down

0 comments on commit f0ea129

Please sign in to comment.