Skip to content

Commit

Permalink
Merge pull request #6791 from AnalyticalGraphicsInc/entity-polygon
Browse files Browse the repository at this point in the history
Support for vertical polygons
  • Loading branch information
mramato authored Jul 16, 2018
2 parents 5585535 + c9550f5 commit d403745
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 11 deletions.
28 changes: 22 additions & 6 deletions Apps/Sandcastle/gallery/Polygon.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
<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">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
if(typeof require === "function") {
require.config({
baseUrl : '../../../Source',
waitSeconds : 120
});
}
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
Expand Down Expand Up @@ -108,8 +110,22 @@
}
});

viewer.zoomTo(viewer.entities);
//Sandcastle_End
var cyanPolygon = viewer.entities.add({
name : 'Cyan vertical polygon with per-position heights and outline',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArrayHeights([
-90.0, 41.0, 0.0,
-85.0, 41.0, 500000.0,
-80.0, 41.0, 0.0
]),
perPositionHeight : true,
material : Cesium.Color.CYAN.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.BLACK
}
});

viewer.zoomTo(viewer.entities);//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
Expand Down
Binary file modified Apps/Sandcastle/gallery/Polygon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Change Log
##### Additions :tada:
* Added support for loading Draco compressed Point Cloud tiles for 2-3x better compression. [#6559](https://github.com/AnalyticalGraphicsInc/cesium/pull/6559)
* Added `TimeDynamicPointCloud` for playback of time-dynamic point cloud data, where each frame is a 3D Tiles Point Cloud tile. [#6721](https://github.com/AnalyticalGraphicsInc/cesium/pull/6721)
* Added `CoplanarPolygonGeometry` and `CoplanarPolygonGeometryOutline` for drawing polygons composed of coplanar positions that are not necessarliy on the ellipsoid surface. [#6769](https://github.com/AnalyticalGraphicsInc/cesium/pull/6769)
* Added `CoplanarPolygonGeometry` and `CoplanarPolygonGeometryOutline` for drawing polygons composed of coplanar positions that are not necessarily on the ellipsoid surface. [#6769](https://github.com/AnalyticalGraphicsInc/cesium/pull/6769)
* Improved support for polygon entities using `perPositionHeight`, including supporting vertical polygons. This also improves KML compatibility. [#6791](https://github.com/AnalyticalGraphicsInc/cesium/pull/6791)

##### Deprecated :hourglass_flowing_sand:
* Support for 3D Tiles `content.url` is deprecated to reflect updates to the [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/pull/301). Use `content.uri instead`. Support for `content.url` will remain for backwards compatibility. [#6744](https://github.com/AnalyticalGraphicsInc/cesium/pull/6744)
Expand Down
27 changes: 23 additions & 4 deletions Source/DataSources/PolygonGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ define([
'../Core/Check',
'../Core/Color',
'../Core/ColorGeometryInstanceAttribute',
'../Core/CoplanarPolygonGeometry',
'../Core/CoplanarPolygonOutlineGeometry',
'../Core/defined',
'../Core/DeveloperError',
'../Core/DistanceDisplayConditionGeometryInstanceAttribute',
Expand Down Expand Up @@ -32,6 +34,8 @@ define([
Check,
Color,
ColorGeometryInstanceAttribute,
CoplanarPolygonGeometry,
CoplanarPolygonOutlineGeometry,
defined,
DeveloperError,
DistanceDisplayConditionGeometryInstanceAttribute,
Expand Down Expand Up @@ -120,6 +124,7 @@ define([

var entity = this._entity;
var isAvailable = entity.isAvailable(time);
var options = this._options;

var attributes = {
show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)),
Expand All @@ -138,13 +143,20 @@ define([
}
attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);
}
if (defined(this._options.offsetAttribute)) {
if (defined(options.offsetAttribute)) {
attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch));
}

var geometry;
if (options.perPositionHeight && !defined(options.extrudedHeight)) {
geometry = new CoplanarPolygonGeometry(options);
} else {
geometry = new PolygonGeometry(options);
}

return new GeometryInstance({
id : entity,
geometry : new PolygonGeometry(this._options),
geometry : geometry,
attributes : attributes
});
};
Expand All @@ -168,6 +180,7 @@ define([

var entity = this._entity;
var isAvailable = entity.isAvailable(time);
var options = this._options;
var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK, scratchColor);
var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time);

Expand All @@ -178,13 +191,19 @@ define([
offset : undefined
};

if (defined(this._options.offsetAttribute)) {
if (defined(options.offsetAttribute)) {
attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch));
}

var geometry;
if (options.perPositionHeight && !defined(options.extrudedHeight)) {
geometry = new CoplanarPolygonOutlineGeometry(options);
} else {
geometry = new PolygonOutlineGeometry(options);
}
return new GeometryInstance({
id : entity,
geometry : new PolygonOutlineGeometry(this._options),
geometry : geometry,
attributes : attributes
});
};
Expand Down
46 changes: 46 additions & 0 deletions Specs/DataSources/PolygonGeometryUpdaterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ defineSuite([
'Core/GeometryOffsetAttribute',
'Core/JulianDate',
'Core/Math',
'Core/CoplanarPolygonGeometry',
'Core/CoplanarPolygonOutlineGeometry',
'Core/PolygonGeometry',
'Core/PolygonOutlineGeometry',
'Core/PolygonHierarchy',
'Core/TimeIntervalCollection',
'DataSources/ConstantProperty',
Expand All @@ -29,6 +33,10 @@ defineSuite([
GeometryOffsetAttribute,
JulianDate,
CesiumMath,
CoplanarPolygonGeometry,
CoplanarPolygonOutlineGeometry,
PolygonGeometry,
PolygonOutlineGeometry,
PolygonHierarchy,
TimeIntervalCollection,
ConstantProperty,
Expand Down Expand Up @@ -78,6 +86,19 @@ defineSuite([
return entity;
}

function createVerticalPolygon() {
var polygon = new PolygonGraphics();
polygon.hierarchy = new ConstantProperty(new PolygonHierarchy(Cartesian3.fromDegreesArrayHeights([
-1.0, 1.0, 0.0,
-2.0, 1.0, 0.0,
-2.0, 1.0, 0.0
])));
polygon.perPositionHeight = true;
var entity = new Entity();
entity.polygon = polygon;
return entity;
}

function createDynamicPolygon() {
var entity = createBasicPolygon();
entity.polygon.extrudedHeight = createDynamicProperty(2);
Expand Down Expand Up @@ -231,6 +252,7 @@ defineSuite([
var geometry;
instance = updater.createFillGeometryInstance(time);
geometry = instance.geometry;
expect(geometry).toBeInstanceOf(PolygonGeometry);
expect(geometry._stRotation).toEqual(options.stRotation);
expect(geometry._height).toEqual(options.height);
expect(geometry._granularity).toEqual(options.granularity);
Expand All @@ -241,13 +263,37 @@ defineSuite([

instance = updater.createOutlineGeometryInstance(time);
geometry = instance.geometry;
expect(geometry).toBeInstanceOf(PolygonOutlineGeometry);
expect(geometry._height).toEqual(options.height);
expect(geometry._granularity).toEqual(options.granularity);
expect(geometry._extrudedHeight).toEqual(options.extrudedHeight);
expect(geometry._perPositionHeight).toEqual(options.perPositionHeight);
expect(geometry._offsetAttribute).toBeUndefined();
});

it('Creates coplanar polygon', function() {
var stRotation = 12;

var entity = createVerticalPolygon();

var polygon = entity.polygon;
polygon.outline = true;
polygon.stRotation = new ConstantProperty(stRotation);

var updater = new PolygonGeometryUpdater(entity, scene);

var instance;
var geometry;
instance = updater.createFillGeometryInstance(time);
geometry = instance.geometry;
expect(geometry).toBeInstanceOf(CoplanarPolygonGeometry);
expect(geometry._stRotation).toEqual(stRotation);

instance = updater.createOutlineGeometryInstance(time);
geometry = instance.geometry;
expect(geometry).toBeInstanceOf(CoplanarPolygonOutlineGeometry);
});

it('Checks that a polygon with per position heights isn\'t on terrain', function() {
var entity = createBasicPolygon();
entity.polygon.height = undefined;
Expand Down

0 comments on commit d403745

Please sign in to comment.