Skip to content

Commit d403745

Browse files
authored
Merge pull request #6791 from AnalyticalGraphicsInc/entity-polygon
Support for vertical polygons
2 parents 5585535 + c9550f5 commit d403745

File tree

5 files changed

+93
-11
lines changed

5 files changed

+93
-11
lines changed

Apps/Sandcastle/gallery/Polygon.html

+22-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
<script type="text/javascript" src="../Sandcastle-header.js"></script>
1111
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
1212
<script type="text/javascript">
13-
require.config({
14-
baseUrl : '../../../Source',
15-
waitSeconds : 60
16-
});
13+
if(typeof require === "function") {
14+
require.config({
15+
baseUrl : '../../../Source',
16+
waitSeconds : 120
17+
});
18+
}
1719
</script>
1820
</head>
1921
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
@@ -108,8 +110,22 @@
108110
}
109111
});
110112

111-
viewer.zoomTo(viewer.entities);
112-
//Sandcastle_End
113+
var cyanPolygon = viewer.entities.add({
114+
name : 'Cyan vertical polygon with per-position heights and outline',
115+
polygon : {
116+
hierarchy : Cesium.Cartesian3.fromDegreesArrayHeights([
117+
-90.0, 41.0, 0.0,
118+
-85.0, 41.0, 500000.0,
119+
-80.0, 41.0, 0.0
120+
]),
121+
perPositionHeight : true,
122+
material : Cesium.Color.CYAN.withAlpha(0.5),
123+
outline : true,
124+
outlineColor : Cesium.Color.BLACK
125+
}
126+
});
127+
128+
viewer.zoomTo(viewer.entities);//Sandcastle_End
113129
Sandcastle.finishedLoading();
114130
}
115131
if (typeof Cesium !== "undefined") {

Apps/Sandcastle/gallery/Polygon.jpg

1.53 KB
Loading

CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Change Log
66
##### Additions :tada:
77
* Added support for loading Draco compressed Point Cloud tiles for 2-3x better compression. [#6559](https://github.com/AnalyticalGraphicsInc/cesium/pull/6559)
88
* 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)
9-
* 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)
9+
* 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)
10+
* Improved support for polygon entities using `perPositionHeight`, including supporting vertical polygons. This also improves KML compatibility. [#6791](https://github.com/AnalyticalGraphicsInc/cesium/pull/6791)
1011

1112
##### Deprecated :hourglass_flowing_sand:
1213
* 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)

