Skip to content

Commit

Permalink
Added request volume support
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 9, 2016
1 parent a458bc6 commit b00bcaa
Show file tree
Hide file tree
Showing 11 changed files with 318 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Apps/Sandcastle/gallery/3D Tiles.html
Expand Up @@ -44,6 +44,8 @@
name : 'Translucent', url : '../../../Specs/Data/Cesium3DTiles/Batched/BatchedTranslucent/'
}, {
name : 'Translucent/Opaque', url : '../../../Specs/Data/Cesium3DTiles/Batched/BatchedTranslucentOpaqueMix/'
}, {
name : 'Request Volume', url : '../../../Specs/Data/Cesium3DTiles/Tilesets/TilesetWithViewerRequestVolume/'
}, {
name : 'Batched', url : '../../../Specs/Data/Cesium3DTiles/Batched/BatchedWithBatchTable/'
}, {
Expand Down Expand Up @@ -379,6 +381,10 @@
tileset.debugShowContentBoundingVolume = !tileset.debugShowContentBoundingVolume;
});

Sandcastle.addToolbarButton('Request Volume on/off', function() {
tileset.debugShowViewerRequestVolume = !tileset.debugShowViewerRequestVolume;
});

Sandcastle.addToolbarButton('SSE++', function() {
++tileset.maximumScreenSpaceError;
console.log('New max SSE: ' + tileset.maximumScreenSpaceError);
Expand Down
37 changes: 37 additions & 0 deletions Source/Scene/Cesium3DTile.js
Expand Up @@ -111,6 +111,12 @@ define([
}
this._contentBoundingVolume = contentBoundingVolume;

var viewerRequestVolume;
if (defined(header.viewerRequestVolume)) {
viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, computedTransform);
}
this._viewerRequestVolume = viewerRequestVolume;

/**
* The error, in meters, introduced if this tile is rendered and its children are not.
* This is used to compute Screen-Space Error (SSE), i.e., the error measured in pixels.
Expand Down Expand Up @@ -316,6 +322,7 @@ define([

this._debugBoundingVolume = undefined;
this._debugContentBoundingVolume = undefined;
this._debugViewerRequestVolume = undefined;
this._debugColor = new Color.fromRandom({ alpha : 1.0 });
this._debugColorizeTiles = false;
}
Expand Down Expand Up @@ -492,6 +499,7 @@ define([

this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
};

/**
Expand Down Expand Up @@ -540,6 +548,21 @@ define([
return this._boundingVolume.distanceToCamera(frameState);
};

/**
* Checks if the camera is inside the viewer request volume.
*
* @param {FrameState} frameState The frame state.
* @returns {Boolean} Whether the camera is inside the volume.
*/
Cesium3DTile.prototype.insideViewerRequestVolume = function(frameState) {
var viewerRequestVolume = this._viewerRequestVolume;
if (!defined(viewerRequestVolume)) {
return true;
}

return (viewerRequestVolume.distanceToCamera(frameState) === 0.0);
};

var scratchMatrix = new Matrix3();
var scratchScale = new Cartesian3();
var scratchHalfAxes = new Matrix3();
Expand Down Expand Up @@ -628,10 +651,14 @@ define([
if (defined(this._contentBoundingVolume)) {
this._contentBoundingVolume = this.createBoundingVolume(content.boundingVolume, computedTransform, this._contentBoundingVolume);
}
if (defined(this._viewerRequestVolume)) {
this._viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, computedTransform, this._viewerRequestVolume);
}

// Destroy the debug bounding volumes. They will be generated fresh.
this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
}
};

Expand All @@ -658,6 +685,15 @@ define([
tile._debugContentBoundingVolume = tile._debugContentBoundingVolume.destroy();
}

if (tileset.debugShowViewerRequestVolume && defined(tile._viewerRequestVolume)) {
if (!defined(tile._debugViewerRequestVolume)) {
tile._debugViewerRequestVolume = tile._viewerRequestVolume.createDebugVolume(Color.YELLOW);
}
tile._debugViewerRequestVolume.update(frameState);
} else if (!tileset.debugShowViewerRequestVolume && defined(tile._debugViewerRequestVolume)) {
tile._debugViewerRequestVolume = tile._debugViewerRequestVolume.destroy();
}

if (tileset.debugColorizeTiles && !tile._debugColorizeTiles) {
tile._debugColorizeTiles = true;
tile._content.applyDebugSettings(true, tile._debugColor);
Expand Down Expand Up @@ -712,6 +748,7 @@ define([
this._content = this._content && this._content.destroy();
this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
return destroyObject(this);
};

Expand Down
48 changes: 38 additions & 10 deletions Source/Scene/Cesium3DTileset.js
Expand Up @@ -76,6 +76,7 @@ define([
* @param {Boolean} [options.debugColorizeTiles=false] For debugging only. When true, assigns a random color to each tile.
* @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile.
* @param {Boolean} [options.debugShowContentBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile's content.
* @param {Boolean} [options.debugShowViewerRequestVolume=false] For debugging only. When true, renders the viewer request volume for each tile.
*
* @example
* var tileset = scene.primitives.add(new Cesium.Cesium3DTileset({
Expand Down Expand Up @@ -237,6 +238,17 @@ define([
*/
this.debugShowContentBoundingVolume = defaultValue(options.debugShowContentBoundingVolume, false);

/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, renders the viewer request volume for each tile.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowViewerRequestVolume = defaultValue(options.debugShowViewerRequestVolume, false);

/**
* The event fired to indicate progress of loading new tiles. This event is fired when a new tile
* is requested, when a requested tile is finished downloading, and when a downloaded tile has been
Expand Down Expand Up @@ -907,6 +919,11 @@ define([

var root = tileset._root;
root.updateTransform(tileset._modelMatrix);

if (!root.insideViewerRequestVolume(frameState)) {
return;
}

root.distanceToCamera = root.distanceToTile(frameState);

if (getScreenSpaceError(tileset._geometricError, root, frameState) <= maximumScreenSpaceError) {
Expand Down Expand Up @@ -991,14 +1008,16 @@ define([
// With additive refinement, we only request or refine when children are visible
for (k = 0; k < childrenLength; ++k) {
child = children[k];
// Use parent's geometric error with child's box to see if we already meet the SSE
if (getScreenSpaceError(t.geometricError, child, frameState) > maximumScreenSpaceError) {
child.visibilityPlaneMask = child.visibility(cullingVolume, visibilityPlaneMask);
if (isVisible(child.visibilityPlaneMask)) {
if (child.contentUnloaded) {
requestContent(tileset, child, outOfCore);
} else {
stack.push(child);
if (child.insideViewerRequestVolume(frameState)) {
// Use parent's geometric error with child's box to see if we already meet the SSE
if (getScreenSpaceError(t.geometricError, child, frameState) > maximumScreenSpaceError) {
child.visibilityPlaneMask = child.visibility(cullingVolume, visibilityPlaneMask);
if (isVisible(child.visibilityPlaneMask)) {
if (child.contentUnloaded) {
requestContent(tileset, child, outOfCore);
} else {
stack.push(child);
}
}
}
}
Expand Down Expand Up @@ -1058,7 +1077,12 @@ define([
// Tile does not meet SSE and its children are loaded. Refine to them in front-to-back order.
for (k = 0; k < childrenLength; ++k) {
child = children[k];
child.visibilityPlaneMask = child.visibility(frameState.cullingVolume, visibilityPlaneMask);
if (child.insideViewerRequestVolume(frameState)) {
child.visibilityPlaneMask = child.visibility(frameState.cullingVolume, visibilityPlaneMask);
} else {
child.visibilityPlaneMask = CullingVolume.MASK_OUTSIDE;
}

if (isVisible(child.visibilityPlaneMask)) {
stack.push(child);
} else {
Expand All @@ -1084,7 +1108,11 @@ define([
for (k = 0; k < childrenLength; ++k) {
child = children[k];
child.updateTransform(t.computedTransform);
child.visibilityPlaneMask = child.visibility(frameState.cullingVolume, visibilityPlaneMask);
if (child.insideViewerRequestVolume(frameState)) {
child.visibilityPlaneMask = child.visibility(frameState.cullingVolume, visibilityPlaneMask);
} else {
child.visibilityPlaneMask = CullingVolume.MASK_OUTSIDE;
}
if (isVisible(child.visibilityPlaneMask)) {
if (child.contentReady) {
someVisibleChildrenLoaded = true;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,144 @@
{
"asset": {
"version": "0.0"
},
"properties": {
"id": {
"minimum": 0,
"maximum": 9
},
"Longitude": {
"minimum": -1.3197190069941716,
"maximum": -1.3196399825465384
},
"Latitude": {
"minimum": 0.6988468038519597,
"maximum": 0.6989046685398855
},
"Height": {
"minimum": 6,
"maximum": 84
}
},
"geometricError": 240,
"root": {
"boundingVolume": {
"region": [
-1.3197209591796106,
0.6988424218,
-1.3196390408203893,
0.6989055782,
0,
20
]
},
"geometricError": 70,
"refine": "add",
"children": [
{
"boundingVolume": {
"region": [
-1.3197209591796106,
0.6988424218,
-1.31968,
0.698874,
0,
20
]
},
"geometricError": 0,
"content": {
"url": "ll.b3dm"
}
},
{
"boundingVolume": {
"region": [
-1.31968,
0.6988424218,
-1.3196390408203893,
0.698874,
0,
20
]
},
"geometricError": 0,
"content": {
"url": "lr.b3dm"
}
},
{
"boundingVolume": {
"region": [
-1.31968,
0.698874,
-1.3196390408203893,
0.6989055782,
0,
20
]
},
"geometricError": 0,
"content": {
"url": "ur.b3dm"
}
},
{
"boundingVolume": {
"region": [
-1.3197209591796106,
0.698874,
-1.31968,
0.6989055782,
0,
20
]
},
"geometricError": 0,
"content": {
"url": "ul.b3dm"
}
},
{
"transform": [
0.9686356343768793,
0.24848542777253738,
0,
0,
-0.1598646089326599,
0.6231776176011753,
0.7655670863691378,
0,
0.19023226494501025,
-0.7415555603632288,
0.643356072690908,
0,
1215014.7852103356,
-4736320.466755246,
4081611.654821087,
1
],
"viewerRequestVolume": {
"sphere": [
0,
0,
0,
1000
]
},
"boundingVolume": {
"sphere": [
0,
0,
0,
10
]
},
"geometricError": 0,
"content": {
"url": "points.pnts"
}
}
]
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit b00bcaa

Please sign in to comment.