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">
<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 : Cesium.Color.GREEN,
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 : Cesium.Color.RED,
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.
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 the entity is dynamic, or height or extrudedHeight are defined. zIndex will be ignored';
Copy link
Contributor

Choose a reason for hiding this comment

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

Are dynamic entities still not supported? This message appears to only be used in one place and doesn't check anything about dynamic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah no, I fixed that. I'll update the message


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 @@ -185,6 +189,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
15 changes: 14 additions & 1 deletion 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 @@ -209,7 +212,15 @@ define([
* @type {Property}
* @default ClassificationType.BOTH
*/
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 All @@ -102,11 +102,11 @@ define([
if (!defined(geometry.fill) || geometry.fill.getValue(time)) {
if (onTerrain) {
options.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT;
this._primitive = groundPrimitives.add(new GroundPrimitive({
this._primitive = orderedGroundPrimitives.add(new GroundPrimitive({
geometryInstances : this._geometryUpdater.createFillGeometryInstance(time),
asynchronous : false,
shadows : shadows
}));
}), Property.getValueOrUndefined(this._geometryUpdater.zIndex, time));
} else {
var fillMaterialProperty = geometryUpdater.fillMaterialProperty;
var isColorAppearance = fillMaterialProperty instanceof ColorMaterialProperty;
Expand Down Expand Up @@ -229,9 +229,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
9 changes: 7 additions & 2 deletions Source/DataSources/EllipseGeometryUpdater.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 Down Expand Up @@ -64,17 +66,19 @@ define([
* @param {Scene} scene The scene where visualization is taking place.
*/
function EllipseGeometryUpdater(entity, scene) {
GeometryUpdater.call(this, {
GroundGeometryUpdater.call(this, {
entity : entity,
scene : scene,
geometryOptions : new EllipseGeometryOptions(entity),
geometryPropertyName : 'ellipse',
observedPropertyNames : ['availability', 'position', 'ellipse']
});

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

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

Expand Down Expand Up @@ -188,6 +192,7 @@ define([
!Property.isConstant(ellipse.stRotation) || //
!Property.isConstant(ellipse.outlineWidth) || //
!Property.isConstant(ellipse.numberOfVerticalLines) || //
!Property.isConstant(ellipse.zIndex) || //
(this._onTerrain && !Property.isConstant(this._materialProperty));
};

Expand Down
Loading