Source/DataSources/PolygonGeometryUpdater.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ define([
44
'../Core/Check',
55
'../Core/Color',
66
'../Core/ColorGeometryInstanceAttribute',
7+
'../Core/CoplanarPolygonGeometry',
8+
'../Core/CoplanarPolygonOutlineGeometry',
79
'../Core/defined',
810
'../Core/DeveloperError',
911
'../Core/DistanceDisplayConditionGeometryInstanceAttribute',
@@ -32,6 +34,8 @@ define([
3234
Check,
3335
Color,
3436
ColorGeometryInstanceAttribute,
37+
CoplanarPolygonGeometry,
38+
CoplanarPolygonOutlineGeometry,
3539
defined,
3640
DeveloperError,
3741
DistanceDisplayConditionGeometryInstanceAttribute,
@@ -120,6 +124,7 @@ define([
120124

121125
var entity = this._entity;
122126
var isAvailable = entity.isAvailable(time);
127+
var options = this._options;
123128

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

150+
var geometry;
151+
if (options.perPositionHeight && !defined(options.extrudedHeight)) {
152+
geometry = new CoplanarPolygonGeometry(options);
153+
} else {
154+
geometry = new PolygonGeometry(options);
155+
}
156+
145157
return new GeometryInstance({
146158
id : entity,
147-
geometry : new PolygonGeometry(this._options),
159+
geometry : geometry,
148160
attributes : attributes
149161
});
150162
};
@@ -168,6 +180,7 @@ define([
168180

169181
var entity = this._entity;
170182
var isAvailable = entity.isAvailable(time);
183+
var options = this._options;
171184
var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK, scratchColor);
172185
var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time);
173186

@@ -178,13 +191,19 @@ define([
178191
offset : undefined
179192
};
180193

181-
if (defined(this._options.offsetAttribute)) {
194+
if (defined(options.offsetAttribute)) {
182195
attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch));
183196
}
184197

198+
var geometry;
199+
if (options.perPositionHeight && !defined(options.extrudedHeight)) {
200+
geometry = new CoplanarPolygonOutlineGeometry(options);
201+
} else {
202+
geometry = new PolygonOutlineGeometry(options);
203+
}
185204
return new GeometryInstance({
186205
id : entity,
187-
geometry : new PolygonOutlineGeometry(this._options),
206+
geometry : geometry,
188207
attributes : attributes
189208
});
190209
};

Specs/DataSources/PolygonGeometryUpdaterSpec.js

+46
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ defineSuite([
66
'Core/GeometryOffsetAttribute',
77
'Core/JulianDate',
88
'Core/Math',
9+
'Core/CoplanarPolygonGeometry',
10+
'Core/CoplanarPolygonOutlineGeometry',
11+
'Core/PolygonGeometry',
12+
'Core/PolygonOutlineGeometry',
913
'Core/PolygonHierarchy',
1014
'Core/TimeIntervalCollection',
1115
'DataSources/ConstantProperty',
@@ -29,6 +33,10 @@ defineSuite([
2933
GeometryOffsetAttribute,
3034
JulianDate,
3135
CesiumMath,
36+
CoplanarPolygonGeometry,
37+
CoplanarPolygonOutlineGeometry,
38+
PolygonGeometry,
39+
PolygonOutlineGeometry,
3240
PolygonHierarchy,
3341
TimeIntervalCollection,
3442
ConstantProperty,
@@ -78,6 +86,19 @@ defineSuite([
7886
return entity;
7987
}
8088

89+
function createVerticalPolygon() {
90+
var polygon = new PolygonGraphics();
91+
polygon.hierarchy = new ConstantProperty(new PolygonHierarchy(Cartesian3.fromDegreesArrayHeights([
92+
-1.0, 1.0, 0.0,
93+
-2.0, 1.0, 0.0,
94+
-2.0, 1.0, 0.0
95+
])));
96+
polygon.perPositionHeight = true;
97+
var entity = new Entity();
98+
entity.polygon = polygon;
99+
return entity;
100+
}
101+
81102
function createDynamicPolygon() {
82103
var entity = createBasicPolygon();
83104
entity.polygon.extrudedHeight = createDynamicProperty(2);
@@ -231,6 +252,7 @@ defineSuite([
231252
var geometry;
232253
instance = updater.createFillGeometryInstance(time);
233254
geometry = instance.geometry;
255+
expect(geometry).toBeInstanceOf(PolygonGeometry);
234256
expect(geometry._stRotation).toEqual(options.stRotation);
235257
expect(geometry._height).toEqual(options.height);
236258
expect(geometry._granularity).toEqual(options.granularity);
@@ -241,13 +263,37 @@ defineSuite([
241263

242264
instance = updater.createOutlineGeometryInstance(time);
243265
geometry = instance.geometry;
266+
expect(geometry).toBeInstanceOf(PolygonOutlineGeometry);
244267
expect(geometry._height).toEqual(options.height);
245268
expect(geometry._granularity).toEqual(options.granularity);
246269
expect(geometry._extrudedHeight).toEqual(options.extrudedHeight);
247270
expect(geometry._perPositionHeight).toEqual(options.perPositionHeight);
248271
expect(geometry._offsetAttribute).toBeUndefined();
249272
});
250273

274+
it('Creates coplanar polygon', function() {
275+
var stRotation = 12;
276+
277+
var entity = createVerticalPolygon();
278+
279+
var polygon = entity.polygon;
280+
polygon.outline = true;
281+
polygon.stRotation = new ConstantProperty(stRotation);
282+
283+
var updater = new PolygonGeometryUpdater(entity, scene);
284+
285+
var instance;
286+
var geometry;
287+
instance = updater.createFillGeometryInstance(time);
288+
geometry = instance.geometry;
289+
expect(geometry).toBeInstanceOf(CoplanarPolygonGeometry);
290+
expect(geometry._stRotation).toEqual(stRotation);
291+
292+
instance = updater.createOutlineGeometryInstance(time);
293+
geometry = instance.geometry;
294+
expect(geometry).toBeInstanceOf(CoplanarPolygonOutlineGeometry);
295+
});
296+
251297
it('Checks that a polygon with per position heights isn\'t on terrain', function() {
252298
var entity = createBasicPolygon();
253299
entity.polygon.height = undefined;

0 commit comments

Comments
 (0)