From 31448d7b9c555f93e971dcd82886f2e23d17026b Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 26 Jun 2018 15:32:30 -0400 Subject: [PATCH 01/10] geometry height reference property --- .../gallery/Geometry Height Reference.html | 86 ++++++++ .../gallery/Geometry Height Reference.jpg | Bin 0 -> 20995 bytes Source/DataSources/CorridorGeometryUpdater.js | 80 +++++-- Source/DataSources/EllipseGeometryUpdater.js | 81 +++++-- Source/DataSources/GeometryHeightProperty.js | 183 ++++++++++++++++ Source/DataSources/GeometryVisualizer.js | 61 ++++-- Source/DataSources/GroundGeometryUpdater.js | 46 +++- Source/DataSources/PolygonGeometryUpdater.js | 102 ++++++--- .../DataSources/RectangleGeometryUpdater.js | 90 ++++++-- .../DataSources/StaticGeometryColorBatch.js | 17 +- .../StaticGeometryPerMaterialBatch.js | 17 +- .../DataSources/StaticOutlineGeometryBatch.js | 17 +- Source/DataSources/TerrainOffsetProperty.js | 199 ++++++++++++++++++ .../CorridorGeometryUpdaterSpec.js | 24 ++- .../DataSources/EllipseGeometryUpdaterSpec.js | 12 ++ .../DataSources/GeometryHeightPropertySpec.js | 150 +++++++++++++ .../DataSources/PolygonGeometryUpdaterSpec.js | 23 +- .../PolylineGeometryUpdaterSpec.js | 2 + .../RectangleGeometryUpdaterSpec.js | 16 +- .../DataSources/TerrainOffsetPropertySpec.js | 77 +++++++ ...reateGeometryUpdaterGroundGeometrySpecs.js | 108 ++++++++++ 21 files changed, 1269 insertions(+), 122 deletions(-) create mode 100644 Apps/Sandcastle/gallery/Geometry Height Reference.html create mode 100644 Apps/Sandcastle/gallery/Geometry Height Reference.jpg create mode 100644 Source/DataSources/GeometryHeightProperty.js create mode 100644 Source/DataSources/TerrainOffsetProperty.js create mode 100644 Specs/DataSources/GeometryHeightPropertySpec.js create mode 100644 Specs/DataSources/TerrainOffsetPropertySpec.js diff --git a/Apps/Sandcastle/gallery/Geometry Height Reference.html b/Apps/Sandcastle/gallery/Geometry Height Reference.html new file mode 100644 index 000000000000..6a31256c48bf --- /dev/null +++ b/Apps/Sandcastle/gallery/Geometry Height Reference.html @@ -0,0 +1,86 @@ + + + + + + + + + Cesium Demo + + + + + + +
+

Loading...

