diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index 258867059060..b3f802f191d7 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -813,12 +813,15 @@ define([ } //>>includeEnd('debug'); + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); + this._positions = positions; this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT)); this._width = width; - this._height = defaultValue(options.height, 0); - this._extrudedHeight = defaultValue(options.extrudedHeight, this._height); + this._height = Math.max(height, extrudedHeight); + this._extrudedHeight = Math.min(height, extrudedHeight); this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._shadowVolume = defaultValue(options.shadowVolume, false); @@ -960,10 +963,7 @@ define([ */ CorridorGeometry.createGeometry = function(corridorGeometry) { var positions = corridorGeometry._positions; - var height = corridorGeometry._height; var width = corridorGeometry._width; - var extrudedHeight = corridorGeometry._extrudedHeight; - var extrude = (height !== extrudedHeight); var ellipsoid = corridorGeometry._ellipsoid; positions = scaleToSurface(positions, ellipsoid); @@ -973,6 +973,10 @@ define([ return; } + var height = corridorGeometry._height; + var extrudedHeight = corridorGeometry._extrudedHeight; + var extrude = !CesiumMath.equalsEpsilon(height, extrudedHeight, CesiumMath.EPSILON2); + var vertexFormat = corridorGeometry._vertexFormat; var params = { ellipsoid : ellipsoid, @@ -984,9 +988,6 @@ define([ }; var attr; if (extrude) { - var h = Math.max(height, extrudedHeight); - extrudedHeight = Math.min(height, extrudedHeight); - height = h; params.height = height; params.extrudedHeight = extrudedHeight; params.shadowVolume = corridorGeometry._shadowVolume; diff --git a/Source/Core/CorridorOutlineGeometry.js b/Source/Core/CorridorOutlineGeometry.js index b047c00f6d9a..937ca0b22229 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -341,11 +341,14 @@ define([ Check.typeOf.number('options.width', width); //>>includeEnd('debug'); + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); + this._positions = positions; this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); this._width = width; - this._height = defaultValue(options.height, 0); - this._extrudedHeight = defaultValue(options.extrudedHeight, this._height); + this._height = Math.max(height, extrudedHeight); + this._extrudedHeight = Math.min(height, extrudedHeight); this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._workerName = 'createCorridorOutlineGeometry'; @@ -389,7 +392,7 @@ define([ array[startingIndex++] = value._height; array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._cornerType; - array[startingIndex] = value._granularity; + array[startingIndex] = value._granularity; return array; }; @@ -465,10 +468,7 @@ define([ */ CorridorOutlineGeometry.createGeometry = function(corridorOutlineGeometry) { var positions = corridorOutlineGeometry._positions; - var height = corridorOutlineGeometry._height; var width = corridorOutlineGeometry._width; - var extrudedHeight = corridorOutlineGeometry._extrudedHeight; - var extrude = (height !== extrudedHeight); var ellipsoid = corridorOutlineGeometry._ellipsoid; positions = scaleToSurface(positions, ellipsoid); @@ -478,6 +478,10 @@ define([ return; } + var height = corridorOutlineGeometry._height; + var extrudedHeight = corridorOutlineGeometry._extrudedHeight; + var extrude = !CesiumMath.equalsEpsilon(height, extrudedHeight, CesiumMath.EPSILON2); + var params = { ellipsoid : ellipsoid, positions : cleanPositions, @@ -488,9 +492,6 @@ define([ }; var attr; if (extrude) { - var h = Math.max(height, extrudedHeight); - extrudedHeight = Math.min(height, extrudedHeight); - height = h; params.height = height; params.extrudedHeight = extrudedHeight; attr = computePositionsExtruded(params); diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index 7f4fd61a02c7..dafb6bfcb6ab 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -722,9 +722,6 @@ define([ var semiMajorAxis = options.semiMajorAxis; var semiMinorAxis = options.semiMinorAxis; var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); - var height = defaultValue(options.height, 0.0); - var extrudedHeight = options.extrudedHeight; - var extrude = (defined(extrudedHeight) && Math.abs(height - extrudedHeight) > 1.0); var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); //>>includeStart('debug', pragmas.debug); @@ -745,17 +742,19 @@ define([ } //>>includeEnd('debug'); + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); + this._center = Cartesian3.clone(center); this._semiMajorAxis = semiMajorAxis; this._semiMinorAxis = semiMinorAxis; this._ellipsoid = Ellipsoid.clone(ellipsoid); this._rotation = defaultValue(options.rotation, 0.0); this._stRotation = defaultValue(options.stRotation, 0.0); - this._height = height; + this._height = Math.max(extrudedHeight, height); this._granularity = granularity; this._vertexFormat = VertexFormat.clone(vertexFormat); - this._extrudedHeight = defaultValue(extrudedHeight, height); - this._extrude = extrude; + this._extrudedHeight = Math.min(extrudedHeight, height); this._shadowVolume = defaultValue(options.shadowVolume, false); this._workerName = 'createEllipseGeometry'; @@ -766,7 +765,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - EllipseGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 9; + EllipseGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 8; /** * Stores the provided instance into the provided array. @@ -805,7 +804,6 @@ define([ array[startingIndex++] = value._height; array[startingIndex++] = value._granularity; array[startingIndex++] = value._extrudedHeight; - array[startingIndex++] = value._extrude ? 1.0 : 0.0; array[startingIndex] = value._shadowVolume ? 1.0 : 0.0; return array; @@ -861,7 +859,6 @@ define([ var height = array[startingIndex++]; var granularity = array[startingIndex++]; var extrudedHeight = array[startingIndex++]; - var extrude = array[startingIndex++] === 1.0; var shadowVolume = array[startingIndex] === 1.0; if (!defined(result)) { @@ -886,7 +883,6 @@ define([ result._height = height; result._granularity = granularity; result._extrudedHeight = extrudedHeight; - result._extrude = extrude; result._shadowVolume = shadowVolume; return result; @@ -903,6 +899,10 @@ define([ return; } + var height = ellipseGeometry._height; + var extrudedHeight = ellipseGeometry._extrudedHeight; + var extrude = !CesiumMath.equalsEpsilon(height, extrudedHeight, CesiumMath.EPSILON2); + ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(ellipseGeometry._center, ellipseGeometry._center); var options = { center : ellipseGeometry._center, @@ -910,16 +910,14 @@ define([ semiMinorAxis : ellipseGeometry._semiMinorAxis, ellipsoid : ellipseGeometry._ellipsoid, rotation : ellipseGeometry._rotation, - height : ellipseGeometry._height, - extrudedHeight : ellipseGeometry._extrudedHeight, + height : height, granularity : ellipseGeometry._granularity, vertexFormat : ellipseGeometry._vertexFormat, stRotation : ellipseGeometry._stRotation }; var geometry; - if (ellipseGeometry._extrude) { - options.extrudedHeight = Math.min(ellipseGeometry._extrudedHeight, ellipseGeometry._height); - options.height = Math.max(ellipseGeometry._extrudedHeight, ellipseGeometry._height); + if (extrude) { + options.extrudedHeight = extrudedHeight; options.shadowVolume = ellipseGeometry._shadowVolume; geometry = computeExtrudedEllipse(options); } else { diff --git a/Source/Core/EllipseOutlineGeometry.js b/Source/Core/EllipseOutlineGeometry.js index b72e86aacd3b..9b21c907ad2b 100644 --- a/Source/Core/EllipseOutlineGeometry.js +++ b/Source/Core/EllipseOutlineGeometry.js @@ -163,9 +163,6 @@ define([ var semiMajorAxis = options.semiMajorAxis; var semiMinorAxis = options.semiMinorAxis; var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); - var height = defaultValue(options.height, 0.0); - var extrudedHeight = options.extrudedHeight; - var extrude = (defined(extrudedHeight) && Math.abs(height - extrudedHeight) > 1.0); //>>includeStart('debug', pragmas.debug); if (!defined(center)) { @@ -185,15 +182,17 @@ define([ } //>>includeEnd('debug'); + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); + this._center = Cartesian3.clone(center); this._semiMajorAxis = semiMajorAxis; this._semiMinorAxis = semiMinorAxis; this._ellipsoid = Ellipsoid.clone(ellipsoid); this._rotation = defaultValue(options.rotation, 0.0); - this._height = height; + this._height = Math.max(extrudedHeight, height); this._granularity = granularity; - this._extrudedHeight = extrudedHeight; - this._extrude = extrude; + this._extrudedHeight = Math.min(extrudedHeight, height); this._numberOfVerticalLines = Math.max(defaultValue(options.numberOfVerticalLines, 16), 0); this._workerName = 'createEllipseOutlineGeometry'; } @@ -202,7 +201,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - EllipseOutlineGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + 9; + EllipseOutlineGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + 7; /** * Stores the provided instance into the provided array. @@ -236,9 +235,7 @@ define([ array[startingIndex++] = value._rotation; array[startingIndex++] = value._height; array[startingIndex++] = value._granularity; - array[startingIndex++] = defined(value._extrudedHeight) ? 1.0 : 0.0; - array[startingIndex++] = defaultValue(value._extrudedHeight, 0.0); - array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex++] = value._extrudedHeight; array[startingIndex] = value._numberOfVerticalLines; return array; @@ -286,14 +283,12 @@ define([ var rotation = array[startingIndex++]; var height = array[startingIndex++]; var granularity = array[startingIndex++]; - var hasExtrudedHeight = array[startingIndex++]; var extrudedHeight = array[startingIndex++]; - var extrude = array[startingIndex++] === 1.0; var numberOfVerticalLines = array[startingIndex]; if (!defined(result)) { scratchOptions.height = height; - scratchOptions.extrudedHeight = hasExtrudedHeight ? extrudedHeight : undefined; + scratchOptions.extrudedHeight = extrudedHeight; scratchOptions.granularity = granularity; scratchOptions.rotation = rotation; scratchOptions.semiMajorAxis = semiMajorAxis; @@ -309,8 +304,7 @@ define([ result._rotation = rotation; result._height = height; result._granularity = granularity; - result._extrudedHeight = hasExtrudedHeight ? extrudedHeight : undefined; - result._extrude = extrude; + result._extrudedHeight = extrudedHeight; result._numberOfVerticalLines = numberOfVerticalLines; return result; @@ -327,6 +321,10 @@ define([ return; } + var height = ellipseGeometry._height; + var extrudedHeight = ellipseGeometry._extrudedHeight; + var extrude = !CesiumMath.equalsEpsilon(height, extrudedHeight, CesiumMath.EPSILON2); + ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(ellipseGeometry._center, ellipseGeometry._center); var options = { center : ellipseGeometry._center, @@ -334,15 +332,13 @@ define([ semiMinorAxis : ellipseGeometry._semiMinorAxis, ellipsoid : ellipseGeometry._ellipsoid, rotation : ellipseGeometry._rotation, - height : ellipseGeometry._height, - extrudedHeight : ellipseGeometry._extrudedHeight, + height : height, granularity : ellipseGeometry._granularity, numberOfVerticalLines : ellipseGeometry._numberOfVerticalLines }; var geometry; - if (ellipseGeometry._extrude) { - options.extrudedHeight = Math.min(ellipseGeometry._extrudedHeight, ellipseGeometry._height); - options.height = Math.max(ellipseGeometry._extrudedHeight, ellipseGeometry._height); + if (extrude) { + options.extrudedHeight = extrudedHeight; geometry = computeExtrudedEllipse(options); } else { geometry = computeEllipse(options); diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index e79ec9eeb6df..e2948690d2c1 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -569,22 +569,14 @@ define([ var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); var stRotation = defaultValue(options.stRotation, 0.0); - var height = defaultValue(options.height, 0.0); var perPositionHeight = defaultValue(options.perPositionHeight, false); + var perPositionHeightExtrude = perPositionHeight && defined(options.extrudedHeight); + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); - var extrudedHeight = options.extrudedHeight; - var extrude = defined(extrudedHeight); - - if (!perPositionHeight && extrude) { - //Ignore extrudedHeight if it matches height - if (CesiumMath.equalsEpsilon(height, extrudedHeight, CesiumMath.EPSILON10)) { - extrudedHeight = undefined; - extrude = false; - } else { - var h = extrudedHeight; - extrudedHeight = Math.min(h, height); - height = Math.max(h, height); - } + if (!perPositionHeightExtrude) { + height = Math.max(height, extrudedHeight); + extrudedHeight = Math.min(height, extrudedHeight); } this._vertexFormat = VertexFormat.clone(vertexFormat); @@ -592,12 +584,12 @@ define([ this._granularity = granularity; this._stRotation = stRotation; this._height = height; - this._extrudedHeight = defaultValue(extrudedHeight, 0.0); - this._extrude = extrude; + this._extrudedHeight = extrudedHeight; this._closeTop = defaultValue(options.closeTop, true); this._closeBottom = defaultValue(options.closeBottom, true); this._polygonHierarchy = polygonHierarchy; this._perPositionHeight = perPositionHeight; + this._perPositionHeightExtrude = perPositionHeightExtrude; this._shadowVolume = defaultValue(options.shadowVolume, false); this._workerName = 'createPolygonGeometry'; @@ -695,7 +687,7 @@ define([ array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._granularity; array[startingIndex++] = value._stRotation; - array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex++] = value._perPositionHeightExtrude ? 1.0 : 0.0; array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0; array[startingIndex++] = value._closeTop ? 1.0 : 0.0; array[startingIndex++] = value._closeBottom ? 1.0 : 0.0; @@ -741,7 +733,7 @@ define([ var extrudedHeight = array[startingIndex++]; var granularity = array[startingIndex++]; var stRotation = array[startingIndex++]; - var extrude = array[startingIndex++] === 1.0; + var perPositionHeightExtrude = array[startingIndex++] === 1.0; var perPositionHeight = array[startingIndex++] === 1.0; var closeTop = array[startingIndex++] === 1.0; var closeBottom = array[startingIndex++] === 1.0; @@ -759,7 +751,7 @@ define([ result._extrudedHeight = extrudedHeight; result._granularity = granularity; result._stRotation = stRotation; - result._extrude = extrude; + result._perPositionHeightExtrude = perPositionHeightExtrude; result._perPositionHeight = perPositionHeight; result._closeTop = closeTop; result._closeBottom = closeBottom; @@ -779,9 +771,6 @@ define([ var ellipsoid = polygonGeometry._ellipsoid; var granularity = polygonGeometry._granularity; var stRotation = polygonGeometry._stRotation; - var height = polygonGeometry._height; - var extrudedHeight = polygonGeometry._extrudedHeight; - var extrude = polygonGeometry._extrude; var polygonHierarchy = polygonGeometry._polygonHierarchy; var perPositionHeight = polygonGeometry._perPositionHeight; var closeTop = polygonGeometry._closeTop; @@ -808,6 +797,10 @@ define([ var geometry; var geometries = []; + var height = polygonGeometry._height; + var extrudedHeight = polygonGeometry._extrudedHeight; + var extrude = polygonGeometry._perPositionHeightExtrude || !CesiumMath.equalsEpsilon(height, extrudedHeight, CesiumMath.EPSILON2); + var options = { perPositionHeight: perPositionHeight, vertexFormat: vertexFormat, @@ -827,6 +820,7 @@ define([ options.top = closeTop; options.bottom = closeBottom; options.shadowVolume = polygonGeometry._shadowVolume; + for (i = 0; i < polygons.length; i++) { geometry = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], granularity, hierarchy[i], perPositionHeight, closeTop, closeBottom, vertexFormat); diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index 53040a1aa5b9..56bbbc5e9168 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -290,7 +290,7 @@ define([ Check.typeOf.object('options', options); Check.typeOf.object('options.polygonHierarchy', options.polygonHierarchy); - if (defined(options.perPositionHeight) && options.perPositionHeight && defined(options.height)) { + if (options.perPositionHeight && defined(options.height)) { throw new DeveloperError('Cannot use both options.perPositionHeight and options.height'); } //>>includeEnd('debug'); @@ -298,24 +298,19 @@ define([ var polygonHierarchy = options.polygonHierarchy; var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); - var height = defaultValue(options.height, 0.0); var perPositionHeight = defaultValue(options.perPositionHeight, false); + var perPositionHeightExtrude = perPositionHeight && defined(options.extrudedHeight); - var extrudedHeight = options.extrudedHeight; - var extrude = defined(extrudedHeight); - if (extrude && !perPositionHeight) { - var h = extrudedHeight; - extrudedHeight = Math.min(h, height); - height = Math.max(h, height); - } + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); this._ellipsoid = Ellipsoid.clone(ellipsoid); this._granularity = granularity; - this._height = height; - this._extrudedHeight = defaultValue(extrudedHeight, 0.0); - this._extrude = extrude; + this._height = Math.max(height, extrudedHeight); + this._extrudedHeight = Math.min(extrudedHeight, height); this._polygonHierarchy = polygonHierarchy; this._perPositionHeight = perPositionHeight; + this._perPositionHeightExtrude = perPositionHeightExtrude; this._workerName = 'createPolygonOutlineGeometry'; /** @@ -350,9 +345,9 @@ define([ array[startingIndex++] = value._height; array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._granularity; - array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex++] = value._perPositionHeightExtrude ? 1.0 : 0.0; array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0; - array[startingIndex++] = value.packedLength; + array[startingIndex] = value.packedLength; return array; }; @@ -387,9 +382,8 @@ define([ var height = array[startingIndex++]; var extrudedHeight = array[startingIndex++]; var granularity = array[startingIndex++]; - var extrude = array[startingIndex++] === 1.0; - var perPositionHeight = array[startingIndex++] === 1.0; - var packedLength = array[startingIndex++]; + var perPositionHeightExtrude = array[startingIndex++] === 1.0; var perPositionHeight = array[startingIndex++] === 1.0; + var packedLength = array[startingIndex]; if (!defined(result)) { result = new PolygonOutlineGeometry(dummyOptions); @@ -400,8 +394,8 @@ define([ result._height = height; result._extrudedHeight = extrudedHeight; result._granularity = granularity; - result._extrude = extrude; result._perPositionHeight = perPositionHeight; + result._perPositionHeightExtrude = perPositionHeightExtrude; result.packedLength = packedLength; return result; @@ -464,9 +458,6 @@ define([ PolygonOutlineGeometry.createGeometry = function(polygonGeometry) { var ellipsoid = polygonGeometry._ellipsoid; var granularity = polygonGeometry._granularity; - var height = polygonGeometry._height; - var extrudedHeight = polygonGeometry._extrudedHeight; - var extrude = polygonGeometry._extrude; var polygonHierarchy = polygonGeometry._polygonHierarchy; var perPositionHeight = polygonGeometry._perPositionHeight; @@ -515,6 +506,10 @@ define([ var geometries = []; var minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius); + var height = polygonGeometry._height; + var extrudedHeight = polygonGeometry._extrudedHeight; + var extrude = polygonGeometry._perPositionHeightExtrude || !CesiumMath.equalsEpsilon(height, extrudedHeight, CesiumMath.EPSILON2); + if (extrude) { for (i = 0; i < polygons.length; i++) { geometry = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], minDistance, perPositionHeight); diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 8e13c29d12c6..33779c798bd4 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -334,10 +334,8 @@ define([ function constructExtrudedRectangle(options) { var shadowVolume = options.shadowVolume; var vertexFormat = options.vertexFormat; - var surfaceHeight = options.surfaceHeight; - var extrudedHeight = options.extrudedHeight; - var minHeight = Math.min(extrudedHeight, surfaceHeight); - var maxHeight = Math.max(extrudedHeight, surfaceHeight); + var minHeight = options.extrudedHeight; + var maxHeight = options.surfaceHeight; var height = options.height; var width = options.width; @@ -349,9 +347,6 @@ define([ options.vertexFormat.normal = true; } var topBottomGeo = constructRectangle(options); - if (CesiumMath.equalsEpsilon(minHeight, maxHeight, CesiumMath.EPSILON10)) { - return topBottomGeo; - } var topPositions = PolygonPipeline.scaleToGeodeticHeight(topBottomGeo.attributes.position.values, maxHeight, ellipsoid, false); topPositions = new Float64Array(topPositions); @@ -642,16 +637,17 @@ define([ } //>>includeEnd('debug'); - var rotation = defaultValue(options.rotation, 0.0); + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); + this._rectangle = rectangle; this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); - this._surfaceHeight = defaultValue(options.height, 0.0); - this._rotation = rotation; + this._surfaceHeight = Math.max(height, extrudedHeight); + this._rotation = defaultValue(options.rotation, 0.0); this._stRotation = defaultValue(options.stRotation, 0.0); this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT)); - this._extrudedHeight = defaultValue(options.extrudedHeight, 0.0); - this._extrude = defined(options.extrudedHeight); + this._extrudedHeight = Math.min(height, extrudedHeight); this._shadowVolume = defaultValue(options.shadowVolume, false); this._workerName = 'createRectangleGeometry'; this._rotatedRectangle = undefined; @@ -661,7 +657,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 7; + RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 6; /** * Stores the provided instance into the provided array. @@ -694,7 +690,6 @@ define([ array[startingIndex++] = value._rotation; array[startingIndex++] = value._stRotation; array[startingIndex++] = value._extrudedHeight; - array[startingIndex++] = value._extrude ? 1.0 : 0.0; array[startingIndex] = value._shadowVolume ? 1.0 : 0.0; return array; @@ -743,7 +738,6 @@ define([ var rotation = array[startingIndex++]; var stRotation = array[startingIndex++]; var extrudedHeight = array[startingIndex++]; - var extrude = array[startingIndex++] === 1.0; var shadowVolume = array[startingIndex] === 1.0; if (!defined(result)) { @@ -751,7 +745,7 @@ define([ scratchOptions.height = surfaceHeight; scratchOptions.rotation = rotation; scratchOptions.stRotation = stRotation; - scratchOptions.extrudedHeight = extrude ? extrudedHeight : undefined; + scratchOptions.extrudedHeight = extrudedHeight; scratchOptions.shadowVolume = shadowVolume; return new RectangleGeometry(scratchOptions); } @@ -763,8 +757,7 @@ define([ result._surfaceHeight = surfaceHeight; result._rotation = rotation; result._stRotation = stRotation; - result._extrudedHeight = extrude ? extrudedHeight : undefined; - result._extrude = extrude; + result._extrudedHeight = extrudedHeight; result._shadowVolume = shadowVolume; return result; @@ -789,9 +782,6 @@ define([ var rectangle = Rectangle.clone(rectangleGeometry._rectangle, rectangleScratch); var ellipsoid = rectangleGeometry._ellipsoid; - var surfaceHeight = rectangleGeometry._surfaceHeight; - var extrude = rectangleGeometry._extrude; - var extrudedHeight = rectangleGeometry._extrudedHeight; var rotation = rectangleGeometry._rotation; var stRotation = rectangleGeometry._stRotation; var vertexFormat = rectangleGeometry._vertexFormat; @@ -808,6 +798,10 @@ define([ Matrix3.clone(Matrix3.IDENTITY, tangentRotationMatrix); } + var surfaceHeight = rectangleGeometry._surfaceHeight; + var extrudedHeight = rectangleGeometry._extrudedHeight; + var extrude = !CesiumMath.equalsEpsilon(surfaceHeight, extrudedHeight, CesiumMath.EPSILON2); + options.lonScalar = 1.0 / rectangleGeometry._rectangle.width; options.latScalar = 1.0 / rectangleGeometry._rectangle.height; options.vertexFormat = vertexFormat; diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index dad4bac5291b..99d6e0375dee 100644 --- a/Source/Core/RectangleOutlineGeometry.js +++ b/Source/Core/RectangleOutlineGeometry.js @@ -112,12 +112,10 @@ define([ var surfaceHeight = options.surfaceHeight; var extrudedHeight = options.extrudedHeight; var ellipsoid = options.ellipsoid; - var minHeight = Math.min(extrudedHeight, surfaceHeight); - var maxHeight = Math.max(extrudedHeight, surfaceHeight); + var minHeight = extrudedHeight; + var maxHeight = surfaceHeight; var geo = constructRectangle(options); - if (CesiumMath.equalsEpsilon(minHeight, maxHeight, CesiumMath.EPSILON10)) { - return geo; - } + var height = options.height; var width = options.width; @@ -196,7 +194,6 @@ define([ var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); var surfaceHeight = defaultValue(options.height, 0.0); var rotation = defaultValue(options.rotation, 0.0); - var extrudedHeight = options.extrudedHeight; //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { @@ -208,12 +205,15 @@ define([ } //>>includeEnd('debug'); + var height = defaultValue(options.height, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, height); + this._rectangle = rectangle; this._granularity = granularity; this._ellipsoid = ellipsoid; - this._surfaceHeight = surfaceHeight; + this._surfaceHeight = Math.max(height, surfaceHeight); this._rotation = rotation; - this._extrudedHeight = extrudedHeight; + this._extrudedHeight = Math.min(height, extrudedHeight); this._workerName = 'createRectangleOutlineGeometry'; } @@ -221,7 +221,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - RectangleOutlineGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + 5; + RectangleOutlineGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + 4; /** * Stores the provided instance into the provided array. @@ -254,8 +254,7 @@ define([ array[startingIndex++] = value._granularity; array[startingIndex++] = value._surfaceHeight; array[startingIndex++] = value._rotation; - array[startingIndex++] = defined(value._extrudedHeight) ? 1.0 : 0.0; - array[startingIndex] = defaultValue(value._extrudedHeight, 0.0); + array[startingIndex] = value._extrudedHeight; return array; }; @@ -297,14 +296,13 @@ define([ var granularity = array[startingIndex++]; var height = array[startingIndex++]; var rotation = array[startingIndex++]; - var hasExtrudedHeight = array[startingIndex++]; var extrudedHeight = array[startingIndex]; if (!defined(result)) { scratchOptions.granularity = granularity; scratchOptions.height = height; scratchOptions.rotation = rotation; - scratchOptions.extrudedHeight = hasExtrudedHeight ? extrudedHeight : undefined; + scratchOptions.extrudedHeight = extrudedHeight; return new RectangleOutlineGeometry(scratchOptions); } @@ -312,7 +310,7 @@ define([ result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); result._surfaceHeight = height; result._rotation = rotation; - result._extrudedHeight = hasExtrudedHeight ? extrudedHeight : undefined; + result._extrudedHeight = extrudedHeight; return result; }; @@ -329,9 +327,6 @@ define([ RectangleOutlineGeometry.createGeometry = function(rectangleGeometry) { var rectangle = Rectangle.clone(rectangleGeometry._rectangle, rectangleScratch); var ellipsoid = rectangleGeometry._ellipsoid; - var surfaceHeight = rectangleGeometry._surfaceHeight; - var extrudedHeight = rectangleGeometry._extrudedHeight; - var options = RectangleGeometryLibrary.computeOptions(rectangleGeometry, rectangle, nwScratch); options.size = 2*options.width + 2*options.height - 4; @@ -343,7 +338,12 @@ define([ (CesiumMath.equalsEpsilon(rectangle.east, rectangle.west, CesiumMath.EPSILON10)))) { return undefined; } - if (defined(extrudedHeight)) { + + var surfaceHeight = rectangleGeometry._surfaceHeight; + var extrudedHeight = rectangleGeometry._extrudedHeight; + var extrude = !CesiumMath.equalsEpsilon(surfaceHeight, extrudedHeight, CesiumMath.EPSILON2); + + if (extrude) { geometry = constructExtrudedRectangle(options); var topBS = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, surfaceHeight, topBoundingSphere); var bottomBS = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, extrudedHeight, bottomBoundingSphere); diff --git a/Specs/Core/CircleGeometrySpec.js b/Specs/Core/CircleGeometrySpec.js index feacdf1e1c8d..a9a9c04ee138 100644 --- a/Specs/Core/CircleGeometrySpec.js +++ b/Specs/Core/CircleGeometrySpec.js @@ -174,6 +174,6 @@ defineSuite([ radius : 1.0, stRotation : CesiumMath.PI_OVER_TWO }); - var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0, 0.0]; + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0]; createPackableSpecs(CircleGeometry, packableInstance, packedInstance); }); diff --git a/Specs/Core/CircleOutlineGeometrySpec.js b/Specs/Core/CircleOutlineGeometrySpec.js index 9d3468a8b576..c99c39102320 100644 --- a/Specs/Core/CircleOutlineGeometrySpec.js +++ b/Specs/Core/CircleOutlineGeometrySpec.js @@ -104,7 +104,7 @@ defineSuite([ height : 5, extrudedHeight : 7 }); - var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 2, 2, 0, 5, 1, 1, 7, 1, 4]; + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 2, 2, 0, 7, 1, 5, 4]; createPackableSpecs(CircleOutlineGeometry, packableInstance, packedInstance, 'extruded'); //Because extrudedHeight is optional and has to be taken into account when packing, we have a second test without it. @@ -116,6 +116,6 @@ defineSuite([ numberOfVerticalLines : 4, height : 5 }); - packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 2, 2, 0, 5, 1, 0, 0, 0, 4]; + packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 2, 2, 0, 5, 1, 5, 4]; createPackableSpecs(CircleOutlineGeometry, packableInstance, packedInstance, 'at height'); }); diff --git a/Specs/Core/EllipseGeometrySpec.js b/Specs/Core/EllipseGeometrySpec.js index df8b2e54caa8..57ef668ed30d 100644 --- a/Specs/Core/EllipseGeometrySpec.js +++ b/Specs/Core/EllipseGeometrySpec.js @@ -275,7 +275,7 @@ defineSuite([ semiMinorAxis : 1.0, stRotation : CesiumMath.PI_OVER_TWO }); - var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0, 0.0]; + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0]; createPackableSpecs(EllipseGeometry, packableInstance, packedInstance); }); diff --git a/Specs/Core/EllipseOutlineGeometrySpec.js b/Specs/Core/EllipseOutlineGeometrySpec.js index 103caadbcbe1..69d38898e1e2 100644 --- a/Specs/Core/EllipseOutlineGeometrySpec.js +++ b/Specs/Core/EllipseOutlineGeometrySpec.js @@ -147,7 +147,7 @@ defineSuite([ rotation : 6, extrudedHeight : 7 }); - var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 3, 2, 6, 5, 1, 1, 7, 1, 4]; + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 3, 2, 6, 7, 1, 5, 4]; createPackableSpecs(EllipseOutlineGeometry, packableInstance, packedInstance, 'extruded'); //Because extrudedHeight is optional and has to be taken into account when packing, we have a second test without it. @@ -161,6 +161,6 @@ defineSuite([ height : 5, rotation : 6 }); - packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 3, 2, 6, 5, 1, 0, 0, 0, 4]; + packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 3, 2, 6, 5, 1, 5, 4]; createPackableSpecs(EllipseOutlineGeometry, packableInstance, packedInstance, 'at height'); });