Skip to content

Commit 87cc8b0

Browse files
authored
Merge pull request #6362 from AnalyticalGraphicsInc/z-index
Z-ordering for ground geometry entities
2 parents 3300963 + 30ae474 commit 87cc8b0

39 files changed

+986
-107
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
7+
<meta name="description" content="Draw a rectangle or extruded rectangle that conforms to the surface of the globe.">
8+
<meta name="cesium-sandcastle-labels" content="Geometries,New in 1.45">
9+
<title>Cesium Demo</title>
10+
<script type="text/javascript" src="../Sandcastle-header.js"></script>
11+
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
12+
<script type="text/javascript">
13+
if(typeof require === "function") {
14+
require.config({
15+
baseUrl : '../../../Source',
16+
waitSeconds : 120
17+
});
18+
}
19+
</script>
20+
</head>
21+
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
22+
<style>
23+
@import url(../templates/bucket.css);
24+
</style>
25+
<div id="cesiumContainer" class="fullSize"></div>
26+
<div id="loadingOverlay"><h1>Loading...</h1></div>
27+
<div id="toolbar"></div>
28+
<script id="cesium_sandcastle_script">
29+
function startup(Cesium) {
30+
'use strict';
31+
//Sandcastle_Begin
32+
var viewer = new Cesium.Viewer('cesiumContainer');
33+
34+
viewer.entities.add({
35+
rectangle : {
36+
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 20.0, -100.5, 30.0),
37+
material : Cesium.Color.RED,
38+
zIndex: 1
39+
}
40+
});
41+
42+
viewer.entities.add({
43+
rectangle : {
44+
coordinates : Cesium.Rectangle.fromDegrees(-112.0, 25.0, -102.5, 35.0),
45+
material : '../images/Cesium_Logo_Color.jpg',
46+
zIndex: 2
47+
}
48+
});
49+
50+
viewer.entities.add({
51+
rectangle : {
52+
coordinates : Cesium.Rectangle.fromDegrees(-110.0, 31.0, -100.5, 41.0),
53+
material : Cesium.Color.BLUE,
54+
zIndex: 3
55+
}
56+
});
57+
58+
viewer.entities.add({
59+
rectangle : {
60+
coordinates : Cesium.Rectangle.fromDegrees(-99.5, 20.0, -90.0, 30.0),
61+
material : '../images/Cesium_Logo_Color.jpg',
62+
zIndex: 3
63+
}
64+
});
65+
66+
viewer.entities.add({
67+
rectangle : {
68+
coordinates : Cesium.Rectangle.fromDegrees(-97.5, 25.0, -88.0, 35.0),
69+
material : Cesium.Color.GREEN,
70+
zIndex: 2
71+
}
72+
});
73+
74+
viewer.entities.add({
75+
rectangle : {
76+
coordinates : Cesium.Rectangle.fromDegrees(-99.5, 31.0, -90.0, 41.0),
77+
material : Cesium.Color.BLUE,
78+
zIndex: 1
79+
}
80+
});
81+
82+
viewer.zoomTo(viewer.entities);
83+
//Sandcastle_End
84+
Sandcastle.finishedLoading();
85+
}
86+
if (typeof Cesium !== "undefined") {
87+
startup(Cesium);
88+
} else if (typeof require === "function") {
89+
require(["Cesium"], startup);
90+
}
91+
</script>
92+
</body>
93+
</html>
17.7 KB
Loading

CHANGES.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Change Log
33

44
### 1.46 - 2018-06-01
55

6+
##### Breaking Changes :mega:
7+
* Removed `Scene.copyGlobeDepth`. Globe depth will now be copied by default when supported. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
8+
* 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`.
9+
610
##### Deprecated :hourglass_flowing_sand:
711
* The `Scene.fxaa` property has been deprecated and will be removed in Cesium 1.47. Use `Scene.postProcessStages.fxaa.enabled`.
812

@@ -17,6 +21,12 @@ Change Log
1721
* Added `PostProcessStageComposite` for multi-stage post-processes like depth of field.
1822
* Added a new Sandcastle label `Post Processing` to showcase the different built-in post-process stages.
1923
* Added `Rectangle.equalsEpsilon` for comparing the equality of two rectangles [#6533](https://github.com/AnalyticalGraphicsInc/cesium/pull/6533)
24+
* Added `zIndex` for ground geometry, including corridor, ellipse, polygon and rectangle entities. [#6362](https://github.com/AnalyticalGraphicsInc/cesium/pull/6362)
25+
* Added support for materials on terrain entities (entities with unspecified `height`) and `GroundPrimitives`. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
26+
* 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`.
27+
* 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.
28+
* Best suited for notational patterns and not intended for precisely mapping textures to terrain - for that use case, use `SingleTileImageryProvider`.
29+
* 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)
2030

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

