Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visit terrain tiles depth first and near-to-far #4616

Merged
merged 23 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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 @@ -7,6 +7,7 @@ Change Log
* Breaking changes
*
* Added support for saving html and css in Github Gists [#4125](https://github.com/AnalyticalGraphicsInc/cesium/issues/4125)
* Improved terrain/imagery load ordering, especially when the terrain is already fully loaded and we add a new imagery layer.

### 1.27 - 2016-11-01
* Deprecated
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ define([
}

var globe = this._scene.globe;
var globeFinishedUpdating = !defined(globe) || (globe._surface.tileProvider.ready && !defined(globe._surface._tileLoadQueue.head) && globe._surface._debug.tilesWaitingForChildren === 0);
var globeFinishedUpdating = !defined(globe) || (globe._surface.tileProvider.ready && globe._surface._tileLoadQueueHigh.length === 0 && globe._surface._tileLoadQueueMedium.length === 0 && globe._surface._tileLoadQueueLow.length === 0 && globe._surface._debug.tilesWaitingForChildren === 0);
if (this._suspendTerrainAdjustment) {
this._suspendTerrainAdjustment = !globeFinishedUpdating;
}
Expand Down
17 changes: 8 additions & 9 deletions Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ define([
var scratchGetHeightCartographic = new Cartographic();
var scratchGetHeightRay = new Ray();

function tileIfContainsCartographic(tile, cartographic) {
return Rectangle.contains(tile.rectangle, cartographic) ? tile : undefined;
}

/**
* Get the height of the surface at a given cartographic.
*
Expand Down Expand Up @@ -407,15 +411,10 @@ define([
}

while (tile.renderable) {
var children = tile.children;
length = children.length;

for (i = 0; i < length; ++i) {
tile = children[i];
if (Rectangle.contains(tile.rectangle, cartographic)) {
break;
}
}
tile = tileIfContainsCartographic(tile.southwestChild, cartographic) ||
tileIfContainsCartographic(tile.southeastChild, cartographic) ||
tileIfContainsCartographic(tile.northwestChild, cartographic) ||
tile.northeastChild;
}

while (defined(tile) && (!defined(tile.data) || !defined(tile.data.pickTerrain))) {
Expand Down
112 changes: 58 additions & 54 deletions Source/Scene/GlobeSurfaceTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,32 +458,34 @@ define([
// of its ancestors receives new (better) data and we want to re-upsample from the
// new data.

if (defined(tile._children)) {
for (var childIndex = 0; childIndex < 4; ++childIndex) {
var childTile = tile._children[childIndex];
if (childTile.state !== QuadtreeTileLoadState.START) {
var childSurfaceTile = childTile.data;
if (defined(childSurfaceTile.terrainData) && !childSurfaceTile.terrainData.wasCreatedByUpsampling()) {
// Data for the child tile has already been loaded.
continue;
}
propagateNewUpsampledDataToChild(tile, tile._southwestChild);
propagateNewUpsampledDataToChild(tile, tile._southeastChild);
propagateNewUpsampledDataToChild(tile, tile._northwestChild);
propagateNewUpsampledDataToChild(tile, tile._northeastChild);
}

// Restart the upsampling process, no matter its current state.
// We create a new instance rather than just restarting the existing one
// because there could be an asynchronous operation pending on the existing one.
if (defined(childSurfaceTile.upsampledTerrain)) {
childSurfaceTile.upsampledTerrain.freeResources();
}
childSurfaceTile.upsampledTerrain = new TileTerrain({
data : surfaceTile.terrainData,
x : tile.x,
y : tile.y,
level : tile.level
});

childTile.state = QuadtreeTileLoadState.LOADING;
}
function propagateNewUpsampledDataToChild(tile, childTile) {
if (defined(childTile) && childTile.state !== QuadtreeTileLoadState.START) {
var childSurfaceTile = childTile.data;
if (defined(childSurfaceTile.terrainData) && !childSurfaceTile.terrainData.wasCreatedByUpsampling()) {
// Data for the child tile has already been loaded.
return;
}

// Restart the upsampling process, no matter its current state.
// We create a new instance rather than just restarting the existing one
// because there could be an asynchronous operation pending on the existing one.
if (defined(childSurfaceTile.upsampledTerrain)) {
childSurfaceTile.upsampledTerrain.freeResources();
}
childSurfaceTile.upsampledTerrain = new TileTerrain({
data : tile.data.terrainData,
x : tile.x,
y : tile.y,
level : tile.level
});

childTile.state = QuadtreeTileLoadState.LOADING;
}
}

Expand All @@ -494,40 +496,42 @@ define([
// - child tiles that were previously upsampled need to be re-upsampled based on the new data.
// - child tiles that were previously deemed unavailable may now be available.

if (defined(tile.children)) {
for (var childIndex = 0; childIndex < 4; ++childIndex) {
var childTile = tile.children[childIndex];
if (childTile.state !== QuadtreeTileLoadState.START) {
var childSurfaceTile = childTile.data;
if (defined(childSurfaceTile.terrainData) && !childSurfaceTile.terrainData.wasCreatedByUpsampling()) {
// Data for the child tile has already been loaded.
continue;
}
propagateNewLoadedDataToChildTile(tile, surfaceTile, tile.southwestChild);
propagateNewLoadedDataToChildTile(tile, surfaceTile, tile.southeastChild);
propagateNewLoadedDataToChildTile(tile, surfaceTile, tile.northwestChild);
propagateNewLoadedDataToChildTile(tile, surfaceTile, tile.northeastChild);
}

// Restart the upsampling process, no matter its current state.
// We create a new instance rather than just restarting the existing one
// because there could be an asynchronous operation pending on the existing one.
if (defined(childSurfaceTile.upsampledTerrain)) {
childSurfaceTile.upsampledTerrain.freeResources();
}
childSurfaceTile.upsampledTerrain = new TileTerrain({
data : surfaceTile.terrainData,
x : tile.x,
y : tile.y,
level : tile.level
});

if (surfaceTile.terrainData.isChildAvailable(tile.x, tile.y, childTile.x, childTile.y)) {
// Data is available for the child now. It might have been before, too.
if (!defined(childSurfaceTile.loadedTerrain)) {
// No load process is in progress, so start one.
childSurfaceTile.loadedTerrain = new TileTerrain();
}
}
function propagateNewLoadedDataToChildTile(tile, surfaceTile, childTile) {
if (childTile.state !== QuadtreeTileLoadState.START) {
var childSurfaceTile = childTile.data;
if (defined(childSurfaceTile.terrainData) && !childSurfaceTile.terrainData.wasCreatedByUpsampling()) {
// Data for the child tile has already been loaded.
return;
}

childTile.state = QuadtreeTileLoadState.LOADING;
// Restart the upsampling process, no matter its current state.
// We create a new instance rather than just restarting the existing one
// because there could be an asynchronous operation pending on the existing one.
if (defined(childSurfaceTile.upsampledTerrain)) {
childSurfaceTile.upsampledTerrain.freeResources();
}
childSurfaceTile.upsampledTerrain = new TileTerrain({
data : surfaceTile.terrainData,
x : tile.x,
y : tile.y,
level : tile.level
});

if (surfaceTile.terrainData.isChildAvailable(tile.x, tile.y, childTile.x, childTile.y)) {
// Data is available for the child now. It might have been before, too.
if (!defined(childSurfaceTile.loadedTerrain)) {
// No load process is in progress, so start one.
childSurfaceTile.loadedTerrain = new TileTerrain();
}
}

childTile.state = QuadtreeTileLoadState.LOADING;
}
}

Expand Down
Loading