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 ability to create open extruded PolygonGeometry #3879

Merged
merged 5 commits into from
Apr 26, 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
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/CZML Polygon.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
}
}
},
"extrudedHeight" : 500000.0
"extrudedHeight" : 500000.0,
"closeTop" : false,
"closeBottom" : false
}
}, {
"id" : "orangePolygon",
Expand Down
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/Polygon.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
-100.0, 42.0,
-104.0, 40.0]),
extrudedHeight: 500000.0,
material : Cesium.Color.GREEN
material : Cesium.Color.GREEN,
closeTop : false,
closeBottom : false
}
});

Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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.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
199 changes: 124 additions & 75 deletions Source/Core/PolygonGeometry.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Source/DataSources/CzmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +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, 'closeTop', polygonData.closeTop, interval, sourceUri, entityCollection);
processPacketData(Boolean, polygon, 'closeBottom', polygonData.closeBottom, interval, sourceUri, entityCollection);
processPositions(polygon, 'hierarchy', polygonData.positions, entityCollection);
}

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

this._fillEnabled = fillEnabled;
this._outlineEnabled = outlineEnabled;
Expand All @@ -463,7 +467,9 @@ define([
!Property.isConstant(granularity) || //
!Property.isConstant(stRotation) || //
!Property.isConstant(outlineWidth) || //
!Property.isConstant(perPositionHeight)) {
!Property.isConstant(perPositionHeight) || //
!Property.isConstant(closeTop) || //
!Property.isConstant(closeBottom)) {
if (!this._dynamic) {
this._dynamic = true;
this._geometryChanged.raiseEvent(this);
Expand All @@ -477,17 +483,21 @@ define([
hierarchyValue = new PolygonHierarchy(hierarchyValue);
}

var heightValue = defined(height) ? height.getValue(Iso8601.MINIMUM_VALUE) : undefined;
var extrudedHeightValue = defined(extrudedHeight) ? extrudedHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined;
var heightValue = Property.getValueOrUndefined(height, 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;
options.height = heightValue;
options.extrudedHeight = extrudedHeightValue;
options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.stRotation = defined(stRotation) ? stRotation.getValue(Iso8601.MINIMUM_VALUE) : undefined;
options.perPositionHeight = defined(perPositionHeight) ? perPositionHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined;
this._outlineWidth = defined(outlineWidth) ? outlineWidth.getValue(Iso8601.MINIMUM_VALUE) : 1.0;
this._isClosed = defined(extrudedHeightValue) && extrudedHeightValue !== heightValue;
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.closeTop = closeTopValue;
options.closeBottom = closeBottomValue;
this._outlineWidth = Property.getValueOrDefault(outlineWidth, Iso8601.MINIMUM_VALUE, 1.0);
this._isClosed = defined(extrudedHeightValue) && extrudedHeightValue !== heightValue && closeTopValue && closeBottomValue;
this._dynamic = false;
this._geometryChanged.raiseEvent(this);
}
Expand Down Expand Up @@ -525,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 @@ -557,11 +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.closeTop = closeTopValue;
options.closeBottom = closeBottomValue;

if (Property.getValueOrDefault(polygon.fill, time, true)) {
var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
Expand All @@ -570,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: 25 additions & 1 deletion Source/DataSources/PolygonGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +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 {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 @@ -68,6 +70,10 @@ define([
this._definitionChanged = new Event();
this._fill = undefined;
this._fillSubscription = undefined;
this._closeTop = undefined;
this._closeTopSubscription = undefined;
this._closeBottom = undefined;
this._closeBottomSubscription = undefined;

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
}
Expand Down Expand Up @@ -181,7 +187,21 @@ define([
* @memberof PolygonGraphics.prototype
* @type {Property}
*/
perPositionHeight : createPropertyDescriptor('perPositionHeight')
perPositionHeight : createPropertyDescriptor('perPositionHeight'),

/**
* Gets or sets a boolean specifying whether or not the top of an extruded polygon is included.
* @memberof PolygonGraphics.prototype
* @type {Property}
*/
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 @@ -206,6 +226,8 @@ define([
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.perPositionHeight = this.perPositionHeight;
result.closeTop = this.closeTop;
result.closeBottom = this.closeBottom;
return result;
};

Expand Down Expand Up @@ -234,6 +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.closeTop = defaultValue(this.closeTop, source.closeTop);
this.closeBottom = defaultValue(this.closeBottom, source.closeBottom);
};

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

it('computes positions extruded and not 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
}));

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
var numTriangles = 16; // 2 triangles * 4 sides
expect(p.attributes.position.values.length).toEqual(numVertices * 3);
expect(p.indices.length).toEqual(numTriangles * 3);
});

it('removes duplicates extruded', function() {
var p = PolygonGeometry.createGeometry(PolygonGeometry.fromPositions({
vertexFormat : VertexFormat.POSITION_ONLY,
Expand Down Expand Up @@ -559,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 @@ -574,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, 49);
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: 5 additions & 1 deletion Specs/DataSources/CzmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,9 @@ defineSuite([
outlineColor : {
rgbaf : [0.2, 0.2, 0.2, 0.2]
},
outlineWidth : 6
outlineWidth : 6,
closeTop : false,
closeBottom : false
}
};

Expand All @@ -1421,6 +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.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
32 changes: 30 additions & 2 deletions Specs/DataSources/PolygonGeometryUpdaterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ defineSuite([
expect(updater.isClosed).toBe(true);
});

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.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);
});

it('A time-varying outlineWidth causes geometry to be dynamic', function() {
var entity = createBasicPolygon();
var updater = new PolygonGeometryUpdater(entity, scene);
Expand Down Expand Up @@ -216,6 +232,8 @@ defineSuite([
polygon.outline = new ConstantProperty(options.outline);
polygon.outlineColor = new ConstantProperty(options.outlineColor);
polygon.perPositionHeight = new ConstantProperty(options.perPositionHeight);
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 @@ -234,6 +252,8 @@ defineSuite([
expect(geometry._height).toEqual(options.height);
expect(geometry._granularity).toEqual(options.granularity);
expect(geometry._extrudedHeight).toEqual(options.extrudedHeight);
expect(geometry._closeTop).toEqual(options.closeTop);
expect(geometry._closeBottom).toEqual(options.closeBottom);

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

Expand All @@ -284,7 +306,9 @@ defineSuite([
fill : true,
outline : true,
outlineColor : Color.BLUE,
perPositionHeight : false
perPositionHeight : false,
closeTop: false,
closeBottom: true
});
});

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

var entity = new Entity();
entity.polygon = polygon;
Expand All @@ -413,6 +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.closeTop).toEqual(polygon.closeTop.getValue());
expect(options.closeBottom).toEqual(polygon.closeBottom.getValue());

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