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

Clamp to 3D Tiles most detailed #7115

Merged
merged 44 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
eb4b83d
Move common code into Cesium3DTile
lilleyse Sep 18, 2018
75d297c
Pass statistics around in preparation for offscreen statistics
lilleyse Sep 19, 2018
96143eb
Merge branch 'pick-ray-2' into offscreen-picking
lilleyse Sep 21, 2018
5392ed7
Merge branch 'master' into offscreen-picking
lilleyse Oct 1, 2018
c389629
Offscreen picking
lilleyse Oct 1, 2018
8b88951
Added Sandcastle demo
lilleyse Oct 3, 2018
8273d8e
Cleaned up Ray.clone
lilleyse Oct 5, 2018
eaa858b
Update frame number and time in main render loop so changes are refle…
lilleyse Oct 5, 2018
93061df
Fix #7120 by picking through primitives that don't write depth for sa…
lilleyse Oct 15, 2018
336bf3a
Merge branch 'master' into offscreen-picking
lilleyse Oct 15, 2018
b950f17
Merge branch 'master' into offscreen-picking
lilleyse Oct 15, 2018
af109b2
Added #7120 to CHANGES
lilleyse Oct 15, 2018
320bf99
Modify arrays in place
lilleyse Oct 15, 2018
751b138
Rename demo
lilleyse Oct 16, 2018
003baa5
Merge branch 'master' into offscreen-picking
lilleyse Oct 16, 2018
b605450
Fix tests
lilleyse Oct 16, 2018
bdd2d78
Added pick tests
lilleyse Oct 18, 2018
67d2a86
Remove updateAsync and use normal update
lilleyse Oct 19, 2018
26a1a66
Fix tests
lilleyse Oct 19, 2018
a75ddf3
Merge branch 'master' into offscreen-picking
lilleyse Oct 19, 2018
db53e33
Minor Scene edits
lilleyse Oct 19, 2018
a8710ff
Undo statistics changes in Cesium3DTileset
lilleyse Oct 19, 2018
ebd65d9
Cleanup and fixes from #7115
lilleyse Oct 19, 2018
955b098
Merge branch 'offscreen-picking-prep' into offscreen-picking
lilleyse Oct 19, 2018
9e89108
Renamed Cesium3DTilesetOffscreenTraversal to Cesium3DTilesetAsyncTrav…
lilleyse Oct 19, 2018
0a805d5
eslint fix
lilleyse Oct 19, 2018
8d1159c
Merge branch 'offscreen-picking-prep' into offscreen-picking
lilleyse Oct 19, 2018
504988a
Merge branch 'offscreen-picking-prep' into offscreen-picking
lilleyse Oct 19, 2018
ab58195
Remove unused include
lilleyse Oct 19, 2018
12e92b5
Ignore async commands in different place
lilleyse Oct 22, 2018
a406d3a
Fix WebGL stub tests
lilleyse Oct 22, 2018
66e626c
Added tileset tests
lilleyse Nov 5, 2018
a5078f5
Added updateAsync function to Cesium3DTileset
lilleyse Nov 5, 2018
470bd0f
Add terrain to Sandcastle demo
lilleyse Nov 5, 2018
d0c16e3
Remove minimumGeometricError
lilleyse Nov 5, 2018
e457213
Formatting
lilleyse Nov 5, 2018
9a2e7eb
Renamed asyncLoaders to asyncRayPicks
lilleyse Nov 5, 2018
3d64294
Scene updates
lilleyse Nov 5, 2018
ac9a986
Merge branch 'master' into offscreen-picking
lilleyse Nov 5, 2018
b5cafd7
Add to doc
lilleyse Nov 5, 2018
3876766
Merge conflict fix
lilleyse Nov 6, 2018
f461329
Merge branch 'master' into offscreen-picking
lilleyse Nov 7, 2018
d115e17
Updated CHANGES.md
lilleyse Nov 7, 2018
9956a08
Merge branch 'master' into offscreen-picking
lilleyse Nov 7, 2018
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
104 changes: 104 additions & 0 deletions Apps/Sandcastle/gallery/Clamp to 3D Tiles Offscreen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!DOCTYPE html>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we should call this "off screen?" What speaks to the user best? Async? Most Detailed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really just that comment for now, this is cool, and could be used for profiles, e.g., change 30 to 300.

I'll also look at the implementation when ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I do support having smaller, more focused Sandcastle examples in general, in this case I wonder if it would be better to combine this with the existing Clamp to 3D Tiles example, in the same way the terrain sample and sampleMostDetailed are in the same example:

http://localhost:8080/Apps/Sandcastle/index.html?src=Terrain.html

"Most detailed" is probably the most relevant to the user, but I can imagine users running into this issue when they realize sampleHeight only works for already visible tiles and want to figure out how to do it for tiles offscreen. I think in any case the goal for the user is just clamping to 3D Tiles/getting tiles height, so a combined example geared towards that use case makes the most sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping them separate is better because they represent different enough use cases.

But maybe the new demo should be called Sample Height from 3D Tiles. The main difference being this demo samples some heights and shows the result while the first demo actually physically clamps something to the tileset.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes more sense! I think that naming will make it easier to find.

<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');
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.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ Change Log
### 1.51 - 2018-11-01

