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

Height Reference for Corridor, Ellipse, Polygon and Rectangle #6717

Merged
merged 18 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
98 changes: 98 additions & 0 deletions Apps/Sandcastle/gallery/Geometry Height Reference.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!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.

My comments in #6434 (comment) still apply here. I would also like to see some inline comments to explain the feature. If I'm just trying to learn Cesium's capabilities from Sandcastle examples, there's very little context here.

<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="An example for how to use the GeometryHeightProperty to height reference a corridor, ellipse, polygon or rectangle.">
<meta name="cesium-sandcastle-labels" content="Geometries">
<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 cesiumTerrainProvider = Cesium.createWorldTerrain();
var ellipsoidTerrainProvider = new Cesium.EllipsoidTerrainProvider();
Copy link
Contributor

Choose a reason for hiding this comment

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

A line break could probably help here.

var viewer = new Cesium.Viewer('cesiumContainer', {
baseLayerPicker: false,
terrainProvider: cesiumTerrainProvider
});
viewer.scene.globe.depthTestAgainstTerrain = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a comment stating why we need to enable depthTestAgainstTerrain for this demo.


Sandcastle.addToolbarButton('Enable Terrain', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make this a checkbox instead of a button and perhaps fly the camera to the location when it changes (because the shapes went mostly out of view when I toggled it because they dropped so far).

viewer.scene.terrainProvider = cesiumTerrainProvider;
});

Sandcastle.addToolbarButton('Disable Terrain', function() {
viewer.scene.terrainProvider = ellipsoidTerrainProvider;
});


Copy link
Contributor

Choose a reason for hiding this comment

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

Extra whitespace

