diff --git a/Apps/Sandcastle/gallery/Polygon.html b/Apps/Sandcastle/gallery/Polygon.html index 56e7e95d5c3f..42acc0be55ce 100644 --- a/Apps/Sandcastle/gallery/Polygon.html +++ b/Apps/Sandcastle/gallery/Polygon.html @@ -10,10 +10,12 @@ @@ -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") { diff --git a/Apps/Sandcastle/gallery/Polygon.jpg b/Apps/Sandcastle/gallery/Polygon.jpg index 730876783006..bbe5a86979a4 100644 Binary files a/Apps/Sandcastle/gallery/Polygon.jpg and b/Apps/Sandcastle/gallery/Polygon.jpg differ diff --git a/CHANGES.md b/CHANGES.md index 838dc23f6e86..845022c190a0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index a26e346dcccd..560e6d84b212 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -4,6 +4,8 @@ define([ '../Core/Check', '../Core/Color', '../Core/ColorGeometryInstanceAttribute', + '../Core/CoplanarPolygonGeometry', + '../Core/CoplanarPolygonOutlineGeometry', '../Core/defined', '../Core/DeveloperError', '../Core/DistanceDisplayConditionGeometryInstanceAttribute', @@ -32,6 +34,8 @@ define([ Check, Color, ColorGeometryInstanceAttribute, + CoplanarPolygonGeometry, + CoplanarPolygonOutlineGeometry, defined, DeveloperError, DistanceDisplayConditionGeometryInstanceAttribute, @@ -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)), @@ -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 }); }; @@ -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); @@ -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 }); }; diff --git a/Specs/DataSources/PolygonGeometryUpdaterSpec.js b/Specs/DataSources/PolygonGeometryUpdaterSpec.js index 18d40f26e264..223eaf337444 100644 --- a/Specs/DataSources/PolygonGeometryUpdaterSpec.js +++ b/Specs/DataSources/PolygonGeometryUpdaterSpec.js @@ -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', @@ -29,6 +33,10 @@ defineSuite([ GeometryOffsetAttribute, JulianDate, CesiumMath, + CoplanarPolygonGeometry, + CoplanarPolygonOutlineGeometry, + PolygonGeometry, + PolygonOutlineGeometry, PolygonHierarchy, TimeIntervalCollection, ConstantProperty, @@ -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); @@ -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); @@ -241,6 +263,7 @@ 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); @@ -248,6 +271,29 @@ defineSuite([ 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;