##### Additions :tada:
* Added `Ray.clone`. [#7115](https://github.com/AnalyticalGraphicsInc/cesium/pull/7115)
* Added WMS-T (time) support in WebMapServiceImageryProvider [#2581](https://github.com/AnalyticalGraphicsInc/cesium/issues/2581)
* Added `cutoutRectangle` to `ImageryLayer`, which allows cutting out rectangular areas in imagery layers to reveal underlying imagery. [#7056](https://github.com/AnalyticalGraphicsInc/cesium/pull/7056)

##### Fixes :wrench:
* Fixed an issue where `pickPosition` would return incorrect results when called after `sampleHeight` or `clampToHeight`. [#7113](https://github.com/AnalyticalGraphicsInc/cesium/pull/7113)
* Fixed an issue where `sampleHeight` and `clampToHeight` would crash if picking a primitive that doesn't write depth. [#7120](https://github.com/AnalyticalGraphicsInc/cesium/issues/7120)

### 1.50 - 2018-10-01

Expand Down
37 changes: 27 additions & 10 deletions Source/Core/Ray.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
define([
'./Cartesian3',
'./Check',
'./defaultValue',
'./defined',
'./DeveloperError'
'./defined'
], function(
Cartesian3,
Check,
defaultValue,
defined,
DeveloperError) {
defined) {
'use strict';

/**
Expand Down Expand Up @@ -38,6 +38,27 @@ define([
this.direction = direction;
}

/**
* Duplicates a Ray instance.
*
* @param {Ray} ray The ray to duplicate.
* @param {Ray} [result] The object onto which to store the result.
* @returns {Ray} The modified result parameter or a new Ray instance if one was not provided.
*/
Ray.clone = function(ray, result) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object('ray', ray);
//>>includeEnd('debug');

if (!defined(result)) {
return new Ray(ray.origin, ray.direction);
}

result.origin = ray.origin;
result.direction = ray.direction;
return result;
};

/**
* Computes the point along the ray given by r(t) = o + t*d,
* where o is the origin of the ray and d is the direction.
Expand All @@ -54,12 +75,8 @@ define([
*/
Ray.getPoint = function(ray, t, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(ray)){
throw new DeveloperError('ray is requred');
}
if (typeof t !== 'number') {
throw new DeveloperError('t is a required number');
}
Check.typeOf.object('ray', ray);
Check.typeOf.number('t', t);
//>>includeEnd('debug');

if (!defined(result)) {
Expand Down
75 changes: 75 additions & 0 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define([
'../Core/Matrix3',
'../Core/Matrix4',
'../Core/OrientedBoundingBox',
'../Core/OrthographicFrustum',
'../Core/Rectangle',
'../Core/Request',
'../Core/RequestScheduler',
Expand Down Expand Up @@ -54,6 +55,7 @@ define([
Matrix3,
Matrix4,
OrientedBoundingBox,
OrthographicFrustum,
Rectangle,
Request,
RequestScheduler,
Expand Down Expand Up @@ -607,6 +609,69 @@ define([

var scratchJulianDate = new JulianDate();

/**
* Get the tile's screen space error.
*
* @private
*/
Cesium3DTile.prototype.getScreenSpaceError = function(frameState, useParentGeometricError) {
var tileset = this._tileset;
var parentGeometricError = defined(this.parent) ? this.parent.geometricError : tileset._geometricError;
var geometricError = useParentGeometricError ? parentGeometricError : this.geometricError;
if (geometricError === 0.0) {
// Leaf tiles do not have any error so save the computation
return 0.0;
}

var camera = frameState.camera;
var frustum = camera.frustum;
var context = frameState.context;
var width = context.drawingBufferWidth;
var height = context.drawingBufferHeight;

var error;
if (frameState.mode === SceneMode.SCENE2D || frustum instanceof OrthographicFrustum) {
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
}
var pixelSize = Math.max(frustum.top - frustum.bottom, frustum.right - frustum.left) / Math.max(width, height);
error = geometricError / pixelSize;
} else {
// Avoid divide by zero when viewer is inside the tile
var distance = Math.max(this._distanceToCamera, CesiumMath.EPSILON7);
var sseDenominator = camera.frustum.sseDenominator;
error = (geometricError * height) / (distance * sseDenominator);

if (tileset.dynamicScreenSpaceError) {
var density = tileset._dynamicScreenSpaceErrorComputedDensity;
var factor = tileset.dynamicScreenSpaceErrorFactor;
var dynamicError = CesiumMath.fog(distance, density) * factor;
error -= dynamicError;
}
}

return error;
};

/**
* Update the tile's visibility.
*
* @private
*/
Cesium3DTile.prototype.updateVisibility = function(frameState) {
var parent = this.parent;
var parentTransform = defined(parent) ? parent.computedTransform : this._tileset.modelMatrix;
var parentVisibilityPlaneMask = defined(parent) ? parent._visibilityPlaneMask : CullingVolume.MASK_INDETERMINATE;

this.updateTransform(parentTransform);
this._distanceToCamera = this.distanceToTile(frameState);
this._centerZDepth = this.distanceToTileCenter(frameState);
this._screenSpaceError = this.getScreenSpaceError(frameState);
this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask); // Use parent's plane mask to speed up visibility test
this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE;
this._inRequestVolume = this.insideViewerRequestVolume(frameState);
};

/**
* Update whether the tile has expired.
*
Expand Down Expand Up @@ -846,6 +911,12 @@ define([
return Intersect.INSIDE;
}

if (this._visibilityPlaneMask === CullingVolume.MASK_INSIDE) {
// The tile's bounding volume is completely inside the culling volume so
// the content bounding volume must also be inside.
return Intersect.INSIDE;
}

// PERFORMANCE_IDEA: is it possible to burn less CPU on this test since we know the
// tile's (not the content's) bounding volume intersects the culling volume?
var cullingVolume = frameState.cullingVolume;
Expand Down Expand Up @@ -1055,6 +1126,10 @@ define([
};

function applyDebugSettings(tile, tileset, frameState) {
if (!frameState.passes.render) {
return;
}

var hasContentBoundingVolume = defined(tile._header.content) && defined(tile._header.content.boundingVolume);
var empty = tile.hasEmptyContent || tile.hasTilesetContent;

Expand Down
Loading