Skip to content

Commit

Permalink
Merge pull request #7115 from AnalyticalGraphicsInc/offscreen-picking
Browse files Browse the repository at this point in the history
Clamp to 3D Tiles most detailed
  • Loading branch information
pjcozzi authored Nov 8, 2018
2 parents 14af39b + 9956a08 commit 97159a4
Show file tree
Hide file tree
Showing 31 changed files with 2,260 additions and 93 deletions.
106 changes: 106 additions & 0 deletions Apps/Sandcastle/gallery/Sample Height from 3D Tiles.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Sample the most detailed heights of a 3D Tileset.">
<meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
if(typeof require === 'function') {
require.config({
baseUrl : '../../../Source',
waitSeconds : 120
});
}
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider : Cesium.createWorldTerrain()
});
var scene = viewer.scene;

var tileset = scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(6074)
})
);

scene.camera.setView({
destination: new Cesium.Cartesian3(1216411.0748779264, -4736313.10747583, 4081359.5125561724),
orientation: new Cesium.HeadingPitchRoll(4.239925103568368, -0.4911293834802475, 6.279849292088564),
endTransform : Cesium.Matrix4.IDENTITY
});

Sandcastle.addToolbarButton('Sample heights', function() {
sampleHeights();
});

function sampleHeights() {
if (!scene.clampToHeightSupported) {
console.log('This browser does not support clampToHeightMostDetailed.');
}

viewer.entities.removeAll();

var cartesian1 = new Cesium.Cartesian3(1216390.063324395, -4736314.814479433, 4081341.9787972216);
var cartesian2 = new Cesium.Cartesian3(1216329.5413318684, -4736272.029009798, 4081407.9342479417);

var count = 30;
var cartesians = new Array(count);
for (var i = 0; i < count; ++i) {
var offset = i / (count - 1);
cartesians[i] = Cesium.Cartesian3.lerp(cartesian1, cartesian2, offset, new Cesium.Cartesian3());
}

scene.clampToHeightMostDetailed(cartesians).then(function(clampedCartesians) {
for (var i = 0; i < count; ++i) {
viewer.entities.add({
position: clampedCartesians[i],
ellipsoid : {
radii : new Cesium.Cartesian3(0.2, 0.2, 0.2),
material : Cesium.Color.RED
}
});
}

viewer.entities.add({
polyline : {
positions : clampedCartesians,
followSurface : false,
width : 2,
material : new Cesium.PolylineOutlineMaterialProperty({
color : Cesium.Color.YELLOW
}),
depthFailMaterial : new Cesium.PolylineOutlineMaterialProperty({
color : Cesium.Color.YELLOW
})
}
});
});
}
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== 'undefined') {
startup(Cesium);
} else if (typeof require === 'function') {
require(['Cesium'], startup);
}
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Change Log
### 1.52 - 2018-12-03