+
+ + + diff --git a/Apps/Sandcastle/gallery/Geometry Height Reference.jpg b/Apps/Sandcastle/gallery/Geometry Height Reference.jpg new file mode 100644 index 0000000000000000000000000000000000000000..054d09cbc2e47e69e334f5ba53d717b3127dd787 GIT binary patch literal 20995 zcmbTcbyOQ&^fnrt7I&8xE5#j(q(G6N#T|-UaSO#uk)j0(6fds9-Q6i}K@+S{f=lp^ z_jkYb-L>vt_uid3$yqb!OwKcB=FGGAex8<|HUWf6@*sHt3JMB9@%aOIf&uL0!1gu( zfT}9sEdT((2B4!*12CRzD9=R-h35a%hnQ9!1FhN=((spm;dbfZ2!~e ze|}xf?VUZjovl3?1-W^-`T3szX$2q)Kt)0MZ~NbdhJp5VPIimVf|OIU*NpJ z#(s&7h4m8eKhuHnp;|X`}zk4hlWQ+XJ+T-7Z#V6p)mN?_Rj9!-~EHrv-69~ zt83)V?SHsX0BHXgtp9`T|AC9>85ipF9H3+UhYJPO=eeK}p<}$_!z7m0z%q9udCeb! zO)8U+ThsG`NkH?2%))*8B{{PojOFw{X#a!k{~fTe|G$v^A7KACE+_yO4dr?A(1-v) zz`gxLx)cpTR5s5Y3#1~Z@nl#Z-E4y!M_B(1QvZpp=i*q~D-CktLTRYv)s8j9z{vW8Y2>U< zHS)mz1fXw-ZtIFQq)qvue?UDk7?bWbs(>O}uJS^*<(Dh2pEmEvxD{H0iAHi>)e`{U zZB#GA?BwsZ#H&;B_a`Z#@PFcTbQBtvEODvj{6{*mtKqgQKiBG*$yP>aGd*U(sl6$; z1btaNeOF)l-R-`l#GRW^5mf?blRP8Mq4_9ZLxR<{e!QFS3V(+V73m8iF_05ZY^A%* zSz&SeT%_!~<#PtdG{yeWpHH=)NnrY~Zv_622N!B$0uIy)qDAE}c{hrkVEiVb;6)cu zcn0N@+GYXDNN&@3S7m-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ccVQI*79(KxLGVU(29G1=meCIXLcsKTy_~&r`Al58AcWr5P9l(zEL8sa)Pc(6` zQU}?HDmVkD1-QwgiXmEUYQm%W}k=u0A}4%>q3uI zj{48|Tr83^atdcEV<3$AoE(Gl=e-nGzS4GDlgS(GdeeTP- z<8KdZ9yIZN)}^dpt;V5p5?h%f+X}uGFmR}WM*;c){66)o@NUD!-wb?pYpnQlRI$_b zt9a!|E+mROm5+2qP8L|5MoST#XK5q76jc3Uqv~kr!rLCT;tz@68#OpC=DP8|pE13- zOUY2!TI^|)lwiMR!r-Jl3&9Ld4RqKay??YTb29f@@Bji0m?n?lR+8rRA%oVBI1zBmUvtxkB|jQTI7XHDWy zj91!i_Md&@i+Qc}D3vCJTU(grIgfThw*Kgo1apxep`waj-hIMUqifjm`TqcAEq>j$ z{{U!dyS8WkJ|xENqyCxn&hNt&()=OuC&Yi*_eRw%{43%s4K4L4)ucaTx41Ixj$|92 zXc@*lzyMMJ4+458j?o5&uc9d3MSgG8< zWeaR{aQtTY`KnvUWcY<>includeStart('debug', pragmas.debug); + Check.defined('time', time); + //>>includeEnd('debug'); + + var heightReference = Property.getValueOrDefault(this._heightReference, time, HeightReference.NONE); + + if (heightReference !== HeightReference.CLAMP_TO_GROUND) { + return Property.getValueOrDefault(this._height, time, 0); + } + return 0; + }; + + /** + * Used to get the minimum terrain value for when extrudedHeight is using CLAMP_TO_GROUND; + * @private + */ + GeometryHeightProperty.getMinimumTerrainValue = function(rectangle) { + //>>includeStart('debug', pragmas.debug); + Check.defined('rectangle', rectangle); + //>>includeEnd('debug'); + return ApproximateTerrainHeights.getApproximateTerrainHeights(rectangle).minimumTerrainHeight; + }; + + /** + * Gets the GeometryOffsetAttribute based on the values of height and extrudedHeight + * @param {Property} height + * @param {Property} extrudedHeight + * @param {JulianDate} time + * @returns {GeometryOffsetAttribute|undefined} + * @private + */ + GeometryHeightProperty.computeGeometryOffsetAttribute = function(height, extrudedHeight, time) { + if (!(extrudedHeight instanceof GeometryHeightProperty) && !(height instanceof GeometryHeightProperty)) { + return undefined; + } + + var heightReference = defined(height) ? Property.getValueOrDefault(height.heightReference, time, HeightReference.NONE) : HeightReference.NONE; + var extrudedHeightReference = defined(extrudedHeight) ? Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) : HeightReference.NONE; + + var n = 0; + if (heightReference !== HeightReference.NONE) { + n++; + } + if (extrudedHeightReference === HeightReference.RELATIVE_TO_GROUND) { + n++; + } + if (n === 2) { + return GeometryOffsetAttribute.ALL; + } + if (n === 1) { + return GeometryOffsetAttribute.TOP; + } + return undefined; + }; + + /** + * Compares this property to the provided property and returns + * true if they are equal, false otherwise. + * + * @param {Property} [other] The other property. + * @returns {Boolean} true if left and right are equal, false otherwise. + */ + GeometryHeightProperty.prototype.equals = function(other) { + return this === other ||// + (other instanceof GeometryHeightProperty && + Property.equals(this._height, other._height) && + Property.equals(this._heightReference, other._heightReference)); + }; + + return GeometryHeightProperty; +}); diff --git a/Source/DataSources/GeometryVisualizer.js b/Source/DataSources/GeometryVisualizer.js index 9ea93859248f..41f4ee0a792c 100644 --- a/Source/DataSources/GeometryVisualizer.js +++ b/Source/DataSources/GeometryVisualizer.js @@ -142,23 +142,31 @@ define([ this._changedObjects = new AssociativeArray(); var numberOfShadowModes = ShadowMode.NUMBER_OF_SHADOW_MODES; - this._outlineBatches = new Array(numberOfShadowModes); - this._closedColorBatches = new Array(numberOfShadowModes); - this._closedMaterialBatches = new Array(numberOfShadowModes); - this._openColorBatches = new Array(numberOfShadowModes); - this._openMaterialBatches = new Array(numberOfShadowModes); + this._outlineBatches = new Array(numberOfShadowModes*2); + this._closedColorBatches = new Array(numberOfShadowModes*2); + this._closedMaterialBatches = new Array(numberOfShadowModes*2); + this._openColorBatches = new Array(numberOfShadowModes*2); + this._openMaterialBatches = new Array(numberOfShadowModes*2); var supportsMaterialsforEntitiesOnTerrain = Entity.supportsMaterialsforEntitiesOnTerrain(scene); this._supportsMaterialsforEntitiesOnTerrain = supportsMaterialsforEntitiesOnTerrain; var i; for (i = 0; i < numberOfShadowModes; ++i) { - this._outlineBatches[i] = new StaticOutlineGeometryBatch(primitives, scene, i); + this._outlineBatches[i] = new StaticOutlineGeometryBatch(primitives, scene, i, false); + this._outlineBatches[numberOfShadowModes + i] = new StaticOutlineGeometryBatch(primitives, scene, i, true); - this._closedColorBatches[i] = new StaticGeometryColorBatch(primitives, PerInstanceColorAppearance, undefined, true, i); - this._closedMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, MaterialAppearance, undefined, true, i); - this._openColorBatches[i] = new StaticGeometryColorBatch(primitives, PerInstanceColorAppearance, undefined, false, i); - this._openMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, MaterialAppearance, undefined, false, i); + this._closedColorBatches[i] = new StaticGeometryColorBatch(primitives, PerInstanceColorAppearance, undefined, true, i, true); + this._closedColorBatches[numberOfShadowModes + i] = new StaticGeometryColorBatch(primitives, PerInstanceColorAppearance, undefined, true, i, false); + + this._closedMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, MaterialAppearance, undefined, true, i, true); + this._closedMaterialBatches[numberOfShadowModes + i] = new StaticGeometryPerMaterialBatch(primitives, MaterialAppearance, undefined, true, i, false); + + this._openColorBatches[i] = new StaticGeometryColorBatch(primitives, PerInstanceColorAppearance, undefined, false, i, true); + this._openColorBatches[numberOfShadowModes + i] = new StaticGeometryColorBatch(primitives, PerInstanceColorAppearance, undefined, false, i, false); + + this._openMaterialBatches[i] = new StaticGeometryPerMaterialBatch(primitives, MaterialAppearance, undefined, false, i, true); + this._openMaterialBatches[numberOfShadowModes + i] = new StaticGeometryPerMaterialBatch(primitives, MaterialAppearance, undefined, false, i, false); } var numberOfClassificationTypes = ClassificationType.NUMBER_OF_CLASSIFICATION_TYPES; @@ -390,8 +398,13 @@ define([ shadows = updater.shadowsProperty.getValue(time); } + var numberOfShadowModes = ShadowMode.NUMBER_OF_SHADOW_MODES; if (updater.outlineEnabled) { - this._outlineBatches[shadows].add(time, updater); + if (defined(updater.terrainOffsetProperty)) { + this._outlineBatches[numberOfShadowModes + shadows].add(time, updater); + } else { + this._outlineBatches[shadows].add(time, updater); + } } if (updater.fillEnabled) { @@ -408,14 +421,32 @@ define([ } } else if (updater.isClosed) { if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { - this._closedColorBatches[shadows].add(time, updater); + if (defined(updater.terrainOffsetProperty)) { + this._closedColorBatches[numberOfShadowModes + shadows].add(time, updater); + } else { + this._closedColorBatches[shadows].add(time, updater); + } } else { - this._closedMaterialBatches[shadows].add(time, updater); + // eslint-disable-next-line no-lonely-if + if (defined(updater.terrainOffsetProperty)) { + this._closedMaterialBatches[numberOfShadowModes + shadows].add(time, updater); + } else { + this._closedMaterialBatches[shadows].add(time, updater); + } } } else if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { - this._openColorBatches[shadows].add(time, updater); + if (defined(updater.terrainOffsetProperty)) { + this._openColorBatches[numberOfShadowModes + shadows].add(time, updater); + } else { + this._openColorBatches[shadows].add(time, updater); + } } else { - this._openMaterialBatches[shadows].add(time, updater); + // eslint-disable-next-line no-lonely-if + if (defined(updater.terrainOffsetProperty)) { + this._openMaterialBatches[numberOfShadowModes + shadows].add(time, updater); + } else { + this._openMaterialBatches[shadows].add(time, updater); + } } } }; diff --git a/Source/DataSources/GroundGeometryUpdater.js b/Source/DataSources/GroundGeometryUpdater.js index 43f2a98afc14..4d4c4d5c629b 100644 --- a/Source/DataSources/GroundGeometryUpdater.js +++ b/Source/DataSources/GroundGeometryUpdater.js @@ -1,19 +1,31 @@ define([ + '../Core/Cartesian3', + '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', + '../Core/DeveloperError', '../Core/Iso8601', '../Core/oneTimeWarning', + '../Scene/HeightReference', './ConstantProperty', - './GeometryUpdater' + './GeometryHeightProperty', + './GeometryUpdater', + './TerrainOffsetProperty' ], function( + Cartesian3, + Check, defaultValue, defined, defineProperties, + DeveloperError, Iso8601, oneTimeWarning, + HeightReference, ConstantProperty, - GeometryUpdater) { + GeometryHeightProperty, + GeometryUpdater, + TerrainOffsetProperty) { 'use strict'; var defaultZIndex = new ConstantProperty(0); @@ -33,6 +45,7 @@ define([ GeometryUpdater.call(this, options); this._zIndex = 0; + this._terrainOffsetProperty = undefined; } if (defined(Object.create)) { @@ -51,9 +64,25 @@ define([ get: function() { return this._zIndex; } + }, + + terrainOffsetProperty: { + get: function() { + return this._terrainOffsetProperty; + } } }); + /** + * @param {Entity} entity + * @param {Object} geometry + * @param {JulianDate} time + * @param {Cartesian3} result + * + * @private + */ + GroundGeometryUpdater.prototype._computeCenter = DeveloperError.throwInstantiationError; + GroundGeometryUpdater.prototype._onEntityPropertyChanged = function(entity, propertyName, newValue, oldValue) { GeometryUpdater.prototype._onEntityPropertyChanged.call(this, entity, propertyName, newValue, oldValue); if (this._observedPropertyNames.indexOf(propertyName) === -1) { @@ -69,6 +98,19 @@ define([ } this._zIndex = defaultValue(geometry.zIndex, defaultZIndex); + + var heightProperty = geometry.height; + var extrudedHeightProperty = geometry.extrudedHeight; + + if (this._terrainOffsetProperty instanceof TerrainOffsetProperty) { + this._terrainOffsetProperty.destroy(); + } + + if (heightProperty instanceof GeometryHeightProperty || extrudedHeightProperty instanceof GeometryHeightProperty) { + this._terrainOffsetProperty = new TerrainOffsetProperty(this._scene, heightProperty, extrudedHeightProperty, this._computeCenter.bind(this)); + } else { + this._terrainOffsetProperty = undefined; + } }; return GroundGeometryUpdater; diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index c56094f34b35..32f55711bad1 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -1,4 +1,5 @@ define([ + '../Core/Cartesian3', '../Core/Check', '../Core/Color', '../Core/ColorGeometryInstanceAttribute', @@ -6,21 +7,26 @@ define([ '../Core/DeveloperError', '../Core/DistanceDisplayConditionGeometryInstanceAttribute', '../Core/GeometryInstance', + '../Core/GeometryOffsetAttribute', '../Core/isArray', '../Core/Iso8601', + '../Core/OffsetGeometryInstanceAttribute', '../Core/PolygonGeometry', '../Core/PolygonHierarchy', '../Core/PolygonOutlineGeometry', '../Core/ShowGeometryInstanceAttribute', '../Scene/GroundPrimitive', + '../Scene/HeightReference', '../Scene/MaterialAppearance', '../Scene/PerInstanceColorAppearance', './ColorMaterialProperty', './DynamicGeometryUpdater', + './GeometryHeightProperty', './GeometryUpdater', './GroundGeometryUpdater', './Property' ], function( + Cartesian3, Check, Color, ColorGeometryInstanceAttribute, @@ -28,23 +34,30 @@ define([ DeveloperError, DistanceDisplayConditionGeometryInstanceAttribute, GeometryInstance, + GeometryOffsetAttribute, isArray, Iso8601, + OffsetGeometryInstanceAttribute, PolygonGeometry, PolygonHierarchy, PolygonOutlineGeometry, ShowGeometryInstanceAttribute, GroundPrimitive, + HeightReference, MaterialAppearance, PerInstanceColorAppearance, ColorMaterialProperty, DynamicGeometryUpdater, + GeometryHeightProperty, GeometryUpdater, GroundGeometryUpdater, Property) { 'use strict'; var scratchColor = new Color(); + var defaultOffset = Cartesian3.ZERO; + var offsetScratch = new Cartesian3(); + var scratchPolygonGeometry = new PolygonGeometry({polygonHierarchy: new PolygonHierarchy}); function PolygonGeometryOptions(entity) { this.id = entity; @@ -57,6 +70,7 @@ define([ this.extrudedHeight = undefined; this.granularity = undefined; this.stRotation = undefined; + this.offsetAttribute = undefined; } /** @@ -105,12 +119,11 @@ define([ var entity = this._entity; var isAvailable = entity.isAvailable(time); - var attributes; + var attributes = { + show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)), + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)) + }; - var color; - var show = new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)); - var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time); - var distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition); if (this._materialProperty instanceof ColorMaterialProperty) { var currentColor; if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) { @@ -119,17 +132,10 @@ define([ if (!defined(currentColor)) { currentColor = Color.WHITE; } - color = ColorGeometryInstanceAttribute.fromColor(currentColor); - attributes = { - show : show, - distanceDisplayCondition : distanceDisplayConditionAttribute, - color : color - }; - } else { - attributes = { - show : show, - distanceDisplayCondition : distanceDisplayConditionAttribute - }; + attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor); + } + if (defined(this._options.offsetAttribute)) { + attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch)); } return new GeometryInstance({ @@ -161,17 +167,44 @@ define([ var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK, scratchColor); var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time); + var attributes = { + show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), + color : ColorGeometryInstanceAttribute.fromColor(outlineColor), + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition) + }; + + if (defined(this._options.offsetAttribute)) { + attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch)); + } + return new GeometryInstance({ id : entity, geometry : new PolygonOutlineGeometry(this._options), - attributes : { - show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), - color : ColorGeometryInstanceAttribute.fromColor(outlineColor), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition) - } + attributes : attributes }); }; + PolygonGeometryUpdater.prototype._computeCenter = function(time, result) { + var positions = Property.getValueOrUndefined(this._entity.polygon.hierarchy, time); + if (defined(positions) && !isArray(positions)) { + positions = positions.positions; + } + if (positions.length === 0) { + return; + } + + var centroid = Cartesian3.clone(Cartesian3.ZERO, result); + var length = positions.length; + for (var i = 0; i < length; i++) { + centroid = Cartesian3.add(positions[i], centroid, centroid); + } + centroid = Cartesian3.multiplyByScalar(centroid, 1 / length, centroid); + if (defined(this._scene.globe)) { + centroid = this._scene.globe.ellipsoid.scaleToGeodeticSurface(centroid, centroid); + } + return centroid; + }; + PolygonGeometryUpdater.prototype._isHidden = function(entity, polygon) { return !defined(polygon.hierarchy) || GeometryUpdater.prototype._isHidden.call(this, entity, polygon); }; @@ -208,10 +241,13 @@ define([ hierarchyValue = new PolygonHierarchy(hierarchyValue); } - var heightValue = Property.getValueOrUndefined(polygon.height, Iso8601.MINIMUM_VALUE); + var height = polygon.height; + var extrudedHeight = polygon.extrudedHeight; + + var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); var closeTopValue = Property.getValueOrDefault(polygon.closeTop, Iso8601.MINIMUM_VALUE, true); var closeBottomValue = Property.getValueOrDefault(polygon.closeBottom, Iso8601.MINIMUM_VALUE, true); - var extrudedHeightValue = Property.getValueOrUndefined(polygon.extrudedHeight, Iso8601.MINIMUM_VALUE); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); var perPositionHeightValue = Property.getValueOrUndefined(polygon.perPositionHeight, Iso8601.MINIMUM_VALUE); if (defined(extrudedHeightValue) && !defined(heightValue) && !defined(perPositionHeightValue)) { @@ -226,6 +262,12 @@ define([ options.perPositionHeight = perPositionHeightValue; options.closeTop = closeTopValue; options.closeBottom = closeBottomValue; + options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); + + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + scratchPolygonGeometry.setOptions(options); + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchPolygonGeometry.rectangle); + } }; PolygonGeometryUpdater.prototype._getIsClosed = function(options) { @@ -255,6 +297,9 @@ define([ DyanmicPolygonGeometryUpdater.prototype._setOptions = function(entity, polygon, time) { var options = this._options; + var height = polygon.height; + var extrudedHeight = polygon.extrudedHeight; + var hierarchy = Property.getValueOrUndefined(polygon.hierarchy, time); if (isArray(hierarchy)) { options.polygonHierarchy = new PolygonHierarchy(hierarchy); @@ -262,13 +307,20 @@ define([ options.polygonHierarchy = hierarchy; } - options.height = Property.getValueOrUndefined(polygon.height, time); - options.extrudedHeight = Property.getValueOrUndefined(polygon.extrudedHeight, time); + options.height = Property.getValueOrUndefined(height, time); + options.extrudedHeight = Property.getValueOrUndefined(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 = Property.getValueOrDefault(polygon.closeTop, time, true); options.closeBottom = Property.getValueOrDefault(polygon.closeBottom, time, true); + options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); + + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + scratchPolygonGeometry.setOptions(options); + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchPolygonGeometry.rectangle); + } + }; return PolygonGeometryUpdater; diff --git a/Source/DataSources/RectangleGeometryUpdater.js b/Source/DataSources/RectangleGeometryUpdater.js index 21e6c35a89a0..48416ea3bd83 100644 --- a/Source/DataSources/RectangleGeometryUpdater.js +++ b/Source/DataSources/RectangleGeometryUpdater.js @@ -1,46 +1,67 @@ define([ + '../Core/Cartesian3', + '../Core/Cartographic', '../Core/Check', '../Core/Color', '../Core/ColorGeometryInstanceAttribute', '../Core/defined', '../Core/DeveloperError', '../Core/DistanceDisplayConditionGeometryInstanceAttribute', + '../Core/Ellipsoid', '../Core/GeometryInstance', + '../Core/GeometryOffsetAttribute', '../Core/Iso8601', + '../Core/OffsetGeometryInstanceAttribute', + '../Core/Rectangle', '../Core/RectangleGeometry', '../Core/RectangleOutlineGeometry', '../Core/ShowGeometryInstanceAttribute', '../Scene/GroundPrimitive', + '../Scene/HeightReference', '../Scene/MaterialAppearance', '../Scene/PerInstanceColorAppearance', './ColorMaterialProperty', './DynamicGeometryUpdater', + './GeometryHeightProperty', './GeometryUpdater', './GroundGeometryUpdater', './Property' ], function( + Cartesian3, + Cartographic, Check, Color, ColorGeometryInstanceAttribute, defined, DeveloperError, DistanceDisplayConditionGeometryInstanceAttribute, + Ellipsoid, GeometryInstance, + GeometryOffsetAttribute, Iso8601, + OffsetGeometryInstanceAttribute, + Rectangle, RectangleGeometry, RectangleOutlineGeometry, ShowGeometryInstanceAttribute, GroundPrimitive, + HeightReference, MaterialAppearance, PerInstanceColorAppearance, ColorMaterialProperty, DynamicGeometryUpdater, + GeometryHeightProperty, GeometryUpdater, GroundGeometryUpdater, Property) { 'use strict'; var scratchColor = new Color(); + var defaultOffset = Cartesian3.ZERO; + var offsetScratch = new Cartesian3(); + var scratchRectangleGeometry = new RectangleGeometry({rectangle: new Rectangle()}); + var scratchCenterRect = new Rectangle(); + var scratchCarto = new Cartographic(); function RectangleGeometryOptions(entity) { this.id = entity; @@ -51,6 +72,7 @@ define([ this.granularity = undefined; this.stRotation = undefined; this.rotation = undefined; + this.offsetAttribute = undefined; } /** @@ -99,12 +121,11 @@ define([ var entity = this._entity; var isAvailable = entity.isAvailable(time); - var attributes; + var attributes = { + show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)), + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)) + }; - var color; - var show = new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)); - var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time); - var distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition); if (this._materialProperty instanceof ColorMaterialProperty) { var currentColor; if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) { @@ -113,17 +134,10 @@ define([ if (!defined(currentColor)) { currentColor = Color.WHITE; } - color = ColorGeometryInstanceAttribute.fromColor(currentColor); - attributes = { - show : show, - distanceDisplayCondition : distanceDisplayConditionAttribute, - color : color - }; - } else { - attributes = { - show : show, - distanceDisplayCondition : distanceDisplayConditionAttribute - }; + attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor); + } + if (defined(this._options.offsetAttribute)) { + attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch)); } return new GeometryInstance({ @@ -155,17 +169,32 @@ define([ var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK, scratchColor); var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time); + var attributes = { + show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), + color : ColorGeometryInstanceAttribute.fromColor(outlineColor), + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition) + }; + + if (defined(this._options.offsetAttribute)) { + attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch)); + } + return new GeometryInstance({ id : entity, geometry : new RectangleOutlineGeometry(this._options), - attributes : { - show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), - color : ColorGeometryInstanceAttribute.fromColor(outlineColor), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition) - } + attributes : attributes }); }; + RectangleGeometryUpdater.prototype._computeCenter = function(time, result) { + var rect = Property.getValueOrUndefined(this._entity.rectangle.coordinates, time, scratchCenterRect); + if (!defined(rect)) { + return; + } + var center = Rectangle.center(rect, scratchCarto); + return Cartographic.toCartesian(center, Ellipsoid.WGS84, result); + }; + RectangleGeometryUpdater.prototype._isHidden = function(entity, rectangle) { return !defined(rectangle.coordinates) || GeometryUpdater.prototype._isHidden.call(this, entity, rectangle); }; @@ -203,6 +232,12 @@ define([ options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.stRotation = defined(stRotation) ? stRotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.rotation = defined(rotation) ? rotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; + options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); + + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + scratchRectangleGeometry.setOptions(options); + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchRectangleGeometry.rectangle); + } }; RectangleGeometryUpdater.prototype._getIsClosed = function(options) { @@ -231,12 +266,21 @@ define([ DynamicRectangleGeometryUpdater.prototype._setOptions = function(entity, rectangle, time) { var options = this._options; + var height = rectangle.height; + var extrudedHeight = rectangle.extrudedHeight; + options.rectangle = Property.getValueOrUndefined(rectangle.coordinates, time, options.rectangle); - options.height = Property.getValueOrUndefined(rectangle.height, time); - options.extrudedHeight = Property.getValueOrUndefined(rectangle.extrudedHeight, time); + options.height = Property.getValueOrUndefined(height, time); + options.extrudedHeight = Property.getValueOrUndefined(extrudedHeight, time); options.granularity = Property.getValueOrUndefined(rectangle.granularity, time); options.stRotation = Property.getValueOrUndefined(rectangle.stRotation, time); options.rotation = Property.getValueOrUndefined(rectangle.rotation, time); + options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); + + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + scratchRectangleGeometry.setOptions(options); + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchRectangleGeometry.rectangle); + } }; return RectangleGeometryUpdater; diff --git a/Source/DataSources/StaticGeometryColorBatch.js b/Source/DataSources/StaticGeometryColorBatch.js index 32168a30c123..7f87f7a1f699 100644 --- a/Source/DataSources/StaticGeometryColorBatch.js +++ b/Source/DataSources/StaticGeometryColorBatch.js @@ -1,10 +1,12 @@ define([ '../Core/AssociativeArray', + '../Core/Cartesian3', '../Core/Color', '../Core/ColorGeometryInstanceAttribute', '../Core/defined', '../Core/DistanceDisplayCondition', '../Core/DistanceDisplayConditionGeometryInstanceAttribute', + '../Core/OffsetGeometryInstanceAttribute', '../Core/ShowGeometryInstanceAttribute', '../Scene/Primitive', './BoundingSphereState', @@ -13,11 +15,13 @@ define([ './Property' ], function( AssociativeArray, + Cartesian3, Color, ColorGeometryInstanceAttribute, defined, DistanceDisplayCondition, DistanceDisplayConditionGeometryInstanceAttribute, + OffsetGeometryInstanceAttribute, ShowGeometryInstanceAttribute, Primitive, BoundingSphereState, @@ -29,6 +33,8 @@ define([ var colorScratch = new Color(); var distanceDisplayConditionScratch = new DistanceDisplayCondition(); var defaultDistanceDisplayCondition = new DistanceDisplayCondition(); + var defaultOffset = Cartesian3.ZERO; + var offsetScratch = new Cartesian3(); function Batch(primitives, translucent, appearanceType, depthFailAppearanceType, depthFailMaterialProperty, closed, shadows) { this.translucent = translucent; @@ -80,7 +86,7 @@ define([ this.createPrimitive = true; this.geometry.set(id, instance); this.updaters.set(id, updater); - if (!updater.hasConstantFill || !updater.fillMaterialProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty)) { + if (!updater.hasConstantFill || !updater.fillMaterialProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty) || !Property.isConstant(updater.terrainOffsetProperty)) { this.updatersWithAttributes.set(id, updater); } else { var that = this; @@ -245,6 +251,15 @@ define([ attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition); } } + + var offsetProperty = updater.terrainOffsetProperty; + if (!Property.isConstant(offsetProperty)) { + var offset = Property.getValueOrDefault(offsetProperty, time, defaultOffset, offsetScratch); + if (!Cartesian3.equals(offset, attributes._lastOffset)) { + attributes._lastOffset = Cartesian3.clone(offset, attributes._lastOffset); + attributes.offset = OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset); + } + } } this.updateShows(primitive); diff --git a/Source/DataSources/StaticGeometryPerMaterialBatch.js b/Source/DataSources/StaticGeometryPerMaterialBatch.js index 4734c5be14fd..0fd9eed26e2c 100644 --- a/Source/DataSources/StaticGeometryPerMaterialBatch.js +++ b/Source/DataSources/StaticGeometryPerMaterialBatch.js @@ -1,10 +1,12 @@ define([ '../Core/AssociativeArray', + '../Core/Cartesian3', '../Core/Color', '../Core/ColorGeometryInstanceAttribute', '../Core/defined', '../Core/DistanceDisplayCondition', '../Core/DistanceDisplayConditionGeometryInstanceAttribute', + '../Core/OffsetGeometryInstanceAttribute', '../Core/ShowGeometryInstanceAttribute', '../Scene/Primitive', './BoundingSphereState', @@ -13,11 +15,13 @@ define([ './Property' ], function( AssociativeArray, + Cartesian3, Color, ColorGeometryInstanceAttribute, defined, DistanceDisplayCondition, DistanceDisplayConditionGeometryInstanceAttribute, + OffsetGeometryInstanceAttribute, ShowGeometryInstanceAttribute, Primitive, BoundingSphereState, @@ -28,6 +32,8 @@ define([ var distanceDisplayConditionScratch = new DistanceDisplayCondition(); var defaultDistanceDisplayCondition = new DistanceDisplayCondition(); + var defaultOffset = Cartesian3.ZERO; + var offsetScratch = new Cartesian3(); function Batch(primitives, appearanceType, materialProperty, depthFailAppearanceType, depthFailMaterialProperty, closed, shadows) { this.primitives = primitives; @@ -74,7 +80,7 @@ define([ var id = updater.id; this.updaters.set(id, updater); this.geometry.set(id, updater.createFillGeometryInstance(time)); - if (!updater.hasConstantFill || !updater.fillMaterialProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty)) { + if (!updater.hasConstantFill || !updater.fillMaterialProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty) || !Property.isConstant(updater.terrainOffsetProperty)) { this.updatersWithAttributes.set(id, updater); } else { var that = this; @@ -234,6 +240,15 @@ define([ attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition); } } + + var offsetProperty = updater.terrainOffsetProperty; + if (!Property.isConstant(offsetProperty)) { + var offset = Property.getValueOrDefault(offsetProperty, time, defaultOffset, offsetScratch); + if (!Cartesian3.equals(offset, attributes._lastOffset)) { + attributes._lastOffset = Cartesian3.clone(offset, attributes._lastOffset); + attributes.offset = OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset); + } + } } this.updateShows(primitive); diff --git a/Source/DataSources/StaticOutlineGeometryBatch.js b/Source/DataSources/StaticOutlineGeometryBatch.js index 848154fa3c51..def326371c71 100644 --- a/Source/DataSources/StaticOutlineGeometryBatch.js +++ b/Source/DataSources/StaticOutlineGeometryBatch.js @@ -1,10 +1,12 @@ define([ '../Core/AssociativeArray', + '../Core/Cartesian3', '../Core/Color', '../Core/ColorGeometryInstanceAttribute', '../Core/defined', '../Core/DistanceDisplayCondition', '../Core/DistanceDisplayConditionGeometryInstanceAttribute', + '../Core/OffsetGeometryInstanceAttribute', '../Core/ShowGeometryInstanceAttribute', '../Scene/PerInstanceColorAppearance', '../Scene/Primitive', @@ -12,11 +14,13 @@ define([ './Property' ], function( AssociativeArray, + Cartesian3, Color, ColorGeometryInstanceAttribute, defined, DistanceDisplayCondition, DistanceDisplayConditionGeometryInstanceAttribute, + OffsetGeometryInstanceAttribute, ShowGeometryInstanceAttribute, PerInstanceColorAppearance, Primitive, @@ -27,6 +31,8 @@ define([ var colorScratch = new Color(); var distanceDisplayConditionScratch = new DistanceDisplayCondition(); var defaultDistanceDisplayCondition = new DistanceDisplayCondition(); + var defaultOffset = Cartesian3.ZERO; + var offsetScratch = new Cartesian3(); function Batch(primitives, translucent, width, shadows) { this.translucent = translucent; @@ -50,7 +56,7 @@ define([ this.createPrimitive = true; this.geometry.set(id, instance); this.updaters.set(id, updater); - if (!updater.hasConstantOutline || !updater.outlineColorProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty)) { + if (!updater.hasConstantOutline || !updater.outlineColorProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty) || !Property.isConstant(updater.terrainOffsetProperty)) { this.updatersWithAttributes.set(id, updater); } else { var that = this; @@ -189,6 +195,15 @@ define([ attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition); } } + + var offsetProperty = updater.terrainOffsetProperty; + if (!Property.isConstant(offsetProperty)) { + var offset = Property.getValueOrDefault(offsetProperty, time, defaultOffset, offsetScratch); + if (!Cartesian3.equals(offset, attributes._lastOffset)) { + attributes._lastOffset = Cartesian3.clone(offset, attributes._lastOffset); + attributes.offset = OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset); + } + } } this.updateShows(primitive); diff --git a/Source/DataSources/TerrainOffsetProperty.js b/Source/DataSources/TerrainOffsetProperty.js new file mode 100644 index 000000000000..7a0612ae1c8f --- /dev/null +++ b/Source/DataSources/TerrainOffsetProperty.js @@ -0,0 +1,199 @@ +define([ + '../Core/Cartesian3', + '../Core/Cartographic', + '../Core/Check', + '../Core/defined', + '../Core/defineProperties', + '../Core/destroyObject', + '../Core/Event', + '../Core/Iso8601', + '../Core/Math', + '../Scene/HeightReference', + './Property' +], function( + Cartesian3, + Cartographic, + Check, + defined, + defineProperties, + destroyObject, + Event, + Iso8601, + CesiumMath, + HeightReference, + Property) { + 'use strict'; + + var scratchPosition = new Cartesian3(); + var scratchCarto = new Cartographic(); + + /** + * @private + * @param {Scene} scene + * @param {Property} height + * @param {Property} extrudedHeight + * @param {TerrainOffsetProperty~PositionFunction} getPosition + * @constructor + */ + function TerrainOffsetProperty(scene, height, extrudedHeight, getPosition) { + //>>includeStart('debug', pragmas.debug); + Check.defined('scene', scene); + Check.defined('height', height); + Check.defined('extrudedHeight', extrudedHeight); + Check.typeOf.func('getPosition', getPosition); + //>>includeEnd('debug'); + + this._scene = scene; + this._height = height; + this._extrudedHeight = extrudedHeight; + this._getPosition = getPosition; + + this._position = new Cartesian3(); + this._cartographicPosition = new Cartographic(); + this._normal = new Cartesian3(); + + this._definitionChanged = new Event(); + this._terrainHeight = 0; + this._removeCallbackFunc = undefined; + this._removeEventListener = undefined; + this._removeModeListener = undefined; + + var that = this; + if (defined(scene.globe)) { + this._removeEventListener = scene.terrainProviderChanged.addEventListener(function() { + that._updateClamping(); + }); + this._removeModeListener = scene.morphComplete.addEventListener(function() { + that._updateClamping(); + }); + } + } + + defineProperties(TerrainOffsetProperty.prototype, { + /** + * Gets a value indicating if this property is constant. + * @memberof TerrainOffsetProperty.prototype + * + * @type {Boolean} + * @readonly + */ + isConstant : { + get : function() { + return false; + } + }, + /** + * Gets the event that is raised whenever the definition of this property changes. + * @memberof TerrainOffsetProperty.prototype + * + * @type {Event} + * @readonly + */ + definitionChanged : { + get : function() { + return this._definitionChanged; + } + } + }); + + /** + * @private + */ + TerrainOffsetProperty.prototype._updateClamping = function() { + var scene = this._scene; + var globe = scene.globe; + if (!defined(globe)) { + this._terrainHeight = 0; + return; + } + var ellipsoid = globe.ellipsoid; + var surface = globe._surface; + + var position = this._position; + if (defined(this._removeCallbackFunc)) { + this._removeCallbackFunc(); + } + + var that = this; + var cartographicPosition = ellipsoid.cartesianToCartographic(position, this._cartographicPosition); + var height = globe.getHeight(cartographicPosition); + if (defined(height)) { + this._terrainHeight = height; + } else { + this._terrainHeight = 0; + } + + function updateFunction(clampedPosition) { + var carto = ellipsoid.cartesianToCartographic(clampedPosition, scratchCarto); + that._terrainHeight = carto.height; + that.definitionChanged.raiseEvent(); + } + this._removeCallbackFunc = surface.updateHeight(cartographicPosition, updateFunction); + }; + + /** + * Gets the height relative to the terrain based on the positions. + * + * @returns {Cartesian3} The offset + */ + TerrainOffsetProperty.prototype.getValue = function(time, result) { + var heightProperty = this._height; + var extrudedHeightProperty = this._extrudedHeight; + var heightReference = HeightReference.NONE; + var extrudedHeightReference = HeightReference.NONE; + if (defined(heightProperty)) { + heightReference = Property.getValueOrDefault(heightProperty.heightReference, time, HeightReference.NONE); + } + if (defined(extrudedHeightProperty)) { + extrudedHeightReference = Property.getValueOrDefault(extrudedHeightProperty.heightReference, time, HeightReference.NONE); + } + + if (heightReference === HeightReference.NONE && extrudedHeightReference !== HeightReference.RELATIVE_TO_GROUND) { + return Cartesian3.clone(Cartesian3.ZERO, result); + } + + var scene = this._scene; + var position = this._getPosition(time, scratchPosition); + if (!defined(position) || Cartesian3.equals(position, Cartesian3.ZERO) || !defined(scene.globe)) { + return Cartesian3.clone(Cartesian3.ZERO, result); + } + + if (Cartesian3.equalsEpsilon(this._position, position, CesiumMath.EPSILON10)) { + return Cartesian3.multiplyByScalar(this._normal, this._terrainHeight, result); + } + + this._position = Cartesian3.clone(position, this._position); + + this._updateClamping(); + + var normal = scene.globe.ellipsoid.geodeticSurfaceNormal(position, this._normal); + return Cartesian3.multiplyByScalar(normal, this._terrainHeight, result); + }; + + TerrainOffsetProperty.prototype.isDestroyed = function() { + return false; + }; + + TerrainOffsetProperty.prototype.destroy = function() { + if (defined(this._removeEventListener)) { + this._removeEventListener(); + } + if (defined(this._removeModeListener)) { + this._removeModeListener(); + } + if (defined(this._removeCallbackFunc)) { + this._removeCallbackFunc(); + } + return destroyObject(this); + }; + + /** + * A function which creates one or more providers. + * @callback TerrainOffsetProperty~PositionFunction + * @param {JulianDate} time The clock time at which to retrieve the position + * @param {Cartesian3} result The result position + * @returns {Cartesian3} The position at which to do the terrain height check + */ + + return TerrainOffsetProperty; +}); diff --git a/Specs/DataSources/CorridorGeometryUpdaterSpec.js b/Specs/DataSources/CorridorGeometryUpdaterSpec.js index 940a2718d92b..d074c244febb 100644 --- a/Specs/DataSources/CorridorGeometryUpdaterSpec.js +++ b/Specs/DataSources/CorridorGeometryUpdaterSpec.js @@ -2,7 +2,9 @@ defineSuite([ 'DataSources/CorridorGeometryUpdater', 'Core/Cartesian3', 'Core/CornerType', + 'Core/GeometryOffsetAttribute', 'Core/JulianDate', + 'Core/Math', 'Core/TimeInterval', 'Core/TimeIntervalCollection', 'DataSources/ConstantProperty', @@ -22,7 +24,9 @@ defineSuite([ CorridorGeometryUpdater, Cartesian3, CornerType, + GeometryOffsetAttribute, JulianDate, + CesiumMath, TimeInterval, TimeIntervalCollection, ConstantProperty, @@ -54,7 +58,7 @@ defineSuite([ function createBasicCorridor() { var corridor = new CorridorGraphics(); - corridor.positions = new ConstantProperty(Cartesian3.fromRadiansArray([ + corridor.positions = new ConstantProperty(Cartesian3.fromDegreesArray([ 0, 0, 1, 0, 1, 1, @@ -69,13 +73,13 @@ defineSuite([ function createDynamicCorridor() { var entity = createBasicCorridor(); - entity.corridor.positions = createDynamicProperty(Cartesian3.fromRadiansArray([0, 0, 1, 0, 1, 1, 0, 1])); + entity.corridor.positions = createDynamicProperty(Cartesian3.fromDegreesArray([0, 0, 1, 0, 1, 1, 0, 1])); return entity; } function createBasicCorridorWithoutHeight() { var corridor = new CorridorGraphics(); - corridor.positions = new ConstantProperty(Cartesian3.fromRadiansArray([ + corridor.positions = new ConstantProperty(Cartesian3.fromDegreesArray([ 0, 0, 1, 0, 1, 1, @@ -89,7 +93,7 @@ defineSuite([ function createDynamicCorridorWithoutHeight() { var entity = createBasicCorridorWithoutHeight(); - entity.corridor.positions = createDynamicProperty(Cartesian3.fromRadiansArray([0, 0, 1, 0, 1, 1, 0, 1])); + entity.corridor.positions = createDynamicProperty(Cartesian3.fromDegreesArray([0, 0, 1, 0, 1, 1, 0, 1])); return entity; } @@ -193,6 +197,7 @@ defineSuite([ expect(geometry._granularity).toEqual(options.granularity); expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); expect(geometry._cornerType).toEqual(options.cornerType); + expect(geometry._offsetAttribute).toBeUndefined(); instance = updater.createOutlineGeometryInstance(time); geometry = instance.geometry; @@ -201,11 +206,12 @@ defineSuite([ expect(geometry._granularity).toEqual(options.granularity); expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); expect(geometry._cornerType).toEqual(options.cornerType); + expect(geometry._offsetAttribute).toBeUndefined(); }); it('dynamic updater sets properties', function() { var corridor = new CorridorGraphics(); - corridor.positions = createDynamicProperty(Cartesian3.fromRadiansArray([ + corridor.positions = createDynamicProperty(Cartesian3.fromDegreesArray([ 0, 0, 1, 0, 1, 1, @@ -234,6 +240,7 @@ defineSuite([ expect(options.width).toEqual(corridor.width.getValue()); expect(options.granularity).toEqual(corridor.granularity.getValue()); expect(options.cornerType).toEqual(corridor.cornerType.getValue()); + expect(options.offsetAttribute).toBeUndefined(); }); it('geometryChanged event is raised when expected', function() { @@ -268,6 +275,13 @@ defineSuite([ expect(listener.calls.count()).toEqual(4); }); + it('computes center', function() { + var entity = createBasicCorridor(); + var updater = new CorridorGeometryUpdater(entity, scene); + + expect(updater._computeCenter(time)).toEqualEpsilon(Cartesian3.fromDegrees(1.0, 1.0), CesiumMath.EPSILON10); + }); + function getScene() { return scene; } diff --git a/Specs/DataSources/EllipseGeometryUpdaterSpec.js b/Specs/DataSources/EllipseGeometryUpdaterSpec.js index a429a8dd859a..a10f242244c3 100644 --- a/Specs/DataSources/EllipseGeometryUpdaterSpec.js +++ b/Specs/DataSources/EllipseGeometryUpdaterSpec.js @@ -1,6 +1,7 @@ defineSuite([ 'DataSources/EllipseGeometryUpdater', 'Core/Cartesian3', + 'Core/GeometryOffsetAttribute', 'Core/JulianDate', 'Core/TimeIntervalCollection', 'DataSources/ConstantPositionProperty', @@ -18,6 +19,7 @@ defineSuite([ ], function( EllipseGeometryUpdater, Cartesian3, + GeometryOffsetAttribute, JulianDate, TimeIntervalCollection, ConstantPositionProperty, @@ -234,6 +236,7 @@ defineSuite([ expect(geometry._height).toEqual(options.height); expect(geometry._granularity).toEqual(options.granularity); expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); + expect(geometry._offsetAttribute).toBeUndefined(); instance = updater.createOutlineGeometryInstance(time); geometry = instance.geometry; @@ -245,6 +248,7 @@ defineSuite([ expect(geometry._granularity).toEqual(options.granularity); expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); expect(geometry._numberOfVerticalLines).toEqual(options.numberOfVerticalLines); + expect(geometry._offsetAttribute).toBeUndefined(); }); it('dynamic updater sets properties', function() { @@ -265,6 +269,7 @@ defineSuite([ expect(options.semiMajorAxis).toEqual(ellipse.semiMajorAxis.getValue()); expect(options.semiMinorAxis).toEqual(ellipse.semiMinorAxis.getValue()); expect(options.height).toEqual(ellipse.height.getValue()); + expect(options.offsetAttribute).toBeUndefined(); }); it('geometryChanged event is raised when expected', function() { @@ -304,6 +309,13 @@ defineSuite([ expect(listener.calls.count()).toEqual(5); }); + it('computes center', function() { + var entity = createBasicEllipse(); + var updater = new EllipseGeometryUpdater(entity, scene); + + expect(updater._computeCenter(time)).toEqual(entity.position.getValue(time)); + }); + function getScene() { return scene; } diff --git a/Specs/DataSources/GeometryHeightPropertySpec.js b/Specs/DataSources/GeometryHeightPropertySpec.js new file mode 100644 index 000000000000..bdaf1021c505 --- /dev/null +++ b/Specs/DataSources/GeometryHeightPropertySpec.js @@ -0,0 +1,150 @@ +defineSuite([ + 'DataSources/GeometryHeightProperty', + 'Core/ApproximateTerrainHeights', + 'Core/Event', + 'Core/JulianDate', + 'Core/Rectangle', + 'Scene/HeightReference', + 'DataSources/ConstantProperty' +], function( + GeometryHeightProperty, + ApproximateTerrainHeights, + Event, + JulianDate, + Rectangle, + HeightReference, + ConstantProperty) { + 'use strict'; + + var time = JulianDate.now(); + beforeAll(function() { + return ApproximateTerrainHeights.initialize(); + }); + + afterAll(function() { + ApproximateTerrainHeights._initPromise = undefined; + ApproximateTerrainHeights._terrainHeights = undefined; + }); + + it('can default construct', function() { + var property = new GeometryHeightProperty(); + expect(property.isConstant).toBe(true); + expect(property.definitionChanged).toBeInstanceOf(Event); + expect(property.height).toBeUndefined(); + expect(property.heightReference).toBeUndefined(); + expect(property.getValue(time)).toBe(0); + }); + + it('can construct with arguments', function() { + var height = new ConstantProperty(30); + var heightReference = new ConstantProperty(HeightReference.NONE); + var property = new GeometryHeightProperty(height, heightReference); + expect(property.isConstant).toBe(true); + expect(property.definitionChanged).toBeInstanceOf(Event); + expect(property.height).toBe(height); + expect(property.heightReference).toBe(heightReference); + expect(property.getValue(time)).toBe(30); + }); + + it('setting height raises definitionChanged event', function() { + var property = new GeometryHeightProperty(); + + var listener = jasmine.createSpy('listener'); + property.definitionChanged.addEventListener(listener); + + property.height = new ConstantProperty(); + expect(listener).toHaveBeenCalledWith(property); + }); + + it('setting heightReference raises definitionChanged event', function() { + var property = new GeometryHeightProperty(); + + var listener = jasmine.createSpy('listener'); + property.definitionChanged.addEventListener(listener); + + property.heightReference = new ConstantProperty(); + expect(listener).toHaveBeenCalledWith(property); + }); + + it('setting height does not raise definitionChanged event for same data', function() { + var height = new ConstantProperty(30); + var property = new GeometryHeightProperty(height); + + var listener = jasmine.createSpy('listener'); + property.definitionChanged.addEventListener(listener); + + property.height = height; + expect(listener.calls.count()).toBe(0); + }); + + it('setting heightReference does not raise definitionChanged event for same data', function() { + var heightReference = new ConstantProperty(HeightReference.NONE); + var property = new GeometryHeightProperty(undefined, heightReference); + + var listener = jasmine.createSpy('listener'); + property.definitionChanged.addEventListener(listener); + + property.heightReference = heightReference; + expect(listener.calls.count()).toBe(0); + }); + + it('getValue works for for height reference NONE and RELATIVE_TO_GROUND', function() { + var expected = 30; + var height = new ConstantProperty(expected); + var heightReference = new ConstantProperty(HeightReference.NONE); + var property = new GeometryHeightProperty(height, heightReference); + expect(property.getValue(time)).toBe(expected); + + property.heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + expect(property.getValue(time)).toBe(expected); + }); + + it('getValue works for for height reference CLAMP_TO_GROUND', function() { + var height = new ConstantProperty(50); + var heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + var property = new GeometryHeightProperty(height, heightReference); + expect(property.getValue(time)).toBe(0); + }); + + it('equals works', function() { + var height = new ConstantProperty(50); + var heightReference = new ConstantProperty(HeightReference.NONE); + + var left = new GeometryHeightProperty(); + var right = new GeometryHeightProperty(); + + expect(left.equals(undefined)).toBe(false); + expect(left.equals(right)).toBe(true); + + left.height = height; + expect(left.equals(right)).toBe(false); + + right.height = height; + expect(left.equals(right)).toBe(true); + + left.heightReference = heightReference; + expect(left.equals(right)).toBe(false); + + right.heightReference = heightReference; + expect(left.equals(right)).toBe(true); + }); + + it('getValue throws without time', function() { + var property = new GeometryHeightProperty(); + expect(function() { + property.getValue(); + }).toThrowDeveloperError(); + }); + + it('getMinimumTerrainValue return terrain value', function() { + var rectangle = Rectangle.fromDegrees(0, 0, 1, 1); + var expected = ApproximateTerrainHeights.getApproximateTerrainHeights(rectangle).minimumTerrainHeight; + expect(GeometryHeightProperty.getMinimumTerrainValue(rectangle)).toBe(expected); + }); + + it('getMinimumTerrainValue throws without rectangle', function() { + expect(function() { + return GeometryHeightProperty.getMinimumTerrainValue(); + }).toThrowDeveloperError(); + }); +}); diff --git a/Specs/DataSources/PolygonGeometryUpdaterSpec.js b/Specs/DataSources/PolygonGeometryUpdaterSpec.js index 1e87f87d4d5a..f9b13de57acb 100644 --- a/Specs/DataSources/PolygonGeometryUpdaterSpec.js +++ b/Specs/DataSources/PolygonGeometryUpdaterSpec.js @@ -1,7 +1,10 @@ defineSuite([ 'DataSources/PolygonGeometryUpdater', 'Core/Cartesian3', + 'Core/Ellipsoid', + 'Core/GeometryOffsetAttribute', 'Core/JulianDate', + 'Core/Math', 'Core/PolygonHierarchy', 'Core/TimeIntervalCollection', 'DataSources/ConstantProperty', @@ -20,7 +23,10 @@ defineSuite([ ], function( PolygonGeometryUpdater, Cartesian3, + Ellipsoid, + GeometryOffsetAttribute, JulianDate, + CesiumMath, PolygonHierarchy, TimeIntervalCollection, ConstantProperty, @@ -55,10 +61,10 @@ defineSuite([ function createBasicPolygon() { var polygon = new PolygonGraphics(); polygon.hierarchy = new ConstantProperty(new PolygonHierarchy(Cartesian3.fromRadiansArray([ - 0, 0, - 1, 0, + -1, -1, + 1, -1, 1, 1, - 0, 1 + -1, 1 ]))); polygon.height = new ConstantProperty(0); var entity = new Entity(); @@ -225,6 +231,7 @@ defineSuite([ expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); expect(geometry._closeTop).toEqual(options.closeTop); expect(geometry._closeBottom).toEqual(options.closeBottom); + expect(geometry._offsetAttribute).toBeUndefined(); instance = updater.createOutlineGeometryInstance(time); geometry = instance.geometry; @@ -232,6 +239,7 @@ defineSuite([ expect(geometry._granularity).toEqual(options.granularity); expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); expect(geometry._perPositionHeight).toEqual(options.perPositionHeight); + expect(geometry._offsetAttribute).toBeUndefined(); }); it('Checks that a polygon with per position heights isn\'t on terrain', function() { @@ -291,6 +299,7 @@ defineSuite([ expect(options.stRotation).toEqual(polygon.stRotation.getValue()); expect(options.closeTop).toEqual(polygon.closeTop.getValue()); expect(options.closeBottom).toEqual(polygon.closeBottom.getValue()); + expect(options.offsetAttribute).toBeUndefined(); }); it('geometryChanged event is raised when expected', function() { @@ -333,6 +342,14 @@ defineSuite([ expect(updater.onTerrain).toBe(false); }); + it('computes center', function() { + var entity = createBasicPolygon(); + var updater = new PolygonGeometryUpdater(entity, scene); + var result = updater._computeCenter(time); + result = Ellipsoid.WGS84.scaleToGeodeticSurface(result, result); + expect(result).toEqualEpsilon(Cartesian3.fromDegrees(0.0, 0.0), CesiumMath.EPSILON10); + }); + function getScene() { return scene; } diff --git a/Specs/DataSources/PolylineGeometryUpdaterSpec.js b/Specs/DataSources/PolylineGeometryUpdaterSpec.js index cc14250f3aef..67f2e43daff3 100644 --- a/Specs/DataSources/PolylineGeometryUpdaterSpec.js +++ b/Specs/DataSources/PolylineGeometryUpdaterSpec.js @@ -800,5 +800,7 @@ defineSuite([ var instance = updater.createFillGeometryInstance(time); expect(instance.geometry instanceof GroundPolylineGeometry).toBe(false); + + updater.destroy(); }); }, 'WebGL'); diff --git a/Specs/DataSources/RectangleGeometryUpdaterSpec.js b/Specs/DataSources/RectangleGeometryUpdaterSpec.js index 2608b931511f..5f14ca3741c2 100644 --- a/Specs/DataSources/RectangleGeometryUpdaterSpec.js +++ b/Specs/DataSources/RectangleGeometryUpdaterSpec.js @@ -1,7 +1,9 @@ defineSuite([ 'DataSources/RectangleGeometryUpdater', 'Core/Cartesian3', + 'Core/GeometryOffsetAttribute', 'Core/JulianDate', + 'Core/Math', 'Core/Rectangle', 'Core/TimeIntervalCollection', 'DataSources/ConstantProperty', @@ -17,7 +19,9 @@ defineSuite([ ], function( RectangleGeometryUpdater, Cartesian3, + GeometryOffsetAttribute, JulianDate, + CesiumMath, Rectangle, TimeIntervalCollection, ConstantProperty, @@ -48,7 +52,7 @@ defineSuite([ var rectangle = new RectangleGraphics(); var entity = new Entity(); entity.rectangle = rectangle; - entity.rectangle.coordinates = new ConstantProperty(new Rectangle(0, 0, 1, 1)); + entity.rectangle.coordinates = new ConstantProperty(new Rectangle(-1, -1, 1, 1)); entity.rectangle.height = new ConstantProperty(0); return entity; } @@ -161,12 +165,14 @@ defineSuite([ expect(geometry._surfaceHeight).toEqual(options.height); expect(geometry._granularity).toEqual(options.granularity); expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); + expect(geometry._offsetAttribute).toBeUndefined(); instance = updater.createOutlineGeometryInstance(time); geometry = instance.geometry; expect(geometry._surfaceHeight).toEqual(options.height); expect(geometry._granularity).toEqual(options.granularity); expect(geometry._extrudedHeight).toEqual(options.extrudedHeight); + expect(geometry._offsetAttribute).toBeUndefined(); }); it('dynamic updater sets properties', function() { @@ -194,6 +200,7 @@ defineSuite([ expect(options.extrudedHeight).toEqual(rectangle.extrudedHeight.getValue()); expect(options.granularity).toEqual(rectangle.granularity.getValue()); expect(options.stRotation).toEqual(rectangle.stRotation.getValue()); + expect(options.offsetAttribute).toBeUndefined(); }); it('geometryChanged event is raised when expected', function() { @@ -224,6 +231,13 @@ defineSuite([ expect(listener.calls.count()).toEqual(3); }); + it('computes center', function() { + var entity = createBasicRectangle(); + var updater = new RectangleGeometryUpdater(entity, scene); + + expect(updater._computeCenter(time)).toEqualEpsilon(Cartesian3.fromDegrees(0.0, 0.0), CesiumMath.EPSILON10); + }); + function getScene() { return scene; } diff --git a/Specs/DataSources/TerrainOffsetPropertySpec.js b/Specs/DataSources/TerrainOffsetPropertySpec.js new file mode 100644 index 000000000000..d565db1d6e27 --- /dev/null +++ b/Specs/DataSources/TerrainOffsetPropertySpec.js @@ -0,0 +1,77 @@ +defineSuite([ + 'DataSources/TerrainOffsetProperty', + 'Core/Cartesian3', + 'Core/Event', + 'Core/JulianDate', + 'Core/Rectangle', + 'Scene/HeightReference', + 'DataSources/ConstantProperty', + 'Specs/createGlobe', + 'Specs/createScene' +], function( + TerrainOffsetProperty, + Cartesian3, + Event, + JulianDate, + Rectangle, + HeightReference, + ConstantProperty, + createGlobe, + createScene) { + 'use strict'; + + var scene; + var time = JulianDate.now(); + beforeAll(function() { + scene = createScene(); + scene.globe = createGlobe(); + }); + + afterAll(function() { + scene.destroyForSpecs(); + }); + + it('can construct and destroy', function() { + var getPosition = jasmine.createSpy(); + var height = new ConstantProperty(30); + var extrudedHeight = new ConstantProperty(0); + var property = new TerrainOffsetProperty(scene, height, extrudedHeight, getPosition); + expect(property.isConstant).toBe(false); + expect(property.getValue(time)).toEqual(Cartesian3.ZERO); + property.destroy(); + expect(property.isDestroyed()).toBe(true); + }); + + it('throws without scene', function() { + var getPosition = jasmine.createSpy(); + var height = new ConstantProperty(30); + var extrudedHeight = new ConstantProperty(0); + expect(function() { + return new TerrainOffsetProperty(undefined, height, extrudedHeight, getPosition); + }).toThrowDeveloperError(); + }); + + it('throws without height', function() { + var getPosition = jasmine.createSpy(); + var extrudedHeight = new ConstantProperty(0); + expect(function() { + return new TerrainOffsetProperty(scene, undefined, extrudedHeight, getPosition); + }).toThrowDeveloperError(); + }); + + it('throws without extrudedHeight', function() { + var getPosition = jasmine.createSpy(); + var height = new ConstantProperty(30); + expect(function() { + return new TerrainOffsetProperty(scene, height, undefined, getPosition); + }).toThrowDeveloperError(); + }); + + it('throws without getPosition', function() { + var height = new ConstantProperty(30); + var extrudedHeight = new ConstantProperty(0); + expect(function() { + return new TerrainOffsetProperty(scene, height, extrudedHeight, undefined); + }).toThrowDeveloperError(); + }); +}); diff --git a/Specs/createGeometryUpdaterGroundGeometrySpecs.js b/Specs/createGeometryUpdaterGroundGeometrySpecs.js index b0ed38ab479c..9334437e320b 100644 --- a/Specs/createGeometryUpdaterGroundGeometrySpecs.js +++ b/Specs/createGeometryUpdaterGroundGeometrySpecs.js @@ -1,20 +1,26 @@ define([ 'Core/Color', + 'Core/GeometryOffsetAttribute', 'Core/JulianDate', 'DataSources/ColorMaterialProperty', 'DataSources/ConstantProperty', + 'DataSources/GeometryHeightProperty', 'DataSources/SampledProperty', 'Scene/ClassificationType', 'Scene/GroundPrimitive', + 'Scene/HeightReference', 'Scene/PrimitiveCollection' ], function( Color, + GeometryOffsetAttribute, JulianDate, ColorMaterialProperty, ConstantProperty, + GeometryHeightProperty, SampledProperty, ClassificationType, GroundPrimitive, + HeightReference, PrimitiveCollection) { 'use strict'; @@ -119,6 +125,108 @@ define([ expect(updater.onTerrain).toBe(false); }); + it('Creates geometry with no offsetAttribute when geometry is on terrain', function() { + var entity = createEntity(); + + var updater = new Updater(entity, getScene()); + + var instance; + var geometry; + instance = updater.createFillGeometryInstance(time); + geometry = instance.geometry; + expect(geometry._offsetAttribute).toBeUndefined(); + }); + + it('Creates geometry with expected offsetAttribute based on height and extrudedHeight', function() { + var entity = createEntity(); + var graphics = entity[geometryPropertyName]; + graphics.outline = true; + graphics.outlineColor = Color.BLACK; + var updater = new Updater(entity, getScene()); + + var instance; + + graphics.height = new ConstantProperty(20.0); + graphics.extrudedHeight = new ConstantProperty(0.0); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toBeUndefined(); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toBeUndefined(); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.NONE); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.NONE); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toBeUndefined(); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toBeUndefined(); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.NONE); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.CLAMP_TO_GROUND); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toBeUndefined(); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toBeUndefined(); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.NONE); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.RELATIVE_TO_GROUND); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.CLAMP_TO_GROUND); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.NONE); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.CLAMP_TO_GROUND); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.CLAMP_TO_GROUND); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.CLAMP_TO_GROUND); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.RELATIVE_TO_GROUND); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.ALL); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.ALL); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.RELATIVE_TO_GROUND); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.NONE); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.RELATIVE_TO_GROUND); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.CLAMP_TO_GROUND); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); + + graphics.height = new GeometryHeightProperty(20.0, HeightReference.RELATIVE_TO_GROUND); + graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.RELATIVE_TO_GROUND); + updater._onEntityPropertyChanged(entity, geometryPropertyName); + instance = updater.createFillGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.ALL); + instance = updater.createOutlineGeometryInstance(time); + expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.ALL); + }); + it('color material sets onTerrain to true', function() { var entity = createEntity(); var geometry = entity[geometryPropertyName]; From 6522aa5d6da2a705071b4c6be777bce28473d4eb Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 26 Jun 2018 16:13:30 -0400 Subject: [PATCH 02/10] cleanup --- Source/DataSources/CorridorGeometryUpdater.js | 21 +++++++++------- Source/DataSources/EllipseGeometryUpdater.js | 25 +++++++++---------- Source/DataSources/GeometryHeightProperty.js | 20 ++++++++++++--- Source/DataSources/GeometryVisualizer.js | 18 +++++-------- Source/DataSources/GroundGeometryUpdater.js | 10 +------- Source/DataSources/PolygonGeometryUpdater.js | 21 +++++++++------- .../DataSources/RectangleGeometryUpdater.js | 19 +++++++------- Source/Scene/Primitive.js | 2 +- .../CorridorGeometryUpdaterSpec.js | 7 ++++++ .../DataSources/EllipseGeometryUpdaterSpec.js | 7 ++++++ .../DataSources/GeometryHeightPropertySpec.js | 10 +++++--- .../DataSources/PolygonGeometryUpdaterSpec.js | 6 +++++ .../RectangleGeometryUpdaterSpec.js | 7 ++++++ 13 files changed, 103 insertions(+), 70 deletions(-) diff --git a/Source/DataSources/CorridorGeometryUpdater.js b/Source/DataSources/CorridorGeometryUpdater.js index 4fbac9960203..c97e1927b4e6 100644 --- a/Source/DataSources/CorridorGeometryUpdater.js +++ b/Source/DataSources/CorridorGeometryUpdater.js @@ -12,6 +12,7 @@ define([ '../Core/GeometryOffsetAttribute', '../Core/Iso8601', '../Core/OffsetGeometryInstanceAttribute', + '../Core/Rectangle', '../Core/ShowGeometryInstanceAttribute', '../Scene/GroundPrimitive', '../Scene/HeightReference', @@ -37,6 +38,7 @@ define([ GeometryOffsetAttribute, Iso8601, OffsetGeometryInstanceAttribute, + Rectangle, ShowGeometryInstanceAttribute, GroundPrimitive, HeightReference, @@ -53,7 +55,7 @@ define([ var scratchColor = new Color(); var defaultOffset = Cartesian3.ZERO; var offsetScratch = new Cartesian3(); - var scratchCorridorGeometry = new CorridorGeometry({positions: [], width: 1}); + var scratchRectangle = new Rectangle(); function CorridorGeometryOptions(entity) { this.id = entity; @@ -115,7 +117,9 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)), + offset : undefined, + color : undefined }; if (this._materialProperty instanceof ColorMaterialProperty) { @@ -164,7 +168,8 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), color : ColorGeometryInstanceAttribute.fromColor(outlineColor), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)), + offset : undefined }; if (defined(this._options.offsetAttribute)) { @@ -231,9 +236,8 @@ define([ options.cornerType = defined(cornerType) ? cornerType.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchCorridorGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchCorridorGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); } }; @@ -268,9 +272,8 @@ define([ options.cornerType = Property.getValueOrUndefined(corridor.cornerType, time); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchCorridorGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchCorridorGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); } }; diff --git a/Source/DataSources/EllipseGeometryUpdater.js b/Source/DataSources/EllipseGeometryUpdater.js index b76ca9f7195b..7169ad369c5b 100644 --- a/Source/DataSources/EllipseGeometryUpdater.js +++ b/Source/DataSources/EllipseGeometryUpdater.js @@ -12,6 +12,7 @@ define([ '../Core/GeometryOffsetAttribute', '../Core/Iso8601', '../Core/OffsetGeometryInstanceAttribute', + '../Core/Rectangle', '../Core/ShowGeometryInstanceAttribute', '../Scene/GroundPrimitive', '../Scene/HeightReference', @@ -37,6 +38,7 @@ define([ GeometryOffsetAttribute, Iso8601, OffsetGeometryInstanceAttribute, + Rectangle, ShowGeometryInstanceAttribute, GroundPrimitive, HeightReference, @@ -53,11 +55,7 @@ define([ var scratchColor = new Color(); var defaultOffset = Cartesian3.ZERO; var offsetScratch = new Cartesian3(); - var scratchEllipseGeometry = new EllipseGeometry({ - center: new Cartesian3(), - semiMajorAxis: 2, - semiMinorAxis: 1 - }); + var scratchRectangle = new Rectangle(); function EllipseGeometryOptions(entity) { this.id = entity; @@ -122,7 +120,9 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)), + offset : undefined, + color : undefined }; if (this._materialProperty instanceof ColorMaterialProperty) { @@ -172,7 +172,8 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), color : ColorGeometryInstanceAttribute.fromColor(outlineColor), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition), + offset : undefined }; if (defined(this._options.offsetAttribute)) { @@ -243,9 +244,8 @@ define([ options.numberOfVerticalLines = defined(numberOfVerticalLines) ? numberOfVerticalLines.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchEllipseGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchEllipseGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); } }; @@ -283,9 +283,8 @@ define([ options.numberOfVerticalLines = Property.getValueOrUndefined(ellipse.numberOfVerticalLines, time); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchEllipseGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchEllipseGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); } }; diff --git a/Source/DataSources/GeometryHeightProperty.js b/Source/DataSources/GeometryHeightProperty.js index dd7438ef9084..b7b68544c3f8 100644 --- a/Source/DataSources/GeometryHeightProperty.js +++ b/Source/DataSources/GeometryHeightProperty.js @@ -21,7 +21,7 @@ define([ 'use strict'; /** - * A {@link Property} which computes height or extrudedHeight for a {@link CorridorGraphics}, {@link EllipseGraphics}, {@link PolygonGraphics} or {@link RectangleGraphics}. + * A {@link Property} which computes height or extrudedHeight in relation to the current terrain visualization. * * @alias GeometryHeightProperty * @constructor @@ -58,6 +58,11 @@ define([ this._heightReferenceSubscription = undefined; this._definitionChanged = new Event(); + this._resultObject = { + height: 0, + heightReference: HeightReference.NONE + }; + this.height = height; this.heightReference = heightReference; } @@ -115,11 +120,18 @@ define([ //>>includeEnd('debug'); var heightReference = Property.getValueOrDefault(this._heightReference, time, HeightReference.NONE); - + var height; if (heightReference !== HeightReference.CLAMP_TO_GROUND) { - return Property.getValueOrDefault(this._height, time, 0); + height = Property.getValueOrDefault(this._height, time, 0); + } else { + height = 0; } - return 0; +/* + var result = this._resultObject; + result.height = height; + result.heightReference = heightReference; +*/ + return height; }; /** diff --git a/Source/DataSources/GeometryVisualizer.js b/Source/DataSources/GeometryVisualizer.js index 41f4ee0a792c..2f70c1eb260a 100644 --- a/Source/DataSources/GeometryVisualizer.js +++ b/Source/DataSources/GeometryVisualizer.js @@ -426,13 +426,10 @@ define([ } else { this._closedColorBatches[shadows].add(time, updater); } + } else if (defined(updater.terrainOffsetProperty)) { + this._closedMaterialBatches[numberOfShadowModes + shadows].add(time, updater); } else { - // eslint-disable-next-line no-lonely-if - if (defined(updater.terrainOffsetProperty)) { - this._closedMaterialBatches[numberOfShadowModes + shadows].add(time, updater); - } else { - this._closedMaterialBatches[shadows].add(time, updater); - } + this._closedMaterialBatches[shadows].add(time, updater); } } else if (updater.fillMaterialProperty instanceof ColorMaterialProperty) { if (defined(updater.terrainOffsetProperty)) { @@ -440,13 +437,10 @@ define([ } else { this._openColorBatches[shadows].add(time, updater); } + } else if (defined(updater.terrainOffsetProperty)) { + this._openMaterialBatches[numberOfShadowModes + shadows].add(time, updater); } else { - // eslint-disable-next-line no-lonely-if - if (defined(updater.terrainOffsetProperty)) { - this._openMaterialBatches[numberOfShadowModes + shadows].add(time, updater); - } else { - this._openMaterialBatches[shadows].add(time, updater); - } + this._openMaterialBatches[shadows].add(time, updater); } } }; diff --git a/Source/DataSources/GroundGeometryUpdater.js b/Source/DataSources/GroundGeometryUpdater.js index 4d4c4d5c629b..7f806f4afa90 100644 --- a/Source/DataSources/GroundGeometryUpdater.js +++ b/Source/DataSources/GroundGeometryUpdater.js @@ -73,14 +73,6 @@ define([ } }); - /** - * @param {Entity} entity - * @param {Object} geometry - * @param {JulianDate} time - * @param {Cartesian3} result - * - * @private - */ GroundGeometryUpdater.prototype._computeCenter = DeveloperError.throwInstantiationError; GroundGeometryUpdater.prototype._onEntityPropertyChanged = function(entity, propertyName, newValue, oldValue) { @@ -102,7 +94,7 @@ define([ var heightProperty = geometry.height; var extrudedHeightProperty = geometry.extrudedHeight; - if (this._terrainOffsetProperty instanceof TerrainOffsetProperty) { + if (defined(this._terrainOffsetProperty)) { this._terrainOffsetProperty.destroy(); } diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index 32f55711bad1..8fbd65c73553 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -14,6 +14,7 @@ define([ '../Core/PolygonGeometry', '../Core/PolygonHierarchy', '../Core/PolygonOutlineGeometry', + '../Core/Rectangle', '../Core/ShowGeometryInstanceAttribute', '../Scene/GroundPrimitive', '../Scene/HeightReference', @@ -41,6 +42,7 @@ define([ PolygonGeometry, PolygonHierarchy, PolygonOutlineGeometry, + Rectangle, ShowGeometryInstanceAttribute, GroundPrimitive, HeightReference, @@ -57,7 +59,7 @@ define([ var scratchColor = new Color(); var defaultOffset = Cartesian3.ZERO; var offsetScratch = new Cartesian3(); - var scratchPolygonGeometry = new PolygonGeometry({polygonHierarchy: new PolygonHierarchy}); + var scratchRectangle = new Rectangle(); function PolygonGeometryOptions(entity) { this.id = entity; @@ -121,7 +123,9 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)), + offset : undefined, + color : undefined }; if (this._materialProperty instanceof ColorMaterialProperty) { @@ -170,7 +174,8 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), color : ColorGeometryInstanceAttribute.fromColor(outlineColor), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition), + offset : undefined }; if (defined(this._options.offsetAttribute)) { @@ -264,9 +269,8 @@ define([ options.closeBottom = closeBottomValue; options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchPolygonGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchPolygonGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); } }; @@ -316,9 +320,8 @@ define([ options.closeBottom = Property.getValueOrDefault(polygon.closeBottom, time, true); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchPolygonGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchPolygonGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); } }; diff --git a/Source/DataSources/RectangleGeometryUpdater.js b/Source/DataSources/RectangleGeometryUpdater.js index 48416ea3bd83..3dbcaff610d8 100644 --- a/Source/DataSources/RectangleGeometryUpdater.js +++ b/Source/DataSources/RectangleGeometryUpdater.js @@ -59,7 +59,7 @@ define([ var scratchColor = new Color(); var defaultOffset = Cartesian3.ZERO; var offsetScratch = new Cartesian3(); - var scratchRectangleGeometry = new RectangleGeometry({rectangle: new Rectangle()}); + var scratchRectangle = new Rectangle(); var scratchCenterRect = new Rectangle(); var scratchCarto = new Cartographic(); @@ -123,7 +123,9 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)), + offset : undefined, + color : undefined }; if (this._materialProperty instanceof ColorMaterialProperty) { @@ -172,7 +174,8 @@ define([ var attributes = { show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)), color : ColorGeometryInstanceAttribute.fromColor(outlineColor), - distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition) + distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition), + offset : undefined }; if (defined(this._options.offsetAttribute)) { @@ -234,9 +237,8 @@ define([ options.rotation = defined(rotation) ? rotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchRectangleGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchRectangleGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); } }; @@ -277,9 +279,8 @@ define([ options.rotation = Property.getValueOrUndefined(rectangle.rotation, time); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.height, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - scratchRectangleGeometry.setOptions(options); - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(scratchRectangleGeometry.rectangle); + if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { + options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); } }; diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index 4e471bd0179b..413d25a81ce1 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -526,7 +526,7 @@ define([ var name; for (name in attributes0) { - if (attributes0.hasOwnProperty(name)) { + if (attributes0.hasOwnProperty(name) && defined(attributes0[name])) { var attribute = attributes0[name]; var inAllInstances = true; diff --git a/Specs/DataSources/CorridorGeometryUpdaterSpec.js b/Specs/DataSources/CorridorGeometryUpdaterSpec.js index d074c244febb..1f4c23f2b3cc 100644 --- a/Specs/DataSources/CorridorGeometryUpdaterSpec.js +++ b/Specs/DataSources/CorridorGeometryUpdaterSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'DataSources/CorridorGeometryUpdater', + 'Core/ApproximateTerrainHeights', 'Core/Cartesian3', 'Core/CornerType', 'Core/GeometryOffsetAttribute', @@ -22,6 +23,7 @@ defineSuite([ 'Specs/createScene' ], function( CorridorGeometryUpdater, + ApproximateTerrainHeights, Cartesian3, CornerType, GeometryOffsetAttribute, @@ -50,10 +52,15 @@ defineSuite([ beforeAll(function() { scene = createScene(); time = JulianDate.now(); + + return ApproximateTerrainHeights.initialize(); }); afterAll(function() { scene.destroyForSpecs(); + + ApproximateTerrainHeights._initPromise = undefined; + ApproximateTerrainHeights._terrainHeights = undefined; }); function createBasicCorridor() { diff --git a/Specs/DataSources/EllipseGeometryUpdaterSpec.js b/Specs/DataSources/EllipseGeometryUpdaterSpec.js index a10f242244c3..559020da2906 100644 --- a/Specs/DataSources/EllipseGeometryUpdaterSpec.js +++ b/Specs/DataSources/EllipseGeometryUpdaterSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'DataSources/EllipseGeometryUpdater', + 'Core/ApproximateTerrainHeights', 'Core/Cartesian3', 'Core/GeometryOffsetAttribute', 'Core/JulianDate', @@ -18,6 +19,7 @@ defineSuite([ 'Specs/createScene' ], function( EllipseGeometryUpdater, + ApproximateTerrainHeights, Cartesian3, GeometryOffsetAttribute, JulianDate, @@ -42,10 +44,15 @@ defineSuite([ beforeAll(function() { scene = createScene(); time = JulianDate.now(); + + return ApproximateTerrainHeights.initialize(); }); afterAll(function() { scene.destroyForSpecs(); + + ApproximateTerrainHeights._initPromise = undefined; + ApproximateTerrainHeights._terrainHeights = undefined; }); function createBasicEllipse() { diff --git a/Specs/DataSources/GeometryHeightPropertySpec.js b/Specs/DataSources/GeometryHeightPropertySpec.js index bdaf1021c505..c7559c025f9c 100644 --- a/Specs/DataSources/GeometryHeightPropertySpec.js +++ b/Specs/DataSources/GeometryHeightPropertySpec.js @@ -52,8 +52,9 @@ defineSuite([ var listener = jasmine.createSpy('listener'); property.definitionChanged.addEventListener(listener); - property.height = new ConstantProperty(); - expect(listener).toHaveBeenCalledWith(property); + var newValue = new ConstantProperty(); + property.height = newValue; + expect(listener).toHaveBeenCalledWith(property, 'height', newValue, undefined); }); it('setting heightReference raises definitionChanged event', function() { @@ -62,8 +63,9 @@ defineSuite([ var listener = jasmine.createSpy('listener'); property.definitionChanged.addEventListener(listener); - property.heightReference = new ConstantProperty(); - expect(listener).toHaveBeenCalledWith(property); + var newValue =new ConstantProperty(); + property.heightReference = newValue; + expect(listener).toHaveBeenCalledWith(property, 'heightReference', newValue, undefined); }); it('setting height does not raise definitionChanged event for same data', function() { diff --git a/Specs/DataSources/PolygonGeometryUpdaterSpec.js b/Specs/DataSources/PolygonGeometryUpdaterSpec.js index f9b13de57acb..18d40f26e264 100644 --- a/Specs/DataSources/PolygonGeometryUpdaterSpec.js +++ b/Specs/DataSources/PolygonGeometryUpdaterSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'DataSources/PolygonGeometryUpdater', + 'Core/ApproximateTerrainHeights', 'Core/Cartesian3', 'Core/Ellipsoid', 'Core/GeometryOffsetAttribute', @@ -22,6 +23,7 @@ defineSuite([ 'Specs/createScene' ], function( PolygonGeometryUpdater, + ApproximateTerrainHeights, Cartesian3, Ellipsoid, GeometryOffsetAttribute, @@ -52,10 +54,14 @@ defineSuite([ scene = createScene(); time = JulianDate.now(); groundPrimitiveSupported = GroundPrimitive.isSupported(scene); + return ApproximateTerrainHeights.initialize(); }); afterAll(function() { scene.destroyForSpecs(); + + ApproximateTerrainHeights._initPromise = undefined; + ApproximateTerrainHeights._terrainHeights = undefined; }); function createBasicPolygon() { diff --git a/Specs/DataSources/RectangleGeometryUpdaterSpec.js b/Specs/DataSources/RectangleGeometryUpdaterSpec.js index 5f14ca3741c2..4f8c74175435 100644 --- a/Specs/DataSources/RectangleGeometryUpdaterSpec.js +++ b/Specs/DataSources/RectangleGeometryUpdaterSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'DataSources/RectangleGeometryUpdater', + 'Core/ApproximateTerrainHeights', 'Core/Cartesian3', 'Core/GeometryOffsetAttribute', 'Core/JulianDate', @@ -18,6 +19,7 @@ defineSuite([ 'Specs/createScene' ], function( RectangleGeometryUpdater, + ApproximateTerrainHeights, Cartesian3, GeometryOffsetAttribute, JulianDate, @@ -42,10 +44,15 @@ defineSuite([ beforeAll(function() { scene = createScene(); time = new JulianDate(0, 0); + + return ApproximateTerrainHeights.initialize(); }); afterAll(function() { scene.destroyForSpecs(); + + ApproximateTerrainHeights._initPromise = undefined; + ApproximateTerrainHeights._terrainHeights = undefined; }); function createBasicRectangle() { From cae76e90142a75b4f1cc61301d183f2bb3a76f6d Mon Sep 17 00:00:00 2001 From: hpinkos Date: Tue, 26 Jun 2018 17:39:19 -0400 Subject: [PATCH 03/10] fix instanceof and sandcastle example --- .../gallery/Geometry Height Reference.html | 32 +++++++++---- Source/DataSources/CorridorGeometryUpdater.js | 41 ++++++++++++---- Source/DataSources/EllipseGeometryUpdater.js | 41 ++++++++++++---- Source/DataSources/GeometryHeightProperty.js | 22 +++++---- Source/DataSources/GroundGeometryUpdater.js | 13 +++-- Source/DataSources/PolygonGeometryUpdater.js | 47 ++++++++++++++----- .../DataSources/RectangleGeometryUpdater.js | 40 ++++++++++++---- Source/DataSources/TerrainOffsetProperty.js | 28 ++++++----- .../DataSources/GeometryHeightPropertySpec.js | 25 ++++++++-- .../DataSources/TerrainOffsetPropertySpec.js | 16 ------- 10 files changed, 214 insertions(+), 91 deletions(-) diff --git a/Apps/Sandcastle/gallery/Geometry Height Reference.html b/Apps/Sandcastle/gallery/Geometry Height Reference.html index 6a31256c48bf..135be5b66a03 100644 --- a/Apps/Sandcastle/gallery/Geometry Height Reference.html +++ b/Apps/Sandcastle/gallery/Geometry Height Reference.html @@ -29,20 +29,32 @@ function startup(Cesium) { 'use strict'; //Sandcastle_Begin +var cesiumTerrainProvider = Cesium.createWorldTerrain(); +var ellipsoidTerrainProvider = new Cesium.EllipsoidTerrainProvider(); var viewer = new Cesium.Viewer('cesiumContainer', { baseLayerPicker: false, - terrainProvider: Cesium.createWorldTerrain() + terrainProvider: cesiumTerrainProvider }); viewer.scene.globe.depthTestAgainstTerrain = true; +Sandcastle.addToolbarButton('Enable Terrain', function() { + viewer.scene.terrainProvider = cesiumTerrainProvider; +}); + +Sandcastle.addToolbarButton('Disable Terrain', function() { + viewer.scene.terrainProvider = ellipsoidTerrainProvider; +}); + + var baseLon = 6.850615989890521; var baseLat = 45.89546589994886; +var delta = 0.001; function addEntity(i, j) { - var lon1 = baseLon + 0.0001*i; - var lon2 = baseLon + 0.0001*i + 0.0001; + var lon1 = baseLon + delta*i; + var lon2 = baseLon + delta*i + delta; - var lat1 = baseLat + 0.0001*j; - var lat2 = baseLat + 0.0001*j + 0.0001; + var lat1 = baseLat + delta*j; + var lat2 = baseLat + delta*j + delta; var a = Cesium.Cartesian3.fromDegrees(lon1, lat1); var b = Cesium.Cartesian3.fromDegrees(lon1, lat2); var c = Cesium.Cartesian3.fromDegrees(lon2, lat2); @@ -53,7 +65,7 @@ polygon : { hierarchy : positions, material : Cesium.Color.fromRandom({alpha: 1}), - height : new Cesium.GeometryHeightProperty(10.0, Cesium.HeightReference.RELATIVE_TO_GROUND), + height : new Cesium.GeometryHeightProperty(40.0, Cesium.HeightReference.RELATIVE_TO_GROUND), extrudedHeight : new Cesium.GeometryHeightProperty(0.0, Cesium.HeightReference.CLAMP_TO_GROUND) } }); @@ -66,11 +78,11 @@ } viewer.scene.camera.flyTo({ - destination: new Cesium.Cartesian3(4415716.090770245, 530458.0589739879, 4558358.470675762), + destination: new Cesium.Cartesian3(4414709.69060132, 531290.9290968775, 4561007.639489886), orientation: { - heading: 2.9422859539310506, - pitch: -0.26904591127394784, - roll: 0.0006888582061437276 + heading: 3.6086529754485834, + pitch: -0.6592870741832781, + roll: 6.28127756699859 } }); //Sandcastle_End diff --git a/Source/DataSources/CorridorGeometryUpdater.js b/Source/DataSources/CorridorGeometryUpdater.js index c97e1927b4e6..da284967840b 100644 --- a/Source/DataSources/CorridorGeometryUpdater.js +++ b/Source/DataSources/CorridorGeometryUpdater.js @@ -226,19 +226,31 @@ define([ var cornerType = corridor.cornerType; var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty; + var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); + var options = this._options; options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; options.positions = corridor.positions.getValue(Iso8601.MINIMUM_VALUE, options.positions); - options.height = defined(height) ? height.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.extrudedHeight = defined(extrudedHeight) ? extrudedHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.width = defined(width) ? width.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.cornerType = defined(cornerType) ? cornerType.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; + } + + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; CorridorGeometryUpdater.DynamicGeometryUpdater = DynamicCorridorGeometryUpdater; @@ -264,17 +276,30 @@ define([ var options = this._options; var height = corridor.height; var extrudedHeight = corridor.extrudedHeight; + + var heightValue = Property.getValueOrUndefined(height, time); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); + options.positions = Property.getValueOrUndefined(corridor.positions, time); options.width = Property.getValueOrUndefined(corridor.width, time); - options.height = Property.getValueOrUndefined(height, time); - options.extrudedHeight = Property.getValueOrUndefined(extrudedHeight, time); options.granularity = Property.getValueOrUndefined(corridor.granularity, time); options.cornerType = Property.getValueOrUndefined(corridor.cornerType, time); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; } + + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } + } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; return CorridorGeometryUpdater; diff --git a/Source/DataSources/EllipseGeometryUpdater.js b/Source/DataSources/EllipseGeometryUpdater.js index 7169ad369c5b..950a87f9d57f 100644 --- a/Source/DataSources/EllipseGeometryUpdater.js +++ b/Source/DataSources/EllipseGeometryUpdater.js @@ -231,22 +231,34 @@ define([ var numberOfVerticalLines = ellipse.numberOfVerticalLines; var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty; + var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); + var options = this._options; options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; options.center = entity.position.getValue(Iso8601.MINIMUM_VALUE, options.center); options.semiMajorAxis = ellipse.semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMajorAxis); options.semiMinorAxis = ellipse.semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMinorAxis); options.rotation = defined(rotation) ? rotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.height = defined(height) ? height.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.extrudedHeight = defined(extrudedHeight) ? extrudedHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.stRotation = defined(stRotation) ? stRotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.numberOfVerticalLines = defined(numberOfVerticalLines) ? numberOfVerticalLines.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; + } + + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; EllipseGeometryUpdater.DynamicGeometryUpdater = DynamicEllipseGeometryUpdater; @@ -272,20 +284,33 @@ define([ var options = this._options; var height = ellipse.height; var extrudedHeight = ellipse.extrudedHeight; + + var heightValue = Property.getValueOrUndefined(height, time); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); + options.center = Property.getValueOrUndefined(entity.position, time, options.center); options.semiMajorAxis = Property.getValueOrUndefined(ellipse.semiMajorAxis, time); options.semiMinorAxis = Property.getValueOrUndefined(ellipse.semiMinorAxis, time); options.rotation = Property.getValueOrUndefined(ellipse.rotation, time); - options.height = Property.getValueOrUndefined(height, time); - options.extrudedHeight = Property.getValueOrUndefined(extrudedHeight, time); options.granularity = Property.getValueOrUndefined(ellipse.granularity, time); options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, time); options.numberOfVerticalLines = Property.getValueOrUndefined(ellipse.numberOfVerticalLines, time); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; } + + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } + } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; return EllipseGeometryUpdater; diff --git a/Source/DataSources/GeometryHeightProperty.js b/Source/DataSources/GeometryHeightProperty.js index b7b68544c3f8..dd47ab357011 100644 --- a/Source/DataSources/GeometryHeightProperty.js +++ b/Source/DataSources/GeometryHeightProperty.js @@ -126,12 +126,12 @@ define([ } else { height = 0; } -/* + var result = this._resultObject; result.height = height; result.heightReference = heightReference; -*/ - return height; + + return result; }; /** @@ -154,12 +154,17 @@ define([ * @private */ GeometryHeightProperty.computeGeometryOffsetAttribute = function(height, extrudedHeight, time) { - if (!(extrudedHeight instanceof GeometryHeightProperty) && !(height instanceof GeometryHeightProperty)) { - return undefined; - } + var heightValue = Property.getValueOrUndefined(height, time); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); - var heightReference = defined(height) ? Property.getValueOrDefault(height.heightReference, time, HeightReference.NONE) : HeightReference.NONE; - var extrudedHeightReference = defined(extrudedHeight) ? Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) : HeightReference.NONE; + var heightReference = HeightReference.NONE; + var extrudedHeightReference = HeightReference.NONE; + if (defined(heightValue) && defined(heightValue.heightReference)) { + heightReference = heightValue.heightReference; + } + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + extrudedHeightReference = extrudedHeightValue.heightReference; + } var n = 0; if (heightReference !== HeightReference.NONE) { @@ -174,6 +179,7 @@ define([ if (n === 1) { return GeometryOffsetAttribute.TOP; } + return undefined; }; diff --git a/Source/DataSources/GroundGeometryUpdater.js b/Source/DataSources/GroundGeometryUpdater.js index 7f806f4afa90..efa54a87cc95 100644 --- a/Source/DataSources/GroundGeometryUpdater.js +++ b/Source/DataSources/GroundGeometryUpdater.js @@ -11,6 +11,7 @@ define([ './ConstantProperty', './GeometryHeightProperty', './GeometryUpdater', + './Property', './TerrainOffsetProperty' ], function( Cartesian3, @@ -25,6 +26,7 @@ define([ ConstantProperty, GeometryHeightProperty, GeometryUpdater, + Property, TerrainOffsetProperty) { 'use strict'; @@ -96,12 +98,15 @@ define([ if (defined(this._terrainOffsetProperty)) { this._terrainOffsetProperty.destroy(); + this._terrainOffsetProperty = undefined; } - if (heightProperty instanceof GeometryHeightProperty || extrudedHeightProperty instanceof GeometryHeightProperty) { - this._terrainOffsetProperty = new TerrainOffsetProperty(this._scene, heightProperty, extrudedHeightProperty, this._computeCenter.bind(this)); - } else { - this._terrainOffsetProperty = undefined; + if (defined(heightProperty) || defined(extrudedHeightProperty)) { + var heightValue = Property.getValueOrUndefined(heightProperty, Iso8601.MINIMUM_VALUE); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeightProperty, Iso8601.MINIMUM_VALUE); + if (this._dynamic || (defined(heightValue) && defined(heightValue.heightReference)) || (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference))) { + this._terrainOffsetProperty = new TerrainOffsetProperty(this._scene, heightProperty, extrudedHeightProperty, this._computeCenter.bind(this)); + } } }; diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index 8fbd65c73553..5fba416b150d 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -250,8 +250,6 @@ define([ var extrudedHeight = polygon.extrudedHeight; var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); - var closeTopValue = Property.getValueOrDefault(polygon.closeTop, Iso8601.MINIMUM_VALUE, true); - var closeBottomValue = Property.getValueOrDefault(polygon.closeBottom, Iso8601.MINIMUM_VALUE, true); var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); var perPositionHeightValue = Property.getValueOrUndefined(polygon.perPositionHeight, Iso8601.MINIMUM_VALUE); @@ -260,18 +258,27 @@ define([ } options.polygonHierarchy = hierarchyValue; - options.height = heightValue; - options.extrudedHeight = extrudedHeightValue; options.granularity = Property.getValueOrUndefined(polygon.granularity, Iso8601.MINIMUM_VALUE); options.stRotation = Property.getValueOrUndefined(polygon.stRotation, Iso8601.MINIMUM_VALUE); options.perPositionHeight = perPositionHeightValue; - options.closeTop = closeTopValue; - options.closeBottom = closeBottomValue; + options.closeTop = Property.getValueOrDefault(polygon.closeTop, Iso8601.MINIMUM_VALUE, true); + options.closeBottom = Property.getValueOrDefault(polygon.closeBottom, Iso8601.MINIMUM_VALUE, true); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; + } + + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; PolygonGeometryUpdater.prototype._getIsClosed = function(options) { @@ -311,8 +318,14 @@ define([ options.polygonHierarchy = hierarchy; } - options.height = Property.getValueOrUndefined(height, time); - options.extrudedHeight = Property.getValueOrUndefined(extrudedHeight, time); + var heightValue = Property.getValueOrUndefined(height, time); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); + var perPositionHeightValue = Property.getValueOrUndefined(polygon.perPositionHeight, time); + + if (defined(extrudedHeightValue) && !defined(heightValue) && !defined(perPositionHeightValue)) { + heightValue = 0; + } + options.granularity = Property.getValueOrUndefined(polygon.granularity, time); options.stRotation = Property.getValueOrUndefined(polygon.stRotation, time); options.perPositionHeight = Property.getValueOrUndefined(polygon.perPositionHeight, time); @@ -320,10 +333,20 @@ define([ options.closeBottom = Property.getValueOrDefault(polygon.closeBottom, time, true); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; } + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } + } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; return PolygonGeometryUpdater; diff --git a/Source/DataSources/RectangleGeometryUpdater.js b/Source/DataSources/RectangleGeometryUpdater.js index 3dbcaff610d8..3cd071a7272e 100644 --- a/Source/DataSources/RectangleGeometryUpdater.js +++ b/Source/DataSources/RectangleGeometryUpdater.js @@ -227,19 +227,31 @@ define([ var stRotation = rectangle.stRotation; var rotation = rectangle.rotation; + var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); + var options = this._options; options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; options.rectangle = rectangle.coordinates.getValue(Iso8601.MINIMUM_VALUE, options.rectangle); - options.height = defined(height) ? height.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.extrudedHeight = defined(extrudedHeight) ? extrudedHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.stRotation = defined(stRotation) ? stRotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.rotation = defined(rotation) ? rotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; } + + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } + } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; RectangleGeometryUpdater.prototype._getIsClosed = function(options) { @@ -271,17 +283,29 @@ define([ var height = rectangle.height; var extrudedHeight = rectangle.extrudedHeight; + var heightValue = Property.getValueOrUndefined(height, time); + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); + options.rectangle = Property.getValueOrUndefined(rectangle.coordinates, time, options.rectangle); - options.height = Property.getValueOrUndefined(height, time); - options.extrudedHeight = Property.getValueOrUndefined(extrudedHeight, time); options.granularity = Property.getValueOrUndefined(rectangle.granularity, time); options.stRotation = Property.getValueOrUndefined(rectangle.stRotation, time); options.rotation = Property.getValueOrUndefined(rectangle.rotation, time); options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - if (extrudedHeight instanceof GeometryHeightProperty && Property.getValueOrDefault(extrudedHeight.heightReference, time, HeightReference.NONE) === HeightReference.CLAMP_TO_GROUND) { - options.extrudedHeight = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); + if (defined(heightValue) && defined(heightValue.height)) { + heightValue = heightValue.height; } + + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { + extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); + } else { + extrudedHeightValue = extrudedHeightValue.height; + } + } + + options.height = heightValue; + options.extrudedHeight = extrudedHeightValue; }; return RectangleGeometryUpdater; diff --git a/Source/DataSources/TerrainOffsetProperty.js b/Source/DataSources/TerrainOffsetProperty.js index 7a0612ae1c8f..3b630ec207bc 100644 --- a/Source/DataSources/TerrainOffsetProperty.js +++ b/Source/DataSources/TerrainOffsetProperty.js @@ -38,8 +38,6 @@ define([ function TerrainOffsetProperty(scene, height, extrudedHeight, getPosition) { //>>includeStart('debug', pragmas.debug); Check.defined('scene', scene); - Check.defined('height', height); - Check.defined('extrudedHeight', extrudedHeight); Check.typeOf.func('getPosition', getPosition); //>>includeEnd('debug'); @@ -100,20 +98,21 @@ define([ * @private */ TerrainOffsetProperty.prototype._updateClamping = function() { + if (defined(this._removeCallbackFunc)) { + this._removeCallbackFunc(); + } + var scene = this._scene; var globe = scene.globe; - if (!defined(globe)) { + var position = this._position; + + if (!defined(globe) || Cartesian3.equals(position, Cartesian3.ZERO)) { this._terrainHeight = 0; return; } var ellipsoid = globe.ellipsoid; var surface = globe._surface; - var position = this._position; - if (defined(this._removeCallbackFunc)) { - this._removeCallbackFunc(); - } - var that = this; var cartographicPosition = ellipsoid.cartesianToCartographic(position, this._cartographicPosition); var height = globe.getHeight(cartographicPosition); @@ -141,14 +140,19 @@ define([ var extrudedHeightProperty = this._extrudedHeight; var heightReference = HeightReference.NONE; var extrudedHeightReference = HeightReference.NONE; - if (defined(heightProperty)) { - heightReference = Property.getValueOrDefault(heightProperty.heightReference, time, HeightReference.NONE); + + var heightValue = Property.getValueOrUndefined(heightProperty, time); + if (defined(heightValue) && defined(heightValue.heightReference)) { + heightReference = heightValue.heightReference; } - if (defined(extrudedHeightProperty)) { - extrudedHeightReference = Property.getValueOrDefault(extrudedHeightProperty.heightReference, time, HeightReference.NONE); + + var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeightProperty, time); + if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { + extrudedHeightReference = extrudedHeightValue.heightReference; } if (heightReference === HeightReference.NONE && extrudedHeightReference !== HeightReference.RELATIVE_TO_GROUND) { + this._position = Cartesian3.clone(Cartesian3.ZERO, this._position); return Cartesian3.clone(Cartesian3.ZERO, result); } diff --git a/Specs/DataSources/GeometryHeightPropertySpec.js b/Specs/DataSources/GeometryHeightPropertySpec.js index c7559c025f9c..42b673608c3a 100644 --- a/Specs/DataSources/GeometryHeightPropertySpec.js +++ b/Specs/DataSources/GeometryHeightPropertySpec.js @@ -32,7 +32,10 @@ defineSuite([ expect(property.definitionChanged).toBeInstanceOf(Event); expect(property.height).toBeUndefined(); expect(property.heightReference).toBeUndefined(); - expect(property.getValue(time)).toBe(0); + expect(property.getValue(time)).toEqual({ + height: 0, + heightReference: HeightReference.NONE + }); }); it('can construct with arguments', function() { @@ -43,7 +46,10 @@ defineSuite([ expect(property.definitionChanged).toBeInstanceOf(Event); expect(property.height).toBe(height); expect(property.heightReference).toBe(heightReference); - expect(property.getValue(time)).toBe(30); + expect(property.getValue(time)).toEqual({ + height: 30, + heightReference: HeightReference.NONE + }); }); it('setting height raises definitionChanged event', function() { @@ -95,17 +101,26 @@ defineSuite([ var height = new ConstantProperty(expected); var heightReference = new ConstantProperty(HeightReference.NONE); var property = new GeometryHeightProperty(height, heightReference); - expect(property.getValue(time)).toBe(expected); + expect(property.getValue(time)).toEqual({ + height: expected, + heightReference: HeightReference.NONE + }); property.heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); - expect(property.getValue(time)).toBe(expected); + expect(property.getValue(time)).toEqual({ + height: expected, + heightReference: HeightReference.RELATIVE_TO_GROUND + }); }); it('getValue works for for height reference CLAMP_TO_GROUND', function() { var height = new ConstantProperty(50); var heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); var property = new GeometryHeightProperty(height, heightReference); - expect(property.getValue(time)).toBe(0); + expect(property.getValue(time)).toEqual({ + height: 0, + heightReference: HeightReference.CLAMP_TO_GROUND + }); }); it('equals works', function() { diff --git a/Specs/DataSources/TerrainOffsetPropertySpec.js b/Specs/DataSources/TerrainOffsetPropertySpec.js index d565db1d6e27..31e97a7659a3 100644 --- a/Specs/DataSources/TerrainOffsetPropertySpec.js +++ b/Specs/DataSources/TerrainOffsetPropertySpec.js @@ -51,22 +51,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('throws without height', function() { - var getPosition = jasmine.createSpy(); - var extrudedHeight = new ConstantProperty(0); - expect(function() { - return new TerrainOffsetProperty(scene, undefined, extrudedHeight, getPosition); - }).toThrowDeveloperError(); - }); - - it('throws without extrudedHeight', function() { - var getPosition = jasmine.createSpy(); - var height = new ConstantProperty(30); - expect(function() { - return new TerrainOffsetProperty(scene, height, undefined, getPosition); - }).toThrowDeveloperError(); - }); - it('throws without getPosition', function() { var height = new ConstantProperty(30); var extrudedHeight = new ConstantProperty(0); From 665e72b0bd5f64a03aba51cdedf8638b30f93c41 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 27 Jun 2018 12:44:28 -0400 Subject: [PATCH 04/10] update sandcastle, fix bounding spheres --- .../gallery/Geometry Height Reference.html | 61 ++++++++++--------- Source/Scene/Primitive.js | 2 + 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Apps/Sandcastle/gallery/Geometry Height Reference.html b/Apps/Sandcastle/gallery/Geometry Height Reference.html index 135be5b66a03..ad86b4b3be76 100644 --- a/Apps/Sandcastle/gallery/Geometry Height Reference.html +++ b/Apps/Sandcastle/gallery/Geometry Height Reference.html @@ -31,61 +31,64 @@ //Sandcastle_Begin var cesiumTerrainProvider = Cesium.createWorldTerrain(); var ellipsoidTerrainProvider = new Cesium.EllipsoidTerrainProvider(); + var viewer = new Cesium.Viewer('cesiumContainer', { - baseLayerPicker: false, - terrainProvider: cesiumTerrainProvider + baseLayerPicker : false, + terrainProvider : cesiumTerrainProvider }); -viewer.scene.globe.depthTestAgainstTerrain = true; -Sandcastle.addToolbarButton('Enable Terrain', function() { - viewer.scene.terrainProvider = cesiumTerrainProvider; -}); +// depth test against terrain is required to make the polygons clamp to terrain +// instead of showing through it from underground +viewer.scene.globe.depthTestAgainstTerrain = true; -Sandcastle.addToolbarButton('Disable Terrain', function() { - viewer.scene.terrainProvider = ellipsoidTerrainProvider; -}); +Sandcastle.addToolbarMenu([{ + text : 'Terrain Enabled', + onselect : function() { + viewer.scene.terrainProvider = cesiumTerrainProvider; + } +}, { + text : 'Terrain Disabled', + onselect : function() { + viewer.scene.terrainProvider = ellipsoidTerrainProvider; + } +}]); -var baseLon = 6.850615989890521; -var baseLat = 45.89546589994886; +var longitude = 6.850615989890521; +var latitude = 45.89546589994886; var delta = 0.001; + function addEntity(i, j) { - var lon1 = baseLon + delta*i; - var lon2 = baseLon + delta*i + delta; + var west = longitude + delta * i; + var east = longitude + delta * i + delta; - var lat1 = baseLat + delta*j; - var lat2 = baseLat + delta*j + delta; - var a = Cesium.Cartesian3.fromDegrees(lon1, lat1); - var b = Cesium.Cartesian3.fromDegrees(lon1, lat2); - var c = Cesium.Cartesian3.fromDegrees(lon2, lat2); - var d = Cesium.Cartesian3.fromDegrees(lon2, lat1); + var south = latitude + delta * j; + var north = latitude + delta * j + delta; + var a = Cesium.Cartesian3.fromDegrees(west, south); + var b = Cesium.Cartesian3.fromDegrees(west, north); + var c = Cesium.Cartesian3.fromDegrees(east, north); + var d = Cesium.Cartesian3.fromDegrees(east, south); var positions = [a, b, c, d]; viewer.entities.add({ polygon : { hierarchy : positions, - material : Cesium.Color.fromRandom({alpha: 1}), + material : Cesium.Color.fromRandom({alpha : 1}), height : new Cesium.GeometryHeightProperty(40.0, Cesium.HeightReference.RELATIVE_TO_GROUND), extrudedHeight : new Cesium.GeometryHeightProperty(0.0, Cesium.HeightReference.CLAMP_TO_GROUND) } }); } +// create 16 polygons that are side-by-side for (var i = 0; i < 4; i++) { for (var j = 0; j < 4; j++) { addEntity(i, j); } } -viewer.scene.camera.flyTo({ - destination: new Cesium.Cartesian3(4414709.69060132, 531290.9290968775, 4561007.639489886), - orientation: { - heading: 3.6086529754485834, - pitch: -0.6592870741832781, - roll: 6.28127756699859 - } -}); -//Sandcastle_End +viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(longitude, latitude, 500), new Cesium.HeadingPitchRange(Cesium.Math.PI, -Cesium.Math.PI_OVER_FOUR, 2000)); +viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);//Sandcastle_End Sandcastle.finishedLoading(); } if (typeof Cesium !== "undefined") { diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index 413d25a81ce1..c179d6307578 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -1341,6 +1341,7 @@ define([ for (i = 0; i < result.length; i++) { var boundingSphere = result[i].clone(primitive._boundingSpheres[i]); + console.log(boundingSphere.radius); primitive._boundingSpheres[i] = boundingSphere; primitive._boundingSphereCV[i] = BoundingSphere.projectTo2D(boundingSphere, frameState.mapProjection, primitive._boundingSphereCV[i]); } @@ -1943,6 +1944,7 @@ define([ get : function() { var boundingSphere = primitive._instanceBoundingSpheres[index]; if (defined(boundingSphere)) { + boundingSphere = boundingSphere.clone(); var modelMatrix = primitive.modelMatrix; var offset = properties.offset; if (defined(offset)) { From 4c6a6b2297ee427f33ab15c3900c19dd30c94703 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 27 Jun 2018 13:00:00 -0400 Subject: [PATCH 05/10] eslint --- Apps/Sandcastle/gallery/Geometry Height Reference.html | 1 - 1 file changed, 1 deletion(-) diff --git a/Apps/Sandcastle/gallery/Geometry Height Reference.html b/Apps/Sandcastle/gallery/Geometry Height Reference.html index ad86b4b3be76..dc9a56ab65bf 100644 --- a/Apps/Sandcastle/gallery/Geometry Height Reference.html +++ b/Apps/Sandcastle/gallery/Geometry Height Reference.html @@ -41,7 +41,6 @@ // instead of showing through it from underground viewer.scene.globe.depthTestAgainstTerrain = true; - Sandcastle.addToolbarMenu([{ text : 'Terrain Enabled', onselect : function() { From a6a4d1fcbf7a58f41de873b3fcce767533ff6abe Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 27 Jun 2018 14:47:57 -0400 Subject: [PATCH 06/10] cleanup --- Source/DataSources/CorridorGeometryUpdater.js | 2 +- Source/Scene/Primitive.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/DataSources/CorridorGeometryUpdater.js b/Source/DataSources/CorridorGeometryUpdater.js index da284967840b..5cc70964ee04 100644 --- a/Source/DataSources/CorridorGeometryUpdater.js +++ b/Source/DataSources/CorridorGeometryUpdater.js @@ -192,7 +192,7 @@ define([ }; CorridorGeometryUpdater.prototype._isHidden = function(entity, corridor) { - return !defined(corridor.positions) || GeometryUpdater.prototype._isHidden.call(this, entity, corridor); + return !defined(corridor.positions) || !defined(corridor.width) || GeometryUpdater.prototype._isHidden.call(this, entity, corridor); }; CorridorGeometryUpdater.prototype._isOnTerrain = function(entity, corridor) { diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index c179d6307578..4b444fc98e65 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -1341,7 +1341,6 @@ define([ for (i = 0; i < result.length; i++) { var boundingSphere = result[i].clone(primitive._boundingSpheres[i]); - console.log(boundingSphere.radius); primitive._boundingSpheres[i] = boundingSphere; primitive._boundingSphereCV[i] = BoundingSphere.projectTo2D(boundingSphere, frameState.mapProjection, primitive._boundingSphereCV[i]); } From fb85bdd260d2ca8c911d77c591c74e29e1abad39 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 27 Jun 2018 16:09:05 -0400 Subject: [PATCH 07/10] okay, I guess that wasn't so bad --- .../gallery/Geometry Height Reference.html | 6 +- Source/DataSources/CorridorGeometryUpdater.js | 62 ++---- Source/DataSources/CorridorGraphics.js | 26 +++ Source/DataSources/EllipseGeometryUpdater.js | 65 ++---- Source/DataSources/EllipseGraphics.js | 26 +++ Source/DataSources/GeometryHeightProperty.js | 201 ------------------ Source/DataSources/GroundGeometryUpdater.js | 72 ++++++- Source/DataSources/PolygonGeometryUpdater.js | 46 ++-- Source/DataSources/PolygonGraphics.js | 26 +++ .../DataSources/RectangleGeometryUpdater.js | 59 ++--- Source/DataSources/RectangleGraphics.js | 26 +++ Source/DataSources/TerrainOffsetProperty.js | 27 +-- .../DataSources/GeometryHeightPropertySpec.js | 167 --------------- .../DataSources/GroundGeometryUpdaterSpec.js | 115 ++++++++++ ...reateGeometryUpdaterGroundGeometrySpecs.js | 42 ++-- 15 files changed, 390 insertions(+), 576 deletions(-) delete mode 100644 Source/DataSources/GeometryHeightProperty.js delete mode 100644 Specs/DataSources/GeometryHeightPropertySpec.js create mode 100644 Specs/DataSources/GroundGeometryUpdaterSpec.js diff --git a/Apps/Sandcastle/gallery/Geometry Height Reference.html b/Apps/Sandcastle/gallery/Geometry Height Reference.html index dc9a56ab65bf..affc60edc5a0 100644 --- a/Apps/Sandcastle/gallery/Geometry Height Reference.html +++ b/Apps/Sandcastle/gallery/Geometry Height Reference.html @@ -73,8 +73,10 @@ polygon : { hierarchy : positions, material : Cesium.Color.fromRandom({alpha : 1}), - height : new Cesium.GeometryHeightProperty(40.0, Cesium.HeightReference.RELATIVE_TO_GROUND), - extrudedHeight : new Cesium.GeometryHeightProperty(0.0, Cesium.HeightReference.CLAMP_TO_GROUND) + height : 40.0, + heightReference : Cesium.HeightReference.RELATIVE_TO_GROUND, + extrudedHeight : 0.0, + extrudedHeightReference : Cesium.HeightReference.CLAMP_TO_GROUND } }); } diff --git a/Source/DataSources/CorridorGeometryUpdater.js b/Source/DataSources/CorridorGeometryUpdater.js index 5cc70964ee04..69a6a65ac7f3 100644 --- a/Source/DataSources/CorridorGeometryUpdater.js +++ b/Source/DataSources/CorridorGeometryUpdater.js @@ -1,4 +1,5 @@ define([ + '../Core/ApproximateTerrainHeights', '../Core/Cartesian3', '../Core/Check', '../Core/Color', @@ -20,11 +21,11 @@ define([ '../Scene/PerInstanceColorAppearance', './ColorMaterialProperty', './DynamicGeometryUpdater', - './GeometryHeightProperty', './GeometryUpdater', './GroundGeometryUpdater', './Property' ], function( + ApproximateTerrainHeights, Cartesian3, Check, Color, @@ -46,7 +47,6 @@ define([ PerInstanceColorAppearance, ColorMaterialProperty, DynamicGeometryUpdater, - GeometryHeightProperty, GeometryUpdater, GroundGeometryUpdater, Property) { @@ -220,36 +220,24 @@ define([ CorridorGeometryUpdater.prototype._setStaticOptions = function(entity, corridor) { var height = corridor.height; + var heightReference = corridor.heightReference; var extrudedHeight = corridor.extrudedHeight; - var granularity = corridor.granularity; - var width = corridor.width; - var cornerType = corridor.cornerType; - var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty; - - var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); + var extrudedHeightReference = corridor.extrudedHeightReference; var options = this._options; - options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; + options.vertexFormat = (this._materialProperty instanceof ColorMaterialProperty) ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; options.positions = corridor.positions.getValue(Iso8601.MINIMUM_VALUE, options.positions); - options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.width = defined(width) ? width.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.cornerType = defined(cornerType) ? cornerType.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; - } - - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } + options.width = corridor.width.getValue(Iso8601.MINIMUM_VALUE); + options.granularity = Property.getValueOrUndefined(corridor.granularity, Iso8601.MINIMUM_VALUE); + options.cornerType = Property.getValueOrUndefined(corridor.cornerType, Iso8601.MINIMUM_VALUE); + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + options.height = GroundGeometryUpdater.getGeometryHeight(height, heightReference, Iso8601.MINIMUM_VALUE); + + var extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(CorridorGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; @@ -275,30 +263,22 @@ define([ DynamicCorridorGeometryUpdater.prototype._setOptions = function(entity, corridor, time) { var options = this._options; var height = corridor.height; + var heightReference = corridor.heightReference; var extrudedHeight = corridor.extrudedHeight; - - var heightValue = Property.getValueOrUndefined(height, time); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); + var extrudedHeightReference = corridor.extrudedHeightReference; options.positions = Property.getValueOrUndefined(corridor.positions, time); options.width = Property.getValueOrUndefined(corridor.width, time); options.granularity = Property.getValueOrUndefined(corridor.granularity, time); options.cornerType = Property.getValueOrUndefined(corridor.cornerType, time); - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; - } + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + options.height = GroundGeometryUpdater.getGeometryHeight(height, heightReference, time); - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(CorridorGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } + var extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, time); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(CorridorGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; diff --git a/Source/DataSources/CorridorGraphics.js b/Source/DataSources/CorridorGraphics.js index a1a7e3e9c8b5..268f4e7da314 100644 --- a/Source/DataSources/CorridorGraphics.js +++ b/Source/DataSources/CorridorGraphics.js @@ -29,7 +29,9 @@ define([ * @param {Property} [options.width] A numeric Property specifying the distance between the edges of the corridor. * @param {Property} [options.cornerType=CornerType.ROUNDED] A {@link CornerType} Property specifying the style of the corners. * @param {Property} [options.height=0] A numeric Property specifying the altitude of the corridor relative to the ellipsoid surface. + * @param {Property} [options.heightReference] A Property specifying what the height is relative to. * @param {Property} [options.extrudedHeight] A numeric Property specifying the altitude of the corridor's extruded face relative to the ellipsoid surface. + * @param {Property} [options.extrudedHeightReference] A Property specifying what the extrudedHeight is relative to. * @param {Property} [options.show=true] A boolean Property specifying the visibility of the corridor. * @param {Property} [options.fill=true] A boolean Property specifying whether the corridor is filled with the provided material. * @param {MaterialProperty} [options.material=Color.WHITE] A Property specifying the material used to fill the corridor. @@ -53,8 +55,12 @@ define([ this._positionsSubscription = undefined; this._height = undefined; this._heightSubscription = undefined; + this._heightReference = undefined; + this._heightReferenceSubscription = undefined; this._extrudedHeight = undefined; this._extrudedHeightSubscription = undefined; + this._extrudedHeightReference = undefined; + this._extrudedHeightReferenceSubscription = undefined; this._granularity = undefined; this._granularitySubscription = undefined; this._width = undefined; @@ -126,6 +132,14 @@ define([ */ height : createPropertyDescriptor('height'), + /** + * Gets or sets the Property specifying the {@link HeightReference}. + * @memberof CorridorGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + heightReference : createPropertyDescriptor('heightReference'), + /** * Gets or sets the numeric Property specifying the altitude of the corridor extrusion. * Setting this property creates a corridor shaped volume starting at height and ending @@ -135,6 +149,14 @@ define([ */ extrudedHeight : createPropertyDescriptor('extrudedHeight'), + /** + * Gets or sets the Property specifying the extruded {@link HeightReference}. + * @memberof CorridorGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + extrudedHeightReference : createPropertyDescriptor('extrudedHeightReference'), + /** * Gets or sets the numeric Property specifying the sampling distance between each latitude and longitude point. * @memberof CorridorGraphics.prototype @@ -237,7 +259,9 @@ define([ result.material = this.material; result.positions = this.positions; result.height = this.height; + result.heightReference = this.heightReference; result.extrudedHeight = this.extrudedHeight; + result.extrudedHeightReference = this.extrudedHeightReference; result.granularity = this.granularity; result.width = this.width; result.fill = this.fill; @@ -269,7 +293,9 @@ define([ this.material = defaultValue(this.material, source.material); this.positions = defaultValue(this.positions, source.positions); this.height = defaultValue(this.height, source.height); + this.heightReference = defaultValue(this.heightReference, source.heightReference); this.extrudedHeight = defaultValue(this.extrudedHeight, source.extrudedHeight); + this.extrudedHeightReference = defaultValue(this.extrudedHeightReference, source.extrudedHeightReference); this.granularity = defaultValue(this.granularity, source.granularity); this.width = defaultValue(this.width, source.width); this.fill = defaultValue(this.fill, source.fill); diff --git a/Source/DataSources/EllipseGeometryUpdater.js b/Source/DataSources/EllipseGeometryUpdater.js index 950a87f9d57f..30fe5088f920 100644 --- a/Source/DataSources/EllipseGeometryUpdater.js +++ b/Source/DataSources/EllipseGeometryUpdater.js @@ -1,4 +1,5 @@ define([ + '../Core/ApproximateTerrainHeights', '../Core/Cartesian3', '../Core/Check', '../Core/Color', @@ -20,11 +21,11 @@ define([ '../Scene/PerInstanceColorAppearance', './ColorMaterialProperty', './DynamicGeometryUpdater', - './GeometryHeightProperty', './GeometryUpdater', './GroundGeometryUpdater', './Property' ], function( + ApproximateTerrainHeights, Cartesian3, Check, Color, @@ -46,7 +47,6 @@ define([ PerInstanceColorAppearance, ColorMaterialProperty, DynamicGeometryUpdater, - GeometryHeightProperty, GeometryUpdater, GroundGeometryUpdater, Property) { @@ -223,41 +223,28 @@ define([ }; EllipseGeometryUpdater.prototype._setStaticOptions = function(entity, ellipse) { - var rotation = ellipse.rotation; var height = ellipse.height; + var heightReference = ellipse.heightReference; var extrudedHeight = ellipse.extrudedHeight; - var granularity = ellipse.granularity; - var stRotation = ellipse.stRotation; - var numberOfVerticalLines = ellipse.numberOfVerticalLines; - var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty; - - var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); + var extrudedHeightReference = ellipse.extrudedHeightReference; var options = this._options; - options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; + options.vertexFormat = (this._materialProperty instanceof ColorMaterialProperty) ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; options.center = entity.position.getValue(Iso8601.MINIMUM_VALUE, options.center); options.semiMajorAxis = ellipse.semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMajorAxis); options.semiMinorAxis = ellipse.semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMinorAxis); - options.rotation = defined(rotation) ? rotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.stRotation = defined(stRotation) ? stRotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.numberOfVerticalLines = defined(numberOfVerticalLines) ? numberOfVerticalLines.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; - } - - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } + options.rotation = Property.getValueOrUndefined(ellipse.rotation, Iso8601.MINIMUM_VALUE); + options.granularity = Property.getValueOrUndefined(ellipse.granularity, Iso8601.MINIMUM_VALUE); + options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, Iso8601.MINIMUM_VALUE); + options.numberOfVerticalLines = Property.getValueOrUndefined(ellipse.numberOfVerticalLines, Iso8601.MINIMUM_VALUE); + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + options.height = GroundGeometryUpdater.getGeometryHeight(height, heightReference, Iso8601.MINIMUM_VALUE); + + var extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(EllipseGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; @@ -283,10 +270,9 @@ define([ DynamicEllipseGeometryUpdater.prototype._setOptions = function(entity, ellipse, time) { var options = this._options; var height = ellipse.height; + var heightReference = ellipse.heightReference; var extrudedHeight = ellipse.extrudedHeight; - - var heightValue = Property.getValueOrUndefined(height, time); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); + var extrudedHeightReference = ellipse.extrudedHeightReference; options.center = Property.getValueOrUndefined(entity.position, time, options.center); options.semiMajorAxis = Property.getValueOrUndefined(ellipse.semiMajorAxis, time); @@ -295,21 +281,14 @@ define([ options.granularity = Property.getValueOrUndefined(ellipse.granularity, time); options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, time); options.numberOfVerticalLines = Property.getValueOrUndefined(ellipse.numberOfVerticalLines, time); - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; - } + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + options.height = GroundGeometryUpdater.getGeometryHeight(height, heightReference, time); - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(EllipseGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } + var extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, time); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(EllipseGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; diff --git a/Source/DataSources/EllipseGraphics.js b/Source/DataSources/EllipseGraphics.js index bdb5e5f99fd0..c120ffc691c1 100644 --- a/Source/DataSources/EllipseGraphics.js +++ b/Source/DataSources/EllipseGraphics.js @@ -29,7 +29,9 @@ define([ * @param {Property} [options.semiMajorAxis] The numeric Property specifying the semi-major axis. * @param {Property} [options.semiMinorAxis] The numeric Property specifying the semi-minor axis. * @param {Property} [options.height=0] A numeric Property specifying the altitude of the ellipse relative to the ellipsoid surface. + * @param {Property} [options.heightReference] A Property specifying what the height is relative to. * @param {Property} [options.extrudedHeight] A numeric Property specifying the altitude of the ellipse's extruded face relative to the ellipsoid surface. + * @param {Property} [options.extrudedHeightReference] A Property specifying what the extrudedHeight is relative to. * @param {Property} [options.show=true] A boolean Property specifying the visibility of the ellipse. * @param {Property} [options.fill=true] A boolean Property specifying whether the ellipse is filled with the provided material. * @param {MaterialProperty} [options.material=Color.WHITE] A Property specifying the material used to fill the ellipse. @@ -59,8 +61,12 @@ define([ this._materialSubscription = undefined; this._height = undefined; this._heightSubscription = undefined; + this._heightReference = undefined; + this._heightReferenceSubscription = undefined; this._extrudedHeight = undefined; this._extrudedHeightSubscription = undefined; + this._extrudedHeightReference = undefined; + this._extrudedHeightReferenceSubscription = undefined; this._granularity = undefined; this._granularitySubscription = undefined; this._stRotation = undefined; @@ -148,6 +154,14 @@ define([ */ height : createPropertyDescriptor('height'), + /** + * Gets or sets the Property specifying the {@link HeightReference}. + * @memberof EllipseGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + heightReference : createPropertyDescriptor('heightReference'), + /** * Gets or sets the numeric Property specifying the altitude of the ellipse extrusion. * Setting this property creates volume starting at height and ending at this altitude. @@ -156,6 +170,14 @@ define([ */ extrudedHeight : createPropertyDescriptor('extrudedHeight'), + /** + * Gets or sets the Property specifying the extruded {@link HeightReference}. + * @memberof EllipseGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + extrudedHeightReference : createPropertyDescriptor('extrudedHeightReference'), + /** * Gets or sets the numeric Property specifying the angular distance between points on the ellipse. * @memberof EllipseGraphics.prototype @@ -261,7 +283,9 @@ define([ result.show = this.show; result.material = this.material; result.height = this.height; + result.heightReference = this.heightReference; result.extrudedHeight = this.extrudedHeight; + result.extrudedHeightReference = this.extrudedHeightReference; result.granularity = this.granularity; result.stRotation = this.stRotation; result.fill = this.fill; @@ -295,7 +319,9 @@ define([ this.show = defaultValue(this.show, source.show); this.material = defaultValue(this.material, source.material); this.height = defaultValue(this.height, source.height); + this.heightReference = defaultValue(this.heightReference, source.heightReference); this.extrudedHeight = defaultValue(this.extrudedHeight, source.extrudedHeight); + this.extrudedHeightReference = defaultValue(this.extrudedHeightReference, source.extrudedHeightReference); this.granularity = defaultValue(this.granularity, source.granularity); this.stRotation = defaultValue(this.stRotation, source.stRotation); this.fill = defaultValue(this.fill, source.fill); diff --git a/Source/DataSources/GeometryHeightProperty.js b/Source/DataSources/GeometryHeightProperty.js deleted file mode 100644 index dd47ab357011..000000000000 --- a/Source/DataSources/GeometryHeightProperty.js +++ /dev/null @@ -1,201 +0,0 @@ -define([ - '../Core/ApproximateTerrainHeights', - '../Core/defined', - '../Core/defineProperties', - '../Core/Check', - '../Core/Event', - '../Core/GeometryOffsetAttribute', - '../Scene/HeightReference', - './createPropertyDescriptor', - './Property' -], function( - ApproximateTerrainHeights, - defined, - defineProperties, - Check, - Event, - GeometryOffsetAttribute, - HeightReference, - createPropertyDescriptor, - Property) { - 'use strict'; - - /** - * A {@link Property} which computes height or extrudedHeight in relation to the current terrain visualization. - * - * @alias GeometryHeightProperty - * @constructor - * - * @param {Property} [height] A Property specifying the height in meters - * @param {Property} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to. - * - * @example - * // A 40 meter tall extruded polygon clamped to terrain - * var redPolygon = viewer.entities.add({ - * polygon : { - * hierarchy : polygonPositions, - * material : Cesium.Color.RED, - * height : Cesium.GeometryHeightProperty(40.0, Cesium.HeightReference.RELATIVE_TO_GROUND), - * extrudedHeight : Cesium.GeometryHeightProperty(0.0, Cesium.HeightReference.CLAMP_TO_GROUND) - * } - * }); - * - * // An flat ellipse at 20 meters above terrain (does not contour to terrain) - * var blueEllipse = viewer.entities.add({ - * position: Cesium.Cartesian3.fromDegrees(-110.0, 43.0), - * ellipse : { - * semiMinorAxis : 300.0, - * semiMajorAxis : 200.0, - * material : Cesium.Color.BLUE, - * height : new Cesium.GeometryHeightProperty(20.0, Cesium.HeightReference.RELATIVE_TO_GROUND) - * } - * }); - */ - function GeometryHeightProperty(height, heightReference) { - this._height = undefined; - this._heightSubscription = undefined; - this._heightReference = undefined; - this._heightReferenceSubscription = undefined; - this._definitionChanged = new Event(); - - this._resultObject = { - height: 0, - heightReference: HeightReference.NONE - }; - - this.height = height; - this.heightReference = heightReference; - } - - defineProperties(GeometryHeightProperty.prototype, { - /** - * Gets a value indicating if this property is constant. - * @memberof GeometryHeightProperty.prototype - * - * @type {Boolean} - * @readonly - */ - isConstant : { - get : function() { - return Property.isConstant(this._height) && Property.isConstant(this._heightReference); - } - }, - /** - * Gets the event that is raised whenever the definition of this property changes. - * @memberof GeometryHeightProperty.prototype - * - * @type {Event} - * @readonly - */ - definitionChanged : { - get : function() { - return this._definitionChanged; - } - }, - /** - * Gets or sets the property used to compute the height. - * @memberof GeometryHeightProperty.prototype - * - * @type {Property} - */ - height : createPropertyDescriptor('height'), - /** - * Gets or sets the property used to define the height reference. - * @memberof GeometryHeightProperty.prototype - * - * @type {Property} - */ - heightReference : createPropertyDescriptor('heightReference') - }); - - /** - * Gets the minimum terrain height based on the positions at the provided time. - * - * @param {JulianDate} time The time for which to retrieve the value. - * @returns {Number} The minimum terrain height - */ - GeometryHeightProperty.prototype.getValue = function(time) { - //>>includeStart('debug', pragmas.debug); - Check.defined('time', time); - //>>includeEnd('debug'); - - var heightReference = Property.getValueOrDefault(this._heightReference, time, HeightReference.NONE); - var height; - if (heightReference !== HeightReference.CLAMP_TO_GROUND) { - height = Property.getValueOrDefault(this._height, time, 0); - } else { - height = 0; - } - - var result = this._resultObject; - result.height = height; - result.heightReference = heightReference; - - return result; - }; - - /** - * Used to get the minimum terrain value for when extrudedHeight is using CLAMP_TO_GROUND; - * @private - */ - GeometryHeightProperty.getMinimumTerrainValue = function(rectangle) { - //>>includeStart('debug', pragmas.debug); - Check.defined('rectangle', rectangle); - //>>includeEnd('debug'); - return ApproximateTerrainHeights.getApproximateTerrainHeights(rectangle).minimumTerrainHeight; - }; - - /** - * Gets the GeometryOffsetAttribute based on the values of height and extrudedHeight - * @param {Property} height - * @param {Property} extrudedHeight - * @param {JulianDate} time - * @returns {GeometryOffsetAttribute|undefined} - * @private - */ - GeometryHeightProperty.computeGeometryOffsetAttribute = function(height, extrudedHeight, time) { - var heightValue = Property.getValueOrUndefined(height, time); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); - - var heightReference = HeightReference.NONE; - var extrudedHeightReference = HeightReference.NONE; - if (defined(heightValue) && defined(heightValue.heightReference)) { - heightReference = heightValue.heightReference; - } - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - extrudedHeightReference = extrudedHeightValue.heightReference; - } - - var n = 0; - if (heightReference !== HeightReference.NONE) { - n++; - } - if (extrudedHeightReference === HeightReference.RELATIVE_TO_GROUND) { - n++; - } - if (n === 2) { - return GeometryOffsetAttribute.ALL; - } - if (n === 1) { - return GeometryOffsetAttribute.TOP; - } - - return undefined; - }; - - /** - * Compares this property to the provided property and returns - * true if they are equal, false otherwise. - * - * @param {Property} [other] The other property. - * @returns {Boolean} true if left and right are equal, false otherwise. - */ - GeometryHeightProperty.prototype.equals = function(other) { - return this === other ||// - (other instanceof GeometryHeightProperty && - Property.equals(this._height, other._height) && - Property.equals(this._heightReference, other._heightReference)); - }; - - return GeometryHeightProperty; -}); diff --git a/Source/DataSources/GroundGeometryUpdater.js b/Source/DataSources/GroundGeometryUpdater.js index efa54a87cc95..056e45537521 100644 --- a/Source/DataSources/GroundGeometryUpdater.js +++ b/Source/DataSources/GroundGeometryUpdater.js @@ -1,30 +1,32 @@ define([ + '../Core/ApproximateTerrainHeights', '../Core/Cartesian3', '../Core/Check', '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', '../Core/DeveloperError', + '../Core/GeometryOffsetAttribute', '../Core/Iso8601', '../Core/oneTimeWarning', '../Scene/HeightReference', './ConstantProperty', - './GeometryHeightProperty', './GeometryUpdater', './Property', './TerrainOffsetProperty' ], function( + ApproximateTerrainHeights, Cartesian3, Check, defaultValue, defined, defineProperties, DeveloperError, + GeometryOffsetAttribute, Iso8601, oneTimeWarning, HeightReference, ConstantProperty, - GeometryHeightProperty, GeometryUpdater, Property, TerrainOffsetProperty) { @@ -93,21 +95,69 @@ define([ this._zIndex = defaultValue(geometry.zIndex, defaultZIndex); - var heightProperty = geometry.height; - var extrudedHeightProperty = geometry.extrudedHeight; - if (defined(this._terrainOffsetProperty)) { this._terrainOffsetProperty.destroy(); this._terrainOffsetProperty = undefined; } - if (defined(heightProperty) || defined(extrudedHeightProperty)) { - var heightValue = Property.getValueOrUndefined(heightProperty, Iso8601.MINIMUM_VALUE); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeightProperty, Iso8601.MINIMUM_VALUE); - if (this._dynamic || (defined(heightValue) && defined(heightValue.heightReference)) || (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference))) { - this._terrainOffsetProperty = new TerrainOffsetProperty(this._scene, heightProperty, extrudedHeightProperty, this._computeCenter.bind(this)); - } + var heightReferenceProperty = geometry.heightReference; + var extrudedHeightReferenceProperty = geometry.extrudedHeightReference; + + if (defined(heightReferenceProperty) || defined(extrudedHeightReferenceProperty)) { + this._terrainOffsetProperty = new TerrainOffsetProperty(this._scene, heightReferenceProperty, extrudedHeightReferenceProperty, this._computeCenter.bind(this)); + } + }; + + /** + * @private + */ + GroundGeometryUpdater.getGeometryHeight = function(heightProperty, heightReferenceProperty, time) { + var heightReference = Property.getValueOrDefault(heightReferenceProperty, time, HeightReference.NONE); + if (heightReference !== HeightReference.CLAMP_TO_GROUND) { + return Property.getValueOrUndefined(heightProperty, time); } + return 0.0; + }; + + /** + * @private + */ + GroundGeometryUpdater.getGeometryExtrudedHeight = function(extrudedHeightProperty, extrudedHeightReferenceProperty, time) { + var heightReference = Property.getValueOrDefault(extrudedHeightReferenceProperty, time, HeightReference.NONE); + if (heightReference !== HeightReference.CLAMP_TO_GROUND) { + return Property.getValueOrUndefined(extrudedHeightProperty, time); + } + + return GroundGeometryUpdater.CLAMP_TO_GROUND; + }; + + /** + * @private + */ + GroundGeometryUpdater.CLAMP_TO_GROUND = 'clamp'; + + /** + * @private + */ + GroundGeometryUpdater.computeGeometryOffsetAttribute = function(heightReferenceProperty, extrudedHeightReferenceProperty, time) { + var heightReference = Property.getValueOrDefault(heightReferenceProperty, time, HeightReference.NONE); + var extrudedHeightReference = Property.getValueOrDefault(extrudedHeightReferenceProperty, time, HeightReference.NONE); + + var n = 0; + if (heightReference !== HeightReference.NONE) { + n++; + } + if (extrudedHeightReference === HeightReference.RELATIVE_TO_GROUND) { + n++; + } + if (n === 2) { + return GeometryOffsetAttribute.ALL; + } + if (n === 1) { + return GeometryOffsetAttribute.TOP; + } + + return undefined; }; return GroundGeometryUpdater; diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index 5fba416b150d..a26e346dcccd 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -1,4 +1,5 @@ define([ + '../Core/ApproximateTerrainHeights', '../Core/Cartesian3', '../Core/Check', '../Core/Color', @@ -22,11 +23,11 @@ define([ '../Scene/PerInstanceColorAppearance', './ColorMaterialProperty', './DynamicGeometryUpdater', - './GeometryHeightProperty', './GeometryUpdater', './GroundGeometryUpdater', './Property' ], function( + ApproximateTerrainHeights, Cartesian3, Check, Color, @@ -50,7 +51,6 @@ define([ PerInstanceColorAppearance, ColorMaterialProperty, DynamicGeometryUpdater, - GeometryHeightProperty, GeometryUpdater, GroundGeometryUpdater, Property) { @@ -247,9 +247,11 @@ define([ } var height = polygon.height; + var heightReference = polygon.heightReference; var extrudedHeight = polygon.extrudedHeight; + var extrudedHeightReference = polygon.extrudedHeightReference; - var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); + var heightValue = GroundGeometryUpdater.getGeometryHeight(height, heightReference, Iso8601.MINIMUM_VALUE); var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); var perPositionHeightValue = Property.getValueOrUndefined(polygon.perPositionHeight, Iso8601.MINIMUM_VALUE); @@ -263,21 +265,14 @@ define([ options.perPositionHeight = perPositionHeightValue; options.closeTop = Property.getValueOrDefault(polygon.closeTop, Iso8601.MINIMUM_VALUE, true); options.closeBottom = Property.getValueOrDefault(polygon.closeBottom, Iso8601.MINIMUM_VALUE, true); - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + options.height = heightValue; - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; + extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(PolygonGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } - } - - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; @@ -309,7 +304,9 @@ define([ DyanmicPolygonGeometryUpdater.prototype._setOptions = function(entity, polygon, time) { var options = this._options; var height = polygon.height; + var heightReference = polygon.heightReference; var extrudedHeight = polygon.extrudedHeight; + var extrudedHeightReference = polygon.extrudedHeightReference; var hierarchy = Property.getValueOrUndefined(polygon.hierarchy, time); if (isArray(hierarchy)) { @@ -318,7 +315,7 @@ define([ options.polygonHierarchy = hierarchy; } - var heightValue = Property.getValueOrUndefined(height, time); + var heightValue = GroundGeometryUpdater.getGeometryHeight(height, heightReference, time); var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); var perPositionHeightValue = Property.getValueOrUndefined(polygon.perPositionHeight, time); @@ -331,21 +328,14 @@ define([ options.perPositionHeight = Property.getValueOrUndefined(polygon.perPositionHeight, time); options.closeTop = Property.getValueOrDefault(polygon.closeTop, time, true); options.closeBottom = Property.getValueOrDefault(polygon.closeBottom, time, true); - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + options.height = heightValue; - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; + extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, time); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(PolygonGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(PolygonGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } - } - - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; diff --git a/Source/DataSources/PolygonGraphics.js b/Source/DataSources/PolygonGraphics.js index 99c5243d86fe..5eb968df4d59 100644 --- a/Source/DataSources/PolygonGraphics.js +++ b/Source/DataSources/PolygonGraphics.js @@ -27,7 +27,9 @@ define([ * @param {Object} [options] Object with the following properties: * @param {Property} [options.hierarchy] A Property specifying the {@link PolygonHierarchy}. * @param {Property} [options.height=0] A numeric Property specifying the altitude of the polygon relative to the ellipsoid surface. + * @param {Property} [options.heightReference] A Property specifying what the height is relative to. * @param {Property} [options.extrudedHeight] A numeric Property specifying the altitude of the polygon's extruded face relative to the ellipsoid surface. + * @param {Property} [options.extrudedHeightReference] A Property specifying what the extrudedHeight is relative to. * @param {Property} [options.show=true] A boolean Property specifying the visibility of the polygon. * @param {Property} [options.fill=true] A boolean Property specifying whether the polygon is filled with the provided material. * @param {MaterialProperty} [options.material=Color.WHITE] A Property specifying the material used to fill the polygon. @@ -55,8 +57,12 @@ define([ this._hierarchySubscription = undefined; this._height = undefined; this._heightSubscription = undefined; + this._heightReference = undefined; + this._heightReferenceSubscription = undefined; this._extrudedHeight = undefined; this._extrudedHeightSubscription = undefined; + this._extrudedHeightReference = undefined; + this._extrudedHeightReferenceSubscription = undefined; this._granularity = undefined; this._granularitySubscription = undefined; this._stRotation = undefined; @@ -133,6 +139,14 @@ define([ */ height : createPropertyDescriptor('height'), + /** + * Gets or sets the Property specifying the {@link HeightReference}. + * @memberof PolygonGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + heightReference : createPropertyDescriptor('heightReference'), + /** * Gets or sets the numeric Property specifying the altitude of the polygon extrusion. * If {@link PolygonGraphics#perPositionHeight} is false, the volume starts at {@link PolygonGraphics#height} and ends at this altitude. @@ -142,6 +156,14 @@ define([ */ extrudedHeight : createPropertyDescriptor('extrudedHeight'), + /** + * Gets or sets the Property specifying the extruded {@link HeightReference}. + * @memberof PolygonGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + extrudedHeightReference : createPropertyDescriptor('extrudedHeightReference'), + /** * Gets or sets the numeric Property specifying the angular distance between points on the polygon. * @memberof PolygonGraphics.prototype @@ -260,7 +282,9 @@ define([ result.material = this.material; result.hierarchy = this.hierarchy; result.height = this.height; + result.heightReference = this.heightReference; result.extrudedHeight = this.extrudedHeight; + result.extrudedHeightReference = this.extrudedHeightReference; result.granularity = this.granularity; result.stRotation = this.stRotation; result.fill = this.fill; @@ -295,7 +319,9 @@ define([ this.material = defaultValue(this.material, source.material); this.hierarchy = defaultValue(this.hierarchy, source.hierarchy); this.height = defaultValue(this.height, source.height); + this.heightReference = defaultValue(this.heightReference, source.heightReference); this.extrudedHeight = defaultValue(this.extrudedHeight, source.extrudedHeight); + this.extrudedHeightReference = defaultValue(this.extrudedHeightReference, source.extrudedHeightReference); this.granularity = defaultValue(this.granularity, source.granularity); this.stRotation = defaultValue(this.stRotation, source.stRotation); this.fill = defaultValue(this.fill, source.fill); diff --git a/Source/DataSources/RectangleGeometryUpdater.js b/Source/DataSources/RectangleGeometryUpdater.js index 3cd071a7272e..9206ba1eb4df 100644 --- a/Source/DataSources/RectangleGeometryUpdater.js +++ b/Source/DataSources/RectangleGeometryUpdater.js @@ -1,4 +1,5 @@ define([ + '../Core/ApproximateTerrainHeights', '../Core/Cartesian3', '../Core/Cartographic', '../Core/Check', @@ -22,11 +23,11 @@ define([ '../Scene/PerInstanceColorAppearance', './ColorMaterialProperty', './DynamicGeometryUpdater', - './GeometryHeightProperty', './GeometryUpdater', './GroundGeometryUpdater', './Property' ], function( + ApproximateTerrainHeights, Cartesian3, Cartographic, Check, @@ -50,7 +51,6 @@ define([ PerInstanceColorAppearance, ColorMaterialProperty, DynamicGeometryUpdater, - GeometryHeightProperty, GeometryUpdater, GroundGeometryUpdater, Property) { @@ -222,35 +222,24 @@ define([ var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty; var height = rectangle.height; + var heightReference = rectangle.heightReference; var extrudedHeight = rectangle.extrudedHeight; - var granularity = rectangle.granularity; - var stRotation = rectangle.stRotation; - var rotation = rectangle.rotation; - - var heightValue = Property.getValueOrUndefined(height, Iso8601.MINIMUM_VALUE); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, Iso8601.MINIMUM_VALUE); + var extrudedHeightReference = rectangle.extrudedHeightReference; var options = this._options; options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat; options.rectangle = rectangle.coordinates.getValue(Iso8601.MINIMUM_VALUE, options.rectangle); - options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.stRotation = defined(stRotation) ? stRotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.rotation = defined(rotation) ? rotation.getValue(Iso8601.MINIMUM_VALUE) : undefined; - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, Iso8601.MINIMUM_VALUE); - - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; - } - - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } + options.granularity = Property.getValueOrUndefined(rectangle.granularity, Iso8601.MINIMUM_VALUE); + options.stRotation = Property.getValueOrUndefined(rectangle.stRotation, Iso8601.MINIMUM_VALUE); + options.rotation = Property.getValueOrUndefined(rectangle.rotation, Iso8601.MINIMUM_VALUE); + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + options.height = GroundGeometryUpdater.getGeometryHeight(height, heightReference, Iso8601.MINIMUM_VALUE); + + var extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, Iso8601.MINIMUM_VALUE); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(RectangleGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; @@ -281,30 +270,22 @@ define([ DynamicRectangleGeometryUpdater.prototype._setOptions = function(entity, rectangle, time) { var options = this._options; var height = rectangle.height; + var heightReference = rectangle.heightReference; var extrudedHeight = rectangle.extrudedHeight; - - var heightValue = Property.getValueOrUndefined(height, time); - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeight, time); + var extrudedHeightReference = rectangle.extrudedHeightReference; options.rectangle = Property.getValueOrUndefined(rectangle.coordinates, time, options.rectangle); options.granularity = Property.getValueOrUndefined(rectangle.granularity, time); options.stRotation = Property.getValueOrUndefined(rectangle.stRotation, time); options.rotation = Property.getValueOrUndefined(rectangle.rotation, time); - options.offsetAttribute = GeometryHeightProperty.computeGeometryOffsetAttribute(height, extrudedHeight, time); - - if (defined(heightValue) && defined(heightValue.height)) { - heightValue = heightValue.height; - } + options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + options.height = GroundGeometryUpdater.getGeometryHeight(height, heightReference, time); - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - if (extrudedHeightValue.heightReference === HeightReference.CLAMP_TO_GROUND) { - extrudedHeightValue = GeometryHeightProperty.getMinimumTerrainValue(RectangleGeometry.computeRectangle(options, scratchRectangle)); - } else { - extrudedHeightValue = extrudedHeightValue.height; - } + var extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeight, extrudedHeightReference, time); + if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) { + extrudedHeightValue = ApproximateTerrainHeights.getApproximateTerrainHeights(RectangleGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight; } - options.height = heightValue; options.extrudedHeight = extrudedHeightValue; }; diff --git a/Source/DataSources/RectangleGraphics.js b/Source/DataSources/RectangleGraphics.js index 290de41f8569..9840679d75d0 100644 --- a/Source/DataSources/RectangleGraphics.js +++ b/Source/DataSources/RectangleGraphics.js @@ -27,7 +27,9 @@ define([ * @param {Object} [options] Object with the following properties: * @param {Property} [options.coordinates] The Property specifying the {@link Rectangle}. * @param {Property} [options.height=0] A numeric Property specifying the altitude of the rectangle relative to the ellipsoid surface. + * @param {Property} [options.heightReference] A Property specifying what the height is relative to. * @param {Property} [options.extrudedHeight] A numeric Property specifying the altitude of the rectangle's extruded face relative to the ellipsoid surface. + * @param {Property} [options.extrudedHeightReference] A Property specifying what the extrudedHeight is relative to. * @param {Property} [options.show=true] A boolean Property specifying the visibility of the rectangle. * @param {Property} [options.fill=true] A boolean Property specifying whether the rectangle is filled with the provided material. * @param {MaterialProperty} [options.material=Color.WHITE] A Property specifying the material used to fill the rectangle. @@ -53,8 +55,12 @@ define([ this._coordinatesSubscription = undefined; this._height = undefined; this._heightSubscription = undefined; + this._heightReference = undefined; + this._heightReferenceSubscription = undefined; this._extrudedHeight = undefined; this._extrudedHeightSubscription = undefined; + this._extrudedHeightReference = undefined; + this._extrudedHeightReferenceSubscription = undefined; this._granularity = undefined; this._granularitySubscription = undefined; this._stRotation = undefined; @@ -128,6 +134,14 @@ define([ */ height : createPropertyDescriptor('height'), + /** + * Gets or sets the Property specifying the {@link HeightReference}. + * @memberof RectangleGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + heightReference : createPropertyDescriptor('heightReference'), + /** * Gets or sets the numeric Property specifying the altitude of the rectangle extrusion. * Setting this property creates volume starting at height and ending at this altitude. @@ -136,6 +150,14 @@ define([ */ extrudedHeight : createPropertyDescriptor('extrudedHeight'), + /** + * Gets or sets the Property specifying the extruded {@link HeightReference}. + * @memberof RectangleGraphics.prototype + * @type {Property} + * @default HeightReference.NONE + */ + extrudedHeightReference : createPropertyDescriptor('extrudedHeightReference'), + /** * Gets or sets the numeric Property specifying the angular distance between points on the rectangle. * @memberof RectangleGraphics.prototype @@ -239,7 +261,9 @@ define([ result.coordinates = this.coordinates; result.material = this.material; result.height = this.height; + result.heightReference = this.heightReference; result.extrudedHeight = this.extrudedHeight; + result.extrudedHeightReference = this.extrudedHeightReference; result.granularity = this.granularity; result.stRotation = this.stRotation; result.rotation = this.rotation; @@ -272,7 +296,9 @@ define([ this.coordinates = defaultValue(this.coordinates, source.coordinates); this.material = defaultValue(this.material, source.material); this.height = defaultValue(this.height, source.height); + this.heightReference = defaultValue(this.heightReference, source.heightReference); this.extrudedHeight = defaultValue(this.extrudedHeight, source.extrudedHeight); + this.extrudedHeightReference = defaultValue(this.extrudedHeightReference, source.extrudedHeightReference); this.granularity = defaultValue(this.granularity, source.granularity); this.stRotation = defaultValue(this.stRotation, source.stRotation); this.rotation = defaultValue(this.rotation, source.rotation); diff --git a/Source/DataSources/TerrainOffsetProperty.js b/Source/DataSources/TerrainOffsetProperty.js index 3b630ec207bc..726eee61f912 100644 --- a/Source/DataSources/TerrainOffsetProperty.js +++ b/Source/DataSources/TerrainOffsetProperty.js @@ -29,21 +29,16 @@ define([ /** * @private - * @param {Scene} scene - * @param {Property} height - * @param {Property} extrudedHeight - * @param {TerrainOffsetProperty~PositionFunction} getPosition - * @constructor */ - function TerrainOffsetProperty(scene, height, extrudedHeight, getPosition) { + function TerrainOffsetProperty(scene, heightReference, extrudedHeightReference, getPosition) { //>>includeStart('debug', pragmas.debug); Check.defined('scene', scene); Check.typeOf.func('getPosition', getPosition); //>>includeEnd('debug'); this._scene = scene; - this._height = height; - this._extrudedHeight = extrudedHeight; + this._heightReference = heightReference; + this._extrudedHeightReference = extrudedHeightReference; this._getPosition = getPosition; this._position = new Cartesian3(); @@ -136,20 +131,8 @@ define([ * @returns {Cartesian3} The offset */ TerrainOffsetProperty.prototype.getValue = function(time, result) { - var heightProperty = this._height; - var extrudedHeightProperty = this._extrudedHeight; - var heightReference = HeightReference.NONE; - var extrudedHeightReference = HeightReference.NONE; - - var heightValue = Property.getValueOrUndefined(heightProperty, time); - if (defined(heightValue) && defined(heightValue.heightReference)) { - heightReference = heightValue.heightReference; - } - - var extrudedHeightValue = Property.getValueOrUndefined(extrudedHeightProperty, time); - if (defined(extrudedHeightValue) && defined(extrudedHeightValue.heightReference)) { - extrudedHeightReference = extrudedHeightValue.heightReference; - } + var heightReference = Property.getValueOrDefault(this._heightReference, time, HeightReference.NONE); + var extrudedHeightReference = Property.getValueOrDefault(this._extrudedHeightReference, time, HeightReference.NONE); if (heightReference === HeightReference.NONE && extrudedHeightReference !== HeightReference.RELATIVE_TO_GROUND) { this._position = Cartesian3.clone(Cartesian3.ZERO, this._position); diff --git a/Specs/DataSources/GeometryHeightPropertySpec.js b/Specs/DataSources/GeometryHeightPropertySpec.js deleted file mode 100644 index 42b673608c3a..000000000000 --- a/Specs/DataSources/GeometryHeightPropertySpec.js +++ /dev/null @@ -1,167 +0,0 @@ -defineSuite([ - 'DataSources/GeometryHeightProperty', - 'Core/ApproximateTerrainHeights', - 'Core/Event', - 'Core/JulianDate', - 'Core/Rectangle', - 'Scene/HeightReference', - 'DataSources/ConstantProperty' -], function( - GeometryHeightProperty, - ApproximateTerrainHeights, - Event, - JulianDate, - Rectangle, - HeightReference, - ConstantProperty) { - 'use strict'; - - var time = JulianDate.now(); - beforeAll(function() { - return ApproximateTerrainHeights.initialize(); - }); - - afterAll(function() { - ApproximateTerrainHeights._initPromise = undefined; - ApproximateTerrainHeights._terrainHeights = undefined; - }); - - it('can default construct', function() { - var property = new GeometryHeightProperty(); - expect(property.isConstant).toBe(true); - expect(property.definitionChanged).toBeInstanceOf(Event); - expect(property.height).toBeUndefined(); - expect(property.heightReference).toBeUndefined(); - expect(property.getValue(time)).toEqual({ - height: 0, - heightReference: HeightReference.NONE - }); - }); - - it('can construct with arguments', function() { - var height = new ConstantProperty(30); - var heightReference = new ConstantProperty(HeightReference.NONE); - var property = new GeometryHeightProperty(height, heightReference); - expect(property.isConstant).toBe(true); - expect(property.definitionChanged).toBeInstanceOf(Event); - expect(property.height).toBe(height); - expect(property.heightReference).toBe(heightReference); - expect(property.getValue(time)).toEqual({ - height: 30, - heightReference: HeightReference.NONE - }); - }); - - it('setting height raises definitionChanged event', function() { - var property = new GeometryHeightProperty(); - - var listener = jasmine.createSpy('listener'); - property.definitionChanged.addEventListener(listener); - - var newValue = new ConstantProperty(); - property.height = newValue; - expect(listener).toHaveBeenCalledWith(property, 'height', newValue, undefined); - }); - - it('setting heightReference raises definitionChanged event', function() { - var property = new GeometryHeightProperty(); - - var listener = jasmine.createSpy('listener'); - property.definitionChanged.addEventListener(listener); - - var newValue =new ConstantProperty(); - property.heightReference = newValue; - expect(listener).toHaveBeenCalledWith(property, 'heightReference', newValue, undefined); - }); - - it('setting height does not raise definitionChanged event for same data', function() { - var height = new ConstantProperty(30); - var property = new GeometryHeightProperty(height); - - var listener = jasmine.createSpy('listener'); - property.definitionChanged.addEventListener(listener); - - property.height = height; - expect(listener.calls.count()).toBe(0); - }); - - it('setting heightReference does not raise definitionChanged event for same data', function() { - var heightReference = new ConstantProperty(HeightReference.NONE); - var property = new GeometryHeightProperty(undefined, heightReference); - - var listener = jasmine.createSpy('listener'); - property.definitionChanged.addEventListener(listener); - - property.heightReference = heightReference; - expect(listener.calls.count()).toBe(0); - }); - - it('getValue works for for height reference NONE and RELATIVE_TO_GROUND', function() { - var expected = 30; - var height = new ConstantProperty(expected); - var heightReference = new ConstantProperty(HeightReference.NONE); - var property = new GeometryHeightProperty(height, heightReference); - expect(property.getValue(time)).toEqual({ - height: expected, - heightReference: HeightReference.NONE - }); - - property.heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); - expect(property.getValue(time)).toEqual({ - height: expected, - heightReference: HeightReference.RELATIVE_TO_GROUND - }); - }); - - it('getValue works for for height reference CLAMP_TO_GROUND', function() { - var height = new ConstantProperty(50); - var heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); - var property = new GeometryHeightProperty(height, heightReference); - expect(property.getValue(time)).toEqual({ - height: 0, - heightReference: HeightReference.CLAMP_TO_GROUND - }); - }); - - it('equals works', function() { - var height = new ConstantProperty(50); - var heightReference = new ConstantProperty(HeightReference.NONE); - - var left = new GeometryHeightProperty(); - var right = new GeometryHeightProperty(); - - expect(left.equals(undefined)).toBe(false); - expect(left.equals(right)).toBe(true); - - left.height = height; - expect(left.equals(right)).toBe(false); - - right.height = height; - expect(left.equals(right)).toBe(true); - - left.heightReference = heightReference; - expect(left.equals(right)).toBe(false); - - right.heightReference = heightReference; - expect(left.equals(right)).toBe(true); - }); - - it('getValue throws without time', function() { - var property = new GeometryHeightProperty(); - expect(function() { - property.getValue(); - }).toThrowDeveloperError(); - }); - - it('getMinimumTerrainValue return terrain value', function() { - var rectangle = Rectangle.fromDegrees(0, 0, 1, 1); - var expected = ApproximateTerrainHeights.getApproximateTerrainHeights(rectangle).minimumTerrainHeight; - expect(GeometryHeightProperty.getMinimumTerrainValue(rectangle)).toBe(expected); - }); - - it('getMinimumTerrainValue throws without rectangle', function() { - expect(function() { - return GeometryHeightProperty.getMinimumTerrainValue(); - }).toThrowDeveloperError(); - }); -}); diff --git a/Specs/DataSources/GroundGeometryUpdaterSpec.js b/Specs/DataSources/GroundGeometryUpdaterSpec.js new file mode 100644 index 000000000000..6974d335bd18 --- /dev/null +++ b/Specs/DataSources/GroundGeometryUpdaterSpec.js @@ -0,0 +1,115 @@ +defineSuite([ + 'DataSources/GroundGeometryUpdater', + 'Core/ApproximateTerrainHeights', + 'Core/Event', + 'Core/GeometryOffsetAttribute', + 'Core/JulianDate', + 'Core/Rectangle', + 'Scene/HeightReference', + 'DataSources/ConstantProperty' +], function( + GroundGeometryUpdater, + ApproximateTerrainHeights, + Event, + GeometryOffsetAttribute, + JulianDate, + Rectangle, + HeightReference, + ConstantProperty) { + 'use strict'; + + var time = JulianDate.now(); + + beforeAll(function() { + return ApproximateTerrainHeights.initialize(); + }); + + afterAll(function() { + ApproximateTerrainHeights._initPromise = undefined; + ApproximateTerrainHeights._terrainHeights = undefined; + }); + + it('getGeometryHeight works for for height reference NONE and RELATIVE_TO_GROUND', function() { + var expected = 30; + var height = new ConstantProperty(expected); + var heightReference = new ConstantProperty(HeightReference.NONE); + expect(GroundGeometryUpdater.getGeometryHeight(height, heightReference, time)).toEqual(expected); + + heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + expect(GroundGeometryUpdater.getGeometryHeight(height, heightReference, time)).toEqual(expected); + }); + + it('getGeometryHeight works for for height reference CLAMP_TO_GROUND', function() { + var height = new ConstantProperty(50); + var heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + expect(GroundGeometryUpdater.getGeometryHeight(height, heightReference, time)).toEqual(0); + }); + + it('getGeometryExtrudedHeight works for for height reference NONE and RELATIVE_TO_GROUND', function() { + var expected = 30; + var height = new ConstantProperty(expected); + var heightReference = new ConstantProperty(HeightReference.NONE); + expect(GroundGeometryUpdater.getGeometryExtrudedHeight(height, heightReference, time)).toEqual(expected); + + heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + expect(GroundGeometryUpdater.getGeometryExtrudedHeight(height, heightReference, time)).toEqual(expected); + }); + + it('getGeometryExtrudedHeight works for for height reference CLAMP_TO_GROUND', function() { + var height = new ConstantProperty(50); + var heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + expect(GroundGeometryUpdater.getGeometryExtrudedHeight(height, heightReference, time)).toEqual(GroundGeometryUpdater.CLAMP_TO_GROUND); + }); + + it('computeGeometryOffsetAttribute works', function() { + var heightReference; + var extrudedHeightReference; + var result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBeUndefined(); + + heightReference = new ConstantProperty(HeightReference.NONE); + extrudedHeightReference = new ConstantProperty(HeightReference.NONE); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBeUndefined(); + + heightReference = new ConstantProperty(HeightReference.NONE); + extrudedHeightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBeUndefined(); + + heightReference = new ConstantProperty(HeightReference.NONE); + extrudedHeightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBe(GeometryOffsetAttribute.TOP); + + heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + extrudedHeightReference = new ConstantProperty(HeightReference.NONE); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBe(GeometryOffsetAttribute.TOP); + + heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + extrudedHeightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBe(GeometryOffsetAttribute.TOP); + + heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + extrudedHeightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBe(GeometryOffsetAttribute.ALL); + + heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + extrudedHeightReference = new ConstantProperty(HeightReference.NONE); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBe(GeometryOffsetAttribute.TOP); + + heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + extrudedHeightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBe(GeometryOffsetAttribute.TOP); + + heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + extrudedHeightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + result = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightReference, extrudedHeightReference, time); + expect(result).toBe(GeometryOffsetAttribute.ALL); + }); +}); diff --git a/Specs/createGeometryUpdaterGroundGeometrySpecs.js b/Specs/createGeometryUpdaterGroundGeometrySpecs.js index 9334437e320b..9a7f3af4efb7 100644 --- a/Specs/createGeometryUpdaterGroundGeometrySpecs.js +++ b/Specs/createGeometryUpdaterGroundGeometrySpecs.js @@ -4,7 +4,6 @@ define([ 'Core/JulianDate', 'DataSources/ColorMaterialProperty', 'DataSources/ConstantProperty', - 'DataSources/GeometryHeightProperty', 'DataSources/SampledProperty', 'Scene/ClassificationType', 'Scene/GroundPrimitive', @@ -16,7 +15,6 @@ define([ JulianDate, ColorMaterialProperty, ConstantProperty, - GeometryHeightProperty, SampledProperty, ClassificationType, GroundPrimitive, @@ -142,84 +140,84 @@ define([ var graphics = entity[geometryPropertyName]; graphics.outline = true; graphics.outlineColor = Color.BLACK; + graphics.height = new ConstantProperty(20.0); + graphics.extrudedHeight = new ConstantProperty(0.0); var updater = new Updater(entity, getScene()); var instance; - graphics.height = new ConstantProperty(20.0); - graphics.extrudedHeight = new ConstantProperty(0.0); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toBeUndefined(); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toBeUndefined(); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.NONE); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.NONE); + graphics.heightReference = new ConstantProperty(HeightReference.NONE); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.NONE); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toBeUndefined(); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toBeUndefined(); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.NONE); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.CLAMP_TO_GROUND); + graphics.heightReference = new ConstantProperty(HeightReference.NONE); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toBeUndefined(); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toBeUndefined(); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.NONE); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.RELATIVE_TO_GROUND); + graphics.heightReference = new ConstantProperty(HeightReference.NONE); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.CLAMP_TO_GROUND); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.NONE); + graphics.heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.NONE); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.CLAMP_TO_GROUND); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.CLAMP_TO_GROUND); + graphics.heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.CLAMP_TO_GROUND); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.RELATIVE_TO_GROUND); + graphics.heightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.ALL); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.ALL); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.RELATIVE_TO_GROUND); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.NONE); + graphics.heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.NONE); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.RELATIVE_TO_GROUND); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.CLAMP_TO_GROUND); + graphics.heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.CLAMP_TO_GROUND); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); instance = updater.createOutlineGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.TOP); - graphics.height = new GeometryHeightProperty(20.0, HeightReference.RELATIVE_TO_GROUND); - graphics.extrudedHeight = new GeometryHeightProperty(0.0, HeightReference.RELATIVE_TO_GROUND); + graphics.heightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); + graphics.extrudedHeightReference = new ConstantProperty(HeightReference.RELATIVE_TO_GROUND); updater._onEntityPropertyChanged(entity, geometryPropertyName); instance = updater.createFillGeometryInstance(time); expect(instance.geometry._offsetAttribute).toEqual(GeometryOffsetAttribute.ALL); From 787a99ab4454959fcf4421f61761001dfcbec01f Mon Sep 17 00:00:00 2001 From: hpinkos Date: Wed, 27 Jun 2018 18:18:05 -0400 Subject: [PATCH 08/10] terrain offset performance --- Source/DataSources/GroundGeometryUpdater.js | 5 +++- Source/DataSources/TerrainOffsetProperty.js | 28 +++++++++++++++---- .../DataSources/TerrainOffsetPropertySpec.js | 12 ++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Source/DataSources/GroundGeometryUpdater.js b/Source/DataSources/GroundGeometryUpdater.js index 056e45537521..76c2c7b1810e 100644 --- a/Source/DataSources/GroundGeometryUpdater.js +++ b/Source/DataSources/GroundGeometryUpdater.js @@ -10,6 +10,7 @@ define([ '../Core/Iso8601', '../Core/oneTimeWarning', '../Scene/HeightReference', + './CallbackProperty', './ConstantProperty', './GeometryUpdater', './Property', @@ -26,6 +27,7 @@ define([ Iso8601, oneTimeWarning, HeightReference, + CallbackProperty, ConstantProperty, GeometryUpdater, Property, @@ -104,7 +106,8 @@ define([ var extrudedHeightReferenceProperty = geometry.extrudedHeightReference; if (defined(heightReferenceProperty) || defined(extrudedHeightReferenceProperty)) { - this._terrainOffsetProperty = new TerrainOffsetProperty(this._scene, heightReferenceProperty, extrudedHeightReferenceProperty, this._computeCenter.bind(this)); + var centerPosition = new CallbackProperty(this._computeCenter.bind(this), !this._dynamic); + this._terrainOffsetProperty = new TerrainOffsetProperty(this._scene, heightReferenceProperty, extrudedHeightReferenceProperty, centerPosition); } }; diff --git a/Source/DataSources/TerrainOffsetProperty.js b/Source/DataSources/TerrainOffsetProperty.js index 726eee61f912..bd35153349c7 100644 --- a/Source/DataSources/TerrainOffsetProperty.js +++ b/Source/DataSources/TerrainOffsetProperty.js @@ -30,16 +30,16 @@ define([ /** * @private */ - function TerrainOffsetProperty(scene, heightReference, extrudedHeightReference, getPosition) { + function TerrainOffsetProperty(scene, heightReferenceProperty, extrudedHeightReferenceProperty, positionProperty) { //>>includeStart('debug', pragmas.debug); Check.defined('scene', scene); - Check.typeOf.func('getPosition', getPosition); + Check.defined('positionProperty', positionProperty); //>>includeEnd('debug'); this._scene = scene; - this._heightReference = heightReference; - this._extrudedHeightReference = extrudedHeightReference; - this._getPosition = getPosition; + this._heightReference = heightReferenceProperty; + this._extrudedHeightReference = extrudedHeightReferenceProperty; + this._positionProperty = positionProperty; this._position = new Cartesian3(); this._cartographicPosition = new Cartographic(); @@ -60,6 +60,18 @@ define([ that._updateClamping(); }); } + + if (positionProperty.isConstant) { + var position = positionProperty.getValue(Iso8601.MINIMUM_VALUE, scratchPosition); + if (!defined(position) || Cartesian3.equals(position, Cartesian3.ZERO) || !defined(scene.globe)) { + return; + } + this._position = Cartesian3.clone(position, this._position); + + this._updateClamping(); + + this._normal = scene.globe.ellipsoid.geodeticSurfaceNormal(position, this._normal); + } } defineProperties(TerrainOffsetProperty.prototype, { @@ -139,8 +151,12 @@ define([ return Cartesian3.clone(Cartesian3.ZERO, result); } + if (this._positionProperty.isConstant) { + return Cartesian3.multiplyByScalar(this._normal, this._terrainHeight, result); + } + var scene = this._scene; - var position = this._getPosition(time, scratchPosition); + var position = this._positionProperty.getValue(time, scratchPosition); if (!defined(position) || Cartesian3.equals(position, Cartesian3.ZERO) || !defined(scene.globe)) { return Cartesian3.clone(Cartesian3.ZERO, result); } diff --git a/Specs/DataSources/TerrainOffsetPropertySpec.js b/Specs/DataSources/TerrainOffsetPropertySpec.js index 31e97a7659a3..9a0b060c5e4f 100644 --- a/Specs/DataSources/TerrainOffsetPropertySpec.js +++ b/Specs/DataSources/TerrainOffsetPropertySpec.js @@ -5,6 +5,7 @@ defineSuite([ 'Core/JulianDate', 'Core/Rectangle', 'Scene/HeightReference', + 'DataSources/CallbackProperty', 'DataSources/ConstantProperty', 'Specs/createGlobe', 'Specs/createScene' @@ -15,6 +16,7 @@ defineSuite([ JulianDate, Rectangle, HeightReference, + CallbackProperty, ConstantProperty, createGlobe, createScene) { @@ -32,10 +34,10 @@ defineSuite([ }); it('can construct and destroy', function() { - var getPosition = jasmine.createSpy(); + var position = new CallbackProperty(jasmine.createSpy(), false); var height = new ConstantProperty(30); var extrudedHeight = new ConstantProperty(0); - var property = new TerrainOffsetProperty(scene, height, extrudedHeight, getPosition); + var property = new TerrainOffsetProperty(scene, height, extrudedHeight, position); expect(property.isConstant).toBe(false); expect(property.getValue(time)).toEqual(Cartesian3.ZERO); property.destroy(); @@ -43,15 +45,15 @@ defineSuite([ }); it('throws without scene', function() { - var getPosition = jasmine.createSpy(); + var position = new CallbackProperty(jasmine.createSpy(), false); var height = new ConstantProperty(30); var extrudedHeight = new ConstantProperty(0); expect(function() { - return new TerrainOffsetProperty(undefined, height, extrudedHeight, getPosition); + return new TerrainOffsetProperty(undefined, height, extrudedHeight, position); }).toThrowDeveloperError(); }); - it('throws without getPosition', function() { + it('throws without position', function() { var height = new ConstantProperty(30); var extrudedHeight = new ConstantProperty(0); expect(function() { From eb0974f0d728060089a07f17cfce65f267988d0f Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 28 Jun 2018 15:08:11 -0400 Subject: [PATCH 09/10] CHANGES.md --- CHANGES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 04cd837bf343..546089ba1afc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,9 +14,12 @@ Change Log * Requires depth texture support (`WEBGL_depth_texture` or `WEBKIT_WEBGL_depth_texture`), otherwise `clampToGround` will be ignored. Use `Entity.supportsPolylinesOnTerrain` to check for support. * Added `GroundPolylinePrimitive` and `GroundPolylineGeometry`. * `PostProcessStage` has a `selected` property which is an array of primitives used for selectively applying a post-process stage. [#6476](https://github.com/AnalyticalGraphicsInc/cesium/pull/6476) - * The `PostProcessStageLibrary.createBlackAndWhiteStage` and `PostProcessStageLibrary.createSilhouetteStage` have per-feature support. + * The `PostProcessStageLibrary.createBlackAndWhiteStage` and `PostProcessStageLibrary.createSilhouetteStage` have per-feature support. * Added CZML support for `zIndex` for `corridor`, `ellipse`, `polygon`, `polyline` and `rectangle`. [#6708](https://github.com/AnalyticalGraphicsInc/cesium/pull/6708) * Added CZML `clampToGround` option for `polyline`. [#6706](https://github.com/AnalyticalGraphicsInc/cesium/pull/6706) +* Added `heightReference` and `extrudedHeightReference` properties to `CorridorGraphics`, `EllipseGraphics`, `PolygonGraphics` and `RectangleGraphics`. [#6717](https://github.com/AnalyticalGraphicsInc/cesium/pull/6717) + * This can be used in conjunction with the `height` and/or `extrudedHeight` properties to clamp the geometry to terrain or set the height relative to terrain. + * Note, this will not make the geometry conform to terrain. Extruded geoemtry that is clamped to the ground will have a flat top will sinks into the terrain at the base. ##### Fixes :wrench: * Fixed a bug that caused Cesium to be unable to load local resources in Electron. [#6726](https://github.com/AnalyticalGraphicsInc/cesium/pull/6726) From 04a82596a1d6eed3b9efbaa5b8ae350f8a787e7e Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 28 Jun 2018 22:27:09 -0400 Subject: [PATCH 10/10] fix height 2D/CV --- Source/DataSources/TerrainOffsetProperty.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/DataSources/TerrainOffsetProperty.js b/Source/DataSources/TerrainOffsetProperty.js index bd35153349c7..7f9f740cf7d7 100644 --- a/Source/DataSources/TerrainOffsetProperty.js +++ b/Source/DataSources/TerrainOffsetProperty.js @@ -9,6 +9,7 @@ define([ '../Core/Iso8601', '../Core/Math', '../Scene/HeightReference', + '../Scene/SceneMode', './Property' ], function( Cartesian3, @@ -21,6 +22,7 @@ define([ Iso8601, CesiumMath, HeightReference, + SceneMode, Property) { 'use strict'; @@ -130,8 +132,12 @@ define([ } function updateFunction(clampedPosition) { - var carto = ellipsoid.cartesianToCartographic(clampedPosition, scratchCarto); - that._terrainHeight = carto.height; + if (scene.mode === SceneMode.SCENE3D) { + var carto = ellipsoid.cartesianToCartographic(clampedPosition, scratchCarto); + that._terrainHeight = carto.height; + } else { + that._terrainHeight = clampedPosition.x; + } that.definitionChanged.raiseEvent(); } this._removeCallbackFunc = surface.updateHeight(cartographicPosition, updateFunction);