var baseLon = 6.850615989890521;
var baseLat = 45.89546589994886;
var delta = 0.001;
function addEntity(i, j) {
var lon1 = baseLon + delta*i;
Copy link
Contributor

Choose a reason for hiding this comment

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

Run the formatter on this example

var lon2 = baseLon + delta*i + delta;

var lat1 = baseLat + delta*j;
var lat2 = baseLat + delta*j + delta;
var a = Cesium.Cartesian3.fromDegrees(lon1, lat1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Try looking at this with beginners eyes. Can be do better with variable names here? Is this north/source/east/west? Why are these polygons instead of rectangles?

var b = Cesium.Cartesian3.fromDegrees(lon1, lat2);
var c = Cesium.Cartesian3.fromDegrees(lon2, lat2);
var d = Cesium.Cartesian3.fromDegrees(lon2, lat1);

var positions = [a, b, c, d];
viewer.entities.add({
polygon : {
hierarchy : positions,
material : Cesium.Color.fromRandom({alpha: 1}),
height : new Cesium.GeometryHeightProperty(40.0, Cesium.HeightReference.RELATIVE_TO_GROUND),
extrudedHeight : new Cesium.GeometryHeightProperty(0.0, Cesium.HeightReference.CLAMP_TO_GROUND)
}
});
}

for (var i = 0; i < 4; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

More context/explanation would be good here as well. Again, look at it with beginner's eyes.

for (var j = 0; j < 4; j++) {
addEntity(i, j);
}
}

viewer.scene.camera.flyTo({
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't hard code camera numbers because the result is not the same for all screen sizes/aspect ratios and it also makes Cesium look hard to use. Use the viewer zoom functions instead, if you can't do this view with those, right up an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I just did this because I was trying to find a spot that you could see the polygons both with and without terrain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well actually, this doesn't work for the same reason viewer.flyTo doesn't really work for billboards on terrain. The position changes as the terrain loads in.

destination: new Cesium.Cartesian3(4414709.69060132, 531290.9290968775, 4561007.639489886),
orientation: {
heading: 3.6086529754485834,
pitch: -0.6592870741832781,
roll: 6.28127756699859
}
});
//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.
112 changes: 88 additions & 24 deletions Source/DataSources/CorridorGeometryUpdater.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define([
'../Core/Cartesian3',
'../Core/Check',
'../Core/Color',
'../Core/ColorGeometryInstanceAttribute',
Expand All @@ -8,17 +9,23 @@ define([
'../Core/DeveloperError',
'../Core/DistanceDisplayConditionGeometryInstanceAttribute',
'../Core/GeometryInstance',
'../Core/GeometryOffsetAttribute',
'../Core/Iso8601',
'../Core/OffsetGeometryInstanceAttribute',
'../Core/Rectangle',
'../Core/ShowGeometryInstanceAttribute',
'../Scene/GroundPrimitive',
'../Scene/HeightReference',
'../Scene/MaterialAppearance',
'../Scene/PerInstanceColorAppearance',
'./ColorMaterialProperty',
'./DynamicGeometryUpdater',
'./GeometryHeightProperty',
'./GeometryUpdater',
'./GroundGeometryUpdater',
'./Property'
], function(
Cartesian3,
Check,
Color,
ColorGeometryInstanceAttribute,
Expand All @@ -28,19 +35,27 @@ define([
DeveloperError,
DistanceDisplayConditionGeometryInstanceAttribute,
GeometryInstance,
GeometryOffsetAttribute,
Iso8601,
OffsetGeometryInstanceAttribute,
Rectangle,
ShowGeometryInstanceAttribute,
GroundPrimitive,
HeightReference,
MaterialAppearance,
PerInstanceColorAppearance,
ColorMaterialProperty,
DynamicGeometryUpdater,
GeometryHeightProperty,
GeometryUpdater,
GroundGeometryUpdater,
Property) {
'use strict';

var scratchColor = new Color();
var defaultOffset = Cartesian3.ZERO;
var offsetScratch = new Cartesian3();
var scratchRectangle = new Rectangle();

function CorridorGeometryOptions(entity) {
this.id = entity;
Expand All @@ -51,6 +66,7 @@ define([
this.height = undefined;
this.extrudedHeight = undefined;
this.granularity = undefined;
this.offsetAttribute = undefined;
}

/**
Expand Down Expand Up @@ -99,11 +115,13 @@ define([
var entity = this._entity;
var isAvailable = entity.isAvailable(time);

var attributes;
var attributes = {
show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)),
distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)),
offset : undefined,
color : undefined
};

var color;
var show = new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time));
var distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time));
if (this._materialProperty instanceof ColorMaterialProperty) {
var currentColor;
if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) {
Expand All @@ -112,17 +130,11 @@ define([
if (!defined(currentColor)) {
currentColor = Color.WHITE;
}
color = ColorGeometryInstanceAttribute.fromColor(currentColor);
attributes = {
show : show,
distanceDisplayCondition : distanceDisplayCondition,
color : color
};
} else {
attributes = {
show : show,
distanceDisplayCondition : distanceDisplayCondition
};
attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);
}

if (defined(this._options.offsetAttribute)) {
attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch));
}

return new GeometryInstance({
Expand Down Expand Up @@ -153,17 +165,32 @@ define([
var isAvailable = entity.isAvailable(time);
var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK, scratchColor);

var attributes = {
show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
color : ColorGeometryInstanceAttribute.fromColor(outlineColor),
distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)),
offset : undefined
};

if (defined(this._options.offsetAttribute)) {
attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch));
}

return new GeometryInstance({
id : entity,
geometry : new CorridorOutlineGeometry(this._options),
attributes : {
show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
color : ColorGeometryInstanceAttribute.fromColor(outlineColor),
distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time))
}
attributes : attributes
});
};

CorridorGeometryUpdater.prototype._computeCenter = function(time, result) {
var positions = Property.getValueOrUndefined(this._entity.corridor.positions, time);
if (!defined(positions) || positions.length === 0) {
return;
}
return Cartesian3.clone(positions[Math.floor(positions.length / 2.0)], result);
};

CorridorGeometryUpdater.prototype._isHidden = function(entity, corridor) {
return !defined(corridor.positions) || GeometryUpdater.prototype._isHidden.call(this, entity, corridor);
};
Expand Down Expand Up @@ -199,14 +226,31 @@ define([
var cornerType = corridor.cornerType;
var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty;

var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE);
var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE);

var options = this._options;
options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
options.positions = corridor.positions.getValue(Iso8601.MINIMUM_VALUE, options.positions);
options.height = defined(height) ? height.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.extrudedHeight = defined(extrudedHeight) ? extrudedHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.width = defined(width) ? width.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.cornerType = defined(cornerType) ? cornerType.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE);

if (defined(heightValue) && defined(heightValue.height)) {
heightValue = heightValue.height;
}

if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) {
if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) {
extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle));
} else {
extrudedHeightValue = extrudedHeightValue.height;
}
}

options.height = heightValue;
options.extrudedHeight = extrudedHeightValue;
};

CorridorGeometryUpdater.DynamicGeometryUpdater = DynamicCorridorGeometryUpdater;
Expand All @@ -230,12 +274,32 @@ define([

DynamicCorridorGeometryUpdater.prototype._setOptions = function(entity, corridor, time) {
var options = this._options;
var height = corridor.height;
var extrudedHeight = corridor.extrudedHeight;

var heightValue = Property.getValueOrUndefined(height, time);
var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time);

options.positions = Property.getValueOrUndefined(corridor.positions, time);
options.width = Property.getValueOrUndefined(corridor.width, time);
options.height = Property.getValueOrUndefined(corridor.height, time);
options.extrudedHeight = Property.getValueOrUndefined(corridor.extrudedHeight, time);
options.granularity = Property.getValueOrUndefined(corridor.granularity, time);
options.cornerType = Property.getValueOrUndefined(corridor.cornerType, time);
options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time);

if (defined(heightValue) && defined(heightValue.height)) {
heightValue = heightValue.height;
}

if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) {
if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) {
extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle));
} else {
extrudedHeightValue = extrudedHeightValue.height;
}
}

options.height = heightValue;
options.extrudedHeight = extrudedHeightValue;
};

return CorridorGeometryUpdater;
Expand Down
Loading