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

Z-ordering for ground geometry entities #6362

Merged
merged 17 commits into from
May 22, 2018
93 changes: 93 additions & 0 deletions Apps/Sandcastle/gallery/Z-Indexing Geometry.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!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="Draw a rectangle or extruded rectangle that conforms to the surface of the globe.">
<meta name="cesium-sandcastle-labels" content="Geometries,New in 1.45">
<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');

viewer.entities.add({
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 20.0, -100.5, 30.0),
material : Cesium.Color.RED,
zIndex: 1
}
});

viewer.entities.add({
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-112.0, 25.0, -102.5, 35.0),
material : '../images/Cesium_Logo_Color.jpg',
zIndex: 2
}
});

viewer.entities.add({
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 31.0, -100.5, 41.0),
material : Cesium.Color.BLUE,
zIndex: 3
}
});

viewer.entities.add({
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-99.5, 20.0, -90.0, 30.0),
material : '../images/Cesium_Logo_Color.jpg',
zIndex: 3
}
});

viewer.entities.add({
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-97.5, 25.0, -88.0, 35.0),
material : Cesium.Color.GREEN,
zIndex: 2
}
});

viewer.entities.add({
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-99.5, 31.0, -90.0, 41.0),
material : Cesium.Color.BLUE,
zIndex: 1
}
});

viewer.zoomTo(viewer.entities);
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/Z-Indexing Geometry.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Change Log

### 1.46 - 2018-06-01

##### Breaking Changes :mega:
* Removed `Scene.copyGlobeDepth`. Globe depth will now be copied by default when supported. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
* The default `classificationType` for `GroundPrimitive`, `CorridorGraphics`, `EllipseGraphics`, `PolygonGraphics` and `RectangleGraphics` is now `ClassificationType.TERRAIN`. If you wish the geometry to color both terrain and 3D tiles, pass in the option `classificationType: Cesium.ClassificationType.BOTH`.

##### Deprecated :hourglass_flowing_sand:
* The `Scene.fxaa` property has been deprecated and will be removed in Cesium 1.47. Use `Scene.postProcessStages.fxaa.enabled`.

