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

Add closeTop and closeBottom to PolygonGeometry #3880

Merged
merged 2 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion Apps/Sandcastle/gallery/CZML Polygon.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
}
},
"extrudedHeight" : 500000.0,
"open" : true
"closeTop" : false,
"closeBottom" : false
}
}, {
"id" : "orangePolygon",
Expand Down
3 changes: 2 additions & 1 deletion Apps/Sandcastle/gallery/Polygon.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
-104.0, 40.0]),
extrudedHeight: 500000.0,
material : Cesium.Color.GREEN,
open : true
closeTop : false,
closeBottom : false
}
});

Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Change Log
*
* Fixed issue causing the sun not to render. [#3801](https://github.com/AnalyticalGraphicsInc/cesium/pull/3801)
* Added ability to import and export Sandcastle example using GitHub Gists. [#3795](https://github.com/AnalyticalGraphicsInc/cesium/pull/3795)
* Added `PolygonGraphics.open` and `PolygonGeometry` option for creating an extruded polygon without a top and bottom.
* Added `PolygonGraphics.closeTop`, `PolygonGraphics.closeBottom`, and `PolygonGeometry` options for creating an extruded polygon without a top or bottom.
* Fixed issue where `Camera.flyTo` does not go to the rectangle. [#3688](https://github.com/AnalyticalGraphicsInc/cesium/issues/3688)
* Fixed issue causing the fog to go dark and the atmosphere to flicker when the camera clips the globe. [#3178](https://github.com/AnalyticalGraphicsInc/cesium/issues/3178)
* Fixed a bug that caused an exception and rendering to stop when using `ArcGisMapServerImageryProvider` to connect to a MapServer specifying the Web Mercator projection and a fullExtent bigger than the valid extent of the projection. [#3854](https://github.com/AnalyticalGraphicsInc/cesium/pull/3854)
Expand Down
197 changes: 118 additions & 79 deletions Source/Core/PolygonGeometry.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Source/DataSources/CzmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,8 @@ define([
processPacketData(Color, polygon, 'outlineColor', polygonData.outlineColor, interval, sourceUri, entityCollection);
processPacketData(Number, polygon, 'outlineWidth', polygonData.outlineWidth, interval, sourceUri, entityCollection);
processPacketData(Boolean, polygon, 'perPositionHeight', polygonData.perPositionHeight, interval, sourceUri, entityCollection);
processPacketData(Boolean, polygon, 'open', polygonData.open, interval, sourceUri, entityCollection);
processPacketData(Boolean, polygon, 'closeTop', polygonData.closeTop, interval, sourceUri, entityCollection);
processPacketData(Boolean, polygon, 'closeBottom', polygonData.closeBottom, interval, sourceUri, entityCollection);
processPositions(polygon, 'hierarchy', polygonData.positions, entityCollection);
}

Expand Down
26 changes: 18 additions & 8 deletions Source/DataSources/PolygonGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ define([
this.vertexFormat = undefined;
this.polygonHierarchy = undefined;
this.perPositionHeight = undefined;
this.open = undefined;
this.closeTop = undefined;
this.closeBottom = undefined;
this.height = undefined;
this.extrudedHeight = undefined;
this.granularity = undefined;
Expand Down Expand Up @@ -454,7 +455,8 @@ define([
var stRotation = polygon.stRotation;
var outlineWidth = polygon.outlineWidth;
var perPositionHeight = polygon.perPositionHeight;
var open = polygon.open;
var closeTop = polygon.closeTop;
var closeBottom = polygon.closeBottom;

this._fillEnabled = fillEnabled;
this._outlineEnabled = outlineEnabled;
Expand All @@ -466,7 +468,8 @@ define([
!Property.isConstant(stRotation) || //
!Property.isConstant(outlineWidth) || //
!Property.isConstant(perPositionHeight) || //
!Property.isConstant(open)) {
!Property.isConstant(closeTop) || //
!Property.isConstant(closeBottom)) {
if (!this._dynamic) {
this._dynamic = true;
this._geometryChanged.raiseEvent(this);
Expand All @@ -481,7 +484,8 @@ define([
}

var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE);
var isOpen = Property.getValueOrUndefined(open, Iso8601.MINIMUM_VALUE);
var closeTopValue = Property.getValueOrDefault(closeTop, Iso8601.MINIMUM_VALUE, true);
var closeBottomValue = Property.getValueOrDefault(closeBottom, Iso8601.MINIMUM_VALUE, true);
var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE);

options.polygonHierarchy = hierarchyValue;
Expand All @@ -490,9 +494,10 @@ define([
options.granularity = Property.getValueOrUndefined(granularity, Iso8601.MINIMUM_VALUE);
options.stRotation = Property.getValueOrUndefined(stRotation, Iso8601.MINIMUM_VALUE);
options.perPositionHeight = Property.getValueOrUndefined(perPositionHeight, Iso8601.MINIMUM_VALUE);
options.open = isOpen;
options.closeTop = closeTopValue;
options.closeBottom = closeBottomValue;
this._outlineWidth = Property.getValueOrDefault(outlineWidth, Iso8601.MINIMUM_VALUE, 1.0);
this._isClosed = defined(extrudedHeightValue) && extrudedHeightValue !== heightValue && !isOpen;
this._isClosed = defined(extrudedHeightValue) && extrudedHeightValue !== heightValue && closeTopValue && closeBottomValue;
this._dynamic = false;
this._geometryChanged.raiseEvent(this);
}
Expand Down Expand Up @@ -530,6 +535,7 @@ define([
this._geometryUpdater = geometryUpdater;
this._options = new GeometryOptions(geometryUpdater._entity);
}

DynamicGeometryUpdater.prototype.update = function(time) {
//>>includeStart('debug', pragmas.debug);
if (!defined(time)) {
Expand Down Expand Up @@ -562,12 +568,16 @@ define([
options.polygonHierarchy = hierarchy;
}

var closeTopValue = Property.getValueOrDefault(polygon.closeTop, time, true);
var closeBottomValue = Property.getValueOrDefault(polygon.closeBottom, time, true);

options.height = Property.getValueOrUndefined(polygon.height, time);
options.extrudedHeight = Property.getValueOrUndefined(polygon.extrudedHeight, time);
options.granularity = Property.getValueOrUndefined(polygon.granularity, time);
options.stRotation = Property.getValueOrUndefined(polygon.stRotation, time);
options.perPositionHeight = Property.getValueOrUndefined(polygon.perPositionHeight, time);
options.open = Property.getValueOrUndefined(polygon.open, time);
options.closeTop = closeTopValue;
options.closeBottom = closeBottomValue;

if (Property.getValueOrDefault(polygon.fill, time, true)) {
var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
Expand All @@ -576,7 +586,7 @@ define([
var appearance = new MaterialAppearance({
material : material,
translucent : material.isTranslucent(),
closed : defined(options.extrudedHeight) && options.extrudedHeight !== options.height
closed : defined(options.extrudedHeight) && options.extrudedHeight !== options.height && closeTopValue && closeBottomValue
});
options.vertexFormat = appearance.vertexFormat;

Expand Down
26 changes: 19 additions & 7 deletions Source/DataSources/PolygonGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ define([
* @param {Property} [options.stRotation=0.0] A numeric property specifying the rotation of the polygon texture counter-clockwise from north.
* @param {Property} [options.granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude point.
* @param {Property} [options.perPositionHeight=false] A boolean specifying whether or not the the height of each position is used.
* @param {Property} [options.open=false] When true, leaves off the top and bottom of an extruded polygon.
* @param {Boolean} [options.closeTop=true] When false, leaves off the top of an extruded polygon open.
* @param {Boolean} [options.closeBottom=true] When false, leaves off the bottom of an extruded polygon open.
*
* @see Entity
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Polygon.html|Cesium Sandcastle Polygon Demo}
Expand Down Expand Up @@ -69,8 +70,10 @@ define([
this._definitionChanged = new Event();
this._fill = undefined;
this._fillSubscription = undefined;
this._open = undefined;
this._openSubscription = undefined;
this._closeTop = undefined;
this._closeTopSubscription = undefined;
this._closeBottom = undefined;
this._closeBottomSubscription = undefined;

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
}
Expand Down Expand Up @@ -187,11 +190,18 @@ define([
perPositionHeight : createPropertyDescriptor('perPositionHeight'),

/**
* Gets or sets the boolean specifying whether or not the the top and bottom an extruded polygon are included.
* Gets or sets a boolean specifying whether or not the top of an extruded polygon is included.
* @memberof PolygonGraphics.prototype
* @type {Property}
*/
open : createPropertyDescriptor('open')
closeTop : createPropertyDescriptor('closeTop'),

/**
* Gets or sets a boolean specifying whether or not the bottom of an extruded polygon is included.
* @memberof PolygonGraphics.prototype
* @type {Property}
*/
closeBottom : createPropertyDescriptor('closeBottom')
});

/**
Expand All @@ -216,7 +226,8 @@ define([
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.perPositionHeight = this.perPositionHeight;
result.open = this.open;
result.closeTop = this.closeTop;
result.closeBottom = this.closeBottom;
return result;
};

Expand Down Expand Up @@ -245,7 +256,8 @@ define([
this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
this.perPositionHeight = defaultValue(this.perPositionHeight, source.perPositionHeight);
this.open = defaultValue(this.open, source.open);
this.closeTop = defaultValue(this.closeTop, source.closeTop);
this.closeBottom = defaultValue(this.closeBottom, source.closeBottom);
};

return PolygonGraphics;
Expand Down
49 changes: 45 additions & 4 deletions Specs/Core/PolygonGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ defineSuite([
expect(p.indices.length).toEqual(numTriangles * 3);
});

it('computes positions extruded and open', function() {
it('computes positions extruded and not closeTop', function() {
var p = PolygonGeometry.createGeometry(PolygonGeometry.fromPositions({
vertexFormat : VertexFormat.POSITION_ONLY,
positions : Cartesian3.fromDegreesArray([
Expand All @@ -388,7 +388,46 @@ defineSuite([
-1.0, 1.0
]),
extrudedHeight: 30000,
open: true
closeTop: false
}));

var numVertices = 37; // 13 bottom + 8 top edge + 8 bottom edge + 4 top corner + 4 bottom corner
var numTriangles = 32; // 16 bottom fill + 2 triangles * 4 sides
expect(p.attributes.position.values.length).toEqual(numVertices * 3);
expect(p.indices.length).toEqual(numTriangles * 3);
});

it('computes positions extruded and not closeBottom', function() {
var p = PolygonGeometry.createGeometry(PolygonGeometry.fromPositions({
vertexFormat : VertexFormat.POSITION_ONLY,
positions : Cartesian3.fromDegreesArray([
-1.0, -1.0,
1.0, -1.0,
1.0, 1.0,
-1.0, 1.0
]),
extrudedHeight: 30000,
closeBottom: false
}));

var numVertices = 37; // 13 top + 8 top edge + 8 bottom edge + 4 top corner + 4 bottom corner
var numTriangles = 32; // 16 top fill + 2 triangles * 4 sides
expect(p.attributes.position.values.length).toEqual(numVertices * 3);
expect(p.indices.length).toEqual(numTriangles * 3);
});

it('computes positions extruded and not closeBottom or closeTop', function() {
var p = PolygonGeometry.createGeometry(PolygonGeometry.fromPositions({
vertexFormat : VertexFormat.POSITION_ONLY,
positions : Cartesian3.fromDegreesArray([
-1.0, -1.0,
1.0, -1.0,
1.0, 1.0,
-1.0, 1.0
]),
extrudedHeight: 30000,
closeTop: false,
closeBottom: false
}));

var numVertices = 24; // 8 top edge + 8 bottom edge + 4 top corner + 4 bottom corner
Expand Down Expand Up @@ -578,7 +617,9 @@ defineSuite([
vertexFormat : VertexFormat.POSITION_ONLY,
polygonHierarchy : hierarchy,
granularity : CesiumMath.PI_OVER_THREE,
perPositionHeight : true
perPositionHeight : true,
closeTop : false,
closeBottom : true
});

function addPositions(array, positions) {
Expand All @@ -593,6 +634,6 @@ defineSuite([
packedInstance.push(3.0, 0.0);
addPositions(packedInstance, holePositions1);
packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z);
packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 50);
packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 1, 51);
createPackableSpecs(PolygonGeometry, polygon, packedInstance);
});
6 changes: 4 additions & 2 deletions Specs/DataSources/CzmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,8 @@ defineSuite([
rgbaf : [0.2, 0.2, 0.2, 0.2]
},
outlineWidth : 6,
open : true
closeTop : false,
closeBottom : false
}
};

Expand All @@ -1422,7 +1423,8 @@ defineSuite([
expect(entity.polygon.outline.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true);
expect(entity.polygon.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2));
expect(entity.polygon.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(6);
expect(entity.polygon.open.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true);
expect(entity.polygon.closeTop.getValue(Iso8601.MINIMUM_VALUE)).toEqual(false);
expect(entity.polygon.closeBottom.getValue(Iso8601.MINIMUM_VALUE)).toEqual(false);
});

it('CZML adds data for constrained polygon.', function() {
Expand Down
30 changes: 22 additions & 8 deletions Specs/DataSources/PolygonGeometryUpdaterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,19 @@ defineSuite([
expect(updater.isClosed).toBe(true);
});

it('Settings extrudedHeight and open causes geometry to be open.', function() {
it('Settings extrudedHeight and closeTop false causes geometry to be open.', function() {
var entity = createBasicPolygon();
var updater = new PolygonGeometryUpdater(entity, scene);
entity.polygon.extrudedHeight = new ConstantProperty(1000);
entity.polygon.open = true;
entity.polygon.closeTop = false;
expect(updater.isClosed).toBe(false);
});

it('Settings extrudedHeight and closeBottom false causes geometry to be open.', function() {
var entity = createBasicPolygon();
var updater = new PolygonGeometryUpdater(entity, scene);
entity.polygon.extrudedHeight = new ConstantProperty(1000);
entity.polygon.closeBottom = false;
expect(updater.isClosed).toBe(false);
});

Expand Down Expand Up @@ -224,7 +232,8 @@ defineSuite([
polygon.outline = new ConstantProperty(options.outline);
polygon.outlineColor = new ConstantProperty(options.outlineColor);
polygon.perPositionHeight = new ConstantProperty(options.perPositionHeight);
polygon.open = new ConstantProperty(options.open);
polygon.closeTop = new ConstantProperty(options.closeTop);
polygon.closeBottom = new ConstantProperty(options.closeBottom);

polygon.stRotation = new ConstantProperty(options.stRotation);
polygon.height = new ConstantProperty(options.height);
Expand All @@ -243,7 +252,8 @@ defineSuite([
expect(geometry._height).toEqual(options.height);
expect(geometry._granularity).toEqual(options.granularity);
expect(geometry._extrudedHeight).toEqual(options.extrudedHeight);
expect(geometry._open).toEqual(options.open);
expect(geometry._closeTop).toEqual(options.closeTop);
expect(geometry._closeBottom).toEqual(options.closeBottom);

attributes = instance.attributes;
if (options.material instanceof ColorMaterialProperty) {
Expand Down Expand Up @@ -280,7 +290,8 @@ defineSuite([
outline : true,
outlineColor : Color.BLUE,
perPositionHeight : true,
open: false
closeTop: true,
closeBottom: false
});
});

Expand All @@ -296,7 +307,8 @@ defineSuite([
outline : true,
outlineColor : Color.BLUE,
perPositionHeight : false,
open : true
closeTop: false,
closeBottom: true
});
});

Expand Down Expand Up @@ -404,7 +416,8 @@ defineSuite([
polygon.perPositionHeight = createDynamicProperty(false);
polygon.granularity = createDynamicProperty(2);
polygon.stRotation = createDynamicProperty(1);
polygon.open = createDynamicProperty(true);
polygon.closeTop = createDynamicProperty(false);
polygon.closeBottom = createDynamicProperty(false);

var entity = new Entity();
entity.polygon = polygon;
Expand All @@ -426,7 +439,8 @@ defineSuite([
expect(options.perPositionHeight).toEqual(polygon.perPositionHeight.getValue());
expect(options.granularity).toEqual(polygon.granularity.getValue());
expect(options.stRotation).toEqual(polygon.stRotation.getValue());
expect(options.open).toEqual(polygon.open.getValue());
expect(options.closeTop).toEqual(polygon.closeTop.getValue());
expect(options.closeBottom).toEqual(polygon.closeBottom.getValue());

entity.show = false;
dynamicUpdater.update(JulianDate.now());
Expand Down
Loading