##### Additions :tada:
* Added functions to get the most detailed height of 3D Tiles on-screen or off-screen. [#7115](https://github.com/AnalyticalGraphicsInc/cesium/pull/7115)
* Added `Scene.sampleHeightMostDetailed`, an asynchronous version of `Scene.sampleHeight` that uses the maximum level of detail for 3D Tiles.
* Added `Scene.clampToHeightMostDetailed`, an asynchronous version of `Scene.clampToHeight` that uses the maximum level of detail for 3D Tiles.
* Added `Scene.invertClassificationSupported` for checking if invert classification is supported.
* Added `computeLineSegmentLineSegmentIntersection` to `Intersections2D`. [#7228](https://github.com/AnalyticalGraphicsInc/Cesium/pull/7228)

Expand Down
78 changes: 52 additions & 26 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ define([
'./Cesium3DTileContentState',
'./Cesium3DTileOptimizations',
'./Cesium3DTileRefine',
'./Cesium3DTilesetAsyncTraversal',
'./Cesium3DTilesetCache',
'./Cesium3DTilesetStatistics',
'./Cesium3DTilesetTraversal',
Expand Down Expand Up @@ -73,6 +74,7 @@ define([
Cesium3DTileContentState,
Cesium3DTileOptimizations,
Cesium3DTileRefine,
Cesium3DTilesetAsyncTraversal,
Cesium3DTilesetCache,
Cesium3DTilesetStatistics,
Cesium3DTilesetTraversal,
Expand Down Expand Up @@ -204,6 +206,7 @@ define([
this._statistics = new Cesium3DTilesetStatistics();
this._statisticsLastRender = new Cesium3DTilesetStatistics();
this._statisticsLastPick = new Cesium3DTilesetStatistics();
this._statisticsLastAsync = new Cesium3DTilesetStatistics();

this._tilesLoaded = false;
this._initialTilesLoaded = false;
Expand Down Expand Up @@ -1707,9 +1710,9 @@ define([
function updateTiles(tileset, frameState) {
tileset._styleEngine.applyStyle(tileset, frameState);

var statistics = tileset._statistics;
var passes = frameState.passes;
var isRender = passes.render;
var statistics = tileset._statistics;
var commandList = frameState.commandList;
var numberOfInitialCommands = commandList.length;
var selectedTiles = tileset._selectedTiles;
Expand Down Expand Up @@ -1899,69 +1902,76 @@ define([

///////////////////////////////////////////////////////////////////////////

/**
* @private
*/
Cesium3DTileset.prototype.update = function(frameState) {
function update(tileset, frameState) {
if (frameState.mode === SceneMode.MORPHING) {
return;
return false;
}

if (!this.show || !this.ready) {
return;
if (!tileset.show || !tileset.ready) {
return false;
}

if (!defined(this._loadTimestamp)) {
this._loadTimestamp = JulianDate.clone(frameState.time);
if (!defined(tileset._loadTimestamp)) {
tileset._loadTimestamp = JulianDate.clone(frameState.time);
}

// Update clipping planes
var clippingPlanes = this._clippingPlanes;
this._clippingPlanesOriginMatrixDirty = true;
var clippingPlanes = tileset._clippingPlanes;
tileset._clippingPlanesOriginMatrixDirty = true;
if (defined(clippingPlanes) && clippingPlanes.enabled) {
clippingPlanes.update(frameState);
}

this._timeSinceLoad = Math.max(JulianDate.secondsDifference(frameState.time, this._loadTimestamp) * 1000, 0.0);
tileset._timeSinceLoad = Math.max(JulianDate.secondsDifference(frameState.time, tileset._loadTimestamp) * 1000, 0.0);

this._skipLevelOfDetail = this.skipLevelOfDetail && !defined(this._classificationType) && !this._disableSkipLevelOfDetail && !this._allTilesAdditive;
tileset._skipLevelOfDetail = tileset.skipLevelOfDetail && !defined(tileset._classificationType) && !tileset._disableSkipLevelOfDetail && !tileset._allTilesAdditive;

// Do out-of-core operations (new content requests, cache removal,
// process new tiles) only during the render pass.
var passes = frameState.passes;
var isRender = passes.render;
var isPick = passes.pick;
var isAsync = passes.async;

var statistics = this._statistics;
var statistics = tileset._statistics;
statistics.clear();

if (this.dynamicScreenSpaceError) {
updateDynamicScreenSpaceError(this, frameState);
if (tileset.dynamicScreenSpaceError) {
updateDynamicScreenSpaceError(tileset, frameState);
}

if (isRender) {
this._cache.reset();
tileset._cache.reset();
}

var ready;

if (isAsync) {
ready = Cesium3DTilesetAsyncTraversal.selectTiles(tileset, frameState);
} else {
ready = Cesium3DTilesetTraversal.selectTiles(tileset, frameState);
}

Cesium3DTilesetTraversal.selectTiles(this, frameState);
if (isRender || isAsync) {
requestTiles(tileset);
}

if (isRender) {
requestTiles(this);
processTiles(this, frameState);
processTiles(tileset, frameState);
}

updateTiles(this, frameState);
updateTiles(tileset, frameState);

if (isRender) {
unloadTiles(this);
unloadTiles(tileset);

// Events are raised (added to the afterRender queue) here since promises
// may resolve outside of the update loop that then raise events, e.g.,
// model's readyPromise.
raiseLoadProgressEvent(this, frameState);
raiseLoadProgressEvent(tileset, frameState);

if (statistics.selected !== 0) {
var credits = this._credits;
var credits = tileset._credits;
if (defined(credits)) {
var length = credits.length;
for (var i = 0; i < length; i++) {
Expand All @@ -1972,8 +1982,24 @@ define([
}

// Update last statistics
var statisticsLast = isPick ? this._statisticsLastPick : this._statisticsLastRender;
var statisticsLast = isAsync ? tileset._statisticsLastAsync : (isPick ? tileset._statisticsLastPick : tileset._statisticsLastRender);
Cesium3DTilesetStatistics.clone(statistics, statisticsLast);

return ready;
}

/**
* @private
*/
Cesium3DTileset.prototype.update = function(frameState) {
update(this, frameState);
};

/**
* @private
*/
Cesium3DTileset.prototype.updateAsync = function(frameState) {
return update(this, frameState);
};

/**
Expand Down
Loading

0 comments on commit 97159a4

Please sign in to comment.