Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request CesiumGS#5788 from AnalyticalGraphicsInc/visibilit…
Browse files Browse the repository at this point in the history
…y-fix

Only load visible tiles during 3D Tiles traversal
  • Loading branch information
lilleyse authored Sep 1, 2017
2 parents 5ac57c7 + 071cec6 commit f158860
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Change Log
* Fixed specular computation for certain models using the `KHR_materials_common` extension. [#5773](https://github.com/AnalyticalGraphicsInc/cesium/pull/5773)
* Fixed a bug where developer error was thrown in Sandcastle example [#5703](https://github.com/AnalyticalGraphicsInc/cesium/issues/5703)
* Fixed a 3D Tiles traversal bug for tilesets using additive refinement. [#5766](https://github.com/AnalyticalGraphicsInc/cesium/issues/5766)
* Fixed a 3D Tiles traversal bug where out-of-view children were being loaded unnecessarily. [#5477](https://github.com/AnalyticalGraphicsInc/cesium/issues/5477)
* Fixed depth picking on 3D Tiles. [#5676](https://github.com/AnalyticalGraphicsInc/cesium/issues/5676)
* Fixed glTF model translucency bug. [#5731](https://github.com/AnalyticalGraphicsInc/cesium/issues/5731)
* Added `classificationType` to `ClassificationPrimitive` and `GroundPrimitive` to choose whether terrain, 3D Tiles, or both are classified. [#5683](https://github.com/AnalyticalGraphicsInc/cesium/issues/5676)
Expand Down
53 changes: 29 additions & 24 deletions Source/Scene/Cesium3DTilesetTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ define([
return;
}

loadTile(tileset, root, frameState);
loadTile(tileset, root, frameState, true);

if (!tileset.skipLevelOfDetail) {
// just execute base traversal and add tiles to _desiredTiles
Expand Down Expand Up @@ -313,7 +313,7 @@ define([
var replacementWithContent = tile.refine === Cesium3DTileRefine.REPLACE && tile.hasRenderableContent;
for (var i = 0; i < childrenLength; ++i) {
var child = children[i];
loadTile(tileset, child, frameState);
loadTile(tileset, child, frameState, true);
touch(tileset, child, outOfCore);

// content cannot be replaced until all of the nearest descendants with content are all loaded
Expand Down Expand Up @@ -413,7 +413,7 @@ define([
var childrenLength = children.length;
for (var i = 0; i < childrenLength; ++i) {
var child = children[i];
loadTile(tileset, child, frameState);
loadTile(tileset, child, frameState, true);
touch(tileset, child, outOfCore);
if (!tile.contentAvailable) {
this.allLoaded = false;
Expand Down Expand Up @@ -507,8 +507,12 @@ define([
}

if (!tile.hasTilesetContent) {
if (hasAdditiveContent(tile)) {
tileset._desiredTiles.push(tile);
if (tile.refine === Cesium3DTileRefine.ADD) {
// Always load additive tiles
loadTile(tileset, tile, this.frameState);
if (hasAdditiveContent(tile)) {
tileset._desiredTiles.push(tile);
}
}

// stop traversal when we've attained the desired level of error
Expand Down Expand Up @@ -540,12 +544,7 @@ define([
var children = tile.children;
var childrenLength = children.length;
for (var i = 0; i < childrenLength; ++i) {
var child = children[i];
if (child.refine === Cesium3DTileRefine.ADD && isVisible(child._visibilityPlaneMask)) {
// Additive refinement tiles are always loaded when they are reached
loadTile(tileset, child, this.frameState);
}
touch(tileset, child, this.outOfCore);
touch(tileset, children[i], this.outOfCore);
}
return children;
}
Expand All @@ -554,14 +553,7 @@ define([
};

InternalSkipTraversal.prototype.shouldVisit = function(tile) {
var maximumScreenSpaceError = this.tileset._maximumScreenSpaceError;
var parent = tile.parent;
if (!defined(parent)) {
return isVisible(tile._visibilityPlaneMask);
}
var showAdditive = parent.refine === Cesium3DTileRefine.ADD && parent._screenSpaceError > maximumScreenSpaceError;

return isVisible(tile._visibilityPlaneMask) && (!showAdditive || getScreenSpaceError(this.tileset, parent.geometricError, tile, this.frameState) > maximumScreenSpaceError);
return isVisibleAndMeetsSSE(this.tileset, tile, this.frameState);
};

InternalSkipTraversal.prototype.leafHandler = function(tile) {
Expand All @@ -576,11 +568,11 @@ define([
var tiles = parent.children;
var length = tiles.length;
for (var i = 0; i < length; ++i) {
loadTile(this.tileset, tiles[i], this.frameState);
loadTile(this.tileset, tiles[i], this.frameState, false);
touch(this.tileset, tiles[i], this.outOfCore);
}
} else {
loadTile(this.tileset, tile, this.frameState);
loadTile(this.tileset, tile, this.frameState, true);
touch(this.tileset, tile, this.outOfCore);
}
}
Expand Down Expand Up @@ -643,10 +635,12 @@ define([
}
}

function loadTile(tileset, tile, frameState) {
function loadTile(tileset, tile, frameState, checkVisibility) {
if ((tile.contentUnloaded || tile.contentExpired) && tile._requestedFrame !== frameState.frameNumber) {
tile._requestedFrame = frameState.frameNumber;
tileset._requestedTiles.push(tile);
if (!checkVisibility || isVisibleAndMeetsSSE(tileset, tile, frameState)) {
tile._requestedFrame = frameState.frameNumber;
tileset._requestedTiles.push(tile);
}
}
}

Expand Down Expand Up @@ -741,6 +735,17 @@ define([
return visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE;
}

function isVisibleAndMeetsSSE(tileset, tile, frameState) {
var maximumScreenSpaceError = tileset._maximumScreenSpaceError;
var parent = tile.parent;
if (!defined(parent)) {
return isVisible(tile._visibilityPlaneMask);
}
var showAdditive = parent.refine === Cesium3DTileRefine.ADD && parent._screenSpaceError > maximumScreenSpaceError;

return isVisible(tile._visibilityPlaneMask) && (!showAdditive || getScreenSpaceError(tileset, parent.geometricError, tile, frameState) > maximumScreenSpaceError);
}

function childrenAreVisible(tile) {
// optimization does not apply for additive refinement
return tile.refine === Cesium3DTileRefine.ADD || tile.children.length === 0 || tile._childrenVisibility & Cesium3DTileChildrenVisibility.VISIBLE !== 0;
Expand Down

0 comments on commit f158860

Please sign in to comment.