Expand All @@ -17,6 +21,12 @@ Change Log
* Added `PostProcessStageComposite` for multi-stage post-processes like depth of field.
* Added a new Sandcastle label `Post Processing` to showcase the different built-in post-process stages.
* Added `Rectangle.equalsEpsilon` for comparing the equality of two rectangles [#6533](https://github.com/AnalyticalGraphicsInc/cesium/pull/6533)
* Added `zIndex` for ground geometry, including corridor, ellipse, polygon and rectangle entities. [#6362](https://github.com/AnalyticalGraphicsInc/cesium/pull/6362)
* Added support for materials on terrain entities (entities with unspecified `height`) and `GroundPrimitives`. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
* Only available for `ClassificationType.TERRAIN` at this time. Adding a material to a terrain `Entity` will cause it to behave as if it is `ClassificationType.TERRAIN`.
* Requires depth texture support (`WEBGL_depth_texture` or `WEBKIT_WEBGL_depth_texture`), so materials on terrain entities and `GroundPrimitives` are not supported in Internet Explorer.
* Best suited for notational patterns and not intended for precisely mapping textures to terrain - for that use case, use `SingleTileImageryProvider`.
* Added `GroundPrimitive.supportsMaterials` and `Entity.supportsMaterialsforEntitiesOnTerrain`, both of which can be used to check if materials on terrain entities and `GroundPrimitives` is supported. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)

##### Fixes :wrench:
* Fixed a bug causing custom TilingScheme classes to not be able to use a GeographicProjection. [#6524](https://github.com/AnalyticalGraphicsInc/cesium/pull/6524)
Expand All @@ -28,16 +38,6 @@ Change Log
* Fixed polygon outline when using `perPositionHeight` and `extrudedHeight`. [#6595](https://github.com/AnalyticalGraphicsInc/cesium/issues/6595)
* Fixed broken links in documentation of `createTileMapServiceImageryProvider`. [#5818](https://github.com/AnalyticalGraphicsInc/cesium/issues/5818)

##### Breaking Changes :mega:
* Removed `Scene.copyGlobeDepth`. Globe depth will now be copied by default when supported. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)

##### Additions :tada:
* Added support for materials on terrain entities (entities with unspecified `height`) and `GroundPrimitives`. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
* Only available for `ClassificationType.TERRAIN` at this time. Adding a material to a terrain `Entity` will cause it to behave as if it is `ClassificationType.TERRAIN`.
* Requires depth texture support (`WEBGL_depth_texture` or `WEBKIT_WEBGL_depth_texture`), so materials on terrain entities and `GroundPrimitives` are not supported in Internet Explorer.
* Best suited for notational patterns and not intended for precisely mapping textures to terrain - for that use case, use `SingleTileImageryProvider`.
* Added `GroundPrimitive.supportsMaterials` and `Entity.supportsMaterialsforEntitiesOnTerrain`, both of which can be used to check if materials on terrain entities and `GroundPrimitives` is supported. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)

### 1.45 - 2018-05-01

##### Major Announcements :loudspeaker:
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/oneTimeWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ define([

oneTimeWarning.geometryOutlines = 'Entity geometry outlines are unsupported on terrain. Outlines will be disabled. To enable outlines, disable geometry terrain clamping by explicitly setting height to 0.';

oneTimeWarning.geometryZIndex = 'Entity geometry with zIndex are unsupported when height or extrudedHeight are defined. zIndex will be ignored';

return oneTimeWarning;
});
2 changes: 2 additions & 0 deletions Source/DataSources/BoxGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ define([
geometryPropertyName : 'box',
observedPropertyNames : ['availability', 'position', 'orientation', 'box']
});

this._onEntityPropertyChanged(entity, 'box', entity.box, undefined);
}

if (defined(Object.create)) {
Expand Down
9 changes: 7 additions & 2 deletions Source/DataSources/CorridorGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define([
'./ColorMaterialProperty',
'./DynamicGeometryUpdater',
'./GeometryUpdater',
'./GroundGeometryUpdater',
'./Property'
], function(
Check,
Expand All @@ -35,6 +36,7 @@ define([
ColorMaterialProperty,
DynamicGeometryUpdater,
GeometryUpdater,
GroundGeometryUpdater,
Property) {
'use strict';

Expand All @@ -61,17 +63,19 @@ define([
* @param {Scene} scene The scene where visualization is taking place.
*/
function CorridorGeometryUpdater(entity, scene) {
GeometryUpdater.call(this, {
GroundGeometryUpdater.call(this, {
entity : entity,
scene : scene,
geometryOptions : new CorridorGeometryOptions(entity),
geometryPropertyName : 'corridor',
observedPropertyNames : ['availability', 'corridor']
});

this._onEntityPropertyChanged(entity, 'corridor', entity.corridor, undefined);
}

if (defined(Object.create)) {
CorridorGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);
CorridorGeometryUpdater.prototype = Object.create(GroundGeometryUpdater.prototype);
CorridorGeometryUpdater.prototype.constructor = CorridorGeometryUpdater;
}

Expand Down Expand Up @@ -183,6 +187,7 @@ define([
!Property.isConstant(corridor.width) || //
!Property.isConstant(corridor.outlineWidth) || //
!Property.isConstant(corridor.cornerType) || //
!Property.isConstant(corridor.zIndex) || //
(this._onTerrain && !Property.isConstant(this._materialProperty));
};

Expand Down
17 changes: 15 additions & 2 deletions Source/DataSources/CorridorGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ define([
* @param {Property} [options.granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the distance between each latitude and longitude.
* @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the corridor casts or receives shadows from each light source.
* @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this corridor will be displayed.
* @param {ConstantProperty} [options.zIndex] A Property specifying the zIndex of the corridor, used for ordering. Only has an effect if height and extrudedHeight are undefined, and if the corridor is static.
*
* @see Entity
* @demo {@link https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}
Expand Down Expand Up @@ -74,6 +75,8 @@ define([
this._distanceDisplayConditionSubscription = undefined;
this._classificationType = undefined;
this._classificationTypeSubscription = undefined;
this._zIndex = undefined;
this._zIndexSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -207,9 +210,17 @@ define([
* Gets or sets the {@link ClassificationType} Property specifying whether this corridor will classify terrain, 3D Tiles, or both when on the ground.
* @memberof CorridorGraphics.prototype
* @type {Property}
* @default ClassificationType.BOTH
* @default ClassificationType.TERRAIN
*/
classificationType : createPropertyDescriptor('classificationType')
classificationType : createPropertyDescriptor('classificationType'),

/**
* Gets or sets the zIndex Property specifying the ordering of the corridor. Only has an effect if the coridor is static and neither height or exturdedHeight are specified.
* @memberof CorridorGraphics.prototype
* @type {ConstantProperty}
* @default 0
Copy link
Contributor

Choose a reason for hiding this comment

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

All of the defaults say 0, but there's not actually a default is there? It's just undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

undefined === 0 for zIndex. I defaultValue(zIndex, 0) in the geometry updaters

*/
zIndex: createPropertyDescriptor('zIndex')
});

/**
Expand Down Expand Up @@ -237,6 +248,7 @@ define([
result.shadows = this.shadows;
result.distanceDisplayCondition = this.distanceDisplayCondition;
result.classificationType = this.classificationType;
result.zIndex = this.zIndex;
return result;
};

Expand Down Expand Up @@ -268,6 +280,7 @@ define([
this.shadows = defaultValue(this.shadows, source.shadows);
this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
this.classificationType = defaultValue(this.classificationType, source.classificationType);
this.zIndex = defaultValue(this.zIndex, source.zIndex);
};

return CorridorGraphics;
Expand Down
2 changes: 2 additions & 0 deletions Source/DataSources/CylinderGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ define([
geometryPropertyName: 'cylinder',
observedPropertyNames: ['availability', 'position', 'orientation', 'cylinder']
});

this._onEntityPropertyChanged(entity, 'cylinder', entity.cylinder, undefined);
}

if (defined(Object.create)) {
Expand Down
4 changes: 3 additions & 1 deletion Source/DataSources/DataSourceDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define([
'../Core/destroyObject',
'../Core/EventHelper',
'../Scene/GroundPrimitive',
'../Scene/OrderedGroundPrimitiveCollection',
'../Scene/PrimitiveCollection',
'./BillboardVisualizer',
'./BoundingSphereState',
Expand All @@ -26,6 +27,7 @@ define([
destroyObject,
EventHelper,
GroundPrimitive,
OrderedGroundPrimitiveCollection,
PrimitiveCollection,
BillboardVisualizer,
BoundingSphereState,
Expand Down Expand Up @@ -362,7 +364,7 @@ define([
var displayGroundPrimitives = this._groundPrimitives;

var primitives = displayPrimitives.add(new PrimitiveCollection());
var groundPrimitives = displayGroundPrimitives.add(new PrimitiveCollection());
var groundPrimitives = displayGroundPrimitives.add(new OrderedGroundPrimitiveCollection());

dataSource._primitives = primitives;
dataSource._groundPrimitives = groundPrimitives;
Expand Down
6 changes: 3 additions & 3 deletions Source/DataSources/DynamicGeometryBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ define([
/**
* @private
*/
function DynamicGeometryBatch(primitives, groundPrimitives) {
function DynamicGeometryBatch(primitives, orderedGroundPrimitives) {
this._primitives = primitives;
this._groundPrimitives = groundPrimitives;
this._orderedGroundPrimitives = orderedGroundPrimitives;
this._dynamicUpdaters = new AssociativeArray();
}

DynamicGeometryBatch.prototype.add = function(time, updater) {
this._dynamicUpdaters.set(updater.id, updater.createDynamicUpdater(this._primitives, this._groundPrimitives));
this._dynamicUpdaters.set(updater.id, updater.createDynamicUpdater(this._primitives, this._orderedGroundPrimitives));
};

DynamicGeometryBatch.prototype.remove = function(updater) {
Expand Down
18 changes: 9 additions & 9 deletions Source/DataSources/DynamicGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ define([
* @constructor
* @private
*/
function DynamicGeometryUpdater(geometryUpdater, primitives, groundPrimitives) {
function DynamicGeometryUpdater(geometryUpdater, primitives, orderedGroundPrimitives) {
//>>includeStart('debug', pragmas.debug);
Check.defined('geometryUpdater', geometryUpdater);
Check.defined('primitives', primitives);
Check.defined('groundPrimitives', groundPrimitives);
Check.defined('orderedGroundPrimitives', orderedGroundPrimitives);
//>>includeEnd('debug');

this._primitives = primitives;
this._groundPrimitives = groundPrimitives;
this._orderedGroundPrimitives = orderedGroundPrimitives;
this._primitive = undefined;
this._outlinePrimitive = undefined;
this._geometryUpdater = geometryUpdater;
Expand Down Expand Up @@ -80,9 +80,9 @@ define([
var onTerrain = geometryUpdater._onTerrain;

var primitives = this._primitives;
var groundPrimitives = this._groundPrimitives;
var orderedGroundPrimitives = this._orderedGroundPrimitives;
if (onTerrain) {
groundPrimitives.removeAndDestroy(this._primitive);
orderedGroundPrimitives.remove(this._primitive);
} else {
primitives.removeAndDestroy(this._primitive);
primitives.removeAndDestroy(this._outlinePrimitive);
Expand Down Expand Up @@ -120,12 +120,12 @@ define([

if (onTerrain) {
options.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT;
this._primitive = groundPrimitives.add(new GroundPrimitive({
this._primitive = orderedGroundPrimitives.add(new GroundPrimitive({
geometryInstances : this._geometryUpdater.createFillGeometryInstance(time),
appearance : appearance,
asynchronous : false,
shadows : shadows
}));
}), Property.getValueOrUndefined(this._geometryUpdater.zIndex, time));
} else {
options.vertexFormat = appearance.vertexFormat;

Expand Down Expand Up @@ -230,9 +230,9 @@ define([
*/
DynamicGeometryUpdater.prototype.destroy = function() {
var primitives = this._primitives;
var groundPrimitives = this._groundPrimitives;
var orderedGroundPrimitives = this._orderedGroundPrimitives;
if (this._geometryUpdater._onTerrain) {
groundPrimitives.removeAndDestroy(this._primitive);
orderedGroundPrimitives.remove(this._primitive);
} else {
primitives.removeAndDestroy(this._primitive);
}
Expand Down
Loading