diff --git a/CHANGES.md b/CHANGES.md index d805bdb8690a..20ddd655d81a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Change Log * The `sourceUri` parameter to `GeoJsonDatasource.load` was deprecated in Cesium 1.4 and has been removed. Use options.sourceUri instead. * Deprecated * +* Improved performance of asynchronous geometry creation (as much as 20% faster in some use cases). [#2342](https://github.com/AnalyticalGraphicsInc/cesium/issues/2342) * Added `PolylineVolumeGraphics` and `Entity.polylineVolume` ### 1.5 - 2015-01-05 diff --git a/Source/Core/BoundingSphere.js b/Source/Core/BoundingSphere.js index ed68fda46900..e235a5a3e120 100644 --- a/Source/Core/BoundingSphere.js +++ b/Source/Core/BoundingSphere.js @@ -598,7 +598,7 @@ define([ * * @param {Number[]} array The packed array. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. - * @param {Cartesian3} [result] The object into which to store the result. + * @param {BoundingSphere} [result] The object into which to store the result. */ BoundingSphere.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); diff --git a/Source/Core/BoxGeometry.js b/Source/Core/BoxGeometry.js index 755c6542d843..839a520262d1 100644 --- a/Source/Core/BoxGeometry.js +++ b/Source/Core/BoxGeometry.js @@ -40,6 +40,7 @@ define([ * * @see BoxGeometry.fromDimensions * @see BoxGeometry.createGeometry + * @see Packable * * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Box.html|Cesium Sandcastle Box Demo} * @@ -115,6 +116,77 @@ define([ return new BoxGeometry(newOptions); }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + BoxGeometry.packedLength = 2 * Cartesian3.packedLength + VertexFormat.packedLength; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + BoxGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Cartesian3.pack(value._minimumCorner, array, startingIndex); + Cartesian3.pack(value._maximumCorner, array, startingIndex + Cartesian3.packedLength); + VertexFormat.pack(value._vertexFormat, array, startingIndex + 2 * Cartesian3.packedLength); + }; + + var scratchMin = new Cartesian3(); + var scratchMax = new Cartesian3(); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + minimumCorner : scratchMin, + maximumCorner : scratchMax, + vertexFormat : scratchVertexFormat + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {BoxGeometry} [result] The object into which to store the result. + */ + BoxGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var min = Cartesian3.unpack(array, startingIndex, scratchMin); + var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength, scratchMax); + var vertexFormat = VertexFormat.unpack(array, startingIndex + 2 * Cartesian3.packedLength, scratchVertexFormat); + + if (!defined(result)) { + return new BoxGeometry(scratchOptions); + } + + result._minimumCorner = Cartesian3.clone(min, result._minimumCorner); + result._maximumCorner = Cartesian3.clone(max, result._maximumCorner); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + + return result; + }; + /** * Computes the geometric representation of a box, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/BoxOutlineGeometry.js b/Source/Core/BoxOutlineGeometry.js index 88637069d47c..8461d0a24d39 100644 --- a/Source/Core/BoxOutlineGeometry.js +++ b/Source/Core/BoxOutlineGeometry.js @@ -36,6 +36,7 @@ define([ * * @see BoxOutlineGeometry.fromDimensions * @see BoxOutlineGeometry.createGeometry + * @see Packable * * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Box%20Outline.html|Cesium Sandcastle Box Outline Demo} * @@ -105,6 +106,72 @@ define([ return new BoxOutlineGeometry(newOptions); }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + BoxOutlineGeometry.packedLength = 2 * Cartesian3.packedLength; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + BoxOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Cartesian3.pack(value._min, array, startingIndex); + Cartesian3.pack(value._max, array, startingIndex + Cartesian3.packedLength); + }; + + var scratchMin = new Cartesian3(); + var scratchMax = new Cartesian3(); + var scratchOptions = { + minimumCorner : scratchMin, + maximumCorner : scratchMax + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {BoxOutlineGeometry} [result] The object into which to store the result. + */ + BoxOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var min = Cartesian3.unpack(array, startingIndex, scratchMin); + var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength, scratchMax); + + if (!defined(result)) { + return new BoxOutlineGeometry(scratchOptions); + } + + result._min = Cartesian3.clone(min, result._min); + result._max = Cartesian3.clone(max, result._max); + + return result; + }; + /** * Computes the geometric representation of an outline of a box, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/CircleGeometry.js b/Source/Core/CircleGeometry.js index 7ad99bf90e6b..1eb967557a95 100644 --- a/Source/Core/CircleGeometry.js +++ b/Source/Core/CircleGeometry.js @@ -1,14 +1,20 @@ /*global define*/ define([ + './Cartesian3', './defaultValue', './defined', './DeveloperError', - './EllipseGeometry' + './EllipseGeometry', + './Ellipsoid', + './VertexFormat' ], function( + Cartesian3, defaultValue, defined, DeveloperError, - EllipseGeometry) { + EllipseGeometry, + Ellipsoid, + VertexFormat) { "use strict"; /** @@ -31,6 +37,7 @@ define([ * @exception {DeveloperError} granularity must be greater than zero. * * @see CircleGeometry.createGeometry + * @see Packable * * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Circle.html|Cesium Sandcastle Circle Demo} * @@ -70,6 +77,75 @@ define([ this._workerName = 'createCircleGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + CircleGeometry.packedLength = EllipseGeometry.packedLength; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + CircleGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + //>>includeEnd('debug'); + EllipseGeometry.pack(value._ellipseGeometry, array, startingIndex); + }; + + var scratchEllipseGeometry = new EllipseGeometry({ + center : new Cartesian3(), + semiMajorAxis : 1.0, + semiMinorAxis : 1.0 + }); + var scratchOptions = { + center : new Cartesian3(), + radius : undefined, + ellipsoid : Ellipsoid.clone(Ellipsoid.UNIT_SPHERE), + height : undefined, + extrudedHeight : undefined, + granularity : undefined, + vertexFormat : new VertexFormat(), + stRotation : undefined, + semiMajorAxis : undefined, + semiMinorAxis : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {CircleGeometry} [result] The object into which to store the result. + */ + CircleGeometry.unpack = function(array, startingIndex, result) { + var ellipseGeometry = EllipseGeometry.unpack(array, startingIndex, scratchEllipseGeometry); + scratchOptions.center = Cartesian3.clone(ellipseGeometry._center, scratchOptions.center); + scratchOptions.ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid); + scratchOptions.height = ellipseGeometry._height; + scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight; + scratchOptions.granularity = ellipseGeometry._granularity; + scratchOptions.vertexFormat = VertexFormat.clone(ellipseGeometry._vertexFormat, scratchOptions.vertexFormat); + scratchOptions.stRotation = ellipseGeometry._stRotation; + + if (!defined(result)) { + scratchOptions.radius = ellipseGeometry._semiMajorAxis; + return new CircleGeometry(scratchOptions); + } + + scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis; + scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis; + result._ellipseGeometry = new EllipseGeometry(scratchOptions); + return result; + }; + /** * Computes the geometric representation of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/CircleOutlineGeometry.js b/Source/Core/CircleOutlineGeometry.js index 4ea1a043db51..b43dca2f57b9 100644 --- a/Source/Core/CircleOutlineGeometry.js +++ b/Source/Core/CircleOutlineGeometry.js @@ -1,14 +1,18 @@ /*global define*/ define([ + './Cartesian3', './defaultValue', './defined', './DeveloperError', - './EllipseOutlineGeometry' + './EllipseOutlineGeometry', + './Ellipsoid' ], function( + Cartesian3, defaultValue, defined, DeveloperError, - EllipseOutlineGeometry) { + EllipseOutlineGeometry, + Ellipsoid) { "use strict"; /** @@ -30,6 +34,7 @@ define([ * @exception {DeveloperError} granularity must be greater than zero. * * @see CircleOutlineGeometry.createGeometry + * @see Packable * * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Circle%20Outline.html|Cesium Sandcastle Circle Outline Demo} * @@ -68,6 +73,73 @@ define([ this._workerName = 'createCircleOutlineGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + CircleOutlineGeometry.packedLength = EllipseOutlineGeometry.packedLength; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + CircleOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + //>>includeEnd('debug'); + EllipseOutlineGeometry.pack(value._ellipseGeometry, array, startingIndex); + }; + + var scratchEllipseGeometry = new EllipseOutlineGeometry({ + center : new Cartesian3(), + semiMajorAxis : 1.0, + semiMinorAxis : 1.0 + }); + var scratchOptions = { + center : new Cartesian3(), + radius : undefined, + ellipsoid : Ellipsoid.clone(Ellipsoid.UNIT_SPHERE), + height : undefined, + extrudedHeight : undefined, + granularity : undefined, + numberOfVerticalLines : undefined, + semiMajorAxis : undefined, + semiMinorAxis : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {CircleOutlineGeometry} [result] The object into which to store the result. + */ + CircleOutlineGeometry.unpack = function(array, startingIndex, result) { + var ellipseGeometry = EllipseOutlineGeometry.unpack(array, startingIndex, scratchEllipseGeometry); + scratchOptions.center = Cartesian3.clone(ellipseGeometry._center, scratchOptions.center); + scratchOptions.ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid); + scratchOptions.height = ellipseGeometry._height; + scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight; + scratchOptions.granularity = ellipseGeometry._granularity; + scratchOptions.numberOfVerticalLines = ellipseGeometry._numberOfVerticalLines; + + if (!defined(result)) { + scratchOptions.radius = ellipseGeometry._semiMajorAxis; + return new CircleOutlineGeometry(scratchOptions); + } + + scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis; + scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis; + result._ellipseGeometry = new EllipseOutlineGeometry(scratchOptions); + return result; + }; + /** * Computes the geometric representation of an outline of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index e53e157261a1..184e2bdc167b 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -637,6 +637,7 @@ define([ * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners. * * @see CorridorGeometry.createGeometry + * @see Packable * * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo} * @@ -662,14 +663,131 @@ define([ //>>includeEnd('debug'); 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._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); this._height = defaultValue(options.height, 0); this._extrudedHeight = defaultValue(options.extrudedHeight, this._height); this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); - this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._workerName = 'createCorridorGeometry'; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 5; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + CorridorGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (var i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._width; + array[startingIndex++] = value._height; + array[startingIndex++] = value._extrudedHeight; + array[startingIndex++] = value._cornerType; + array[startingIndex] = value._granularity; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + positions : undefined, + ellipsoid : scratchEllipsoid, + vertexFormat : scratchVertexFormat, + width : undefined, + height : undefined, + extrudedHeight : undefined, + cornerType : undefined, + granularity : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {CorridorGeometry} [result] The object into which to store the result. + */ + CorridorGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (var i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var width = array[startingIndex++]; + var height = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var cornerType = array[startingIndex++]; + var granularity = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.positions = positions; + scratchOptions.width = width; + scratchOptions.height = height; + scratchOptions.extrudedHeight = extrudedHeight; + scratchOptions.cornerType = cornerType; + scratchOptions.granularity = granularity; + return new CorridorGeometry(scratchOptions); + } + + result._positions = positions; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._width = width; + result._height = height; + result._extrudedHeight = extrudedHeight; + result._cornerType = cornerType; + result._granularity = granularity; + + return result; }; /** diff --git a/Source/Core/CorridorOutlineGeometry.js b/Source/Core/CorridorOutlineGeometry.js index ef013ca3a3f4..851175437a9c 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -340,13 +340,121 @@ define([ //>>includeEnd('debug'); this._positions = positions; + this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); this._width = width; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); this._height = defaultValue(options.height, 0); this._extrudedHeight = defaultValue(options.extrudedHeight, this._height); this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._workerName = 'createCorridorOutlineGeometry'; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + 5; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + CorridorOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (var i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + array[startingIndex++] = value._width; + array[startingIndex++] = value._height; + array[startingIndex++] = value._extrudedHeight; + array[startingIndex++] = value._cornerType; + array[startingIndex] = value._granularity; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchOptions = { + positions : undefined, + ellipsoid : scratchEllipsoid, + width : undefined, + height : undefined, + extrudedHeight : undefined, + cornerType : undefined, + granularity : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {CorridorOutlineGeometry} [result] The object into which to store the result. + */ + CorridorOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (var i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var width = array[startingIndex++]; + var height = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var cornerType = array[startingIndex++]; + var granularity = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.positions = positions; + scratchOptions.width = width; + scratchOptions.height = height; + scratchOptions.extrudedHeight = extrudedHeight; + scratchOptions.cornerType = cornerType; + scratchOptions.granularity = granularity; + return new CorridorOutlineGeometry(scratchOptions); + } + + result._positions = positions; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._width = width; + result._height = height; + result._extrudedHeight = extrudedHeight; + result._cornerType = cornerType; + result._granularity = granularity; + + return result; }; /** diff --git a/Source/Core/CylinderGeometry.js b/Source/Core/CylinderGeometry.js index 41d9e0488095..a6d76998523f 100644 --- a/Source/Core/CylinderGeometry.js +++ b/Source/Core/CylinderGeometry.js @@ -102,11 +102,96 @@ define([ this._length = length; this._topRadius = topRadius; this._bottomRadius = bottomRadius; - this._vertexFormat = vertexFormat; + this._vertexFormat = VertexFormat.clone(vertexFormat); this._slices = slices; this._workerName = 'createCylinderGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + CylinderGeometry.packedLength = VertexFormat.packedLength + 4; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + CylinderGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._length; + array[startingIndex++] = value._topRadius; + array[startingIndex++] = value._bottomRadius; + array[startingIndex] = value._slices; + }; + + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + vertexFormat : scratchVertexFormat, + length : undefined, + topRadius : undefined, + bottomRadius : undefined, + slices : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {CylinderGeometry} [result] The object into which to store the result. + */ + CylinderGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var length = array[startingIndex++]; + var topRadius = array[startingIndex++]; + var bottomRadius = array[startingIndex++]; + var slices = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.length = length; + scratchOptions.topRadius = topRadius; + scratchOptions.bottomRadius = bottomRadius; + scratchOptions.slices = slices; + return new CylinderGeometry(scratchOptions); + } + + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._length = length; + result._topRadius = topRadius; + result._bottomRadius = bottomRadius; + result._slices = slices; + + return result; + }; + /** * Computes the geometric representation of a cylinder, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/CylinderOutlineGeometry.js b/Source/Core/CylinderOutlineGeometry.js index 393ab81d0a7b..89953caac132 100644 --- a/Source/Core/CylinderOutlineGeometry.js +++ b/Source/Core/CylinderOutlineGeometry.js @@ -98,6 +98,87 @@ define([ this._workerName = 'createCylinderOutlineGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + CylinderOutlineGeometry.packedLength = 5; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + CylinderOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value._length; + array[startingIndex++] = value._topRadius; + array[startingIndex++] = value._bottomRadius; + array[startingIndex++] = value._slices; + array[startingIndex] = value._numberOfVerticalLines; + }; + + var scratchOptions = { + length : undefined, + topRadius : undefined, + bottomRadius : undefined, + slices : undefined, + numberOfVerticalLines : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {CylinderOutlineGeometry} [result] The object into which to store the result. + */ + CylinderOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var length = array[startingIndex++]; + var topRadius = array[startingIndex++]; + var bottomRadius = array[startingIndex++]; + var slices = array[startingIndex++]; + var numberOfVerticalLines = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.length = length; + scratchOptions.topRadius = topRadius; + scratchOptions.bottomRadius = bottomRadius; + scratchOptions.slices = slices; + scratchOptions.numberOfVerticalLines = numberOfVerticalLines; + return new CylinderOutlineGeometry(scratchOptions); + } + + result._length = length; + result._topRadius = topRadius; + result._bottomRadius = bottomRadius; + result._slices = slices; + result._numberOfVerticalLines = numberOfVerticalLines; + + return result; + }; + /** * Computes the geometric representation of an outline of a cylinder, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index 3808fd394092..e95ac358184b 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -590,12 +590,14 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); var center = options.center; + var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); 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); if (!defined(center)) { @@ -621,17 +623,138 @@ define([ this._center = Cartesian3.clone(center); this._semiMajorAxis = semiMajorAxis; this._semiMinorAxis = semiMinorAxis; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._rotation = defaultValue(options.rotation, 0.0); this._stRotation = defaultValue(options.stRotation, 0.0); this._height = height; this._granularity = granularity; - this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - this._extrudedHeight = extrudedHeight; + this._vertexFormat = VertexFormat.clone(vertexFormat); + this._extrudedHeight = defaultValue(extrudedHeight, height); this._extrude = extrude; this._workerName = 'createEllipseGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + EllipseGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 8; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + EllipseGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Cartesian3.pack(value._center, array, startingIndex); + startingIndex += Cartesian3.packedLength; + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._semiMajorAxis; + array[startingIndex++] = value._semiMinorAxis; + array[startingIndex++] = value._rotation; + array[startingIndex++] = value._stRotation; + array[startingIndex++] = value._height; + array[startingIndex++] = value._granularity; + array[startingIndex++] = value._extrudedHeight; + array[startingIndex] = value._extrude ? 1.0 : 0.0; + }; + + var scratchCenter = new Cartesian3(); + var scratchEllipsoid = new Ellipsoid(); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + center : scratchCenter, + ellipsoid : scratchEllipsoid, + vertexFormat : scratchVertexFormat, + semiMajorAxis : undefined, + semiMinorAxis : undefined, + rotation : undefined, + stRotation : undefined, + height : undefined, + granularity : undefined, + extrudedHeight : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {EllipseGeometry} [result] The object into which to store the result. + */ + EllipseGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var center = Cartesian3.unpack(array, startingIndex, scratchCenter); + startingIndex += Cartesian3.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var semiMajorAxis = array[startingIndex++]; + var semiMinorAxis = array[startingIndex++]; + var rotation = array[startingIndex++]; + var stRotation = array[startingIndex++]; + var height = array[startingIndex++]; + var granularity = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var extrude = array[startingIndex] === 1.0; + + if (!defined(result)) { + scratchOptions.height = height; + scratchOptions.extrudedHeight = extrudedHeight; + scratchOptions.granularity = granularity; + scratchOptions.stRotation = stRotation; + scratchOptions.rotation = rotation; + scratchOptions.semiMajorAxis = semiMajorAxis; + scratchOptions.semiMinorAxis = semiMinorAxis; + return new EllipseGeometry(scratchOptions); + } + + result._center = Cartesian3.clone(center, result._center); + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._semiMajorAxis = semiMajorAxis; + result._semiMinorAxis = semiMinorAxis; + result._rotation = rotation; + result._stRotation = stRotation; + result._height = height; + result._granularity = granularity; + result._extrudedHeight = extrudedHeight; + result._extrude = extrude; + + return result; + }; + /** * Computes the geometric representation of a ellipse on an ellipsoid, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/EllipseOutlineGeometry.js b/Source/Core/EllipseOutlineGeometry.js index fc6ea4b4d990..f74f8cdfe6f4 100644 --- a/Source/Core/EllipseOutlineGeometry.js +++ b/Source/Core/EllipseOutlineGeometry.js @@ -165,6 +165,7 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); var center = options.center; + var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); var semiMajorAxis = options.semiMajorAxis; var semiMinorAxis = options.semiMinorAxis; var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); @@ -196,16 +197,128 @@ define([ this._center = Cartesian3.clone(center); this._semiMajorAxis = semiMajorAxis; this._semiMinorAxis = semiMinorAxis; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._rotation = defaultValue(options.rotation, 0.0); this._height = height; this._granularity = granularity; - this._extrudedHeight = extrudedHeight; + this._extrudedHeight = defaultValue(extrudedHeight, 0.0); this._extrude = extrude; this._numberOfVerticalLines = Math.max(defaultValue(options.numberOfVerticalLines, 16), 0); this._workerName = 'createEllipseOutlineGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + EllipseOutlineGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + 8; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + EllipseOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Cartesian3.pack(value._center, array, startingIndex); + startingIndex += Cartesian3.packedLength; + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + array[startingIndex++] = value._semiMajorAxis; + array[startingIndex++] = value._semiMinorAxis; + array[startingIndex++] = value._rotation; + array[startingIndex++] = value._height; + array[startingIndex++] = value._granularity; + array[startingIndex++] = value._extrudedHeight; + array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex] = value._numberOfVerticalLines; + }; + + var scratchCenter = new Cartesian3(); + var scratchEllipsoid = new Ellipsoid(); + var scratchOptions = { + center : scratchCenter, + ellipsoid : scratchEllipsoid, + semiMajorAxis : undefined, + semiMinorAxis : undefined, + rotation : undefined, + height : undefined, + granularity : undefined, + extrudedHeight : undefined, + numberOfVerticalLines : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {EllipseOutlineGeometry} [result] The object into which to store the result. + */ + EllipseOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var center = Cartesian3.unpack(array, startingIndex, scratchCenter); + startingIndex += Cartesian3.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var semiMajorAxis = array[startingIndex++]; + var semiMinorAxis = array[startingIndex++]; + var rotation = array[startingIndex++]; + var height = array[startingIndex++]; + var granularity = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var extrude = array[startingIndex++] === 1.0; + var numberOfVerticalLines = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.height = height; + scratchOptions.extrudedHeight = extrudedHeight; + scratchOptions.granularity = granularity; + scratchOptions.rotation = rotation; + scratchOptions.semiMajorAxis = semiMajorAxis; + scratchOptions.semiMinorAxis = semiMinorAxis; + scratchOptions.numberOfVerticalLines = numberOfVerticalLines; + return new EllipseOutlineGeometry(scratchOptions); + } + + result._center = Cartesian3.clone(center, result._center); + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._semiMajorAxis = semiMajorAxis; + result._semiMinorAxis = semiMinorAxis; + result._rotation = rotation; + result._height = height; + result._granularity = granularity; + result._extrudedHeight = extrudedHeight; + result._extrude = extrude; + result._numberOfVerticalLines = numberOfVerticalLines; + + return result; + }; + /** * Computes the geometric representation of an outline of an ellipse on an ellipsoid, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/Ellipsoid.js b/Source/Core/Ellipsoid.js index af2621665333..881938d614f9 100644 --- a/Source/Core/Ellipsoid.js +++ b/Source/Core/Ellipsoid.js @@ -250,6 +250,55 @@ define([ return Ellipsoid.clone(this, result); }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + Ellipsoid.packedLength = Cartesian3.packedLength; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + Ellipsoid.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Cartesian3.pack(value._radii, array, startingIndex); + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Ellipsoid} [result] The object into which to store the result. + */ + Ellipsoid.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var radii = Cartesian3.unpack(array, startingIndex); + return Ellipsoid.fromCartesian3(radii, result); + }; + /** * Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position. * @function diff --git a/Source/Core/EllipsoidGeometry.js b/Source/Core/EllipsoidGeometry.js index 0a13c31d3556..571dcbef3ddc 100644 --- a/Source/Core/EllipsoidGeometry.js +++ b/Source/Core/EllipsoidGeometry.js @@ -5,6 +5,7 @@ define([ './Cartesian3', './ComponentDatatype', './defaultValue', + './defined', './DeveloperError', './Ellipsoid', './Geometry', @@ -20,6 +21,7 @@ define([ Cartesian3, ComponentDatatype, defaultValue, + defined, DeveloperError, Ellipsoid, Geometry, @@ -87,10 +89,94 @@ define([ this._radii = Cartesian3.clone(radii); this._stackPartitions = stackPartitions; this._slicePartitions = slicePartitions; - this._vertexFormat = vertexFormat; + this._vertexFormat = VertexFormat.clone(vertexFormat); this._workerName = 'createEllipsoidGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + EllipsoidGeometry.packedLength = Cartesian3.packedLength + VertexFormat.packedLength + 2; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + EllipsoidGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Cartesian3.pack(value._radii, array, startingIndex); + startingIndex += Cartesian3.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._stackPartitions; + array[startingIndex] = value._slicePartitions; + }; + + var scratchRadii = new Cartesian3(); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + radii : scratchRadii, + vertexFormat : scratchVertexFormat, + stackPartitions : undefined, + slicePartitions : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {EllipsoidGeometry} [result] The object into which to store the result. + */ + EllipsoidGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var radii = Cartesian3.unpack(array, startingIndex, scratchRadii); + startingIndex += Cartesian3.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var stackPartitions = array[startingIndex++]; + var slicePartitions = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.stackPartitions = stackPartitions; + scratchOptions.slicePartitions = slicePartitions; + return new EllipsoidGeometry(scratchOptions); + } + + result._radii = Cartesian3.clone(radii, result._radii); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._stackPartitions = stackPartitions; + result._slicePartitions = slicePartitions; + + return result; + }; + /** * Computes the geometric representation of an ellipsoid, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/EllipsoidOutlineGeometry.js b/Source/Core/EllipsoidOutlineGeometry.js index bd0180b3f75a..70a523b743d0 100644 --- a/Source/Core/EllipsoidOutlineGeometry.js +++ b/Source/Core/EllipsoidOutlineGeometry.js @@ -4,6 +4,7 @@ define([ './Cartesian3', './ComponentDatatype', './defaultValue', + './defined', './DeveloperError', './Ellipsoid', './Geometry', @@ -17,6 +18,7 @@ define([ Cartesian3, ComponentDatatype, defaultValue, + defined, DeveloperError, Ellipsoid, Geometry, @@ -84,6 +86,86 @@ define([ this._workerName = 'createEllipsoidOutlineGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + EllipsoidOutlineGeometry.packedLength = Cartesian3.packedLength + 3; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + EllipsoidOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Cartesian3.pack(value._radii, array, startingIndex); + startingIndex += Cartesian3.packedLength; + + array[startingIndex++] = value._stackPartitions; + array[startingIndex++] = value._slicePartitions; + array[startingIndex] = value._subdivisions; + }; + + var scratchRadii = new Cartesian3(); + var scratchOptions = { + radii : scratchRadii, + stackPartitions : undefined, + slicePartitions : undefined, + subdivisions : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {EllipsoidOutlineGeometry} [result] The object into which to store the result. + */ + EllipsoidOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var radii = Cartesian3.unpack(array, startingIndex, scratchRadii); + startingIndex += Cartesian3.packedLength; + + var stackPartitions = array[startingIndex++]; + var slicePartitions = array[startingIndex++]; + var subdivisions = array[startingIndex++]; + + if (!defined(result)) { + scratchOptions.stackPartitions = stackPartitions; + scratchOptions.slicePartitions = slicePartitions; + scratchOptions.subdivisions = subdivisions; + return new EllipsoidOutlineGeometry(scratchOptions); + } + + result._radii = Cartesian3.clone(radii, result._radii); + result._stackPartitions = stackPartitions; + result._slicePartitions = slicePartitions; + result._subdivisions = subdivisions; + + return result; + }; + /** * Computes the geometric representation of an outline of an ellipsoid, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index 61abfde3ec09..25aea1ac76a5 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -628,16 +628,22 @@ define([ } //>>includeEnd('debug'); - this._vertexFormat = vertexFormat; - this._ellipsoid = ellipsoid; + this._vertexFormat = VertexFormat.clone(vertexFormat); + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._granularity = granularity; this._stRotation = stRotation; this._height = height; - this._extrudedHeight = extrudedHeight; + this._extrudedHeight = defaultValue(extrudedHeight, 0.0); this._extrude = extrude; this._polygonHierarchy = polygonHierarchy; this._perPositionHeight = perPositionHeight; this._workerName = 'createPolygonGeometry'; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + VertexFormat.packedLength + 6; }; /** @@ -691,6 +697,111 @@ define([ return new PolygonGeometry(newOptions); }; + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + PolygonGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(value._polygonHierarchy, array, startingIndex); + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._height; + array[startingIndex++] = value._extrudedHeight; + array[startingIndex++] = value._granularity; + array[startingIndex++] = value._stRotation; + array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex] = value._perPositionHeight ? 1.0 : 0.0; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + polygonHierarchy : undefined, + ellipsoid : scratchEllipsoid, + vertexFormat : scratchVertexFormat, + height : undefined, + extrudedHeight : undefined, + granularity : undefined, + stRotation : undefined, + perPositionHeight : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {PolygonGeometry} [result] The object into which to store the result. + */ + PolygonGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + startingIndex = polygonHierarchy.startingIndex; + delete polygonHierarchy.startingIndex; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var height = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var granularity = array[startingIndex++]; + var stRotation = array[startingIndex++]; + var extrude = array[startingIndex++] === 1.0; + var perPositionHeight = array[startingIndex] === 1.0; + + if (!defined(result)) { + scratchOptions.polygonHierarchy = polygonHierarchy; + scratchOptions.height = height; + scratchOptions.extrudedHeight = extrudedHeight; + scratchOptions.granularity = granularity; + scratchOptions.stRotation = stRotation; + scratchOptions.perPositionHeight = perPositionHeight; + return new PolygonGeometry(scratchOptions); + } + + result._polygonHierarchy = polygonHierarchy; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._height = height; + result._extrudedHeight = extrudedHeight; + result._granularity = granularity; + result._stRotation = stRotation; + result._extrude = extrude; + result._perPositionHeight = perPositionHeight; + + return result; + }; + /** * Computes the geometric representation of a polygon, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/PolygonGeometryLibrary.js b/Source/Core/PolygonGeometryLibrary.js index fea04668280d..f3014bbe82ce 100644 --- a/Source/Core/PolygonGeometryLibrary.js +++ b/Source/Core/PolygonGeometryLibrary.js @@ -16,6 +16,91 @@ define([ */ var PolygonGeometryLibrary = {}; + PolygonGeometryLibrary.computeHierarchyPackedLength = function(polygonHierarchy) { + var numComponents = 0; + var stack = [polygonHierarchy]; + while (stack.length > 0) { + var hierarchy = stack.pop(); + if (!defined(hierarchy)) { + continue; + } + + numComponents += 2; + + var positions = hierarchy.positions; + var holes = hierarchy.holes; + + if (defined(positions)) { + numComponents += positions.length * Cartesian3.packedLength; + } + + if (defined(holes)) { + var length = holes.length; + for (var i = 0; i < length; ++i) { + stack.push(holes[i]); + } + } + } + + return numComponents; + }; + + PolygonGeometryLibrary.packPolygonHierarchy = function(polygonHierarchy, array, startingIndex) { + var stack = [polygonHierarchy]; + while (stack.length > 0) { + var hierarchy = stack.pop(); + if (!defined(hierarchy)) { + continue; + } + + var positions = hierarchy.positions; + var holes = hierarchy.holes; + + array[startingIndex++] = defined(positions) ? positions.length : 0; + array[startingIndex++] = defined(holes) ? holes.length : 0; + + if (defined(positions)) { + var positionsLength = positions.length; + for (var i = 0; i < positionsLength; ++i, startingIndex += 3) { + Cartesian3.pack(positions[i], array, startingIndex); + } + } + + if (defined(holes)) { + var holesLength = holes.length; + for (var j = 0; j < holesLength; ++j) { + stack.push(holes[j]); + } + } + } + + return startingIndex; + }; + + PolygonGeometryLibrary.unpackPolygonHierarchy = function(array, startingIndex) { + var positionsLength = array[startingIndex++]; + var holesLength = array[startingIndex++]; + + var positions = new Array(positionsLength); + var holes = holesLength > 0 ? new Array(holesLength) : undefined; + + for (var i = 0; i < positionsLength; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + for (var j = 0; j < holesLength; ++j) { + holes[j] = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + startingIndex = holes[j].startingIndex; + delete holes[j].startingIndex; + } + + return { + positions : positions, + holes : holes, + startingIndex : startingIndex + }; + }; + var distanceScratch = new Cartesian3(); function getPointAtDistance(p0, p1, distance, length) { Cartesian3.subtract(p1, p0, distanceScratch); diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index a229073d71a6..d7ae8bf92bc4 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -321,14 +321,111 @@ define([ } //>>includeEnd('debug'); - this._ellipsoid = ellipsoid; + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._granularity = granularity; this._height = height; - this._extrudedHeight = extrudedHeight; + this._extrudedHeight = defaultValue(extrudedHeight, 0.0); this._extrude = extrude; this._polygonHierarchy = polygonHierarchy; this._perPositionHeight = perPositionHeight; this._workerName = 'createPolygonOutlineGeometry'; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + 5; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + PolygonOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(value._polygonHierarchy, array, startingIndex); + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + array[startingIndex++] = value._height; + array[startingIndex++] = value._extrudedHeight; + array[startingIndex++] = value._granularity; + array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex] = value._perPositionHeight ? 1.0 : 0.0; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchOptions = { + polygonHierarchy : undefined, + ellipsoid : scratchEllipsoid, + height : undefined, + extrudedHeight : undefined, + granularity : undefined, + perPositionHeight : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {PolygonOutlineGeometry} [result] The object into which to store the result. + */ + PolygonOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + startingIndex = polygonHierarchy.startingIndex; + delete polygonHierarchy.startingIndex; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var height = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var granularity = array[startingIndex++]; + var extrude = array[startingIndex++] === 1.0; + var perPositionHeight = array[startingIndex] === 1.0; + + if (!defined(result)) { + scratchOptions.polygonHierarchy = polygonHierarchy; + scratchOptions.height = height; + scratchOptions.extrudedHeight = extrudedHeight; + scratchOptions.granularity = granularity; + scratchOptions.perPositionHeight = perPositionHeight; + return new PolygonOutlineGeometry(scratchOptions); + } + + result._polygonHierarchy = polygonHierarchy; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._height = height; + result._extrudedHeight = extrudedHeight; + result._granularity = granularity; + result._extrude = extrude; + result._perPositionHeight = perPositionHeight; + + return result; }; /** diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index f9f1a900c6ff..026ee480ab76 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -133,11 +133,148 @@ define([ this._colors = colors; this._width = width; this._perVertex = perVertex; - this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT)); this._followSurface = defaultValue(options.followSurface, true); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); this._workerName = 'createPolylineGeometry'; + + var numComponents = 1 + positions.length * Cartesian3.packedLength; + numComponents += defined(colors) ? 1 + colors.length * Color.packedLength : 1; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 4; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + PolylineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + var colors = value._colors; + length = defined(colors) ? colors.length : 0.0; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { + Color.pack(colors[i], array, startingIndex); + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._width; + array[startingIndex++] = value._perVertex ? 1.0 : 0.0; + array[startingIndex++] = value._followSurface ? 1.0 : 0.0; + array[startingIndex] = value._granularity; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + positions : undefined, + colors : undefined, + ellipsoid : scratchEllipsoid, + vertexFormat : scratchVertexFormat, + width : undefined, + perVertex : undefined, + followSurface : undefined, + granularity : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {PolylineGeometry} [result] The object into which to store the result. + */ + PolylineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + length = array[startingIndex++]; + var colors = length > 0 ? new Array(length) : undefined; + + for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { + colors[i] = Color.unpack(array, startingIndex); + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var width = array[startingIndex++]; + var perVertex = array[startingIndex++] === 1.0; + var followSurface = array[startingIndex++] === 1.0; + var granularity = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.positions = positions; + scratchOptions.colors = colors; + scratchOptions.width = width; + scratchOptions.perVertex = perVertex; + scratchOptions.followSurface = followSurface; + scratchOptions.granularity = granularity; + return new PolylineGeometry(scratchOptions); + } + + result._positions = positions; + result._colors = colors; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._width = width; + result._perVertex = perVertex; + result._followSurface = followSurface; + result._granularity = granularity; + + return result; }; var scratchCartesian3 = new Cartesian3(); diff --git a/Source/Core/PolylineVolumeGeometry.js b/Source/Core/PolylineVolumeGeometry.js index b5e62f2bbed2..e17a26928f34 100644 --- a/Source/Core/PolylineVolumeGeometry.js +++ b/Source/Core/PolylineVolumeGeometry.js @@ -2,6 +2,8 @@ define([ './BoundingRectangle', './BoundingSphere', + './Cartesian2', + './Cartesian3', './ComponentDatatype', './CornerType', './defaultValue', @@ -22,6 +24,8 @@ define([ ], function( BoundingRectangle, BoundingSphere, + Cartesian2, + Cartesian3, ComponentDatatype, CornerType, defaultValue, @@ -180,10 +184,9 @@ define([ * * @param {Object} options Object with the following properties: * @param {Cartesian3[]} options.polylinePositions An array of {@link Cartesain3} positions that define the center of the polyline volume. - * @param {Number} options.shapePositions An array of {@link Cartesian2} positions that define the shape to be extruded along the polyline + * @param {Cartesian2[]} options.shapePositions An array of {@link Cartesian2} positions that define the shape to be extruded along the polyline * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer. - * @param {Number} [options.height=0] The distance between the ellipsoid surface and the positions. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed. * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners. * @@ -226,12 +229,138 @@ define([ this._positions = positions; this._shape = shape; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); - this._height = defaultValue(options.height, 0.0); + this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); - this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT)); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._workerName = 'createPolylineVolumeGeometry'; + + var numComponents = 1 + positions.length * Cartesian3.packedLength; + numComponents += 1 + shape.length * Cartesian2.packedLength; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 2; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + PolylineVolumeGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + var shape = value._shape; + length = shape.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) { + Cartesian2.pack(shape[i], array, startingIndex); + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._cornerType; + array[startingIndex] = value._granularity; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + polylinePositions : undefined, + shapePositions : undefined, + ellipsoid : scratchEllipsoid, + vertexFormat : scratchVertexFormat, + cornerType : undefined, + granularity : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {PolylineVolumeGeometry} [result] The object into which to store the result. + */ + PolylineVolumeGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + length = array[startingIndex++]; + var shape = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) { + shape[i] = Cartesian2.unpack(array, startingIndex); + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var cornerType = array[startingIndex++]; + var granularity = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.polylinePositions = positions; + scratchOptions.shapePositions = shape; + scratchOptions.cornerType = cornerType; + scratchOptions.granularity = granularity; + return new PolylineVolumeGeometry(scratchOptions); + } + + result._positions = positions; + result._shape = shape; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._cornerType = cornerType; + result._granularity = granularity; + + return result; }; var brScratch = new BoundingRectangle(); diff --git a/Source/Core/PolylineVolumeOutlineGeometry.js b/Source/Core/PolylineVolumeOutlineGeometry.js index 5a75242779cf..fa1a0226377e 100644 --- a/Source/Core/PolylineVolumeOutlineGeometry.js +++ b/Source/Core/PolylineVolumeOutlineGeometry.js @@ -2,6 +2,8 @@ define([ './BoundingRectangle', './BoundingSphere', + './Cartesian2', + './Cartesian3', './ComponentDatatype', './CornerType', './defaultValue', @@ -20,6 +22,8 @@ define([ ], function( BoundingRectangle, BoundingSphere, + Cartesian2, + Cartesian3, ComponentDatatype, CornerType, defaultValue, @@ -140,10 +144,129 @@ define([ this._positions = positions; this._shape = shape; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._workerName = 'createPolylineVolumeOutlineGeometry'; + + var numComponents = 1 + positions.length * Cartesian3.packedLength; + numComponents += 1 + shape.length * Cartesian2.packedLength; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = numComponents + Ellipsoid.packedLength + 2; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + PolylineVolumeOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + var shape = value._shape; + length = shape.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) { + Cartesian2.pack(shape[i], array, startingIndex); + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + array[startingIndex++] = value._cornerType; + array[startingIndex] = value._granularity; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchOptions = { + polylinePositions : undefined, + shapePositions : undefined, + ellipsoid : scratchEllipsoid, + height : undefined, + cornerType : undefined, + granularity : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {PolylineVolumeOutlineGeometry} [result] The object into which to store the result. + */ + PolylineVolumeOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + length = array[startingIndex++]; + var shape = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) { + shape[i] = Cartesian2.unpack(array, startingIndex); + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var cornerType = array[startingIndex++]; + var granularity = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.polylinePositions = positions; + scratchOptions.shapePositions = shape; + scratchOptions.cornerType = cornerType; + scratchOptions.granularity = granularity; + return new PolylineVolumeOutlineGeometry(scratchOptions); + } + + result._positions = positions; + result._shape = shape; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._cornerType = cornerType; + result._granularity = granularity; + + return result; }; var brScratch = new BoundingRectangle(); diff --git a/Source/Core/Rectangle.js b/Source/Core/Rectangle.js index c39f8f461b08..6fb751a2ad31 100644 --- a/Source/Core/Rectangle.js +++ b/Source/Core/Rectangle.js @@ -90,6 +90,65 @@ define([ } }); + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + Rectangle.packedLength = 4; + + /** + * Stores the provided instance into the provided array. + * + * @param {BoundingSphere} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + Rectangle.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value.west; + array[startingIndex++] = value.south; + array[startingIndex++] = value.east; + array[startingIndex] = value.north; + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {Rectangle} [result] The object into which to store the result. + */ + Rectangle.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + if (!defined(result)) { + result = new Rectangle(); + } + + result.west = array[startingIndex++]; + result.south = array[startingIndex++]; + result.east = array[startingIndex++]; + result.north = array[startingIndex]; + return result; + }; + /** * Computes the width of a rectangle in radians. * @param {Rectangle} rectangle The rectangle to compute the width of. diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 2b775f07dcd1..d27f0affc3cb 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -550,9 +550,13 @@ define([ var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); var surfaceHeight = defaultValue(options.height, 0.0); - var rotation = options.rotation; - var stRotation = options.stRotation; + var rotation = defaultValue(options.rotation, 0.0); + var stRotation = defaultValue(options.stRotation, 0.0); var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + var extrudedHeight = options.extrudedHeight; + var extrude = (defined(extrudedHeight) && Math.abs(surfaceHeight - extrudedHeight) > 1.0); + var closeTop = defaultValue(options.closeTop, true); + var closeBottom = defaultValue(options.closeBottom, true); //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { @@ -566,17 +570,139 @@ define([ this._rectangle = rectangle; this._granularity = granularity; - this._ellipsoid = ellipsoid; + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._surfaceHeight = surfaceHeight; this._rotation = rotation; this._stRotation = stRotation; - this._vertexFormat = vertexFormat; - this._extrudedHeight = options.extrudedHeight; - this._closeTop = options.closeTop; - this._closeBottom = options.closeBottom; + this._vertexFormat = VertexFormat.clone(vertexFormat); + this._extrudedHeight = defaultValue(extrudedHeight, 0.0); + this._extrude = extrude; + this._closeTop = closeTop; + this._closeBottom = closeBottom; this._workerName = 'createRectangleGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 8; + + /** + * Stores the provided instance into the provided array. + * + * @param {BoundingSphere} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + RectangleGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Rectangle.pack(value._rectangle, array, startingIndex); + startingIndex += Rectangle.packedLength; + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex++] = value._granularity; + array[startingIndex++] = value._surfaceHeight; + array[startingIndex++] = value._rotation; + array[startingIndex++] = value._stRotation; + array[startingIndex++] = value._extrudedHeight; + array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex++] = value._closeTop ? 1.0 : 0.0; + array[startingIndex] = value._closeBottom ? 1.0 : 0.0; + }; + + var scratchRectangle = new Rectangle(); + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + rectangle : scratchRectangle, + ellipsoid : scratchEllipsoid, + vertexFormat : scratchVertexFormat, + granularity : undefined, + height : undefined, + rotation : undefined, + stRotation : undefined, + extrudedHeight : undefined, + closeTop : undefined, + closeBottom : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {RectangleGeometry} [result] The object into which to store the result. + */ + RectangleGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle); + startingIndex += Rectangle.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var granularity = array[startingIndex++]; + var surfaceHeight = array[startingIndex++]; + var rotation = array[startingIndex++]; + var stRotation = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var extrude = array[startingIndex++] === 1.0; + var closeTop = array[startingIndex++] === 1.0; + var closeBottom = array[startingIndex] === 1.0; + + if (!defined(result)) { + scratchOptions.granularity = granularity; + scratchOptions.height = surfaceHeight; + scratchOptions.rotation = rotation; + scratchOptions.stRotation = stRotation; + scratchOptions.extrudedHeight = extrude ? extrudedHeight : undefined; + scratchOptions.closeTop = closeTop; + scratchOptions.closeBottom = closeBottom; + return new RectangleGeometry(scratchOptions); + } + + result._rectangle = Rectangle.clone(rectangle, result._rectangle); + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._granularity = granularity; + result._surfaceHeight = surfaceHeight; + result._rotation = rotation; + result._stRotation = stRotation; + result._extrudedHeight = extrude ? extrudedHeight : undefined; + result._extrude = extrude; + result._closeTop = closeTop; + result._closeBottom = closeBottom; + + return result; + }; + var textureMatrixScratch = new Matrix2(); var tangentRotationMatrixScratch = new Matrix3(); var nwScratch = new Cartographic(); @@ -594,6 +720,7 @@ 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 stRotation = rectangleGeometry._stRotation; var vertexFormat = rectangleGeometry._vertexFormat; @@ -625,7 +752,7 @@ define([ var geometry; var boundingSphere; rectangle = rectangleGeometry._rectangle; - if (defined(extrudedHeight)) { + if (extrude) { geometry = constructExtrudedRectangle(options); var topBS = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, surfaceHeight, topBoundingSphere); var bottomBS = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, extrudedHeight, bottomBoundingSphere); diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index bf2b4eb8e279..d36637df5b8b 100644 --- a/Source/Core/RectangleOutlineGeometry.js +++ b/Source/Core/RectangleOutlineGeometry.js @@ -200,7 +200,8 @@ define([ var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); var surfaceHeight = defaultValue(options.height, 0.0); - var rotation = options.rotation; + var rotation = defaultValue(options.rotation, 0.0); + var extrudedHeight = defaultValue(options.extrudedHeight, surfaceHeight); //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { @@ -217,10 +218,103 @@ define([ this._ellipsoid = ellipsoid; this._surfaceHeight = surfaceHeight; this._rotation = rotation; - this._extrudedHeight = options.extrudedHeight; + this._extrudedHeight = extrudedHeight; this._workerName = 'createRectangleOutlineGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + RectangleOutlineGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + 4; + + /** + * Stores the provided instance into the provided array. + * + * @param {BoundingSphere} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + RectangleOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + Rectangle.pack(value._rectangle, array, startingIndex); + startingIndex += Rectangle.packedLength; + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + array[startingIndex++] = value._granularity; + array[startingIndex++] = value._surfaceHeight; + array[startingIndex++] = value._rotation; + array[startingIndex] = value._extrudedHeight; + }; + + var scratchRectangle = new Rectangle(); + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchOptions = { + rectangle : scratchRectangle, + ellipsoid : scratchEllipsoid, + granularity : undefined, + height : undefined, + rotation : undefined, + extrudedHeight : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {RectangleGeometry} [result] The object into which to store the result. + */ + RectangleOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle); + startingIndex += Rectangle.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var granularity = array[startingIndex++]; + var height = array[startingIndex++]; + var rotation = array[startingIndex++]; + var extrudedHeight = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.granularity = granularity; + scratchOptions.height = height; + scratchOptions.rotation = rotation; + scratchOptions.extrudedHeight = extrudedHeight; + return new RectangleOutlineGeometry(scratchOptions); + } + + result._rectangle = Rectangle.clone(rectangle, result._rectangle); + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._surfaceHeight = height; + result._rotation = rotation; + result._extrudedHeight = extrudedHeight; + + return result; + }; + var nwScratch = new Cartographic(); /** * Computes the geometric representation of an outline of an rectangle, including its vertices, indices, and a bounding sphere. diff --git a/Source/Core/SimplePolylineGeometry.js b/Source/Core/SimplePolylineGeometry.js index d02b9f3661b2..203146b7a490 100644 --- a/Source/Core/SimplePolylineGeometry.js +++ b/Source/Core/SimplePolylineGeometry.js @@ -128,6 +128,121 @@ define([ this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); this._workerName = 'createSimplePolylineGeometry'; + + var numComponents = 1 + positions.length * Cartesian3.packedLength; + numComponents += defined(colors) ? 1 + colors.length * Color.packedLength : 1; + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = numComponents + Ellipsoid.packedLength + 3; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + SimplePolylineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + var colors = value._colors; + length = defined(colors) ? colors.length : 0.0; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { + Color.pack(colors[i], array, startingIndex); + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + array[startingIndex++] = value._perVertex ? 1.0 : 0.0; + array[startingIndex++] = value._followSurface ? 1.0 : 0.0; + array[startingIndex] = value._granularity; + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {SimplePolylineGeometry} [result] The object into which to store the result. + */ + SimplePolylineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + length = array[startingIndex++]; + var colors = length > 0 ? new Array(length) : undefined; + + for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { + colors[i] = Color.unpack(array, startingIndex); + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + var perVertex = array[startingIndex++] === 1.0; + var followSurface = array[startingIndex++] === 1.0; + var granularity = array[startingIndex]; + + if (!defined(result)) { + return new SimplePolylineGeometry({ + positions : positions, + colors : colors, + ellipsoid : ellipsoid, + perVertex : perVertex, + followSurface : followSurface, + granularity : granularity + }); + } + + result._positions = positions; + result._colors = colors; + result._ellipsoid = ellipsoid; + result._perVertex = perVertex; + result._followSurface = followSurface; + result._granularity = granularity; + + return result; }; var scratchArray1 = new Array(2); diff --git a/Source/Core/SphereGeometry.js b/Source/Core/SphereGeometry.js index 8340cf1707dd..6e8b6e8bdd58 100644 --- a/Source/Core/SphereGeometry.js +++ b/Source/Core/SphereGeometry.js @@ -2,11 +2,17 @@ define([ './Cartesian3', './defaultValue', - './EllipsoidGeometry' + './defined', + './DeveloperError', + './EllipsoidGeometry', + './VertexFormat' ], function( Cartesian3, defaultValue, - EllipsoidGeometry) { + defined, + DeveloperError, + EllipsoidGeometry, + VertexFormat) { "use strict"; /** @@ -49,6 +55,62 @@ define([ this._workerName = 'createSphereGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + SphereGeometry.packedLength = EllipsoidGeometry.packedLength; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + SphereGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + //>>includeEnd('debug'); + + EllipsoidGeometry.pack(value._ellipsoidGeometry, array, startingIndex); + }; + + var scratchEllipsoidGeometry = new EllipsoidGeometry(); + var scratchOptions = { + radius : undefined, + radii : new Cartesian3(), + vertexFormat : new VertexFormat(), + stackPartitions : undefined, + slicePartitions : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {SphereGeometry} [result] The object into which to store the result. + */ + SphereGeometry.unpack = function(array, startingIndex, result) { + var ellipsoidGeometry = EllipsoidGeometry.unpack(array, startingIndex, scratchEllipsoidGeometry); + scratchOptions.vertexFormat = VertexFormat.clone(ellipsoidGeometry._vertexFormat, scratchOptions.vertexFormat); + scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions; + scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions; + + if (!defined(result)) { + scratchOptions.radius = ellipsoidGeometry._radii.x; + return new SphereGeometry(scratchOptions); + } + + Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii); + result._ellipsoidGeometry = new EllipsoidGeometry(scratchOptions); + return result; + }; + /** * Computes the geometric representation of a sphere, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/SphereOutlineGeometry.js b/Source/Core/SphereOutlineGeometry.js index 5519c9f9fc41..739e3409a07c 100644 --- a/Source/Core/SphereOutlineGeometry.js +++ b/Source/Core/SphereOutlineGeometry.js @@ -2,10 +2,14 @@ define([ './Cartesian3', './defaultValue', + './defined', + './DeveloperError', './EllipsoidOutlineGeometry' ], function( Cartesian3, defaultValue, + defined, + DeveloperError, EllipsoidOutlineGeometry) { "use strict"; @@ -49,6 +53,62 @@ define([ this._workerName = 'createSphereOutlineGeometry'; }; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + SphereOutlineGeometry.packedLength = EllipsoidOutlineGeometry.packedLength; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + SphereOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + //>>includeEnd('debug'); + + EllipsoidOutlineGeometry.pack(value._ellipsoidGeometry, array, startingIndex); + }; + + var scratchEllipsoidGeometry = new EllipsoidOutlineGeometry(); + var scratchOptions = { + radius : undefined, + radii : new Cartesian3(), + stackPartitions : undefined, + slicePartitions : undefined, + subdivisions : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {SphereOutlineGeometry} [result] The object into which to store the result. + */ + SphereOutlineGeometry.unpack = function(array, startingIndex, result) { + var ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(array, startingIndex, scratchEllipsoidGeometry); + scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions; + scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions; + scratchOptions.subdivisions = ellipsoidGeometry._subdivisions; + + if (!defined(result)) { + scratchOptions.radius = ellipsoidGeometry._radii.x; + return new SphereOutlineGeometry(scratchOptions); + } + + Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii); + result._ellipsoidGeometry = new EllipsoidOutlineGeometry(scratchOptions); + return result; + }; + /** * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere. * diff --git a/Source/Core/VertexFormat.js b/Source/Core/VertexFormat.js index 3fdc13441cf9..07e06c9a9f3d 100644 --- a/Source/Core/VertexFormat.js +++ b/Source/Core/VertexFormat.js @@ -1,9 +1,13 @@ /*global define*/ define([ './defaultValue', + './defined', + './DeveloperError', './freezeObject' ], function( defaultValue, + defined, + DeveloperError, freezeObject) { "use strict"; @@ -25,6 +29,7 @@ define([ * }); * * @see Geometry#attributes + * @see Packable */ var VertexFormat = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); @@ -210,5 +215,92 @@ define([ */ VertexFormat.DEFAULT = VertexFormat.POSITION_NORMAL_AND_ST; + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + VertexFormat.packedLength = 6; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + VertexFormat.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + array[startingIndex++] = value.position ? 1.0 : 0.0; + array[startingIndex++] = value.normal ? 1.0 : 0.0; + array[startingIndex++] = value.st ? 1.0 : 0.0; + array[startingIndex++] = value.binormal ? 1.0 : 0.0; + array[startingIndex++] = value.tangent ? 1.0 : 0.0; + array[startingIndex++] = value.color ? 1.0 : 0.0; + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {VertexFormat} [result] The object into which to store the result. + */ + VertexFormat.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + if (!defined(result)) { + result = new VertexFormat(); + } + + result.position = array[startingIndex++] === 1.0; + result.normal = array[startingIndex++] === 1.0; + result.st = array[startingIndex++] === 1.0; + result.binormal = array[startingIndex++] === 1.0; + result.tangent = array[startingIndex++] === 1.0; + result.color = array[startingIndex++] === 1.0; + return result; + }; + + /** + * Duplicates a VertexFormat instance. + * + * @param {VertexFormat} cartesian The vertex format to duplicate. + * @param {VertexFormat} [result] The object onto which to store the result. + * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided. (Returns undefined if vertexFormat is undefined) + */ + VertexFormat.clone = function(vertexFormat, result) { + if (!defined(vertexFormat)) { + return undefined; + } + if (!defined(result)) { + result = new VertexFormat(); + } + + result.position = vertexFormat.position; + result.normal = vertexFormat.normal; + result.st = vertexFormat.st; + result.binormal = vertexFormat.binormal; + result.tangent = vertexFormat.tangent; + result.color = vertexFormat.color; + return result; + }; + return VertexFormat; }); \ No newline at end of file diff --git a/Source/Core/WallGeometry.js b/Source/Core/WallGeometry.js index b3626d02e8a7..79bdf9a77925 100644 --- a/Source/Core/WallGeometry.js +++ b/Source/Core/WallGeometry.js @@ -106,10 +106,165 @@ define([ this._positions = wallPositions; this._minimumHeights = minimumHeights; this._maximumHeights = maximumHeights; - this._vertexFormat = vertexFormat; + this._vertexFormat = VertexFormat.clone(vertexFormat); this._granularity = granularity; - this._ellipsoid = ellipsoid; + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._workerName = 'createWallGeometry'; + + var numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2; + if (defined(minimumHeights)) { + numComponents += minimumHeights.length; + } + if (defined(maximumHeights)) { + numComponents += maximumHeights.length; + } + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 1; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + WallGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + var minimumHeights = value._minimumHeights; + length = defined(minimumHeights) ? minimumHeights.length : 0; + array[startingIndex++] = length; + + if (defined(minimumHeights)) { + for (i = 0; i < length; ++i) { + array[startingIndex++] = minimumHeights[i]; + } + } + + var maximumHeights = value._maximumHeights; + length = defined(maximumHeights) ? maximumHeights.length : 0; + array[startingIndex++] = length; + + if (defined(maximumHeights)) { + for (i = 0; i < length; ++i) { + array[startingIndex++] = maximumHeights[i]; + } + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + VertexFormat.pack(value._vertexFormat, array, startingIndex); + startingIndex += VertexFormat.packedLength; + + array[startingIndex] = value._granularity; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchVertexFormat = new VertexFormat(); + var scratchOptions = { + positions : undefined, + minimumHeights : undefined, + maximumHeights : undefined, + ellipsoid : scratchEllipsoid, + vertexFormat : scratchVertexFormat, + granularity : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {WallGeometry} [result] The object into which to store the result. + */ + WallGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + length = array[startingIndex++]; + var minimumHeights; + + if (length > 0) { + minimumHeights = new Array(length); + for (i = 0; i < length; ++i) { + minimumHeights[i] = array[startingIndex++]; + } + } + + length = array[startingIndex++]; + var maximumHeights; + + if (length > 0) { + maximumHeights = new Array(length); + for (i = 0; i < length; ++i) { + maximumHeights[i] = array[startingIndex++]; + } + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); + startingIndex += VertexFormat.packedLength; + + var granularity = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.positions = positions; + scratchOptions.minimumHeights = minimumHeights; + scratchOptions.maximumHeights = maximumHeights; + scratchOptions.granularity = granularity; + return new WallGeometry(scratchOptions); + } + + result._positions = positions; + result._minimumHeights = minimumHeights; + result._maximumHeights = maximumHeights; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); + result._granularity = granularity; + + return result; }; /** diff --git a/Source/Core/WallOutlineGeometry.js b/Source/Core/WallOutlineGeometry.js index 375cb4f9d1da..4ebc9e0a6df4 100644 --- a/Source/Core/WallOutlineGeometry.js +++ b/Source/Core/WallOutlineGeometry.js @@ -97,8 +97,154 @@ define([ this._minimumHeights = minimumHeights; this._maximumHeights = maximumHeights; this._granularity = granularity; - this._ellipsoid = ellipsoid; + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._workerName = 'createWallOutlineGeometry'; + + var numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2; + if (defined(minimumHeights)) { + numComponents += minimumHeights.length; + } + if (defined(maximumHeights)) { + numComponents += maximumHeights.length; + } + + /** + * The number of elements used to pack the object into an array. + * @type {Number} + */ + this.packedLength = numComponents + Ellipsoid.packedLength + 1; + }; + + /** + * Stores the provided instance into the provided array. + * @function + * + * @param {Object} value The value to pack. + * @param {Number[]} array The array to pack into. + * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements. + */ + WallOutlineGeometry.pack = function(value, array, startingIndex) { + //>>includeStart('debug', pragmas.debug); + if (!defined(value)) { + throw new DeveloperError('value is required'); + } + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var positions = value._positions; + var length = positions.length; + array[startingIndex++] = length; + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + Cartesian3.pack(positions[i], array, startingIndex); + } + + var minimumHeights = value._minimumHeights; + length = defined(minimumHeights) ? minimumHeights.length : 0; + array[startingIndex++] = length; + + if (defined(minimumHeights)) { + for (i = 0; i < length; ++i) { + array[startingIndex++] = minimumHeights[i]; + } + } + + var maximumHeights = value._maximumHeights; + length = defined(maximumHeights) ? maximumHeights.length : 0; + array[startingIndex++] = length; + + if (defined(maximumHeights)) { + for (i = 0; i < length; ++i) { + array[startingIndex++] = maximumHeights[i]; + } + } + + Ellipsoid.pack(value._ellipsoid, array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + array[startingIndex] = value._granularity; + }; + + var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); + var scratchOptions = { + positions : undefined, + minimumHeights : undefined, + maximumHeights : undefined, + ellipsoid : scratchEllipsoid, + granularity : undefined + }; + + /** + * Retrieves an instance from a packed array. + * + * @param {Number[]} array The packed array. + * @param {Number} [startingIndex=0] The starting index of the element to be unpacked. + * @param {WallOutlineGeometry} [result] The object into which to store the result. + */ + WallOutlineGeometry.unpack = function(array, startingIndex, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(array)) { + throw new DeveloperError('array is required'); + } + //>>includeEnd('debug'); + + startingIndex = defaultValue(startingIndex, 0); + + var i; + + var length = array[startingIndex++]; + var positions = new Array(length); + + for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) { + positions[i] = Cartesian3.unpack(array, startingIndex); + } + + length = array[startingIndex++]; + var minimumHeights; + + if (length > 0) { + minimumHeights = new Array(length); + for (i = 0; i < length; ++i) { + minimumHeights[i] = array[startingIndex++]; + } + } + + length = array[startingIndex++]; + var maximumHeights; + + if (length > 0) { + maximumHeights = new Array(length); + for (i = 0; i < length; ++i) { + maximumHeights[i] = array[startingIndex++]; + } + } + + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); + startingIndex += Ellipsoid.packedLength; + + var granularity = array[startingIndex]; + + if (!defined(result)) { + scratchOptions.positions = positions; + scratchOptions.minimumHeights = minimumHeights; + scratchOptions.maximumHeights = maximumHeights; + scratchOptions.granularity = granularity; + return new WallOutlineGeometry(scratchOptions); + } + + result._positions = positions; + result._minimumHeights = minimumHeights; + result._maximumHeights = maximumHeights; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._granularity = granularity; + + return result; }; /** diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index c9de92e5443d..aaa2b30b12e6 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -744,11 +744,41 @@ define([ } } + var subTask; subTasks = subdivideArray(subTasks, numberOfCreationWorkers); + for (i = 0; i < subTasks.length; i++) { + var packedLength = 0; + var workerSubTasks = subTasks[i]; + var workerSubTasksLength = workerSubTasks.length; + for (j = 0; j < workerSubTasksLength; ++j) { + subTask = workerSubTasks[j]; + geometry = subTask.geometry; + if (defined(geometry.constructor.pack)) { + subTask.offset = packedLength; + packedLength += defaultValue(geometry.constructor.packedLength, geometry.packedLength); + } + } + + var subTaskTransferableObjects; + + if (packedLength > 0) { + var array = new Float64Array(packedLength); + subTaskTransferableObjects = [array.buffer]; + + for (j = 0; j < workerSubTasksLength; ++j) { + subTask = workerSubTasks[j]; + geometry = subTask.geometry; + if (defined(geometry.constructor.pack)) { + geometry.constructor.pack(geometry, array, subTask.offset); + subTask.geometry = array; + } + } + } + promises.push(createGeometryTaskProcessors[i].scheduleTask({ subTasks : subTasks[i] - })); + }, subTaskTransferableObjects)); } this._state = PrimitiveState.CREATING; diff --git a/Source/Workers/createBoxGeometry.js b/Source/Workers/createBoxGeometry.js index 595406788f47..aaf24fbe30ee 100644 --- a/Source/Workers/createBoxGeometry.js +++ b/Source/Workers/createBoxGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ - '../Core/BoxGeometry' + '../Core/BoxGeometry', + '../Core/defined' ], function( - BoxGeometry) { + BoxGeometry, + defined) { "use strict"; - return BoxGeometry.createGeometry; + return function(boxGeometry, offset) { + if (defined(offset)) { + boxGeometry = BoxGeometry.unpack(boxGeometry, offset); + } + return BoxGeometry.createGeometry(boxGeometry); + }; }); diff --git a/Source/Workers/createBoxOutlineGeometry.js b/Source/Workers/createBoxOutlineGeometry.js index f83503ccff09..0c0ac8ae76c4 100644 --- a/Source/Workers/createBoxOutlineGeometry.js +++ b/Source/Workers/createBoxOutlineGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ - '../Core/BoxOutlineGeometry' + '../Core/BoxOutlineGeometry', + '../Core/defined' ], function( - BoxOutlineGeometry) { + BoxOutlineGeometry, + defined) { "use strict"; - return BoxOutlineGeometry.createGeometry; + return function(boxGeometry, offset) { + if (defined(offset)) { + boxGeometry = BoxOutlineGeometry.unpack(boxGeometry, offset); + } + return BoxOutlineGeometry.createGeometry(boxGeometry); + }; }); diff --git a/Source/Workers/createCircleGeometry.js b/Source/Workers/createCircleGeometry.js index dfcc164232fa..3eba599f2d13 100644 --- a/Source/Workers/createCircleGeometry.js +++ b/Source/Workers/createCircleGeometry.js @@ -2,14 +2,19 @@ define([ '../Core/Cartesian3', '../Core/CircleGeometry', + '../Core/defined', '../Core/Ellipsoid' ], function( Cartesian3, CircleGeometry, + defined, Ellipsoid) { "use strict"; - function createCircleGeometry(circleGeometry) { + function createCircleGeometry(circleGeometry, offset) { + if (defined(offset)) { + circleGeometry = CircleGeometry.unpack(circleGeometry, offset); + } circleGeometry._ellipseGeometry._center = Cartesian3.clone(circleGeometry._ellipseGeometry._center); circleGeometry._ellipseGeometry._ellipsoid = Ellipsoid.clone(circleGeometry._ellipseGeometry._ellipsoid); return CircleGeometry.createGeometry(circleGeometry); diff --git a/Source/Workers/createCircleOutlineGeometry.js b/Source/Workers/createCircleOutlineGeometry.js index 22fcf494949a..5df6cc94814f 100644 --- a/Source/Workers/createCircleOutlineGeometry.js +++ b/Source/Workers/createCircleOutlineGeometry.js @@ -2,14 +2,19 @@ define([ '../Core/Cartesian3', '../Core/CircleOutlineGeometry', + '../Core/defined', '../Core/Ellipsoid' ], function( Cartesian3, CircleOutlineGeometry, + defined, Ellipsoid) { "use strict"; - function createCircleOutlineGeometry(circleGeometry) { + function createCircleOutlineGeometry(circleGeometry, offset) { + if (defined(offset)) { + circleGeometry = CircleOutlineGeometry.unpack(circleGeometry, offset); + } circleGeometry._ellipseGeometry._center = Cartesian3.clone(circleGeometry._ellipseGeometry._center); circleGeometry._ellipseGeometry._ellipsoid = Ellipsoid.clone(circleGeometry._ellipseGeometry._ellipsoid); return CircleOutlineGeometry.createGeometry(circleGeometry); diff --git a/Source/Workers/createCorridorGeometry.js b/Source/Workers/createCorridorGeometry.js index 536011483640..ba673a27f803 100644 --- a/Source/Workers/createCorridorGeometry.js +++ b/Source/Workers/createCorridorGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ '../Core/CorridorGeometry', + '../Core/defined', '../Core/Ellipsoid' ], function( CorridorGeometry, + defined, Ellipsoid) { "use strict"; - function createCorridorGeometry(corridorGeometry) { + function createCorridorGeometry(corridorGeometry, offset) { + if (defined(offset)) { + corridorGeometry = CorridorGeometry.unpack(corridorGeometry, offset); + } corridorGeometry._ellipsoid = Ellipsoid.clone(corridorGeometry._ellipsoid); return CorridorGeometry.createGeometry(corridorGeometry); } diff --git a/Source/Workers/createCorridorOutlineGeometry.js b/Source/Workers/createCorridorOutlineGeometry.js index 91dab3bc82a7..45cca03cbc43 100644 --- a/Source/Workers/createCorridorOutlineGeometry.js +++ b/Source/Workers/createCorridorOutlineGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ '../Core/CorridorOutlineGeometry', + '../Core/defined', '../Core/Ellipsoid' ], function( CorridorOutlineGeometry, + defined, Ellipsoid) { "use strict"; - function createCorridorOutlineGeometry(corridorOutlineGeometry) { + function createCorridorOutlineGeometry(corridorOutlineGeometry, offset) { + if (defined(offset)) { + corridorOutlineGeometry = CorridorOutlineGeometry.unpack(corridorOutlineGeometry, offset); + } corridorOutlineGeometry._ellipsoid = Ellipsoid.clone(corridorOutlineGeometry._ellipsoid); return CorridorOutlineGeometry.createGeometry(corridorOutlineGeometry); } diff --git a/Source/Workers/createCylinderGeometry.js b/Source/Workers/createCylinderGeometry.js index df72a1e2216b..309ea24cd175 100644 --- a/Source/Workers/createCylinderGeometry.js +++ b/Source/Workers/createCylinderGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ - '../Core/CylinderGeometry' + '../Core/CylinderGeometry', + '../Core/defined' ], function( - CylinderGeometry) { + CylinderGeometry, + defined) { "use strict"; - return CylinderGeometry.createGeometry; + return function(cylinderGeometry, offset) { + if (defined(offset)) { + cylinderGeometry = CylinderGeometry.unpack(cylinderGeometry, offset); + } + return CylinderGeometry.createGeometry(cylinderGeometry); + }; }); diff --git a/Source/Workers/createCylinderOutlineGeometry.js b/Source/Workers/createCylinderOutlineGeometry.js index 2b1910f24f85..e17895dd6608 100644 --- a/Source/Workers/createCylinderOutlineGeometry.js +++ b/Source/Workers/createCylinderOutlineGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ - '../Core/CylinderOutlineGeometry' + '../Core/CylinderOutlineGeometry', + '../Core/defined' ], function( - CylinderOutlineGeometry) { + CylinderOutlineGeometry, + defined) { "use strict"; - return CylinderOutlineGeometry.createGeometry; + return function(cylinderGeometry, offset) { + if (defined(offset)) { + cylinderGeometry = CylinderOutlineGeometry.unpack(cylinderGeometry, offset); + } + return CylinderOutlineGeometry.createGeometry(cylinderGeometry); + }; }); diff --git a/Source/Workers/createEllipseGeometry.js b/Source/Workers/createEllipseGeometry.js index 468f637af01a..626e24e3dbb3 100644 --- a/Source/Workers/createEllipseGeometry.js +++ b/Source/Workers/createEllipseGeometry.js @@ -1,15 +1,20 @@ /*global define*/ define([ '../Core/Cartesian3', + '../Core/defined', '../Core/EllipseGeometry', '../Core/Ellipsoid' ], function( Cartesian3, + defined, EllipseGeometry, Ellipsoid) { "use strict"; - function createEllipseGeometry(ellipseGeometry) { + function createEllipseGeometry(ellipseGeometry, offset) { + if (defined(offset)) { + ellipseGeometry = EllipseGeometry.unpack(ellipseGeometry, offset); + } ellipseGeometry._center = Cartesian3.clone(ellipseGeometry._center); ellipseGeometry._ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid); return EllipseGeometry.createGeometry(ellipseGeometry); diff --git a/Source/Workers/createEllipseOutlineGeometry.js b/Source/Workers/createEllipseOutlineGeometry.js index 955394361694..9a0ffe328e46 100644 --- a/Source/Workers/createEllipseOutlineGeometry.js +++ b/Source/Workers/createEllipseOutlineGeometry.js @@ -1,15 +1,20 @@ /*global define*/ define([ '../Core/Cartesian3', + '../Core/defined', '../Core/EllipseOutlineGeometry', '../Core/Ellipsoid' ], function( Cartesian3, + defined, EllipseOutlineGeometry, Ellipsoid) { "use strict"; - function createEllipseOutlineGeometry(ellipseGeometry) { + function createEllipseOutlineGeometry(ellipseGeometry, offset) { + if (defined(offset)) { + ellipseGeometry = EllipseOutlineGeometry.unpack(ellipseGeometry, offset); + } ellipseGeometry._center = Cartesian3.clone(ellipseGeometry._center); ellipseGeometry._ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid); return EllipseOutlineGeometry.createGeometry(ellipseGeometry); diff --git a/Source/Workers/createEllipsoidGeometry.js b/Source/Workers/createEllipsoidGeometry.js index b9829c72ee78..a5de0a49bc8d 100644 --- a/Source/Workers/createEllipsoidGeometry.js +++ b/Source/Workers/createEllipsoidGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ + '../Core/defined', '../Core/EllipsoidGeometry' ], function( + defined, EllipsoidGeometry) { "use strict"; - return EllipsoidGeometry.createGeometry; + return function(ellipsoidGeometry, offset) { + if (defined(offset)) { + ellipsoidGeometry = EllipsoidGeometry.unpack(ellipsoidGeometry, offset); + } + return EllipsoidGeometry.createGeometry(ellipsoidGeometry); + }; }); diff --git a/Source/Workers/createEllipsoidOutlineGeometry.js b/Source/Workers/createEllipsoidOutlineGeometry.js index 680daf6966fd..7f720a2df884 100644 --- a/Source/Workers/createEllipsoidOutlineGeometry.js +++ b/Source/Workers/createEllipsoidOutlineGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ + '../Core/defined', '../Core/EllipsoidOutlineGeometry' ], function( + defined, EllipsoidOutlineGeometry) { "use strict"; - return EllipsoidOutlineGeometry.createGeometry; + return function(ellipsoidGeometry, offset) { + if (defined(ellipsoidGeometry.buffer, offset)) { + ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(ellipsoidGeometry, offset); + } + return EllipsoidOutlineGeometry.createGeometry(ellipsoidGeometry); + }; }); diff --git a/Source/Workers/createGeometry.js b/Source/Workers/createGeometry.js index 7570a29d5231..24570db39d42 100644 --- a/Source/Workers/createGeometry.js +++ b/Source/Workers/createGeometry.js @@ -36,7 +36,7 @@ define([ if (defined(moduleName)) { var createFunction = getModule(moduleName); - results.push(createFunction(geometry)); + results.push(createFunction(geometry, task.offset)); } else { //Already created geometry results.push(geometry); diff --git a/Source/Workers/createPolygonGeometry.js b/Source/Workers/createPolygonGeometry.js index 342737e8426a..1f03cc8386af 100644 --- a/Source/Workers/createPolygonGeometry.js +++ b/Source/Workers/createPolygonGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/PolygonGeometry' ], function( + defined, Ellipsoid, PolygonGeometry) { "use strict"; - function createPolygonGeometry(polygonGeometry) { + function createPolygonGeometry(polygonGeometry, offset) { + if (defined(offset)) { + polygonGeometry = PolygonGeometry.unpack(polygonGeometry, offset); + } polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); return PolygonGeometry.createGeometry(polygonGeometry); } diff --git a/Source/Workers/createPolygonOutlineGeometry.js b/Source/Workers/createPolygonOutlineGeometry.js index 32f359dbaa0f..1c298701111e 100644 --- a/Source/Workers/createPolygonOutlineGeometry.js +++ b/Source/Workers/createPolygonOutlineGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/PolygonOutlineGeometry' ], function( + defined, Ellipsoid, PolygonOutlineGeometry) { "use strict"; - function createPolygonOutlineGeometry(polygonGeometry) { + function createPolygonOutlineGeometry(polygonGeometry, offset) { + if (defined(offset)) { + polygonGeometry = PolygonOutlineGeometry.unpack(polygonGeometry, offset); + } polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); return PolygonOutlineGeometry.createGeometry(polygonGeometry); } diff --git a/Source/Workers/createPolylineGeometry.js b/Source/Workers/createPolylineGeometry.js index 3a116a28a0a9..4fb72ce64831 100644 --- a/Source/Workers/createPolylineGeometry.js +++ b/Source/Workers/createPolylineGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/PolylineGeometry' ], function( + defined, Ellipsoid, PolylineGeometry) { "use strict"; - function createPolylineGeometry(polylineGeometry) { + function createPolylineGeometry(polylineGeometry, offset) { + if (defined(offset)) { + polylineGeometry = PolylineGeometry.unpack(polylineGeometry, offset); + } polylineGeometry._ellipsoid = Ellipsoid.clone(polylineGeometry._ellipsoid); return PolylineGeometry.createGeometry(polylineGeometry); } diff --git a/Source/Workers/createPolylineVolumeGeometry.js b/Source/Workers/createPolylineVolumeGeometry.js index df2b5f6f2f92..914b710246e7 100644 --- a/Source/Workers/createPolylineVolumeGeometry.js +++ b/Source/Workers/createPolylineVolumeGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/PolylineVolumeGeometry' ], function( + defined, Ellipsoid, PolylineVolumeGeometry) { "use strict"; - function createPolylineVolumeGeometry(polylineVolumeGeometry) { + function createPolylineVolumeGeometry(polylineVolumeGeometry, offset) { + if (defined(offset)) { + polylineVolumeGeometry = PolylineVolumeGeometry.unpack(polylineVolumeGeometry, offset); + } polylineVolumeGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeGeometry._ellipsoid); return PolylineVolumeGeometry.createGeometry(polylineVolumeGeometry); } diff --git a/Source/Workers/createPolylineVolumeOutlineGeometry.js b/Source/Workers/createPolylineVolumeOutlineGeometry.js index 8831bed87e07..5ef898e172c2 100644 --- a/Source/Workers/createPolylineVolumeOutlineGeometry.js +++ b/Source/Workers/createPolylineVolumeOutlineGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/PolylineVolumeOutlineGeometry' ], function( + defined, Ellipsoid, PolylineVolumeOutlineGeometry) { "use strict"; - function createPolylineVolumeOutlineGeometry(polylineVolumeOutlineGeometry) { + function createPolylineVolumeOutlineGeometry(polylineVolumeOutlineGeometry, offset) { + if (defined(offset)) { + polylineVolumeOutlineGeometry = PolylineVolumeOutlineGeometry.unpack(polylineVolumeOutlineGeometry, offset); + } polylineVolumeOutlineGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeOutlineGeometry._ellipsoid); return PolylineVolumeOutlineGeometry.createGeometry(polylineVolumeOutlineGeometry); } diff --git a/Source/Workers/createRectangleGeometry.js b/Source/Workers/createRectangleGeometry.js index 245b68cd26c6..13d87bffe571 100644 --- a/Source/Workers/createRectangleGeometry.js +++ b/Source/Workers/createRectangleGeometry.js @@ -1,15 +1,20 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/Rectangle', '../Core/RectangleGeometry' ], function( + defined, Ellipsoid, Rectangle, RectangleGeometry) { "use strict"; - function createRectangleGeometry(rectangleGeometry) { + function createRectangleGeometry(rectangleGeometry, offset) { + if (defined(offset)) { + rectangleGeometry = RectangleGeometry.unpack(rectangleGeometry, offset); + } rectangleGeometry._ellipsoid = Ellipsoid.clone(rectangleGeometry._ellipsoid); rectangleGeometry._rectangle = Rectangle.clone(rectangleGeometry._rectangle); return RectangleGeometry.createGeometry(rectangleGeometry); diff --git a/Source/Workers/createRectangleOutlineGeometry.js b/Source/Workers/createRectangleOutlineGeometry.js index 841169363082..afa790575283 100644 --- a/Source/Workers/createRectangleOutlineGeometry.js +++ b/Source/Workers/createRectangleOutlineGeometry.js @@ -1,15 +1,20 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/Rectangle', '../Core/RectangleOutlineGeometry' ], function( + defined, Ellipsoid, Rectangle, RectangleOutlineGeometry) { "use strict"; - function createRectangleOutlineGeometry(rectangleGeometry) { + function createRectangleOutlineGeometry(rectangleGeometry, offset) { + if (defined(offset)) { + rectangleGeometry = RectangleOutlineGeometry.unpack(rectangleGeometry, offset); + } rectangleGeometry._ellipsoid = Ellipsoid.clone(rectangleGeometry._ellipsoid); rectangleGeometry._rectangle = Rectangle.clone(rectangleGeometry._rectangle); return RectangleOutlineGeometry.createGeometry(rectangleGeometry); diff --git a/Source/Workers/createSimplePolylineGeometry.js b/Source/Workers/createSimplePolylineGeometry.js index 46f95deaf14c..6ab03361b05e 100644 --- a/Source/Workers/createSimplePolylineGeometry.js +++ b/Source/Workers/createSimplePolylineGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/SimplePolylineGeometry' ], function( + defined, Ellipsoid, SimplePolylineGeometry) { "use strict"; - function createSimplePolylineGeometry(simplePolylineGeometry) { + function createSimplePolylineGeometry(simplePolylineGeometry, offset) { + if (defined(offset)) { + simplePolylineGeometry = SimplePolylineGeometry.unpack(simplePolylineGeometry, offset); + } simplePolylineGeometry._ellipsoid = Ellipsoid.clone(simplePolylineGeometry._ellipsoid); return SimplePolylineGeometry.createGeometry(simplePolylineGeometry); } diff --git a/Source/Workers/createSphereGeometry.js b/Source/Workers/createSphereGeometry.js index d3fc46e8bc6d..db749b945e19 100644 --- a/Source/Workers/createSphereGeometry.js +++ b/Source/Workers/createSphereGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ + '../Core/defined', '../Core/SphereGeometry' ], function( + defined, SphereGeometry) { "use strict"; - return SphereGeometry.createGeometry; + return function(sphereGeometry, offset) { + if (defined(offset)) { + sphereGeometry = SphereGeometry.unpack(sphereGeometry, offset); + } + return SphereGeometry.createGeometry(sphereGeometry); + }; }); diff --git a/Source/Workers/createSphereOutlineGeometry.js b/Source/Workers/createSphereOutlineGeometry.js index 067baf6905ba..144a2944cc2e 100644 --- a/Source/Workers/createSphereOutlineGeometry.js +++ b/Source/Workers/createSphereOutlineGeometry.js @@ -1,9 +1,16 @@ /*global define*/ define([ + '../Core/defined', '../Core/SphereOutlineGeometry' ], function( + defined, SphereOutlineGeometry) { "use strict"; - return SphereOutlineGeometry.createGeometry; + return function(sphereGeometry, offset) { + if (defined(offset)) { + sphereGeometry = SphereOutlineGeometry.unpack(sphereGeometry, offset); + } + return SphereOutlineGeometry.createGeometry(sphereGeometry); + }; }); diff --git a/Source/Workers/createWallGeometry.js b/Source/Workers/createWallGeometry.js index 8a210451bc6e..8326b64f8e5f 100644 --- a/Source/Workers/createWallGeometry.js +++ b/Source/Workers/createWallGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/WallGeometry' ], function( + defined, Ellipsoid, WallGeometry) { "use strict"; - function createWallGeometry(wallGeometry) { + function createWallGeometry(wallGeometry, offset) { + if (defined(offset)) { + wallGeometry = WallGeometry.unpack(wallGeometry, offset); + } wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); return WallGeometry.createGeometry(wallGeometry); } diff --git a/Source/Workers/createWallOutlineGeometry.js b/Source/Workers/createWallOutlineGeometry.js index beb3b69453f7..fd555460b045 100644 --- a/Source/Workers/createWallOutlineGeometry.js +++ b/Source/Workers/createWallOutlineGeometry.js @@ -1,13 +1,18 @@ /*global define*/ define([ + '../Core/defined', '../Core/Ellipsoid', '../Core/WallOutlineGeometry' ], function( + defined, Ellipsoid, WallOutlineGeometry) { "use strict"; - function createWallOutlineGeometry(wallGeometry) { + function createWallOutlineGeometry(wallGeometry, offset) { + if (defined(offset)) { + wallGeometry = WallOutlineGeometry.unpack(wallGeometry, offset); + } wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); return WallOutlineGeometry.createGeometry(wallGeometry); } diff --git a/Specs/Core/BoundingSphereSpec.js b/Specs/Core/BoundingSphereSpec.js index 9583812c0e37..25d37c16e4a8 100644 --- a/Specs/Core/BoundingSphereSpec.js +++ b/Specs/Core/BoundingSphereSpec.js @@ -10,7 +10,8 @@ defineSuite([ 'Core/Interval', 'Core/Math', 'Core/Matrix4', - 'Core/Rectangle' + 'Core/Rectangle', + 'Specs/createPackableSpecs' ], function( BoundingSphere, Cartesian3, @@ -22,7 +23,8 @@ defineSuite([ Interval, CesiumMath, Matrix4, - Rectangle) { + Rectangle, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -717,4 +719,6 @@ defineSuite([ point = new Cartographic(rectangle.east, Rectangle.center(rectangle).latitude, maxHeight); expectBoundingSphereToContainPoint(boundingSphere, point, projection); }); + + createPackableSpecs(BoundingSphere, new BoundingSphere(new Cartesian3(1.0, 2.0, 3.0), 4.0), [1.0, 2.0, 3.0, 4.0]); }); diff --git a/Specs/Core/BoxGeometrySpec.js b/Specs/Core/BoxGeometrySpec.js index aa08e9cb4afc..dd0fd3515c16 100644 --- a/Specs/Core/BoxGeometrySpec.js +++ b/Specs/Core/BoxGeometrySpec.js @@ -2,11 +2,13 @@ defineSuite([ 'Core/BoxGeometry', 'Core/Cartesian3', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( BoxGeometry, Cartesian3, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -81,4 +83,10 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(8 * 3); expect(m.indices.length).toEqual(12 * 3); }); + + createPackableSpecs(BoxGeometry, new BoxGeometry({ + minimumCorner : new Cartesian3(1.0, 2.0, 3.0), + maximumCorner : new Cartesian3(4.0, 5.0, 6.0), + vertexFormat : VertexFormat.POSITION_AND_NORMAL + }), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]); }); diff --git a/Specs/Core/BoxOutlineGeometrySpec.js b/Specs/Core/BoxOutlineGeometrySpec.js index 9cec7fa26df6..7217808839d8 100644 --- a/Specs/Core/BoxOutlineGeometrySpec.js +++ b/Specs/Core/BoxOutlineGeometrySpec.js @@ -1,10 +1,12 @@ /*global defineSuite*/ defineSuite([ 'Core/BoxOutlineGeometry', - 'Core/Cartesian3' + 'Core/Cartesian3', + 'Specs/createPackableSpecs' ], function( BoxOutlineGeometry, - Cartesian3) { + Cartesian3, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -56,4 +58,9 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(8 * 3); expect(m.indices.length).toEqual(12 * 2); }); + + createPackableSpecs(BoxOutlineGeometry, new BoxOutlineGeometry({ + minimumCorner : new Cartesian3(1.0, 2.0, 3.0), + maximumCorner : new Cartesian3(4.0, 5.0, 6.0) + }), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]); }); \ No newline at end of file diff --git a/Specs/Core/CircleGeometrySpec.js b/Specs/Core/CircleGeometrySpec.js index fbce5794e27a..c2fbe0334c0e 100644 --- a/Specs/Core/CircleGeometrySpec.js +++ b/Specs/Core/CircleGeometrySpec.js @@ -4,13 +4,15 @@ defineSuite([ 'Core/Cartesian3', 'Core/Ellipsoid', 'Core/Math', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( CircleGeometry, Cartesian3, Ellipsoid, CesiumMath, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -133,4 +135,17 @@ defineSuite([ expect(st[length - 2]).toEqualEpsilon(0.5, CesiumMath.EPSILON2); expect(st[length - 1]).toEqualEpsilon(0.0, CesiumMath.EPSILON2); }); + + var center = Cartesian3.fromDegrees(0,0); + var ellipsoid = Ellipsoid.WGS84; + var packableInstance = new CircleGeometry({ + vertexFormat : VertexFormat.POSITION_AND_ST, + ellipsoid : ellipsoid, + center : center, + granularity : 0.1, + 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]; + createPackableSpecs(CircleGeometry, packableInstance, packedInstance); }); diff --git a/Specs/Core/CircleOutlineGeometrySpec.js b/Specs/Core/CircleOutlineGeometrySpec.js index 69c7323d1191..3b520bf1be3a 100644 --- a/Specs/Core/CircleOutlineGeometrySpec.js +++ b/Specs/Core/CircleOutlineGeometrySpec.js @@ -2,11 +2,13 @@ defineSuite([ 'Core/CircleOutlineGeometry', 'Core/Cartesian3', - 'Core/Ellipsoid' + 'Core/Ellipsoid', + 'Specs/createPackableSpecs' ], function( CircleOutlineGeometry, Cartesian3, - Ellipsoid) { + Ellipsoid, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -84,4 +86,16 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(2 * 6 * 3); expect(m.indices.length).toEqual(2 * 6 * 2); }); + + var center = Cartesian3.fromDegrees(0,0); + var ellipsoid = Ellipsoid.WGS84; + var packableInstance = new CircleOutlineGeometry({ + ellipsoid : ellipsoid, + center : center, + granularity : 0.1, + radius : 1.0, + numberOfVerticalLines : 0 + }); + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 1.0, 0.0, 0.0, 0.1, 0.0, 0.0, 0.0]; + createPackableSpecs(CircleOutlineGeometry, packableInstance, packedInstance); }); diff --git a/Specs/Core/CorridorGeometrySpec.js b/Specs/Core/CorridorGeometrySpec.js index 328eb161b82d..39ee05d6e0ab 100644 --- a/Specs/Core/CorridorGeometrySpec.js +++ b/Specs/Core/CorridorGeometrySpec.js @@ -3,12 +3,16 @@ defineSuite([ 'Core/CorridorGeometry', 'Core/Cartesian3', 'Core/CornerType', - 'Core/VertexFormat' + 'Core/Ellipsoid', + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( CorridorGeometry, Cartesian3, CornerType, - VertexFormat) { + Ellipsoid, + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -176,4 +180,20 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(3 * 10); expect(m.indices.length).toEqual(3 * 8); }); + + var positions = Cartesian3.fromDegreesArray([ + 90.0, -30.0, + 90.0, -31.0 + ]); + var corridor = new CorridorGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + positions : positions, + cornerType: CornerType.BEVELED, + width : 30000.0, + granularity : 0.1 + }); + var packedInstance = [2, positions[0].x, positions[0].y, positions[0].z, positions[1].x, positions[1].y, positions[1].z]; + packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z); + packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 30000.0, 0.0, 0.0, 2.0, 0.1); + createPackableSpecs(CorridorGeometry, corridor, packedInstance); }); diff --git a/Specs/Core/CorridorOutlineGeometrySpec.js b/Specs/Core/CorridorOutlineGeometrySpec.js index 25fad5b6b225..d56039c7f3b4 100644 --- a/Specs/Core/CorridorOutlineGeometrySpec.js +++ b/Specs/Core/CorridorOutlineGeometrySpec.js @@ -2,11 +2,15 @@ defineSuite([ 'Core/CorridorOutlineGeometry', 'Core/Cartesian3', - 'Core/CornerType' + 'Core/CornerType', + 'Core/Ellipsoid', + 'Specs/createPackableSpecs' ], function( CorridorOutlineGeometry, Cartesian3, - CornerType) { + CornerType, + Ellipsoid, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -128,4 +132,19 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(3 * 10); expect(m.indices.length).toEqual(2 * 10); }); + + var positions = Cartesian3.fromDegreesArray([ + 90.0, -30.0, + 90.0, -31.0 + ]); + var corridor = new CorridorOutlineGeometry({ + positions : positions, + cornerType: CornerType.BEVELED, + width : 30000.0, + granularity : 0.1 + }); + var packedInstance = [2, positions[0].x, positions[0].y, positions[0].z, positions[1].x, positions[1].y, positions[1].z]; + packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z); + packedInstance.push(30000.0, 0.0, 0.0, 2.0, 0.1); + createPackableSpecs(CorridorOutlineGeometry, corridor, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/CylinderGeometrySpec.js b/Specs/Core/CylinderGeometrySpec.js index 44a0f73337e4..c6f3e7f7a353 100644 --- a/Specs/Core/CylinderGeometrySpec.js +++ b/Specs/Core/CylinderGeometrySpec.js @@ -1,10 +1,12 @@ /*global defineSuite*/ defineSuite([ 'Core/CylinderGeometry', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( CylinderGeometry, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -134,4 +136,14 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(3 * 3 * 4); expect(m.indices.length).toEqual(8 * 3); }); + + var cylinder = new CylinderGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + length: 1, + topRadius: 1, + bottomRadius: 0, + slices: 3 + }); + var packedInstance = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 3.0]; + createPackableSpecs(CylinderGeometry, cylinder, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/CylinderOutlineGeometrySpec.js b/Specs/Core/CylinderOutlineGeometrySpec.js index 8efe3001c07b..87e1fed702ba 100644 --- a/Specs/Core/CylinderOutlineGeometrySpec.js +++ b/Specs/Core/CylinderOutlineGeometrySpec.js @@ -1,8 +1,10 @@ /*global defineSuite*/ defineSuite([ - 'Core/CylinderOutlineGeometry' + 'Core/CylinderOutlineGeometry', + 'Specs/createPackableSpecs' ], function( - CylinderOutlineGeometry) { + CylinderOutlineGeometry, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -101,4 +103,14 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(3 * 3 * 2); expect(m.indices.length).toEqual(6 * 2); }); + + var cylinder = new CylinderOutlineGeometry({ + length: 1, + topRadius: 1, + bottomRadius: 0, + slices: 3, + numberOfVerticalLines: 0 + }); + var packedInstance = [1.0, 1.0, 0.0, 3.0, 0.0]; + createPackableSpecs(CylinderOutlineGeometry, cylinder, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/EllipseGeometrySpec.js b/Specs/Core/EllipseGeometrySpec.js index 5d68dca6f6e7..7eee5000729f 100644 --- a/Specs/Core/EllipseGeometrySpec.js +++ b/Specs/Core/EllipseGeometrySpec.js @@ -4,13 +4,15 @@ defineSuite([ 'Core/Cartesian3', 'Core/Ellipsoid', 'Core/Math', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( EllipseGeometry, Cartesian3, Ellipsoid, CesiumMath, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -161,4 +163,19 @@ defineSuite([ expect(m.attributes.binormal.values.length).toEqual(3 * (12 + 6) * 2); expect(m.indices.length).toEqual(3 * (14 + 6) * 2); }); + + var center = Cartesian3.fromDegrees(0,0); + var ellipsoid = Ellipsoid.WGS84; + var packableInstance = new EllipseGeometry({ + vertexFormat : VertexFormat.POSITION_AND_ST, + ellipsoid : ellipsoid, + center : center, + granularity : 0.1, + semiMajorAxis : 1.0, + 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]; + createPackableSpecs(EllipseGeometry, packableInstance, packedInstance); + }); diff --git a/Specs/Core/EllipseOutlineGeometrySpec.js b/Specs/Core/EllipseOutlineGeometrySpec.js index c762843c763d..515a53e07081 100644 --- a/Specs/Core/EllipseOutlineGeometrySpec.js +++ b/Specs/Core/EllipseOutlineGeometrySpec.js @@ -2,11 +2,13 @@ defineSuite([ 'Core/EllipseOutlineGeometry', 'Core/Cartesian3', - 'Core/Ellipsoid' + 'Core/Ellipsoid', + 'Specs/createPackableSpecs' ], function( EllipseOutlineGeometry, Cartesian3, - Ellipsoid) { + Ellipsoid, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -110,4 +112,17 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(3 * 6 * 2); expect(m.indices.length).toEqual(2 * 6 * 2); }); + + var center = Cartesian3.fromDegrees(0,0); + var ellipsoid = Ellipsoid.WGS84; + var packableInstance = new EllipseOutlineGeometry({ + ellipsoid : ellipsoid, + center : center, + granularity : 0.1, + semiMajorAxis : 1.0, + semiMinorAxis : 1.0, + numberOfVerticalLines : 0 + }); + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 1.0, 0.0, 0.0, 0.1, 0.0, 0.0, 0.0]; + createPackableSpecs(EllipseOutlineGeometry, packableInstance, packedInstance); }); diff --git a/Specs/Core/EllipsoidGeometrySpec.js b/Specs/Core/EllipsoidGeometrySpec.js index d7761eeb19af..0a34be613cfd 100644 --- a/Specs/Core/EllipsoidGeometrySpec.js +++ b/Specs/Core/EllipsoidGeometrySpec.js @@ -3,12 +3,14 @@ defineSuite([ 'Core/EllipsoidGeometry', 'Core/Cartesian3', 'Core/Math', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( EllipsoidGeometry, Cartesian3, CesiumMath, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -79,4 +81,13 @@ defineSuite([ expect(binormal).toEqualEpsilon(Cartesian3.cross(normal, tangent, new Cartesian3()), CesiumMath.EPSILON7); } }); + + var ellipsoidgeometry = new EllipsoidGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + radii : new Cartesian3(1.0, 2.0, 3.0), + slicePartitions: 3, + stackPartitions: 3 + }); + var packedInstance = [1.0, 2.0, 3.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 3.0]; + createPackableSpecs(EllipsoidGeometry, ellipsoidgeometry, packedInstance); }); diff --git a/Specs/Core/EllipsoidOutlineGeometrySpec.js b/Specs/Core/EllipsoidOutlineGeometrySpec.js index 63e73ea6f586..fb5abaaa1b76 100644 --- a/Specs/Core/EllipsoidOutlineGeometrySpec.js +++ b/Specs/Core/EllipsoidOutlineGeometrySpec.js @@ -1,8 +1,12 @@ /*global defineSuite*/ defineSuite([ - 'Core/EllipsoidOutlineGeometry' + 'Core/EllipsoidOutlineGeometry', + 'Core/Cartesian3', + 'Specs/createPackableSpecs' ], function( - EllipsoidOutlineGeometry) { + EllipsoidOutlineGeometry, + Cartesian3, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -41,4 +45,13 @@ defineSuite([ expect(m.indices.length).toEqual(15 * 2); expect(m.boundingSphere.radius).toEqual(1); }); + + var ellipsoidgeometry = new EllipsoidOutlineGeometry({ + radii : new Cartesian3(1.0, 2.0, 3.0), + slicePartitions: 3, + stackPartitions: 3, + subdivisions: 3 + }); + var packedInstance = [1.0, 2.0, 3.0, 3.0, 3.0, 3.0]; + createPackableSpecs(EllipsoidOutlineGeometry, ellipsoidgeometry, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/EllipsoidSpec.js b/Specs/Core/EllipsoidSpec.js index ccaa69a04f58..32e5635420da 100644 --- a/Specs/Core/EllipsoidSpec.js +++ b/Specs/Core/EllipsoidSpec.js @@ -3,12 +3,14 @@ defineSuite([ 'Core/Ellipsoid', 'Core/Cartesian3', 'Core/Cartographic', - 'Core/Math' + 'Core/Math', + 'Specs/createPackableSpecs' ], function( Ellipsoid, Cartesian3, Cartographic, - CesiumMath) { + CesiumMath, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -432,4 +434,6 @@ defineSuite([ expect(cloned).toBe(result); expect(cloned).toEqual(myEllipsoid); }); + + createPackableSpecs(Ellipsoid, Ellipsoid.WGS84, [Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z]); }); diff --git a/Specs/Core/PolygonGeometrySpec.js b/Specs/Core/PolygonGeometrySpec.js index 8893b406cb75..6ca7991832ca 100644 --- a/Specs/Core/PolygonGeometrySpec.js +++ b/Specs/Core/PolygonGeometrySpec.js @@ -6,14 +6,16 @@ defineSuite([ 'Core/Cartesian3', 'Core/Ellipsoid', 'Core/Math', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( PolygonGeometry, BoundingSphere, Cartesian3, Ellipsoid, CesiumMath, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -393,4 +395,49 @@ defineSuite([ expect(p.indices.length).toEqual(3 * 22 * 2); }); + var positions = Cartesian3.fromDegreesArray([ + -124.0, 35.0, + -110.0, 35.0, + -110.0, 40.0 + ]); + var holePositions0 = Cartesian3.fromDegreesArray([ + -122.0, 36.0, + -122.0, 39.0, + -112.0, 39.0 + ]); + var holePositions1 = Cartesian3.fromDegreesArray([ + -120.0, 36.5, + -114.0, 36.5, + -114.0, 38.5 + ]); + var hierarchy = { + positions : positions, + holes : [{ + positions : holePositions0, + holes : [{ + positions : holePositions1 + }] + }] + }; + + var polygon = new PolygonGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + polygonHierarchy : hierarchy, + granularity : CesiumMath.PI_OVER_THREE + }); + + function addPositions(array, positions) { + for (var i = 0; i < positions.length; ++i) { + array.push(positions[i].x, positions[i].y, positions[i].z); + } + } + var packedInstance = [3.0, 1.0]; + addPositions(packedInstance, positions); + packedInstance.push(3.0, 1.0); + addPositions(packedInstance, holePositions0); + packedInstance.push(3.0, 0.0); + addPositions(packedInstance, holePositions1); + packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z); + packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 0.0); + createPackableSpecs(PolygonGeometry, polygon, packedInstance); }); diff --git a/Specs/Core/PolygonOutlineGeometrySpec.js b/Specs/Core/PolygonOutlineGeometrySpec.js index e1210107ef94..f029d3adebef 100644 --- a/Specs/Core/PolygonOutlineGeometrySpec.js +++ b/Specs/Core/PolygonOutlineGeometrySpec.js @@ -4,13 +4,15 @@ defineSuite([ 'Core/BoundingSphere', 'Core/Cartesian3', 'Core/Ellipsoid', - 'Core/Math' + 'Core/Math', + 'Specs/createPackableSpecs' ], function( PolygonOutlineGeometry, BoundingSphere, Cartesian3, Ellipsoid, - CesiumMath) { + CesiumMath, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -285,4 +287,47 @@ defineSuite([ expect(p.indices.length).toEqual(2 * 12 * 2 + 12*2); }); + var positions = Cartesian3.fromDegreesArray([ + -124.0, 35.0, + -110.0, 35.0, + -110.0, 40.0 + ]); + var holePositions0 = Cartesian3.fromDegreesArray([ + -122.0, 36.0, + -122.0, 39.0, + -112.0, 39.0 + ]); + var holePositions1 = Cartesian3.fromDegreesArray([ + -120.0, 36.5, + -114.0, 36.5, + -114.0, 38.5 + ]); + var hierarchy = { + positions : positions, + holes : [{ + positions : holePositions0, + holes : [{ + positions : holePositions1 + }] + }] + }; + var polygon = new PolygonOutlineGeometry({ + polygonHierarchy : hierarchy, + granularity : CesiumMath.PI_OVER_THREE + }); + function addPositions(array, positions) { + for (var i = 0; i < positions.length; ++i) { + array.push(positions[i].x, positions[i].y, positions[i].z); + } + } + var packedInstance = [3.0, 1.0]; + addPositions(packedInstance, positions); + packedInstance.push(3.0, 1.0); + addPositions(packedInstance, holePositions0); + packedInstance.push(3.0, 0.0); + addPositions(packedInstance, holePositions1); + packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z); + packedInstance.push(0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0); + createPackableSpecs(PolygonOutlineGeometry, polygon, packedInstance); + }); diff --git a/Specs/Core/PolylineGeometrySpec.js b/Specs/Core/PolylineGeometrySpec.js index 6efdd388f7f7..c30f221bda46 100644 --- a/Specs/Core/PolylineGeometrySpec.js +++ b/Specs/Core/PolylineGeometrySpec.js @@ -5,14 +5,16 @@ defineSuite([ 'Core/Color', 'Core/Ellipsoid', 'Core/Math', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( PolylineGeometry, Cartesian3, Color, Ellipsoid, CesiumMath, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -159,4 +161,15 @@ defineSuite([ })); }).toThrowDeveloperError(); }); + + var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)]; + var line = new PolylineGeometry({ + positions : positions, + width : 10.0, + vertexFormat : VertexFormat.POSITION_ONLY, + granularity : Math.PI, + ellipsoid: Ellipsoid.UNIT_SPHERE + }); + var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 1.0, Math.PI]; + createPackableSpecs(PolylineGeometry, line, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/PolylineVolumeGeometrySpec.js b/Specs/Core/PolylineVolumeGeometrySpec.js index 68a9c14a03de..2a4f9a38e09e 100644 --- a/Specs/Core/PolylineVolumeGeometrySpec.js +++ b/Specs/Core/PolylineVolumeGeometrySpec.js @@ -4,13 +4,17 @@ defineSuite([ 'Core/Cartesian2', 'Core/Cartesian3', 'Core/CornerType', - 'Core/VertexFormat' + 'Core/Ellipsoid', + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( PolylineVolumeGeometry, Cartesian2, Cartesian3, CornerType, - VertexFormat) { + Ellipsoid, + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ var shape; @@ -166,4 +170,17 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(3 * (2 * 8 + 4 * 2 * 9)); expect(m.indices.length).toEqual(3 * (8 * 2 + 4 * 7 * 2 + 4)); }); + + var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)]; + var volumeShape = [new Cartesian2(0.0, 0.0), new Cartesian2(1.0, 0.0), new Cartesian2(0.0, 1.0)]; + var volume = new PolylineVolumeGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + polylinePositions : positions, + cornerType: CornerType.BEVELED, + shapePositions: volumeShape, + ellipsoid : Ellipsoid.UNIT_SPHERE, + granularity : 0.1 + }); + var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.1]; + createPackableSpecs(PolylineVolumeGeometry, volume, packedInstance); }); diff --git a/Specs/Core/PolylineVolumeOutlineGeometrySpec.js b/Specs/Core/PolylineVolumeOutlineGeometrySpec.js index c585063da9df..8786e3476a37 100644 --- a/Specs/Core/PolylineVolumeOutlineGeometrySpec.js +++ b/Specs/Core/PolylineVolumeOutlineGeometrySpec.js @@ -3,12 +3,16 @@ defineSuite([ 'Core/PolylineVolumeOutlineGeometry', 'Core/Cartesian2', 'Core/Cartesian3', - 'Core/CornerType' + 'Core/CornerType', + 'Core/Ellipsoid', + 'Specs/createPackableSpecs' ], function( PolylineVolumeOutlineGeometry, Cartesian2, Cartesian3, - CornerType) { + CornerType, + Ellipsoid, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -140,4 +144,16 @@ defineSuite([ expect(m.attributes.position.values.length).toEqual(3 * 20 * 2); expect(m.indices.length).toEqual(2 * 20 * 2 + 8); }); + + var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)]; + var volumeShape = [new Cartesian2(0.0, 0.0), new Cartesian2(1.0, 0.0), new Cartesian2(0.0, 1.0)]; + var volume = new PolylineVolumeOutlineGeometry({ + polylinePositions : positions, + cornerType: CornerType.BEVELED, + shapePositions: volumeShape, + ellipsoid : Ellipsoid.UNIT_SPHERE, + granularity : 0.1 + }); + var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 3.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 0.1]; + createPackableSpecs(PolylineVolumeOutlineGeometry, volume, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/RectangleGeometrySpec.js b/Specs/Core/RectangleGeometrySpec.js index 4b6cd2b3877b..9305b8b7fb86 100644 --- a/Specs/Core/RectangleGeometrySpec.js +++ b/Specs/Core/RectangleGeometrySpec.js @@ -8,7 +8,8 @@ defineSuite([ 'Core/Math', 'Core/Matrix2', 'Core/Rectangle', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( RectangleGeometry, Cartesian2, @@ -18,7 +19,8 @@ defineSuite([ CesiumMath, Matrix2, Rectangle, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -234,4 +236,12 @@ defineSuite([ expect(m.indices.length).toEqual(8 * 3); }); + var rectangle = new RectangleGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + rectangle : new Rectangle(-2.0, -1.0, 0.0, 1.0), + granularity : 1.0, + ellipsoid : Ellipsoid.UNIT_SPHERE + }); + var packedInstance = [-2.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0]; + createPackableSpecs(RectangleGeometry, rectangle, packedInstance); }); diff --git a/Specs/Core/RectangleOutlineGeometrySpec.js b/Specs/Core/RectangleOutlineGeometrySpec.js index b9c467ae0517..19366caf43ac 100644 --- a/Specs/Core/RectangleOutlineGeometrySpec.js +++ b/Specs/Core/RectangleOutlineGeometrySpec.js @@ -7,7 +7,8 @@ defineSuite([ 'Core/GeographicProjection', 'Core/Math', 'Core/Matrix2', - 'Core/Rectangle' + 'Core/Rectangle', + 'Specs/createPackableSpecs' ], function( RectangleOutlineGeometry, Cartesian2, @@ -16,7 +17,8 @@ defineSuite([ GeographicProjection, CesiumMath, Matrix2, - Rectangle) { + Rectangle, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -149,4 +151,12 @@ defineSuite([ expect(m.indices.length).toEqual(8 * 2); }); + var rectangle = new RectangleOutlineGeometry({ + rectangle : new Rectangle(-2.0, -1.0, 0.0, 1.0), + granularity : 1.0, + ellipsoid : Ellipsoid.UNIT_SPHERE + }); + var packedInstance = [-2.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0]; + createPackableSpecs(RectangleOutlineGeometry, rectangle, packedInstance); + }); diff --git a/Specs/Core/RectangleSpec.js b/Specs/Core/RectangleSpec.js index 6a5fbf0010af..0b0a3b4e6d79 100644 --- a/Specs/Core/RectangleSpec.js +++ b/Specs/Core/RectangleSpec.js @@ -4,13 +4,15 @@ defineSuite([ 'Core/Cartesian3', 'Core/Cartographic', 'Core/Ellipsoid', - 'Core/Math' + 'Core/Math', + 'Specs/createPackableSpecs' ], function( Rectangle, Cartesian3, Cartographic, Ellipsoid, - CesiumMath) { + CesiumMath, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -641,4 +643,8 @@ defineSuite([ Rectangle.contains(rectangle, undefined); }).toThrowDeveloperError(); }); + + var rectangle = new Rectangle(west, south, east, north); + var packedInstance = [west, south, east, north]; + createPackableSpecs(Rectangle, rectangle, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/SimplePolylineGeometrySpec.js b/Specs/Core/SimplePolylineGeometrySpec.js index 248cc3e19535..c177c6b72052 100644 --- a/Specs/Core/SimplePolylineGeometrySpec.js +++ b/Specs/Core/SimplePolylineGeometrySpec.js @@ -6,7 +6,8 @@ defineSuite([ 'Core/Color', 'Core/Ellipsoid', 'Core/Math', - 'Core/PrimitiveType' + 'Core/PrimitiveType', + 'Specs/createPackableSpecs' ], function( SimplePolylineGeometry, BoundingSphere, @@ -14,7 +15,8 @@ defineSuite([ Color, Ellipsoid, CesiumMath, - PrimitiveType) { + PrimitiveType, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -132,4 +134,14 @@ defineSuite([ var numVertices = positions.length; expect(line.attributes.color.values.length).toEqual(numVertices * 4); }); + + var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)]; + var line = new SimplePolylineGeometry({ + positions : positions, + ellipsoid : Ellipsoid.UNIT_SPHERE, + granularity : 0.1, + followSurface: false + }); + var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.1]; + createPackableSpecs(SimplePolylineGeometry, line, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/SphereGeometrySpec.js b/Specs/Core/SphereGeometrySpec.js index d900739e1110..180363a22b8f 100644 --- a/Specs/Core/SphereGeometrySpec.js +++ b/Specs/Core/SphereGeometrySpec.js @@ -3,12 +3,14 @@ defineSuite([ 'Core/SphereGeometry', 'Core/Cartesian3', 'Core/Math', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( SphereGeometry, Cartesian3, CesiumMath, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -82,4 +84,13 @@ defineSuite([ expect(binormal).toEqualEpsilon(Cartesian3.cross(normal, tangent, normal), CesiumMath.EPSILON7); } }); + + var sphere = new SphereGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + radius : 1, + stackPartitions : 3, + slicePartitions: 3 + }); + var packedInstance = [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 3.0]; + createPackableSpecs(SphereGeometry, sphere, packedInstance); }); diff --git a/Specs/Core/SphereOutlineGeometrySpec.js b/Specs/Core/SphereOutlineGeometrySpec.js index 20e3f25bbd66..dc84af78a0bc 100644 --- a/Specs/Core/SphereOutlineGeometrySpec.js +++ b/Specs/Core/SphereOutlineGeometrySpec.js @@ -1,8 +1,10 @@ /*global defineSuite*/ defineSuite([ - 'Core/SphereOutlineGeometry' + 'Core/SphereOutlineGeometry', + 'Specs/createPackableSpecs' ], function( - SphereOutlineGeometry) { + SphereOutlineGeometry, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ it('constructor throws if stackPartitions less than 1', function() { @@ -40,4 +42,13 @@ defineSuite([ expect(m.indices.length).toEqual(6 * 2); expect(m.boundingSphere.radius).toEqual(1); }); + + var sphere = new SphereOutlineGeometry({ + radius : 1, + stackPartitions : 3, + slicePartitions: 3, + subdivisions: 2 + }); + var packedInstance = [1.0, 1.0, 1.0, 3.0, 3.0, 2.0]; + createPackableSpecs(SphereOutlineGeometry, sphere, packedInstance); }); \ No newline at end of file diff --git a/Specs/Core/VertexFormatSpec.js b/Specs/Core/VertexFormatSpec.js new file mode 100644 index 000000000000..95e27689287c --- /dev/null +++ b/Specs/Core/VertexFormatSpec.js @@ -0,0 +1,33 @@ +/*global defineSuite*/ +defineSuite([ + 'Core/VertexFormat', + 'Specs/createPackableSpecs' + ], function( + VertexFormat, + createPackableSpecs) { + "use strict"; + /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ + + it('clone', function() { + var vertexFormat = new VertexFormat({ + position : true, + normal : true + }); + var cloned = VertexFormat.clone(vertexFormat); + expect(cloned instanceof VertexFormat).toBe(true); + expect(cloned).toEqual(vertexFormat); + }); + + it('clone uses result parameter if provided', function() { + var vertexFormat = new VertexFormat({ + position : true, + normal : true + }); + var result = new VertexFormat(); + var cloned = VertexFormat.clone(vertexFormat, result); + expect(cloned).toBe(result); + expect(cloned).toEqual(vertexFormat); + }); + + createPackableSpecs(VertexFormat, VertexFormat.POSITION_AND_NORMAL, [1.0, 1.0, 0.0, 0.0, 0.0, 0.0]); +}); diff --git a/Specs/Core/WallGeometrySpec.js b/Specs/Core/WallGeometrySpec.js index d54fa6864b3d..be36eb936314 100644 --- a/Specs/Core/WallGeometrySpec.js +++ b/Specs/Core/WallGeometrySpec.js @@ -4,13 +4,15 @@ defineSuite([ 'Core/Cartesian3', 'Core/Ellipsoid', 'Core/Math', - 'Core/VertexFormat' + 'Core/VertexFormat', + 'Specs/createPackableSpecs' ], function( WallGeometry, Cartesian3, Ellipsoid, CesiumMath, - VertexFormat) { + VertexFormat, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -222,5 +224,15 @@ defineSuite([ cartographic = ellipsoid.cartesianToCartographic(Cartesian3.fromArray(positions, 9)); expect(cartographic.height).toEqualEpsilon(max, CesiumMath.EPSILON8); }); + + var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)]; + var wall = new WallGeometry({ + positions : positions, + vertexFormat : VertexFormat.POSITION_ONLY, + granularity : 0.01, + ellipsoid: Ellipsoid.UNIT_SPHERE + }); + var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01]; + createPackableSpecs(WallGeometry, wall, packedInstance); }); diff --git a/Specs/Core/WallOutlineGeometrySpec.js b/Specs/Core/WallOutlineGeometrySpec.js index c58ab150a937..f724b7c06a92 100644 --- a/Specs/Core/WallOutlineGeometrySpec.js +++ b/Specs/Core/WallOutlineGeometrySpec.js @@ -3,12 +3,14 @@ defineSuite([ 'Core/WallOutlineGeometry', 'Core/Cartesian3', 'Core/Ellipsoid', - 'Core/Math' + 'Core/Math', + 'Specs/createPackableSpecs' ], function( WallOutlineGeometry, Cartesian3, Ellipsoid, - CesiumMath) { + CesiumMath, + createPackableSpecs) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -165,5 +167,14 @@ defineSuite([ cartographic = ellipsoid.cartesianToCartographic(Cartesian3.fromArray(positions, 9)); expect(cartographic.height).toEqualEpsilon(max, CesiumMath.EPSILON8); }); + + var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)]; + var wall = new WallOutlineGeometry({ + positions : positions, + granularity : 0.01, + ellipsoid: Ellipsoid.UNIT_SPHERE + }); + var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.01]; + createPackableSpecs(WallOutlineGeometry, wall, packedInstance); }); diff --git a/Specs/createPackableSpecs.js b/Specs/createPackableSpecs.js index 6b83617af716..14bbb9fdef84 100644 --- a/Specs/createPackableSpecs.js +++ b/Specs/createPackableSpecs.js @@ -1,13 +1,17 @@ /*global define*/ -define(function() { +define(['Core/defined'], function(defined) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ function createPackableSpecs(packable, instance, packedInstance) { + instance = JSON.parse(JSON.stringify(instance)); + packedInstance = JSON.parse(JSON.stringify(packedInstance)); + it('can pack', function() { var packedArray = []; packable.pack(instance, packedArray); - expect(packedArray.length).toEqual(packable.packedLength); + var packedLength = defined(packable.packedLength) ? packable.packedLength : instance.packedLength; + expect(packedArray.length).toEqual(packedLength); expect(packedArray).toEqual(packedInstance); });