31-
##### Breaking Changes :mega:
32-
* Removed `Scene.copyGlobeDepth`. Globe depth will now be copied by default when supported. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
33-
34-
##### Additions :tada:
35-
* Added support for materials on terrain entities (entities with unspecified `height`) and `GroundPrimitives`. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
36-
* 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`.
37-
* 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.
38-
* Best suited for notational patterns and not intended for precisely mapping textures to terrain - for that use case, use `SingleTileImageryProvider`.
39-
* 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)
40-
4141
### 1.45 - 2018-05-01
4242

4343
##### Major Announcements :loudspeaker:

Source/Core/oneTimeWarning.js

+2
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ define([
4747

4848
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.';
4949

50+
oneTimeWarning.geometryZIndex = 'Entity geometry with zIndex are unsupported when height or extrudedHeight are defined. zIndex will be ignored';
51+
5052
return oneTimeWarning;
5153
});

Source/DataSources/BoxGeometryUpdater.js

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ define([
6464
geometryPropertyName : 'box',
6565
observedPropertyNames : ['availability', 'position', 'orientation', 'box']
6666
});
67+
68+
this._onEntityPropertyChanged(entity, 'box', entity.box, undefined);
6769
}
6870

6971
if (defined(Object.create)) {

Source/DataSources/CorridorGeometryUpdater.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ define([
1616
'./ColorMaterialProperty',
1717
'./DynamicGeometryUpdater',
1818
'./GeometryUpdater',
19+
'./GroundGeometryUpdater',
1920
'./Property'
2021
], function(
2122
Check,
@@ -35,6 +36,7 @@ define([
3536
ColorMaterialProperty,
3637
DynamicGeometryUpdater,
3738
GeometryUpdater,
39+
GroundGeometryUpdater,
3840
Property) {
3941
'use strict';
4042

@@ -61,17 +63,19 @@ define([
6163
* @param {Scene} scene The scene where visualization is taking place.
6264
*/
6365
function CorridorGeometryUpdater(entity, scene) {
64-
GeometryUpdater.call(this, {
66+
GroundGeometryUpdater.call(this, {
6567
entity : entity,
6668
scene : scene,
6769
geometryOptions : new CorridorGeometryOptions(entity),
6870
geometryPropertyName : 'corridor',
6971
observedPropertyNames : ['availability', 'corridor']
7072
});
73+
74+
this._onEntityPropertyChanged(entity, 'corridor', entity.corridor, undefined);
7175
}
7276

7377
if (defined(Object.create)) {
74-
CorridorGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);
78+
CorridorGeometryUpdater.prototype = Object.create(GroundGeometryUpdater.prototype);
7579
CorridorGeometryUpdater.prototype.constructor = CorridorGeometryUpdater;
7680
}
7781

@@ -183,6 +187,7 @@ define([
183187
!Property.isConstant(corridor.width) || //
184188
!Property.isConstant(corridor.outlineWidth) || //
185189
!Property.isConstant(corridor.cornerType) || //
190+
!Property.isConstant(corridor.zIndex) || //
186191
(this._onTerrain && !Property.isConstant(this._materialProperty));
187192
};
188193

Source/DataSources/CorridorGraphics.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ define([
3939
* @param {Property} [options.granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the distance between each latitude and longitude.
4040
* @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the corridor casts or receives shadows from each light source.
4141
* @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this corridor will be displayed.
42+
* @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.
4243
*
4344
* @see Entity
4445
* @demo {@link https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}
@@ -74,6 +75,8 @@ define([
7475
this._distanceDisplayConditionSubscription = undefined;
7576
this._classificationType = undefined;
7677
this._classificationTypeSubscription = undefined;
78+
this._zIndex = undefined;
79+
this._zIndexSubscription = undefined;
7780
this._definitionChanged = new Event();
7881

7982
this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
@@ -207,9 +210,17 @@ define([
207210
* Gets or sets the {@link ClassificationType} Property specifying whether this corridor will classify terrain, 3D Tiles, or both when on the ground.
208211
* @memberof CorridorGraphics.prototype
209212
* @type {Property}
210-
* @default ClassificationType.BOTH
213+
* @default ClassificationType.TERRAIN
211214
*/
212-
classificationType : createPropertyDescriptor('classificationType')
215+
classificationType : createPropertyDescriptor('classificationType'),
216+
217+
/**
218+
* 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.
219+
* @memberof CorridorGraphics.prototype
220+
* @type {ConstantProperty}
221+
* @default 0
222+
*/
223+
zIndex: createPropertyDescriptor('zIndex')
213224
});
214225

215226
/**
@@ -237,6 +248,7 @@ define([
237248
result.shadows = this.shadows;
238249
result.distanceDisplayCondition = this.distanceDisplayCondition;
239250
result.classificationType = this.classificationType;
251+
result.zIndex = this.zIndex;
240252
return result;
241253
};
242254

@@ -268,6 +280,7 @@ define([
268280
this.shadows = defaultValue(this.shadows, source.shadows);
269281
this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
270282
this.classificationType = defaultValue(this.classificationType, source.classificationType);
283+
this.zIndex = defaultValue(this.zIndex, source.zIndex);
271284
};
272285

273286
return CorridorGraphics;

Source/DataSources/CylinderGeometryUpdater.js

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ define([
6868
geometryPropertyName: 'cylinder',
6969
observedPropertyNames: ['availability', 'position', 'orientation', 'cylinder']
7070
});
71+
72+
this._onEntityPropertyChanged(entity, 'cylinder', entity.cylinder, undefined);
7173
}
7274

7375
if (defined(Object.create)) {

Source/DataSources/DataSourceDisplay.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ define([
77
'../Core/destroyObject',
88
'../Core/EventHelper',
99
'../Scene/GroundPrimitive',
10+
'../Scene/OrderedGroundPrimitiveCollection',
1011
'../Scene/PrimitiveCollection',
1112
'./BillboardVisualizer',
1213
'./BoundingSphereState',
@@ -26,6 +27,7 @@ define([
2627
destroyObject,
2728
EventHelper,
2829
GroundPrimitive,
30+
OrderedGroundPrimitiveCollection,
2931
PrimitiveCollection,
3032
BillboardVisualizer,
3133
BoundingSphereState,
@@ -362,7 +364,7 @@ define([
362364
var displayGroundPrimitives = this._groundPrimitives;
363365

364366
var primitives = displayPrimitives.add(new PrimitiveCollection());
365-
var groundPrimitives = displayGroundPrimitives.add(new PrimitiveCollection());
367+
var groundPrimitives = displayGroundPrimitives.add(new OrderedGroundPrimitiveCollection());
366368

367369
dataSource._primitives = primitives;
368370
dataSource._groundPrimitives = groundPrimitives;

Source/DataSources/DynamicGeometryBatch.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ define([
1111
/**
1212
* @private
1313
*/
14-
function DynamicGeometryBatch(primitives, groundPrimitives) {
14+
function DynamicGeometryBatch(primitives, orderedGroundPrimitives) {
1515
this._primitives = primitives;
16-
this._groundPrimitives = groundPrimitives;
16+
this._orderedGroundPrimitives = orderedGroundPrimitives;
1717
this._dynamicUpdaters = new AssociativeArray();
1818
}
1919

2020
DynamicGeometryBatch.prototype.add = function(time, updater) {
21-
this._dynamicUpdaters.set(updater.id, updater.createDynamicUpdater(this._primitives, this._groundPrimitives));
21+
this._dynamicUpdaters.set(updater.id, updater.createDynamicUpdater(this._primitives, this._orderedGroundPrimitives));
2222
};
2323

2424
DynamicGeometryBatch.prototype.remove = function(updater) {

Source/DataSources/DynamicGeometryUpdater.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ define([
4141
* @constructor
4242
* @private
4343
*/
44-
function DynamicGeometryUpdater(geometryUpdater, primitives, groundPrimitives) {
44+
function DynamicGeometryUpdater(geometryUpdater, primitives, orderedGroundPrimitives) {
4545
//>>includeStart('debug', pragmas.debug);
4646
Check.defined('geometryUpdater', geometryUpdater);
4747
Check.defined('primitives', primitives);
48-
Check.defined('groundPrimitives', groundPrimitives);
48+
Check.defined('orderedGroundPrimitives', orderedGroundPrimitives);
4949
//>>includeEnd('debug');
5050

5151
this._primitives = primitives;
52-
this._groundPrimitives = groundPrimitives;
52+
this._orderedGroundPrimitives = orderedGroundPrimitives;
5353
this._primitive = undefined;
5454
this._outlinePrimitive = undefined;
5555
this._geometryUpdater = geometryUpdater;
@@ -80,9 +80,9 @@ define([
8080
var onTerrain = geometryUpdater._onTerrain;
8181

8282
var primitives = this._primitives;
83-
var groundPrimitives = this._groundPrimitives;
83+
var orderedGroundPrimitives = this._orderedGroundPrimitives;
8484
if (onTerrain) {
85-
groundPrimitives.removeAndDestroy(this._primitive);
85+
orderedGroundPrimitives.remove(this._primitive);
8686
} else {
8787
primitives.removeAndDestroy(this._primitive);
8888
primitives.removeAndDestroy(this._outlinePrimitive);
@@ -120,12 +120,12 @@ define([
120120

121121
if (onTerrain) {
122122
options.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT;
123-
this._primitive = groundPrimitives.add(new GroundPrimitive({
123+
this._primitive = orderedGroundPrimitives.add(new GroundPrimitive({
124124
geometryInstances : this._geometryUpdater.createFillGeometryInstance(time),
125125
appearance : appearance,
126126
asynchronous : false,
127127
shadows : shadows
128-
}));
128+
}), Property.getValueOrUndefined(this._geometryUpdater.zIndex, time));
129129
} else {
130130
options.vertexFormat = appearance.vertexFormat;
131131

@@ -230,9 +230,9 @@ define([
230230
*/
231231
DynamicGeometryUpdater.prototype.destroy = function() {
232232
var primitives = this._primitives;
233-
var groundPrimitives = this._groundPrimitives;
233+
var orderedGroundPrimitives = this._orderedGroundPrimitives;
234234
if (this._geometryUpdater._onTerrain) {
235-
groundPrimitives.removeAndDestroy(this._primitive);
235+
orderedGroundPrimitives.remove(this._primitive);
236236
} else {
237237
primitives.removeAndDestroy(this._primitive);
238238
}

0 commit comments

Comments
 (0)