From 8db80fb9b12cfaa1d572143133619f782c8ee89c Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 18 Dec 2014 19:03:11 -0500 Subject: [PATCH 01/22] Make Ellipsoid and VertexFormat implement packable in order to make geometries packable. --- Source/Core/BoundingSphere.js | 2 +- Source/Core/Ellipsoid.js | 49 +++++++++++++++++++++++++ Source/Core/VertexFormat.js | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) 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/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/VertexFormat.js b/Source/Core/VertexFormat.js index 3fdc13441cf9..9d4901c6bfc1 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,68 @@ 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; + }; + return VertexFormat; }); \ No newline at end of file From 5c976c61f966b8dae72e7a67208dfe3e659a4602 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 18 Dec 2014 19:15:57 -0500 Subject: [PATCH 02/22] Make box, circle, corridor, cylinder, and ellipse fill/outline geometries packable. --- Source/Core/BoxGeometry.js | 67 +++++++++++++++ Source/Core/BoxOutlineGeometry.js | 63 ++++++++++++++ Source/Core/CircleGeometry.js | 51 +++++++++++ Source/Core/CircleOutlineGeometry.js | 50 +++++++++++ Source/Core/CorridorGeometry.js | 112 ++++++++++++++++++++++++- Source/Core/CorridorOutlineGeometry.js | 101 +++++++++++++++++++++- Source/Core/CylinderGeometry.js | 78 +++++++++++++++++ Source/Core/CylinderOutlineGeometry.js | 74 ++++++++++++++++ Source/Core/EllipseGeometry.js | 110 ++++++++++++++++++++++++ Source/Core/EllipseOutlineGeometry.js | 102 ++++++++++++++++++++++ 10 files changed, 805 insertions(+), 3 deletions(-) diff --git a/Source/Core/BoxGeometry.js b/Source/Core/BoxGeometry.js index 755c6542d843..0567e2616086 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,72 @@ 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); + }; + + /** + * 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); + var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength); + var vertexFormat = VertexFormat.unpack(array, startingIndex + 2 * Cartesian3.packedLength); + + if (!defined(result)) { + return new BoxGeometry({ + minimumCorner : min, + maximumCorner : max, + vertexFormat : vertexFormat + }); + } + + result._minimumCorner = min; + result._maximumCorner = max; + result._vertexFormat = 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..5046dfc8b2f7 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,68 @@ 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._minimumCorner, array, startingIndex); + Cartesian3.pack(value._maximumCorner, array, startingIndex + Cartesian3.packedLength); + }; + + /** + * 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); + var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength); + + if (!defined(result)) { + return new BoxOutlineGeometry({ + minimumCorner : min, + maximumCorner : max + }); + } + + result._minimumCorner = min; + result._maximumCorner = 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..442093c75e77 100644 --- a/Source/Core/CircleGeometry.js +++ b/Source/Core/CircleGeometry.js @@ -31,6 +31,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 +71,56 @@ 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); + }; + + /** + * 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); + + if (!defined(result)) { + return new CircleGeometry({ + center : ellipseGeometry._center, + radius : ellipseGeometry._semiMajorAxis, + ellipsoid : ellipseGeometry._ellipsoid, + height : ellipseGeometry._height, + extrudedHeight : ellipseGeometry._extrudedHeight, + granularity : ellipseGeometry._granularity, + vertexFormat : ellipseGeometry._vertexFormat, + stRotation : ellipseGeometry._stRotation + }); + } + + result._ellipseGeometry = ellipseGeometry; + 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..06cbe5fcc70a 100644 --- a/Source/Core/CircleOutlineGeometry.js +++ b/Source/Core/CircleOutlineGeometry.js @@ -30,6 +30,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 +69,55 @@ 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); + }; + + /** + * 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); + + if (!defined(result)) { + return new CircleOutlineGeometry({ + center : ellipseGeometry._center, + radius : ellipseGeometry._semiMajorAxis, + ellipsoid : ellipseGeometry._ellipsoid, + height : ellipseGeometry._height, + extrudedHeight : ellipseGeometry._extrudedHeight, + granularity : ellipseGeometry._granularity, + numberOfVerticalLines : ellipseGeometry._numberOfVerticalLines + }); + } + + result._ellipseGeometry = ellipseGeometry; + 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..e2ad04783787 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,121 @@ define([ //>>includeEnd('debug'); this._positions = positions; - this._width = width; this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + this._width = width; 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; + }; + + /** + * 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); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex); + 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)) { + return new CorridorGeometry({ + positions : positions, + ellipsoid : ellipsoid, + vertexFormat : vertexFormat, + width : width, + height : height, + extrudedHeight : extrudedHeight, + cornerType : cornerType, + granularity : granularity + }); + } + + result._positions = positions; + result._ellipsoid = ellipsoid; + result._vertexFormat = 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..9d316de01e5a 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -340,13 +340,112 @@ define([ //>>includeEnd('debug'); this._positions = positions; - this._width = width; this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._width = width; 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; + }; + + /** + * 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); + 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)) { + return new CorridorOutlineGeometry({ + positions : positions, + ellipsoid : ellipsoid, + width : width, + height : height, + extrudedHeight : extrudedHeight, + cornerType : cornerType, + granularity : granularity + }); + } + + result._positions = positions; + result._ellipsoid = 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..5b65fe954bdf 100644 --- a/Source/Core/CylinderGeometry.js +++ b/Source/Core/CylinderGeometry.js @@ -107,6 +107,84 @@ define([ 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; + }; + + /** + * 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); + startingIndex += VertexFormat.packedLength; + + var length = array[startingIndex++]; + var topRadius = array[startingIndex++]; + var bottomRadius = array[startingIndex++]; + var slices = array[startingIndex]; + + if (!defined(result)) { + return new CylinderGeometry({ + vertexFormat : vertexFormat, + length : length, + topRadius : topRadius, + bottomRadius : bottomRadius, + slices : slices + }); + } + + result._vertexFormat = 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..338c5bbf63f4 100644 --- a/Source/Core/CylinderOutlineGeometry.js +++ b/Source/Core/CylinderOutlineGeometry.js @@ -98,6 +98,80 @@ 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; + }; + + /** + * 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)) { + return new CylinderOutlineGeometry({ + length : length, + topRadius : topRadius, + bottomRadius : bottomRadius, + slices : slices, + numberOfVerticalLines : numberOfVerticalLines + }); + } + + 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..1651385044e2 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -632,6 +632,116 @@ define([ 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; + }; + + /** + * 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); + startingIndex += Cartesian3.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex); + 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)) { + return new EllipseGeometry({ + center : center, + ellipsoid : ellipsoid, + vertexFormat : vertexFormat, + semiMajorAxis : semiMajorAxis, + semiMinorAxis : semiMinorAxis, + rotation : rotation, + stRotation : stRotation, + height : height, + granularity : granularity, + extrudedHeight : extrudedHeight, + extrude : extrude + }); + } + + result._center = center; + result._ellipsoid = ellipsoid; + result._vertexFormat = 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..e4d7a45d3e36 100644 --- a/Source/Core/EllipseOutlineGeometry.js +++ b/Source/Core/EllipseOutlineGeometry.js @@ -206,6 +206,108 @@ define([ 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; + }; + + /** + * 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); + startingIndex += Cartesian3.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex); + 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)) { + return new EllipseOutlineGeometry({ + center : center, + ellipsoid : ellipsoid, + semiMajorAxis : semiMajorAxis, + semiMinorAxis : semiMinorAxis, + rotation : rotation, + height : height, + granularity : granularity, + extrudedHeight : extrudedHeight, + extrude : extrude, + numberOfVerticalLines : numberOfVerticalLines + }); + } + + result._center = center; + result._ellipsoid = 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. * From 64aa675597aa760db2fd00a4b322e364ea6a05f7 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 18 Dec 2014 20:24:51 -0500 Subject: [PATCH 03/22] Make ellipsoid and polygon fill/outline geometries implement packable. --- Source/Core/EllipsoidGeometry.js | 80 ++++++++++++++++++++ Source/Core/EllipsoidOutlineGeometry.js | 76 +++++++++++++++++++ Source/Core/PolygonGeometry.js | 99 +++++++++++++++++++++++++ Source/Core/PolygonGeometryLibrary.js | 80 ++++++++++++++++++++ Source/Core/PolygonOutlineGeometry.js | 87 ++++++++++++++++++++++ 5 files changed, 422 insertions(+) diff --git a/Source/Core/EllipsoidGeometry.js b/Source/Core/EllipsoidGeometry.js index 0a13c31d3556..d6acc2912173 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, @@ -91,6 +93,84 @@ define([ 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; + }; + + /** + * 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); + startingIndex += Cartesian3.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex); + startingIndex += VertexFormat.packedLength; + + var stackPartitions = array[startingIndex++]; + var slicePartitions = array[startingIndex]; + + if (!defined(result)) { + return new EllipsoidGeometry({ + radii : radii, + vertexFormat : vertexFormat, + stackPartitions : stackPartitions, + slicePartitions : slicePartitions + }); + } + + result._radii = radii; + result._vertexFormat = 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..9cc8f5f2cbfa 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,80 @@ 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; + }; + + /** + * 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); + startingIndex += Cartesian3.packedLength; + + var stackPartitions = array[startingIndex++]; + var slicePartitions = array[startingIndex++]; + var subdivisions = array[startingIndex++]; + + if (!defined(result)) { + return new EllipsoidOutlineGeometry({ + radii : radii, + stackPartitions : stackPartitions, + slicePartitions : slicePartitions, + subdivisions : subdivisions + }); + } + + result._radii = 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 c672daca3c5b..32bb9f373677 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -638,6 +638,12 @@ define([ 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,99 @@ 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); + + PolygonGeometryLibrary.pack(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; + }; + + /** + * 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); + + var ellipsoid = Ellipsoid.unpack(array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex); + 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)) { + return new PolygonGeometry({ + polygonHierarchy : polygonHierarchy, + ellipsoid : ellipsoid, + vertexFormat : vertexFormat, + height : height, + extrudedHeight : extrudedHeight, + granularity : granularity, + stRotation : stRotation, + perPositionHeight : perPositionHeight + }); + } + + result._polygonHierarchy = polygonHierarchy; + result._ellipsoid = ellipsoid; + result._vertexFormat = 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 b851e5a8bae4..9cb926940068 100644 --- a/Source/Core/PolygonGeometryLibrary.js +++ b/Source/Core/PolygonGeometryLibrary.js @@ -16,6 +16,86 @@ 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.pack = 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]); + } + } + } + }; + + 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[i] = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + } + + return { + positions : positions, + holes : holes + }; + }; + 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..ec3a0af1f9be 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -329,6 +329,93 @@ define([ 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); + + PolygonGeometryLibrary.pack(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; + }; + + /** + * 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); + + var ellipsoid = Ellipsoid.unpack(array, startingIndex); + 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)) { + return new PolygonOutlineGeometry({ + polygonHierarchy : polygonHierarchy, + ellipsoid : ellipsoid, + height : height, + extrudedHeight : extrudedHeight, + granularity : granularity, + perPositionHeight : perPositionHeight + }); + } + + result._polygonHierarchy = polygonHierarchy; + result._ellipsoid = ellipsoid; + result._height = height; + result._extrudedHeight = extrudedHeight; + result._granularity = granularity; + result._extrude = extrude; + result._perPositionHeight = perPositionHeight; + + return result; }; /** From 2308c57565c3ab309c4d61b911858940d58f7cc7 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 18 Dec 2014 20:44:13 -0500 Subject: [PATCH 04/22] Make polyline, simple polyline, sphere and sphere outline geometries implement packable. --- Source/Core/PolylineGeometry.js | 127 ++++++++++++++++++++++++++ Source/Core/SimplePolylineGeometry.js | 115 +++++++++++++++++++++++ Source/Core/SphereGeometry.js | 55 +++++++++++ Source/Core/SphereOutlineGeometry.js | 55 +++++++++++ 4 files changed, 352 insertions(+) diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index f9f1a900c6ff..a587c39d3781 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -138,6 +138,133 @@ define([ this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); this._workerName = 'createPolylineGeometry'; + + var numComponents = 1 + positions.length * Cartesian3.packedLength; + numComponents = 1 + colors.length * Color.packedLength; + + /** + * 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 = colors.length; + 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; + }; + + /** + * 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 = new Array(length); + + 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 vertexFormat = VertexFormat.unpack(array, startingIndex); + 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)) { + return new PolylineGeometry({ + positions : positions, + colors : colors, + ellipsoid : ellipsoid, + vertexFormat : vertexFormat, + width : width, + perVertex : perVertex, + followSurface : followSurface, + granularity : granularity + }); + } + + result._positions = positions; + result._colors = colors; + result._ellipsoid = ellipsoid; + result._vertexFormat = vertexFormat; + result._width = width; + result._perVertex = perVertex; + result._followSurface = followSurface; + result._granularity = granularity; + + return result; }; var scratchCartesian3 = new Cartesian3(); diff --git a/Source/Core/SimplePolylineGeometry.js b/Source/Core/SimplePolylineGeometry.js index d02b9f3661b2..3e4e2ed64d1b 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 = 1 + colors.length * Color.packedLength; + + /** + * 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 = colors.length; + 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 = new Array(length); + + 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..36c17a923d9f 100644 --- a/Source/Core/SphereGeometry.js +++ b/Source/Core/SphereGeometry.js @@ -2,10 +2,14 @@ define([ './Cartesian3', './defaultValue', + './defined', + './DeveloperError', './EllipsoidGeometry' ], function( Cartesian3, defaultValue, + defined, + DeveloperError, EllipsoidGeometry) { "use strict"; @@ -49,6 +53,57 @@ 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); + }; + + /** + * 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); + + if (!defined(result)) { + return new SphereGeometry({ + radius : ellipsoidGeometry._radii.x, + vertexFormat : ellipsoidGeometry._vertexFormat, + stackPartitions : ellipsoidGeometry._stackPartitions, + slicePartitions : ellipsoidGeometry._slicePartitions + }); + } + + result._radius = ellipsoidGeometry._radii.x; + result._vertexFormat = ellipsoidGeometry._vertexFormat; + result._stackPartitions = ellipsoidGeometry._stackPartitions; + result._slicePartitions = ellipsoidGeometry._slicePartitions; + + 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..fe7dc139553b 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,57 @@ 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); + }; + + /** + * 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); + + if (!defined(result)) { + return new SphereOutlineGeometry({ + radius : ellipsoidGeometry._radii.x, + stackPartitions : ellipsoidGeometry._stackPartitions, + slicePartitions : ellipsoidGeometry._slicePartitions, + subdivisions : ellipsoidGeometry._subdivisions + }); + } + + result._radius = ellipsoidGeometry._radii.x; + result._stackPartitions = ellipsoidGeometry._stackPartitions; + result._slicePartitions = ellipsoidGeometry._slicePartitions; + result._subdivisions = ellipsoidGeometry._subdivisions; + + return result; + }; + /** * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere. * From 86eac1336e94874f00a65ca099dfcfd375e6ba14 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 18 Dec 2014 22:20:09 -0500 Subject: [PATCH 05/22] Make Rectangle implement packable. --- Source/Core/Rectangle.js | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Source/Core/Rectangle.js b/Source/Core/Rectangle.js index 215c9f1efa66..6f0f93f0c382 100644 --- a/Source/Core/Rectangle.js +++ b/Source/Core/Rectangle.js @@ -92,6 +92,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. From fb59f28729d28248ee2fe84133d6bf2e07d0cd93 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 18 Dec 2014 23:16:54 -0500 Subject: [PATCH 06/22] Make polyline volume, rectangle, and wall fill/outline geometries implement the packable interface. --- Source/Core/PolylineVolumeGeometry.js | 129 +++++++++++++++- Source/Core/PolylineVolumeOutlineGeometry.js | 115 +++++++++++++++ Source/Core/RectangleGeometry.js | 105 +++++++++++++ Source/Core/RectangleOutlineGeometry.js | 85 +++++++++++ Source/Core/WallGeometry.js | 147 +++++++++++++++++++ Source/Core/WallOutlineGeometry.js | 139 ++++++++++++++++++ 6 files changed, 719 insertions(+), 1 deletion(-) diff --git a/Source/Core/PolylineVolumeGeometry.js b/Source/Core/PolylineVolumeGeometry.js index b5e62f2bbed2..9b4c4b503799 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,7 +184,7 @@ 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. @@ -232,6 +236,129 @@ define([ this._vertexFormat = 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 + 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. + */ + 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._height; + array[startingIndex++] = value._cornerType; + 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 {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); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex); + startingIndex += VertexFormat.packedLength; + + var height = array[startingIndex++]; + var cornerType = array[startingIndex++]; + var granularity = array[startingIndex]; + + if (!defined(result)) { + return new PolylineVolumeGeometry({ + positions : positions, + shape : shape, + ellipsoid : ellipsoid, + vertexFormat : vertexFormat, + height : height, + cornerType : cornerType, + granularity : granularity + }); + } + + result._positions = positions; + result._shape = shape; + result._ellipsoid = ellipsoid; + result._vertexFormat = vertexFormat; + result._height = height; + 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..d9c4e1de465e 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, @@ -144,6 +148,117 @@ define([ 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; + }; + + /** + * 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); + startingIndex += Ellipsoid.packedLength; + + var cornerType = array[startingIndex++]; + var granularity = array[startingIndex]; + + if (!defined(result)) { + return new PolylineVolumeOutlineGeometry({ + positions : positions, + shape : shape, + ellipsoid : ellipsoid, + cornerType : cornerType, + granularity : granularity + }); + } + + result._positions = positions; + result._shape = shape; + result._ellipsoid = ellipsoid; + result._cornerType = cornerType; + result._granularity = granularity; + + return result; }; var brScratch = new BoundingRectangle(); diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 2b775f07dcd1..0d2cc7c2a3f2 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -577,6 +577,111 @@ define([ 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 + 7; + + /** + * 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._closeTop ? 1.0 : 0.0; + array[startingIndex] = value._closeBottom ? 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 {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); + startingIndex += Rectangle.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.pack(array, startingIndex); + startingIndex += VertexFormat.packedLength; + + var granularity = array[startingIndex++]; + var surfaceHeight = array[startingIndex++]; + var rotation = array[startingIndex++]; + var stRotation = array[startingIndex++]; + var extrudedHeight = array[startingIndex++]; + var closeTop = array[startingIndex++] === 1.0; + var closeBottom = array[startingIndex] === 1.0; + + if (!defined(result)) { + return new RectangleGeometry({ + rectangle : rectangle, + ellipsoid : ellipsoid, + vertexFormat : vertexFormat, + granularity : granularity, + surfaceHeight : surfaceHeight, + rotation : rotation, + stRotation : stRotation, + extrudedHeight : extrudedHeight, + closeTop : closeTop, + closeBottom : closeBottom + }); + } + + result._rectangle = rectangle; + result._ellipsoid = ellipsoid; + result._vertexFormat = vertexFormat; + result._surfaceHeight = surfaceHeight; + result._rotation = rotation; + result._stRotation = stRotation; + result._extrudedHeight = extrudedHeight; + result._closeTop = closeTop; + result._closeBottom = closeBottom; + + return result; + }; + var textureMatrixScratch = new Matrix2(); var tangentRotationMatrixScratch = new Matrix3(); var nwScratch = new Cartographic(); diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index bf2b4eb8e279..1104ea1b94f3 100644 --- a/Source/Core/RectangleOutlineGeometry.js +++ b/Source/Core/RectangleOutlineGeometry.js @@ -221,6 +221,91 @@ define([ 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; + }; + + /** + * 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); + startingIndex += Rectangle.packedLength; + + var ellipsoid = Ellipsoid.unpack(array, startingIndex); + startingIndex += Ellipsoid.packedLength; + + var granularity = array[startingIndex++]; + var surfaceHeight = array[startingIndex++]; + var rotation = array[startingIndex++]; + var extrudedHeight = array[startingIndex]; + + if (!defined(result)) { + return new RectangleOutlineGeometry({ + rectangle : rectangle, + ellipsoid : ellipsoid, + granularity : granularity, + surfaceHeight : surfaceHeight, + rotation : rotation, + extrudedHeight : extrudedHeight + }); + } + + result._rectangle = rectangle; + result._ellipsoid = ellipsoid; + result._surfaceHeight = surfaceHeight; + 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/WallGeometry.js b/Source/Core/WallGeometry.js index b3626d02e8a7..d5dea4bfab71 100644 --- a/Source/Core/WallGeometry.js +++ b/Source/Core/WallGeometry.js @@ -110,6 +110,153 @@ define([ this._granularity = granularity; this._ellipsoid = 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; + }; + + /** + * 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); + startingIndex += Ellipsoid.packedLength; + + var vertexFormat = VertexFormat.unpack(array, startingIndex); + startingIndex += VertexFormat.packedLength; + + var granularity = array[startingIndex]; + + if (!defined(result)) { + return new WallGeometry({ + positions : positions, + minimumHeights : minimumHeights, + maximumHeights : maximumHeights, + ellipsoid : ellipsoid, + vertexFormat : vertexFormat, + granularity : granularity + }); + } + + result._positions = positions; + result._minimumHeights = minimumHeights; + result._maximumHeights = maximumHeights; + result._ellipsoid = ellipsoid; + result._vertexFormat = vertexFormat; + result._granularity = granularity; + + return result; }; /** diff --git a/Source/Core/WallOutlineGeometry.js b/Source/Core/WallOutlineGeometry.js index 375cb4f9d1da..cfa7d460280e 100644 --- a/Source/Core/WallOutlineGeometry.js +++ b/Source/Core/WallOutlineGeometry.js @@ -99,6 +99,145 @@ define([ this._granularity = granularity; this._ellipsoid = 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. + */ + 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; + + 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 {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); + startingIndex += Ellipsoid.packedLength; + + var granularity = array[startingIndex]; + + if (!defined(result)) { + return new WallGeometry({ + positions : positions, + minimumHeights : minimumHeights, + maximumHeights : maximumHeights, + ellipsoid : ellipsoid, + granularity : granularity + }); + } + + result._positions = positions; + result._minimumHeights = minimumHeights; + result._maximumHeights = maximumHeights; + result._ellipsoid = ellipsoid; + result._granularity = granularity; + + return result; }; /** From 56e147d849c219fa3790edc104336d88e97d0aed Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 22 Dec 2014 16:20:26 -0500 Subject: [PATCH 07/22] Add packable tests for bounding sphere, ellipsoid and vertex format. Also added packable tests for box, circle and ellipse fill/outline geometries. --- Source/Core/BoxOutlineGeometry.js | 8 ++++---- Source/Core/EllipseGeometry.js | 2 +- Source/Core/EllipseOutlineGeometry.js | 2 +- Source/Core/PolylineGeometry.js | 2 +- Source/Core/WallOutlineGeometry.js | 8 ++++---- Specs/Core/BoundingSphereSpec.js | 8 ++++++-- Specs/Core/BoxGeometrySpec.js | 12 ++++++++++-- Specs/Core/BoxOutlineGeometrySpec.js | 11 +++++++++-- Specs/Core/CircleGeometrySpec.js | 19 +++++++++++++++++-- Specs/Core/CircleOutlineGeometrySpec.js | 18 ++++++++++++++++-- Specs/Core/EllipseGeometrySpec.js | 21 +++++++++++++++++++-- Specs/Core/EllipseOutlineGeometrySpec.js | 19 +++++++++++++++++-- Specs/Core/EllipsoidSpec.js | 8 ++++++-- Specs/Core/VertexFormatSpec.js | 12 ++++++++++++ Specs/createPackableSpecs.js | 5 ++++- 15 files changed, 127 insertions(+), 28 deletions(-) create mode 100644 Specs/Core/VertexFormatSpec.js diff --git a/Source/Core/BoxOutlineGeometry.js b/Source/Core/BoxOutlineGeometry.js index 5046dfc8b2f7..5847e163944c 100644 --- a/Source/Core/BoxOutlineGeometry.js +++ b/Source/Core/BoxOutlineGeometry.js @@ -132,8 +132,8 @@ define([ startingIndex = defaultValue(startingIndex, 0); - Cartesian3.pack(value._minimumCorner, array, startingIndex); - Cartesian3.pack(value._maximumCorner, array, startingIndex + Cartesian3.packedLength); + Cartesian3.pack(value._min, array, startingIndex); + Cartesian3.pack(value._max, array, startingIndex + Cartesian3.packedLength); }; /** @@ -162,8 +162,8 @@ define([ }); } - result._minimumCorner = min; - result._maximumCorner = max; + result._min = min; + result._max = max; return result; }; diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index 1651385044e2..f140b47487b2 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -627,7 +627,7 @@ define([ this._height = height; this._granularity = granularity; this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - this._extrudedHeight = extrudedHeight; + this._extrudedHeight = defaultValue(extrudedHeight, 0.0); this._extrude = extrude; this._workerName = 'createEllipseGeometry'; }; diff --git a/Source/Core/EllipseOutlineGeometry.js b/Source/Core/EllipseOutlineGeometry.js index e4d7a45d3e36..3d921bedcc5c 100644 --- a/Source/Core/EllipseOutlineGeometry.js +++ b/Source/Core/EllipseOutlineGeometry.js @@ -200,7 +200,7 @@ define([ 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'; diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index a587c39d3781..45473a045111 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -140,7 +140,7 @@ define([ this._workerName = 'createPolylineGeometry'; var numComponents = 1 + positions.length * Cartesian3.packedLength; - numComponents = 1 + colors.length * Color.packedLength; + numComponents = defined(colors) ? 1 + colors.length * Color.packedLength : 1; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/WallOutlineGeometry.js b/Source/Core/WallOutlineGeometry.js index cfa7d460280e..f4035fe57f7d 100644 --- a/Source/Core/WallOutlineGeometry.js +++ b/Source/Core/WallOutlineGeometry.js @@ -123,7 +123,7 @@ define([ * @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) { + WallOutlineGeometry.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); if (!defined(value)) { throw new DeveloperError('value is required'); @@ -176,9 +176,9 @@ define([ * * @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. + * @param {WallOutlineGeometry} [result] The object into which to store the result. */ - WallGeometry.unpack = function(array, startingIndex, result) { + WallOutlineGeometry.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); if (!defined(array)) { throw new DeveloperError('array is required'); @@ -222,7 +222,7 @@ define([ var granularity = array[startingIndex]; if (!defined(result)) { - return new WallGeometry({ + return new WallOutlineGeometry({ positions : positions, minimumHeights : minimumHeights, maximumHeights : maximumHeights, 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/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/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/VertexFormatSpec.js b/Specs/Core/VertexFormatSpec.js new file mode 100644 index 000000000000..7bc4f4ba4e75 --- /dev/null +++ b/Specs/Core/VertexFormatSpec.js @@ -0,0 +1,12 @@ +/*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*/ + + createPackableSpecs(VertexFormat, VertexFormat.POSITION_AND_NORMAL, [1.0, 1.0, 0.0, 0.0, 0.0, 0.0]); +}); diff --git a/Specs/createPackableSpecs.js b/Specs/createPackableSpecs.js index 6b83617af716..5dc6998363cf 100644 --- a/Specs/createPackableSpecs.js +++ b/Specs/createPackableSpecs.js @@ -1,9 +1,12 @@ /*global define*/ -define(function() { +define(['Core/clone'], function(clone) { "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); From 30766efdc792608071d538ce30f576eb0a2f9cdf Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 22 Dec 2014 16:50:40 -0500 Subject: [PATCH 08/22] Add packable tests for corridor, cylinder, and ellipsoid fill/outline geometries. --- Specs/Core/CorridorGeometrySpec.js | 24 ++++++++++++++++++++-- Specs/Core/CorridorOutlineGeometrySpec.js | 23 +++++++++++++++++++-- Specs/Core/CylinderGeometrySpec.js | 16 +++++++++++++-- Specs/Core/CylinderOutlineGeometrySpec.js | 16 +++++++++++++-- Specs/Core/EllipsoidGeometrySpec.js | 15 ++++++++++++-- Specs/Core/EllipsoidOutlineGeometrySpec.js | 17 +++++++++++++-- Specs/createPackableSpecs.js | 5 +++-- 7 files changed, 102 insertions(+), 14 deletions(-) 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/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/createPackableSpecs.js b/Specs/createPackableSpecs.js index 5dc6998363cf..14bbb9fdef84 100644 --- a/Specs/createPackableSpecs.js +++ b/Specs/createPackableSpecs.js @@ -1,5 +1,5 @@ /*global define*/ -define(['Core/clone'], function(clone) { +define(['Core/defined'], function(defined) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ @@ -10,7 +10,8 @@ define(['Core/clone'], function(clone) { 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); }); From 4053cf142a4eb5fb8172ff089c4389e1c12ef190 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 22 Dec 2014 17:35:39 -0500 Subject: [PATCH 09/22] Add packable tests for polygon fill/outline geometries. --- Source/Core/PolygonGeometry.js | 6 ++- Source/Core/PolygonGeometryLibrary.js | 11 +++-- Source/Core/PolygonOutlineGeometry.js | 6 ++- Specs/Core/PolygonGeometrySpec.js | 51 +++++++++++++++++++++++- Specs/Core/PolygonOutlineGeometrySpec.js | 49 ++++++++++++++++++++++- 5 files changed, 112 insertions(+), 11 deletions(-) diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index 32bb9f373677..b7f9eccb0269 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -633,7 +633,7 @@ define([ 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; @@ -717,7 +717,7 @@ define([ startingIndex = defaultValue(startingIndex, 0); - PolygonGeometryLibrary.pack(value._polygonHierarchy, array, startingIndex); + startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(value._polygonHierarchy, array, startingIndex); Ellipsoid.pack(value._ellipsoid, array, startingIndex); startingIndex += Ellipsoid.packedLength; @@ -750,6 +750,8 @@ define([ startingIndex = defaultValue(startingIndex, 0); var polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + startingIndex = polygonHierarchy.startingIndex; + delete polygonHierarchy.startingIndex; var ellipsoid = Ellipsoid.unpack(array, startingIndex); startingIndex += Ellipsoid.packedLength; diff --git a/Source/Core/PolygonGeometryLibrary.js b/Source/Core/PolygonGeometryLibrary.js index 9cb926940068..e01b005b435f 100644 --- a/Source/Core/PolygonGeometryLibrary.js +++ b/Source/Core/PolygonGeometryLibrary.js @@ -45,7 +45,7 @@ define([ return numComponents; }; - PolygonGeometryLibrary.pack = function(polygonHierarchy, array, startingIndex) { + PolygonGeometryLibrary.packPolygonHierarchy = function(polygonHierarchy, array, startingIndex) { var stack = [polygonHierarchy]; while (stack.length > 0) { var hierarchy = stack.pop(); @@ -73,6 +73,8 @@ define([ } } } + + return startingIndex; }; PolygonGeometryLibrary.unpackPolygonHierarchy = function(array, startingIndex) { @@ -87,12 +89,15 @@ define([ } for (var j = 0; j < holesLength; ++j) { - holes[i] = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + holes[j] = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + startingIndex = holes[j].startingIndex; + delete holes[j].startingIndex; } return { positions : positions, - holes : holes + holes : holes, + startingIndex : startingIndex }; }; diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index ec3a0af1f9be..5fe805d63069 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -324,7 +324,7 @@ define([ this._ellipsoid = 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; @@ -357,7 +357,7 @@ define([ startingIndex = defaultValue(startingIndex, 0); - PolygonGeometryLibrary.pack(value._polygonHierarchy, array, startingIndex); + startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(value._polygonHierarchy, array, startingIndex); Ellipsoid.pack(value._ellipsoid, array, startingIndex); startingIndex += Ellipsoid.packedLength; @@ -386,6 +386,8 @@ define([ startingIndex = defaultValue(startingIndex, 0); var polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex); + startingIndex = polygonHierarchy.startingIndex; + delete polygonHierarchy.startingIndex; var ellipsoid = Ellipsoid.unpack(array, startingIndex); startingIndex += Ellipsoid.packedLength; 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); + }); From f4c6aeca711bb13f050f42bac622d3af3c1bdc5e Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 22 Dec 2014 19:57:38 -0500 Subject: [PATCH 10/22] Add packable tests for polyline, polyline volume and rectangle fill/outline geometries. --- Source/Core/PolylineGeometry.js | 6 +++--- Source/Core/PolylineVolumeGeometry.js | 6 +++--- Source/Core/PolylineVolumeOutlineGeometry.js | 6 +++--- Source/Core/RectangleGeometry.js | 15 +++++++------ Source/Core/RectangleOutlineGeometry.js | 5 +++-- Specs/Core/PolylineGeometrySpec.js | 17 +++++++++++++-- Specs/Core/PolylineVolumeGeometrySpec.js | 21 +++++++++++++++++-- .../Core/PolylineVolumeOutlineGeometrySpec.js | 20 ++++++++++++++++-- Specs/Core/RectangleGeometrySpec.js | 14 +++++++++++-- Specs/Core/RectangleOutlineGeometrySpec.js | 14 +++++++++++-- Specs/Core/RectangleSpec.js | 10 +++++++-- 11 files changed, 105 insertions(+), 29 deletions(-) diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index 45473a045111..4de1479e0d53 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -140,7 +140,7 @@ define([ this._workerName = 'createPolylineGeometry'; var numComponents = 1 + positions.length * Cartesian3.packedLength; - numComponents = defined(colors) ? 1 + colors.length * Color.packedLength : 1; + numComponents += defined(colors) ? 1 + colors.length * Color.packedLength : 1; /** * The number of elements used to pack the object into an array. @@ -180,7 +180,7 @@ define([ } var colors = value._colors; - length = colors.length; + length = defined(colors) ? colors.length : 0.0; array[startingIndex++] = length; for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { @@ -225,7 +225,7 @@ define([ } length = array[startingIndex++]; - var colors = new Array(length); + var colors = length > 0 ? new Array(length) : undefined; for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { colors[i] = Color.unpack(array, startingIndex); diff --git a/Source/Core/PolylineVolumeGeometry.js b/Source/Core/PolylineVolumeGeometry.js index 9b4c4b503799..55369f1716db 100644 --- a/Source/Core/PolylineVolumeGeometry.js +++ b/Source/Core/PolylineVolumeGeometry.js @@ -238,7 +238,7 @@ define([ this._workerName = 'createPolylineVolumeGeometry'; var numComponents = 1 + positions.length * Cartesian3.packedLength; - numComponents = 1 + shape.length * Cartesian2.packedLength; + numComponents += 1 + shape.length * Cartesian2.packedLength; /** * The number of elements used to pack the object into an array. @@ -340,8 +340,8 @@ define([ if (!defined(result)) { return new PolylineVolumeGeometry({ - positions : positions, - shape : shape, + polylinePositions : positions, + shapePositions : shape, ellipsoid : ellipsoid, vertexFormat : vertexFormat, height : height, diff --git a/Source/Core/PolylineVolumeOutlineGeometry.js b/Source/Core/PolylineVolumeOutlineGeometry.js index d9c4e1de465e..b4ac4187c30d 100644 --- a/Source/Core/PolylineVolumeOutlineGeometry.js +++ b/Source/Core/PolylineVolumeOutlineGeometry.js @@ -150,7 +150,7 @@ define([ this._workerName = 'createPolylineVolumeOutlineGeometry'; var numComponents = 1 + positions.length * Cartesian3.packedLength; - numComponents = 1 + shape.length * Cartesian2.packedLength; + numComponents += 1 + shape.length * Cartesian2.packedLength; /** * The number of elements used to pack the object into an array. @@ -244,8 +244,8 @@ define([ if (!defined(result)) { return new PolylineVolumeOutlineGeometry({ - positions : positions, - shape : shape, + polylinePositions : positions, + shapePositions : shape, ellipsoid : ellipsoid, cornerType : cornerType, granularity : granularity diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 0d2cc7c2a3f2..3a5fe240349d 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -550,9 +550,12 @@ 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 = defaultValue(options.extrudedHeight, surfaceHeight); + var closeTop = defaultValue(options.closeTop, true); + var closeBottom = defaultValue(options.closeBottom, true); //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { @@ -571,9 +574,9 @@ define([ this._rotation = rotation; this._stRotation = stRotation; this._vertexFormat = vertexFormat; - this._extrudedHeight = options.extrudedHeight; - this._closeTop = options.closeTop; - this._closeBottom = options.closeBottom; + this._extrudedHeight = extrudedHeight; + this._closeTop = closeTop; + this._closeBottom = closeBottom; this._workerName = 'createRectangleGeometry'; }; @@ -643,7 +646,7 @@ define([ var ellipsoid = Ellipsoid.unpack(array, startingIndex); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.pack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex); startingIndex += VertexFormat.packedLength; var granularity = array[startingIndex++]; diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index 1104ea1b94f3..44108e92ff92 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,7 +218,7 @@ define([ this._ellipsoid = ellipsoid; this._surfaceHeight = surfaceHeight; this._rotation = rotation; - this._extrudedHeight = options.extrudedHeight; + this._extrudedHeight = extrudedHeight; this._workerName = 'createRectangleOutlineGeometry'; }; 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..c11efbcb6372 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, 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..71fd1d65edd2 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, 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 From 9f0745ae02e01cd0315dd8af09a89b24d2c5d003 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 22 Dec 2014 20:13:56 -0500 Subject: [PATCH 11/22] Add packable tests for simple polyline, sphere and wall fill/outline geometries. --- Source/Core/SimplePolylineGeometry.js | 6 +++--- Source/Core/WallGeometry.js | 2 +- Specs/Core/SimplePolylineGeometrySpec.js | 16 ++++++++++++++-- Specs/Core/SphereGeometrySpec.js | 15 +++++++++++++-- Specs/Core/SphereOutlineGeometrySpec.js | 15 +++++++++++++-- Specs/Core/WallGeometrySpec.js | 16 ++++++++++++++-- Specs/Core/WallOutlineGeometrySpec.js | 15 +++++++++++++-- 7 files changed, 71 insertions(+), 14 deletions(-) diff --git a/Source/Core/SimplePolylineGeometry.js b/Source/Core/SimplePolylineGeometry.js index 3e4e2ed64d1b..203146b7a490 100644 --- a/Source/Core/SimplePolylineGeometry.js +++ b/Source/Core/SimplePolylineGeometry.js @@ -130,7 +130,7 @@ define([ this._workerName = 'createSimplePolylineGeometry'; var numComponents = 1 + positions.length * Cartesian3.packedLength; - numComponents = 1 + colors.length * Color.packedLength; + numComponents += defined(colors) ? 1 + colors.length * Color.packedLength : 1; /** * The number of elements used to pack the object into an array. @@ -170,7 +170,7 @@ define([ } var colors = value._colors; - length = colors.length; + length = defined(colors) ? colors.length : 0.0; array[startingIndex++] = length; for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { @@ -211,7 +211,7 @@ define([ } length = array[startingIndex++]; - var colors = new Array(length); + var colors = length > 0 ? new Array(length) : undefined; for (i = 0; i < length; ++i, startingIndex += Color.packedLength) { colors[i] = Color.unpack(array, startingIndex); diff --git a/Source/Core/WallGeometry.js b/Source/Core/WallGeometry.js index d5dea4bfab71..466da8a49b41 100644 --- a/Source/Core/WallGeometry.js +++ b/Source/Core/WallGeometry.js @@ -182,7 +182,7 @@ define([ VertexFormat.pack(value._vertexFormat, array, startingIndex); startingIndex += VertexFormat.packedLength; - array[startingIndex] = value._granularity; + array[startingIndex] = value._granularity; }; /** 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/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); }); From 9af7036927f9d1e5cbc21f0c52bccc41da898ec4 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 22 Dec 2014 20:26:11 -0500 Subject: [PATCH 12/22] Initial pack geometries before sending to web worker. Still needs web worker support to unpack the geometry. --- Source/Scene/Primitive.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index c9de92e5443d..bd194bd5909c 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -731,10 +731,22 @@ define([ for (i = 0; i < length; ++i) { geometry = instances[i].geometry; instanceIds.push(instances[i].id); - subTasks.push({ - moduleName : geometry._workerName, - geometry : geometry - }); + if (false/*defined(geometry.constructor.pack)*/) { + var packedLength = defined(geometry.constructor.packedLength) ? geometry.constructor.packedLength : geometry.packedLength; + var array = new Float64Array(packedLength); + geometry.constructor.pack(geometry, array); + + subTasks.push({ + moduleName : geometry._workerName, + geometry : array, + transferableObjects : [array.buffer] + }); + } else { + subTasks.push({ + moduleName : geometry._workerName, + geometry : geometry + }); + } } if (!defined(createGeometryTaskProcessors)) { @@ -748,7 +760,7 @@ define([ for (i = 0; i < subTasks.length; i++) { promises.push(createGeometryTaskProcessors[i].scheduleTask({ subTasks : subTasks[i] - })); + }, subTasks[i].transferableObjects)); } this._state = PrimitiveState.CREATING; From 8fca16c8de2bae20042f65d4d77991e5c8d10ff5 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 22 Dec 2014 22:07:24 -0500 Subject: [PATCH 13/22] Pack geometries into an array when possible before passing to a web worker. Unpack when necessary of the web worker. --- Source/Scene/Primitive.js | 2 +- Source/Workers/createBoxGeometry.js | 13 ++++++++++--- Source/Workers/createBoxOutlineGeometry.js | 13 ++++++++++--- Source/Workers/createCircleGeometry.js | 5 +++++ Source/Workers/createCircleOutlineGeometry.js | 5 +++++ Source/Workers/createCorridorGeometry.js | 5 +++++ Source/Workers/createCorridorOutlineGeometry.js | 5 +++++ Source/Workers/createCylinderGeometry.js | 13 ++++++++++--- Source/Workers/createCylinderOutlineGeometry.js | 13 ++++++++++--- Source/Workers/createEllipseGeometry.js | 5 +++++ Source/Workers/createEllipseOutlineGeometry.js | 5 +++++ Source/Workers/createEllipsoidGeometry.js | 9 ++++++++- Source/Workers/createEllipsoidOutlineGeometry.js | 9 ++++++++- Source/Workers/createPolygonGeometry.js | 5 +++++ Source/Workers/createPolygonOutlineGeometry.js | 5 +++++ Source/Workers/createPolylineGeometry.js | 5 +++++ Source/Workers/createPolylineVolumeGeometry.js | 5 +++++ .../Workers/createPolylineVolumeOutlineGeometry.js | 5 +++++ Source/Workers/createRectangleGeometry.js | 5 +++++ Source/Workers/createRectangleOutlineGeometry.js | 5 +++++ Source/Workers/createSimplePolylineGeometry.js | 5 +++++ Source/Workers/createSphereGeometry.js | 9 ++++++++- Source/Workers/createSphereOutlineGeometry.js | 9 ++++++++- Source/Workers/createWallGeometry.js | 5 +++++ Source/Workers/createWallOutlineGeometry.js | 5 +++++ 25 files changed, 153 insertions(+), 17 deletions(-) diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index bd194bd5909c..33c20be3e4fe 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -731,7 +731,7 @@ define([ for (i = 0; i < length; ++i) { geometry = instances[i].geometry; instanceIds.push(instances[i].id); - if (false/*defined(geometry.constructor.pack)*/) { + if (defined(geometry.constructor.pack)) { var packedLength = defined(geometry.constructor.packedLength) ? geometry.constructor.packedLength : geometry.packedLength; var array = new Float64Array(packedLength); geometry.constructor.pack(geometry, array); diff --git a/Source/Workers/createBoxGeometry.js b/Source/Workers/createBoxGeometry.js index 595406788f47..47f26c085aaa 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) { + if (defined(boxGeometry.buffer)) { + boxGeometry = BoxGeometry.unpack(boxGeometry); + } + return BoxGeometry.createGeometry(boxGeometry); + }; }); diff --git a/Source/Workers/createBoxOutlineGeometry.js b/Source/Workers/createBoxOutlineGeometry.js index f83503ccff09..22150ecd6869 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) { + if (defined(boxGeometry.buffer)) { + boxGeometry = BoxOutlineGeometry.unpack(boxGeometry); + } + return BoxOutlineGeometry.createGeometry(boxGeometry); + }; }); diff --git a/Source/Workers/createCircleGeometry.js b/Source/Workers/createCircleGeometry.js index dfcc164232fa..957e1ddd1b31 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) { + if (defined(circleGeometry.buffer)) { + circleGeometry = CircleGeometry.unpack(circleGeometry); + } 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..9de5d33fcfa6 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) { + if (defined(circleGeometry.buffer)) { + circleGeometry = CircleOutlineGeometry.unpack(circleGeometry); + } 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..350343717c9e 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) { + if (defined(corridorGeometry.buffer)) { + corridorGeometry = CorridorGeometry.unpack(corridorGeometry); + } corridorGeometry._ellipsoid = Ellipsoid.clone(corridorGeometry._ellipsoid); return CorridorGeometry.createGeometry(corridorGeometry); } diff --git a/Source/Workers/createCorridorOutlineGeometry.js b/Source/Workers/createCorridorOutlineGeometry.js index 91dab3bc82a7..94e29ea44c03 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) { + if (defined(corridorOutlineGeometry.buffer)) { + corridorOutlineGeometry = CorridorOutlineGeometry.unpack(corridorOutlineGeometry); + } corridorOutlineGeometry._ellipsoid = Ellipsoid.clone(corridorOutlineGeometry._ellipsoid); return CorridorOutlineGeometry.createGeometry(corridorOutlineGeometry); } diff --git a/Source/Workers/createCylinderGeometry.js b/Source/Workers/createCylinderGeometry.js index df72a1e2216b..62af53977377 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) { + if (defined(cylinderGeometry.buffer)) { + cylinderGeometry = CylinderGeometry.unpack(cylinderGeometry); + } + return CylinderGeometry.createGeometry(cylinderGeometry); + }; }); diff --git a/Source/Workers/createCylinderOutlineGeometry.js b/Source/Workers/createCylinderOutlineGeometry.js index 2b1910f24f85..361afad3d105 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) { + if (defined(cylinderGeometry.buffer)) { + cylinderGeometry = CylinderOutlineGeometry.unpack(cylinderGeometry); + } + return CylinderOutlineGeometry.createGeometry(cylinderGeometry); + }; }); diff --git a/Source/Workers/createEllipseGeometry.js b/Source/Workers/createEllipseGeometry.js index 468f637af01a..c540b2cc5db7 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) { + if (defined(ellipseGeometry.buffer)) { + ellipseGeometry = EllipseGeometry.unpack(ellipseGeometry); + } 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..f16b372b5d1c 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) { + if (defined(ellipseGeometry.buffer)) { + ellipseGeometry = EllipseOutlineGeometry.unpack(ellipseGeometry); + } 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..2d204e67d5c3 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) { + if (defined(ellipsoidGeometry.buffer)) { + ellipsoidGeometry = EllipsoidGeometry.unpack(ellipsoidGeometry); + } + return EllipsoidGeometry.createGeometry(ellipsoidGeometry); + }; }); diff --git a/Source/Workers/createEllipsoidOutlineGeometry.js b/Source/Workers/createEllipsoidOutlineGeometry.js index 680daf6966fd..488cdd2d51ab 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) { + if (defined(ellipsoidGeometry.buffer)) { + ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(ellipsoidGeometry); + } + return EllipsoidOutlineGeometry.createGeometry(ellipsoidGeometry); + }; }); diff --git a/Source/Workers/createPolygonGeometry.js b/Source/Workers/createPolygonGeometry.js index 342737e8426a..26946324a6e7 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) { + if (defined(polygonGeometry.buffer)) { + polygonGeometry = PolygonGeometry.unpack(polygonGeometry); + } polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); return PolygonGeometry.createGeometry(polygonGeometry); } diff --git a/Source/Workers/createPolygonOutlineGeometry.js b/Source/Workers/createPolygonOutlineGeometry.js index 32f359dbaa0f..7f1df76551f7 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) { + if (defined(polygonGeometry.buffer)) { + polygonGeometry = PolygonOutlineGeometry.unpack(polygonGeometry); + } polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); return PolygonOutlineGeometry.createGeometry(polygonGeometry); } diff --git a/Source/Workers/createPolylineGeometry.js b/Source/Workers/createPolylineGeometry.js index 3a116a28a0a9..75c414d44229 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) { + if (defined(polylineGeometry.buffer)) { + polylineGeometry = PolylineGeometry.unpack(polylineGeometry); + } polylineGeometry._ellipsoid = Ellipsoid.clone(polylineGeometry._ellipsoid); return PolylineGeometry.createGeometry(polylineGeometry); } diff --git a/Source/Workers/createPolylineVolumeGeometry.js b/Source/Workers/createPolylineVolumeGeometry.js index df2b5f6f2f92..106384c590c0 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) { + if (defined(polylineVolumeGeometry.buffer)) { + polylineVolumeGeometry = PolylineVolumeGeometry.unpack(polylineVolumeGeometry); + } polylineVolumeGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeGeometry._ellipsoid); return PolylineVolumeGeometry.createGeometry(polylineVolumeGeometry); } diff --git a/Source/Workers/createPolylineVolumeOutlineGeometry.js b/Source/Workers/createPolylineVolumeOutlineGeometry.js index 8831bed87e07..572d10dcfa60 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) { + if (defined(polylineVolumeOutlineGeometry.buffer)) { + polylineVolumeOutlineGeometry = PolylineVolumeOutlineGeometry.unpack(polylineVolumeOutlineGeometry); + } polylineVolumeOutlineGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeOutlineGeometry._ellipsoid); return PolylineVolumeOutlineGeometry.createGeometry(polylineVolumeOutlineGeometry); } diff --git a/Source/Workers/createRectangleGeometry.js b/Source/Workers/createRectangleGeometry.js index 245b68cd26c6..64b63491b38e 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) { + if (defined(rectangleGeometry.buffer)) { + rectangleGeometry = RectangleGeometry.unpack(rectangleGeometry); + } 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..1f9a69442359 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) { + if (defined(rectangleGeometry.buffer)) { + rectangleGeometry = RectangleOutlineGeometry.unpack(rectangleGeometry); + } 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..5242320d39c7 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) { + if (defined(simplePolylineGeometry.buffer)) { + simplePolylineGeometry = SimplePolylineGeometry.unpack(simplePolylineGeometry); + } simplePolylineGeometry._ellipsoid = Ellipsoid.clone(simplePolylineGeometry._ellipsoid); return SimplePolylineGeometry.createGeometry(simplePolylineGeometry); } diff --git a/Source/Workers/createSphereGeometry.js b/Source/Workers/createSphereGeometry.js index d3fc46e8bc6d..d56859de87c5 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) { + if (defined(sphereGeometry.buffer)) { + sphereGeometry = SphereGeometry.unpack(sphereGeometry); + } + return SphereGeometry.createGeometry(sphereGeometry); + }; }); diff --git a/Source/Workers/createSphereOutlineGeometry.js b/Source/Workers/createSphereOutlineGeometry.js index 067baf6905ba..c3cf4915e415 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) { + if (defined(sphereGeometry.buffer)) { + sphereGeometry = SphereOutlineGeometry.unpack(sphereGeometry); + } + return SphereOutlineGeometry.createGeometry(sphereGeometry); + }; }); diff --git a/Source/Workers/createWallGeometry.js b/Source/Workers/createWallGeometry.js index 8a210451bc6e..f38fdf01a38c 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) { + if (defined(wallGeometry.buffer)) { + wallGeometry = WallGeometry.unpack(wallGeometry); + } wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); return WallGeometry.createGeometry(wallGeometry); } diff --git a/Source/Workers/createWallOutlineGeometry.js b/Source/Workers/createWallOutlineGeometry.js index beb3b69453f7..835cbae82366 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) { + if (defined(wallGeometry.buffer)) { + wallGeometry = WallOutlineGeometry.unpack(wallGeometry); + } wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); return WallOutlineGeometry.createGeometry(wallGeometry); } From 87fb7669816b3160986de95ba4dc39fb09f5833a Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Tue, 30 Dec 2014 17:49:45 -0500 Subject: [PATCH 14/22] Fix ellipse and rectangle geometry when extruded. --- Source/Core/EllipseGeometry.js | 2 +- Source/Core/RectangleGeometry.js | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index f140b47487b2..8aa58f1c5d35 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -627,7 +627,7 @@ define([ this._height = height; this._granularity = granularity; this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - this._extrudedHeight = defaultValue(extrudedHeight, 0.0); + this._extrudedHeight = defaultValue(extrudedHeight, height); this._extrude = extrude; this._workerName = 'createEllipseGeometry'; }; diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 3a5fe240349d..3c42745e820e 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -553,7 +553,8 @@ define([ var rotation = defaultValue(options.rotation, 0.0); var stRotation = defaultValue(options.stRotation, 0.0); var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - var extrudedHeight = defaultValue(options.extrudedHeight, surfaceHeight); + 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); @@ -574,7 +575,8 @@ define([ this._rotation = rotation; this._stRotation = stRotation; this._vertexFormat = vertexFormat; - this._extrudedHeight = extrudedHeight; + this._extrudedHeight = defaultValue(extrudedHeight, 0.0); + this._extrude = extrude; this._closeTop = closeTop; this._closeBottom = closeBottom; this._workerName = 'createRectangleGeometry'; @@ -584,7 +586,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 7; + RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 8; /** * Stores the provided instance into the provided array. @@ -620,6 +622,7 @@ define([ 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; }; @@ -654,6 +657,7 @@ define([ 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; @@ -663,10 +667,10 @@ define([ ellipsoid : ellipsoid, vertexFormat : vertexFormat, granularity : granularity, - surfaceHeight : surfaceHeight, + height : surfaceHeight, rotation : rotation, stRotation : stRotation, - extrudedHeight : extrudedHeight, + extrudedHeight : extrude ? extrudedHeight : undefined, closeTop : closeTop, closeBottom : closeBottom }); @@ -679,6 +683,7 @@ define([ result._rotation = rotation; result._stRotation = stRotation; result._extrudedHeight = extrudedHeight; + result._extrude = extrude; result._closeTop = closeTop; result._closeBottom = closeBottom; @@ -702,6 +707,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; @@ -733,7 +739,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); From d04291823b61371f9a088c221fe30d980b106c82 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Tue, 30 Dec 2014 17:50:45 -0500 Subject: [PATCH 15/22] Pack geometries after they have been separated into sub-tasks. --- Source/Scene/Primitive.js | 52 +++++++++++++------ Source/Workers/createBoxGeometry.js | 6 +-- Source/Workers/createBoxOutlineGeometry.js | 6 +-- Source/Workers/createCircleGeometry.js | 6 +-- Source/Workers/createCircleOutlineGeometry.js | 6 +-- Source/Workers/createCorridorGeometry.js | 6 +-- .../Workers/createCorridorOutlineGeometry.js | 6 +-- Source/Workers/createCylinderGeometry.js | 6 +-- .../Workers/createCylinderOutlineGeometry.js | 6 +-- Source/Workers/createEllipseGeometry.js | 6 +-- .../Workers/createEllipseOutlineGeometry.js | 6 +-- Source/Workers/createEllipsoidGeometry.js | 6 +-- .../Workers/createEllipsoidOutlineGeometry.js | 6 +-- Source/Workers/createGeometry.js | 2 +- Source/Workers/createPolygonGeometry.js | 6 +-- .../Workers/createPolygonOutlineGeometry.js | 6 +-- Source/Workers/createPolylineGeometry.js | 6 +-- .../Workers/createPolylineVolumeGeometry.js | 6 +-- .../createPolylineVolumeOutlineGeometry.js | 6 +-- Source/Workers/createRectangleGeometry.js | 6 +-- .../Workers/createRectangleOutlineGeometry.js | 6 +-- .../Workers/createSimplePolylineGeometry.js | 6 +-- Source/Workers/createSphereGeometry.js | 6 +-- Source/Workers/createSphereOutlineGeometry.js | 6 +-- Source/Workers/createWallGeometry.js | 6 +-- Source/Workers/createWallOutlineGeometry.js | 6 +-- 26 files changed, 108 insertions(+), 90 deletions(-) diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index 33c20be3e4fe..6c4cd704a032 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -731,22 +731,10 @@ define([ for (i = 0; i < length; ++i) { geometry = instances[i].geometry; instanceIds.push(instances[i].id); - if (defined(geometry.constructor.pack)) { - var packedLength = defined(geometry.constructor.packedLength) ? geometry.constructor.packedLength : geometry.packedLength; - var array = new Float64Array(packedLength); - geometry.constructor.pack(geometry, array); - - subTasks.push({ - moduleName : geometry._workerName, - geometry : array, - transferableObjects : [array.buffer] - }); - } else { - subTasks.push({ - moduleName : geometry._workerName, - geometry : geometry - }); - } + subTasks.push({ + moduleName : geometry._workerName, + geometry : geometry + }); } if (!defined(createGeometryTaskProcessors)) { @@ -756,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 += defined(geometry.constructor.packedLength) ? 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] - }, subTasks[i].transferableObjects)); + }, subTaskTransferableObjects)); } this._state = PrimitiveState.CREATING; diff --git a/Source/Workers/createBoxGeometry.js b/Source/Workers/createBoxGeometry.js index 47f26c085aaa..aaf24fbe30ee 100644 --- a/Source/Workers/createBoxGeometry.js +++ b/Source/Workers/createBoxGeometry.js @@ -7,9 +7,9 @@ define([ defined) { "use strict"; - return function(boxGeometry) { - if (defined(boxGeometry.buffer)) { - boxGeometry = BoxGeometry.unpack(boxGeometry); + 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 22150ecd6869..0c0ac8ae76c4 100644 --- a/Source/Workers/createBoxOutlineGeometry.js +++ b/Source/Workers/createBoxOutlineGeometry.js @@ -7,9 +7,9 @@ define([ defined) { "use strict"; - return function(boxGeometry) { - if (defined(boxGeometry.buffer)) { - boxGeometry = BoxOutlineGeometry.unpack(boxGeometry); + 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 957e1ddd1b31..3eba599f2d13 100644 --- a/Source/Workers/createCircleGeometry.js +++ b/Source/Workers/createCircleGeometry.js @@ -11,9 +11,9 @@ define([ Ellipsoid) { "use strict"; - function createCircleGeometry(circleGeometry) { - if (defined(circleGeometry.buffer)) { - circleGeometry = CircleGeometry.unpack(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); diff --git a/Source/Workers/createCircleOutlineGeometry.js b/Source/Workers/createCircleOutlineGeometry.js index 9de5d33fcfa6..5df6cc94814f 100644 --- a/Source/Workers/createCircleOutlineGeometry.js +++ b/Source/Workers/createCircleOutlineGeometry.js @@ -11,9 +11,9 @@ define([ Ellipsoid) { "use strict"; - function createCircleOutlineGeometry(circleGeometry) { - if (defined(circleGeometry.buffer)) { - circleGeometry = CircleOutlineGeometry.unpack(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); diff --git a/Source/Workers/createCorridorGeometry.js b/Source/Workers/createCorridorGeometry.js index 350343717c9e..ba673a27f803 100644 --- a/Source/Workers/createCorridorGeometry.js +++ b/Source/Workers/createCorridorGeometry.js @@ -9,9 +9,9 @@ define([ Ellipsoid) { "use strict"; - function createCorridorGeometry(corridorGeometry) { - if (defined(corridorGeometry.buffer)) { - corridorGeometry = CorridorGeometry.unpack(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 94e29ea44c03..45cca03cbc43 100644 --- a/Source/Workers/createCorridorOutlineGeometry.js +++ b/Source/Workers/createCorridorOutlineGeometry.js @@ -9,9 +9,9 @@ define([ Ellipsoid) { "use strict"; - function createCorridorOutlineGeometry(corridorOutlineGeometry) { - if (defined(corridorOutlineGeometry.buffer)) { - corridorOutlineGeometry = CorridorOutlineGeometry.unpack(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 62af53977377..309ea24cd175 100644 --- a/Source/Workers/createCylinderGeometry.js +++ b/Source/Workers/createCylinderGeometry.js @@ -7,9 +7,9 @@ define([ defined) { "use strict"; - return function(cylinderGeometry) { - if (defined(cylinderGeometry.buffer)) { - cylinderGeometry = CylinderGeometry.unpack(cylinderGeometry); + 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 361afad3d105..e17895dd6608 100644 --- a/Source/Workers/createCylinderOutlineGeometry.js +++ b/Source/Workers/createCylinderOutlineGeometry.js @@ -7,9 +7,9 @@ define([ defined) { "use strict"; - return function(cylinderGeometry) { - if (defined(cylinderGeometry.buffer)) { - cylinderGeometry = CylinderOutlineGeometry.unpack(cylinderGeometry); + 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 c540b2cc5db7..626e24e3dbb3 100644 --- a/Source/Workers/createEllipseGeometry.js +++ b/Source/Workers/createEllipseGeometry.js @@ -11,9 +11,9 @@ define([ Ellipsoid) { "use strict"; - function createEllipseGeometry(ellipseGeometry) { - if (defined(ellipseGeometry.buffer)) { - ellipseGeometry = EllipseGeometry.unpack(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); diff --git a/Source/Workers/createEllipseOutlineGeometry.js b/Source/Workers/createEllipseOutlineGeometry.js index f16b372b5d1c..9a0ffe328e46 100644 --- a/Source/Workers/createEllipseOutlineGeometry.js +++ b/Source/Workers/createEllipseOutlineGeometry.js @@ -11,9 +11,9 @@ define([ Ellipsoid) { "use strict"; - function createEllipseOutlineGeometry(ellipseGeometry) { - if (defined(ellipseGeometry.buffer)) { - ellipseGeometry = EllipseOutlineGeometry.unpack(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); diff --git a/Source/Workers/createEllipsoidGeometry.js b/Source/Workers/createEllipsoidGeometry.js index 2d204e67d5c3..a5de0a49bc8d 100644 --- a/Source/Workers/createEllipsoidGeometry.js +++ b/Source/Workers/createEllipsoidGeometry.js @@ -7,9 +7,9 @@ define([ EllipsoidGeometry) { "use strict"; - return function(ellipsoidGeometry) { - if (defined(ellipsoidGeometry.buffer)) { - ellipsoidGeometry = EllipsoidGeometry.unpack(ellipsoidGeometry); + 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 488cdd2d51ab..7f720a2df884 100644 --- a/Source/Workers/createEllipsoidOutlineGeometry.js +++ b/Source/Workers/createEllipsoidOutlineGeometry.js @@ -7,9 +7,9 @@ define([ EllipsoidOutlineGeometry) { "use strict"; - return function(ellipsoidGeometry) { - if (defined(ellipsoidGeometry.buffer)) { - ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(ellipsoidGeometry); + 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 26946324a6e7..1f03cc8386af 100644 --- a/Source/Workers/createPolygonGeometry.js +++ b/Source/Workers/createPolygonGeometry.js @@ -9,9 +9,9 @@ define([ PolygonGeometry) { "use strict"; - function createPolygonGeometry(polygonGeometry) { - if (defined(polygonGeometry.buffer)) { - polygonGeometry = PolygonGeometry.unpack(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 7f1df76551f7..1c298701111e 100644 --- a/Source/Workers/createPolygonOutlineGeometry.js +++ b/Source/Workers/createPolygonOutlineGeometry.js @@ -9,9 +9,9 @@ define([ PolygonOutlineGeometry) { "use strict"; - function createPolygonOutlineGeometry(polygonGeometry) { - if (defined(polygonGeometry.buffer)) { - polygonGeometry = PolygonOutlineGeometry.unpack(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 75c414d44229..4fb72ce64831 100644 --- a/Source/Workers/createPolylineGeometry.js +++ b/Source/Workers/createPolylineGeometry.js @@ -9,9 +9,9 @@ define([ PolylineGeometry) { "use strict"; - function createPolylineGeometry(polylineGeometry) { - if (defined(polylineGeometry.buffer)) { - polylineGeometry = PolylineGeometry.unpack(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 106384c590c0..914b710246e7 100644 --- a/Source/Workers/createPolylineVolumeGeometry.js +++ b/Source/Workers/createPolylineVolumeGeometry.js @@ -9,9 +9,9 @@ define([ PolylineVolumeGeometry) { "use strict"; - function createPolylineVolumeGeometry(polylineVolumeGeometry) { - if (defined(polylineVolumeGeometry.buffer)) { - polylineVolumeGeometry = PolylineVolumeGeometry.unpack(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 572d10dcfa60..5ef898e172c2 100644 --- a/Source/Workers/createPolylineVolumeOutlineGeometry.js +++ b/Source/Workers/createPolylineVolumeOutlineGeometry.js @@ -9,9 +9,9 @@ define([ PolylineVolumeOutlineGeometry) { "use strict"; - function createPolylineVolumeOutlineGeometry(polylineVolumeOutlineGeometry) { - if (defined(polylineVolumeOutlineGeometry.buffer)) { - polylineVolumeOutlineGeometry = PolylineVolumeOutlineGeometry.unpack(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 64b63491b38e..13d87bffe571 100644 --- a/Source/Workers/createRectangleGeometry.js +++ b/Source/Workers/createRectangleGeometry.js @@ -11,9 +11,9 @@ define([ RectangleGeometry) { "use strict"; - function createRectangleGeometry(rectangleGeometry) { - if (defined(rectangleGeometry.buffer)) { - rectangleGeometry = RectangleGeometry.unpack(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); diff --git a/Source/Workers/createRectangleOutlineGeometry.js b/Source/Workers/createRectangleOutlineGeometry.js index 1f9a69442359..afa790575283 100644 --- a/Source/Workers/createRectangleOutlineGeometry.js +++ b/Source/Workers/createRectangleOutlineGeometry.js @@ -11,9 +11,9 @@ define([ RectangleOutlineGeometry) { "use strict"; - function createRectangleOutlineGeometry(rectangleGeometry) { - if (defined(rectangleGeometry.buffer)) { - rectangleGeometry = RectangleOutlineGeometry.unpack(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); diff --git a/Source/Workers/createSimplePolylineGeometry.js b/Source/Workers/createSimplePolylineGeometry.js index 5242320d39c7..6ab03361b05e 100644 --- a/Source/Workers/createSimplePolylineGeometry.js +++ b/Source/Workers/createSimplePolylineGeometry.js @@ -9,9 +9,9 @@ define([ SimplePolylineGeometry) { "use strict"; - function createSimplePolylineGeometry(simplePolylineGeometry) { - if (defined(simplePolylineGeometry.buffer)) { - simplePolylineGeometry = SimplePolylineGeometry.unpack(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 d56859de87c5..db749b945e19 100644 --- a/Source/Workers/createSphereGeometry.js +++ b/Source/Workers/createSphereGeometry.js @@ -7,9 +7,9 @@ define([ SphereGeometry) { "use strict"; - return function(sphereGeometry) { - if (defined(sphereGeometry.buffer)) { - sphereGeometry = SphereGeometry.unpack(sphereGeometry); + 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 c3cf4915e415..144a2944cc2e 100644 --- a/Source/Workers/createSphereOutlineGeometry.js +++ b/Source/Workers/createSphereOutlineGeometry.js @@ -7,9 +7,9 @@ define([ SphereOutlineGeometry) { "use strict"; - return function(sphereGeometry) { - if (defined(sphereGeometry.buffer)) { - sphereGeometry = SphereOutlineGeometry.unpack(sphereGeometry); + 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 f38fdf01a38c..8326b64f8e5f 100644 --- a/Source/Workers/createWallGeometry.js +++ b/Source/Workers/createWallGeometry.js @@ -9,9 +9,9 @@ define([ WallGeometry) { "use strict"; - function createWallGeometry(wallGeometry) { - if (defined(wallGeometry.buffer)) { - wallGeometry = WallGeometry.unpack(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 835cbae82366..fd555460b045 100644 --- a/Source/Workers/createWallOutlineGeometry.js +++ b/Source/Workers/createWallOutlineGeometry.js @@ -9,9 +9,9 @@ define([ WallOutlineGeometry) { "use strict"; - function createWallOutlineGeometry(wallGeometry) { - if (defined(wallGeometry.buffer)) { - wallGeometry = WallOutlineGeometry.unpack(wallGeometry); + function createWallOutlineGeometry(wallGeometry, offset) { + if (defined(offset)) { + wallGeometry = WallOutlineGeometry.unpack(wallGeometry, offset); } wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); return WallOutlineGeometry.createGeometry(wallGeometry); From d1ba16477eef4782f01149a3d5d072f160990e5d Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 31 Dec 2014 15:13:20 -0500 Subject: [PATCH 16/22] Updates from review: Use scratch variables when unpacking box, circle, ellipse, sphere, and ellipsoid fill/outline geometries. --- Source/Core/BoxGeometry.js | 27 +++++++----- Source/Core/BoxOutlineGeometry.js | 20 +++++---- Source/Core/CircleGeometry.js | 53 +++++++++++++++++------- Source/Core/CircleOutlineGeometry.js | 48 +++++++++++++++------ Source/Core/EllipseGeometry.js | 55 +++++++++++++++---------- Source/Core/EllipseOutlineGeometry.js | 45 ++++++++++++-------- Source/Core/EllipsoidGeometry.js | 28 ++++++++----- Source/Core/EllipsoidOutlineGeometry.js | 22 ++++++---- Source/Core/SphereGeometry.js | 35 +++++++++------- Source/Core/SphereOutlineGeometry.js | 29 +++++++------ Source/Core/VertexFormat.js | 24 +++++++++++ Source/Scene/Primitive.js | 2 +- 12 files changed, 258 insertions(+), 130 deletions(-) diff --git a/Source/Core/BoxGeometry.js b/Source/Core/BoxGeometry.js index 0567e2616086..839a520262d1 100644 --- a/Source/Core/BoxGeometry.js +++ b/Source/Core/BoxGeometry.js @@ -147,6 +147,15 @@ define([ 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. * @@ -163,21 +172,17 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var min = Cartesian3.unpack(array, startingIndex); - var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength); - var vertexFormat = VertexFormat.unpack(array, startingIndex + 2 * Cartesian3.packedLength); + 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({ - minimumCorner : min, - maximumCorner : max, - vertexFormat : vertexFormat - }); + return new BoxGeometry(scratchOptions); } - result._minimumCorner = min; - result._maximumCorner = max; - result._vertexFormat = vertexFormat; + result._minimumCorner = Cartesian3.clone(min, result._minimumCorner); + result._maximumCorner = Cartesian3.clone(max, result._maximumCorner); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); return result; }; diff --git a/Source/Core/BoxOutlineGeometry.js b/Source/Core/BoxOutlineGeometry.js index 5847e163944c..8461d0a24d39 100644 --- a/Source/Core/BoxOutlineGeometry.js +++ b/Source/Core/BoxOutlineGeometry.js @@ -136,6 +136,13 @@ define([ 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. * @@ -152,18 +159,15 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var min = Cartesian3.unpack(array, startingIndex); - var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength); + var min = Cartesian3.unpack(array, startingIndex, scratchMin); + var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength, scratchMax); if (!defined(result)) { - return new BoxOutlineGeometry({ - minimumCorner : min, - maximumCorner : max - }); + return new BoxOutlineGeometry(scratchOptions); } - result._min = min; - result._max = max; + result._min = Cartesian3.clone(min, result._min); + result._max = Cartesian3.clone(max, result._max); return result; }; diff --git a/Source/Core/CircleGeometry.js b/Source/Core/CircleGeometry.js index 442093c75e77..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"; /** @@ -94,6 +100,24 @@ define([ 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. * @@ -102,22 +126,23 @@ define([ * @param {CircleGeometry} [result] The object into which to store the result. */ CircleGeometry.unpack = function(array, startingIndex, result) { - var ellipseGeometry = EllipseGeometry.unpack(array, startingIndex); + 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)) { - return new CircleGeometry({ - center : ellipseGeometry._center, - radius : ellipseGeometry._semiMajorAxis, - ellipsoid : ellipseGeometry._ellipsoid, - height : ellipseGeometry._height, - extrudedHeight : ellipseGeometry._extrudedHeight, - granularity : ellipseGeometry._granularity, - vertexFormat : ellipseGeometry._vertexFormat, - stRotation : ellipseGeometry._stRotation - }); + scratchOptions.radius = ellipseGeometry._semiMajorAxis; + return new CircleGeometry(scratchOptions); } - result._ellipseGeometry = ellipseGeometry; + scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis; + scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis; + result._ellipseGeometry = new EllipseGeometry(scratchOptions); return result; }; diff --git a/Source/Core/CircleOutlineGeometry.js b/Source/Core/CircleOutlineGeometry.js index 06cbe5fcc70a..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"; /** @@ -92,6 +96,23 @@ define([ 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. * @@ -100,21 +121,22 @@ define([ * @param {CircleOutlineGeometry} [result] The object into which to store the result. */ CircleOutlineGeometry.unpack = function(array, startingIndex, result) { - var ellipseGeometry = EllipseOutlineGeometry.unpack(array, startingIndex); + 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)) { - return new CircleOutlineGeometry({ - center : ellipseGeometry._center, - radius : ellipseGeometry._semiMajorAxis, - ellipsoid : ellipseGeometry._ellipsoid, - height : ellipseGeometry._height, - extrudedHeight : ellipseGeometry._extrudedHeight, - granularity : ellipseGeometry._granularity, - numberOfVerticalLines : ellipseGeometry._numberOfVerticalLines - }); + scratchOptions.radius = ellipseGeometry._semiMajorAxis; + return new CircleOutlineGeometry(scratchOptions); } - result._ellipseGeometry = ellipseGeometry; + scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis; + scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis; + result._ellipseGeometry = new EllipseOutlineGeometry(scratchOptions); return result; }; diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index 8aa58f1c5d35..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,12 +623,12 @@ 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._vertexFormat = VertexFormat.clone(vertexFormat); this._extrudedHeight = defaultValue(extrudedHeight, height); this._extrude = extrude; this._workerName = 'createEllipseGeometry'; @@ -677,6 +679,22 @@ define([ 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. * @@ -693,13 +711,13 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var center = Cartesian3.unpack(array, startingIndex); + var center = Cartesian3.unpack(array, startingIndex, scratchCenter); startingIndex += Cartesian3.packedLength; - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var semiMajorAxis = array[startingIndex++]; @@ -712,24 +730,19 @@ define([ var extrude = array[startingIndex] === 1.0; if (!defined(result)) { - return new EllipseGeometry({ - center : center, - ellipsoid : ellipsoid, - vertexFormat : vertexFormat, - semiMajorAxis : semiMajorAxis, - semiMinorAxis : semiMinorAxis, - rotation : rotation, - stRotation : stRotation, - height : height, - granularity : granularity, - extrudedHeight : extrudedHeight, - extrude : extrude - }); + 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 = center; - result._ellipsoid = ellipsoid; - result._vertexFormat = vertexFormat; + 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; diff --git a/Source/Core/EllipseOutlineGeometry.js b/Source/Core/EllipseOutlineGeometry.js index 3d921bedcc5c..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,7 +197,7 @@ 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; @@ -248,6 +249,20 @@ define([ 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. * @@ -264,10 +279,10 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var center = Cartesian3.unpack(array, startingIndex); + var center = Cartesian3.unpack(array, startingIndex, scratchCenter); startingIndex += Cartesian3.packedLength; - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; var semiMajorAxis = array[startingIndex++]; @@ -280,22 +295,18 @@ define([ var numberOfVerticalLines = array[startingIndex]; if (!defined(result)) { - return new EllipseOutlineGeometry({ - center : center, - ellipsoid : ellipsoid, - semiMajorAxis : semiMajorAxis, - semiMinorAxis : semiMinorAxis, - rotation : rotation, - height : height, - granularity : granularity, - extrudedHeight : extrudedHeight, - extrude : extrude, - numberOfVerticalLines : numberOfVerticalLines - }); + 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 = center; - result._ellipsoid = ellipsoid; + result._center = Cartesian3.clone(center, result._center); + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); result._semiMajorAxis = semiMajorAxis; result._semiMinorAxis = semiMinorAxis; result._rotation = rotation; diff --git a/Source/Core/EllipsoidGeometry.js b/Source/Core/EllipsoidGeometry.js index d6acc2912173..571dcbef3ddc 100644 --- a/Source/Core/EllipsoidGeometry.js +++ b/Source/Core/EllipsoidGeometry.js @@ -89,7 +89,7 @@ define([ this._radii = Cartesian3.clone(radii); this._stackPartitions = stackPartitions; this._slicePartitions = slicePartitions; - this._vertexFormat = vertexFormat; + this._vertexFormat = VertexFormat.clone(vertexFormat); this._workerName = 'createEllipsoidGeometry'; }; @@ -129,6 +129,15 @@ define([ 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. * @@ -145,26 +154,23 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var radii = Cartesian3.unpack(array, startingIndex); + var radii = Cartesian3.unpack(array, startingIndex, scratchRadii); startingIndex += Cartesian3.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var stackPartitions = array[startingIndex++]; var slicePartitions = array[startingIndex]; if (!defined(result)) { - return new EllipsoidGeometry({ - radii : radii, - vertexFormat : vertexFormat, - stackPartitions : stackPartitions, - slicePartitions : slicePartitions - }); + scratchOptions.stackPartitions = stackPartitions; + scratchOptions.slicePartitions = slicePartitions; + return new EllipsoidGeometry(scratchOptions); } - result._radii = radii; - result._vertexFormat = vertexFormat; + result._radii = Cartesian3.clone(radii, result._radii); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); result._stackPartitions = stackPartitions; result._slicePartitions = slicePartitions; diff --git a/Source/Core/EllipsoidOutlineGeometry.js b/Source/Core/EllipsoidOutlineGeometry.js index 9cc8f5f2cbfa..70a523b743d0 100644 --- a/Source/Core/EllipsoidOutlineGeometry.js +++ b/Source/Core/EllipsoidOutlineGeometry.js @@ -120,6 +120,14 @@ define([ 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. * @@ -136,7 +144,7 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var radii = Cartesian3.unpack(array, startingIndex); + var radii = Cartesian3.unpack(array, startingIndex, scratchRadii); startingIndex += Cartesian3.packedLength; var stackPartitions = array[startingIndex++]; @@ -144,15 +152,13 @@ define([ var subdivisions = array[startingIndex++]; if (!defined(result)) { - return new EllipsoidOutlineGeometry({ - radii : radii, - stackPartitions : stackPartitions, - slicePartitions : slicePartitions, - subdivisions : subdivisions - }); + scratchOptions.stackPartitions = stackPartitions; + scratchOptions.slicePartitions = slicePartitions; + scratchOptions.subdivisions = subdivisions; + return new EllipsoidOutlineGeometry(scratchOptions); } - result._radii = radii; + result._radii = Cartesian3.clone(radii, result._radii); result._stackPartitions = stackPartitions; result._slicePartitions = slicePartitions; result._subdivisions = subdivisions; diff --git a/Source/Core/SphereGeometry.js b/Source/Core/SphereGeometry.js index 36c17a923d9f..a54da65075fe 100644 --- a/Source/Core/SphereGeometry.js +++ b/Source/Core/SphereGeometry.js @@ -4,13 +4,15 @@ define([ './defaultValue', './defined', './DeveloperError', - './EllipsoidGeometry' + './EllipsoidGeometry', + './VertexFormat' ], function( Cartesian3, defaultValue, defined, DeveloperError, - EllipsoidGeometry) { + EllipsoidGeometry, + VertexFormat) { "use strict"; /** @@ -77,6 +79,15 @@ define([ 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. * @@ -85,22 +96,18 @@ define([ * @param {SphereGeometry} [result] The object into which to store the result. */ SphereGeometry.unpack = function(array, startingIndex, result) { - var ellipsoidGeometry = EllipsoidGeometry.unpack(array, startingIndex); + 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)) { - return new SphereGeometry({ - radius : ellipsoidGeometry._radii.x, - vertexFormat : ellipsoidGeometry._vertexFormat, - stackPartitions : ellipsoidGeometry._stackPartitions, - slicePartitions : ellipsoidGeometry._slicePartitions - }); + scratchOptions.radius = ellipsoidGeometry._radius; + return new SphereGeometry(scratchOptions); } - result._radius = ellipsoidGeometry._radii.x; - result._vertexFormat = ellipsoidGeometry._vertexFormat; - result._stackPartitions = ellipsoidGeometry._stackPartitions; - result._slicePartitions = ellipsoidGeometry._slicePartitions; - + Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii); + result._ellipsoidGeometry = new EllipsoidGeometry(scratchOptions); return result; }; diff --git a/Source/Core/SphereOutlineGeometry.js b/Source/Core/SphereOutlineGeometry.js index fe7dc139553b..748ab6b12949 100644 --- a/Source/Core/SphereOutlineGeometry.js +++ b/Source/Core/SphereOutlineGeometry.js @@ -77,6 +77,15 @@ define([ 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. * @@ -85,22 +94,18 @@ define([ * @param {SphereOutlineGeometry} [result] The object into which to store the result. */ SphereOutlineGeometry.unpack = function(array, startingIndex, result) { - var ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(array, startingIndex); + var ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(array, startingIndex, scratchEllipsoidGeometry); + scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions; + scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions; + scratchOptions.subdivisions = ellipsoidGeometry._subdivisions; if (!defined(result)) { - return new SphereOutlineGeometry({ - radius : ellipsoidGeometry._radii.x, - stackPartitions : ellipsoidGeometry._stackPartitions, - slicePartitions : ellipsoidGeometry._slicePartitions, - subdivisions : ellipsoidGeometry._subdivisions - }); + scratchOptions.radius = ellipsoidGeometry._radius; + return new SphereOutlineGeometry(scratchOptions); } - result._radius = ellipsoidGeometry._radii.x; - result._stackPartitions = ellipsoidGeometry._stackPartitions; - result._slicePartitions = ellipsoidGeometry._slicePartitions; - result._subdivisions = ellipsoidGeometry._subdivisions; - + Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii); + result._ellipsoidGeometry = new EllipsoidOutlineGeometry(scratchOptions); return result; }; diff --git a/Source/Core/VertexFormat.js b/Source/Core/VertexFormat.js index 9d4901c6bfc1..07e06c9a9f3d 100644 --- a/Source/Core/VertexFormat.js +++ b/Source/Core/VertexFormat.js @@ -278,5 +278,29 @@ define([ 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/Scene/Primitive.js b/Source/Scene/Primitive.js index 6c4cd704a032..aaa2b30b12e6 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -756,7 +756,7 @@ define([ geometry = subTask.geometry; if (defined(geometry.constructor.pack)) { subTask.offset = packedLength; - packedLength += defined(geometry.constructor.packedLength) ? geometry.constructor.packedLength : geometry.packedLength; + packedLength += defaultValue(geometry.constructor.packedLength, geometry.packedLength); } } From e5d3f39c30405266e3b94137c6f415ab82d26665 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 31 Dec 2014 17:57:11 -0500 Subject: [PATCH 17/22] Updates from review: use scratch variables when unpacking corridor, cylinder, polygon, polyline, polyline volume, rectangle, and wall fill/outline geometries. --- Source/Core/CorridorGeometry.js | 42 +++++++++------ Source/Core/CorridorOutlineGeometry.js | 33 +++++++----- Source/Core/CylinderGeometry.js | 27 ++++++---- Source/Core/CylinderOutlineGeometry.js | 21 +++++--- Source/Core/PolygonGeometry.js | 42 +++++++++------ Source/Core/PolygonOutlineGeometry.js | 30 +++++++---- Source/Core/PolylineGeometry.js | 42 +++++++++------ Source/Core/PolylineVolumeGeometry.js | 44 ++++++++-------- Source/Core/PolylineVolumeOutlineGeometry.js | 28 ++++++---- Source/Core/RectangleGeometry.js | 55 ++++++++++++-------- Source/Core/RectangleOutlineGeometry.js | 36 ++++++++----- Source/Core/WallGeometry.js | 36 ++++++++----- Source/Core/WallOutlineGeometry.js | 27 ++++++---- Specs/Core/PolylineVolumeGeometrySpec.js | 2 +- Specs/Core/RectangleGeometrySpec.js | 2 +- 15 files changed, 287 insertions(+), 180 deletions(-) diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index e2ad04783787..184e2bdc167b 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -663,8 +663,8 @@ define([ //>>includeEnd('debug'); this._positions = positions; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); - this._vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); + this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT)); this._width = width; this._height = defaultValue(options.height, 0); this._extrudedHeight = defaultValue(options.extrudedHeight, this._height); @@ -720,6 +720,19 @@ define([ 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. * @@ -743,10 +756,10 @@ define([ positions[i] = Cartesian3.unpack(array, startingIndex); } - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var width = array[startingIndex++]; @@ -756,21 +769,18 @@ define([ var granularity = array[startingIndex]; if (!defined(result)) { - return new CorridorGeometry({ - positions : positions, - ellipsoid : ellipsoid, - vertexFormat : vertexFormat, - width : width, - height : height, - extrudedHeight : extrudedHeight, - cornerType : cornerType, - granularity : granularity - }); + 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; - result._vertexFormat = vertexFormat; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); result._width = width; result._height = height; result._extrudedHeight = extrudedHeight; diff --git a/Source/Core/CorridorOutlineGeometry.js b/Source/Core/CorridorOutlineGeometry.js index 9d316de01e5a..851175437a9c 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -340,7 +340,7 @@ define([ //>>includeEnd('debug'); this._positions = positions; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); this._width = width; this._height = defaultValue(options.height, 0); this._extrudedHeight = defaultValue(options.extrudedHeight, this._height); @@ -393,6 +393,17 @@ define([ 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. * @@ -416,7 +427,7 @@ define([ positions[i] = Cartesian3.unpack(array, startingIndex); } - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; var width = array[startingIndex++]; @@ -426,19 +437,17 @@ define([ var granularity = array[startingIndex]; if (!defined(result)) { - return new CorridorOutlineGeometry({ - positions : positions, - ellipsoid : ellipsoid, - width : width, - height : height, - extrudedHeight : extrudedHeight, - cornerType : cornerType, - granularity : granularity - }); + 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; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); result._width = width; result._height = height; result._extrudedHeight = extrudedHeight; diff --git a/Source/Core/CylinderGeometry.js b/Source/Core/CylinderGeometry.js index 5b65fe954bdf..a6d76998523f 100644 --- a/Source/Core/CylinderGeometry.js +++ b/Source/Core/CylinderGeometry.js @@ -102,7 +102,7 @@ define([ this._length = length; this._topRadius = topRadius; this._bottomRadius = bottomRadius; - this._vertexFormat = vertexFormat; + this._vertexFormat = VertexFormat.clone(vertexFormat); this._slices = slices; this._workerName = 'createCylinderGeometry'; }; @@ -142,6 +142,15 @@ define([ 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. * @@ -158,7 +167,7 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var length = array[startingIndex++]; @@ -167,16 +176,14 @@ define([ var slices = array[startingIndex]; if (!defined(result)) { - return new CylinderGeometry({ - vertexFormat : vertexFormat, - length : length, - topRadius : topRadius, - bottomRadius : bottomRadius, - slices : slices - }); + scratchOptions.length = length; + scratchOptions.topRadius = topRadius; + scratchOptions.bottomRadius = bottomRadius; + scratchOptions.slices = slices; + return new CylinderGeometry(scratchOptions); } - result._vertexFormat = vertexFormat; + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); result._length = length; result._topRadius = topRadius; result._bottomRadius = bottomRadius; diff --git a/Source/Core/CylinderOutlineGeometry.js b/Source/Core/CylinderOutlineGeometry.js index 338c5bbf63f4..89953caac132 100644 --- a/Source/Core/CylinderOutlineGeometry.js +++ b/Source/Core/CylinderOutlineGeometry.js @@ -131,6 +131,14 @@ define([ array[startingIndex] = value._numberOfVerticalLines; }; + var scratchOptions = { + length : undefined, + topRadius : undefined, + bottomRadius : undefined, + slices : undefined, + numberOfVerticalLines : undefined + }; + /** * Retrieves an instance from a packed array. * @@ -154,13 +162,12 @@ define([ var numberOfVerticalLines = array[startingIndex]; if (!defined(result)) { - return new CylinderOutlineGeometry({ - length : length, - topRadius : topRadius, - bottomRadius : bottomRadius, - slices : slices, - numberOfVerticalLines : numberOfVerticalLines - }); + scratchOptions.length = length; + scratchOptions.topRadius = topRadius; + scratchOptions.bottomRadius = bottomRadius; + scratchOptions.slices = slices; + scratchOptions.numberOfVerticalLines = numberOfVerticalLines; + return new CylinderOutlineGeometry(scratchOptions); } result._length = length; diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index b7f9eccb0269..cd87fd4f4562 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -628,8 +628,8 @@ 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; @@ -733,6 +733,19 @@ define([ 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. * @@ -753,10 +766,10 @@ define([ startingIndex = polygonHierarchy.startingIndex; delete polygonHierarchy.startingIndex; - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var height = array[startingIndex++]; @@ -767,21 +780,18 @@ define([ var perPositionHeight = array[startingIndex] === 1.0; if (!defined(result)) { - return new PolygonGeometry({ - polygonHierarchy : polygonHierarchy, - ellipsoid : ellipsoid, - vertexFormat : vertexFormat, - height : height, - extrudedHeight : extrudedHeight, - granularity : granularity, - stRotation : stRotation, - perPositionHeight : perPositionHeight - }); + 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; - result._vertexFormat = vertexFormat; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); result._height = height; result._extrudedHeight = extrudedHeight; result._granularity = granularity; diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index 5fe805d63069..d7ae8bf92bc4 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -321,7 +321,7 @@ define([ } //>>includeEnd('debug'); - this._ellipsoid = ellipsoid; + this._ellipsoid = Ellipsoid.clone(ellipsoid); this._granularity = granularity; this._height = height; this._extrudedHeight = defaultValue(extrudedHeight, 0.0); @@ -369,6 +369,16 @@ define([ 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. * @@ -389,7 +399,7 @@ define([ startingIndex = polygonHierarchy.startingIndex; delete polygonHierarchy.startingIndex; - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; var height = array[startingIndex++]; @@ -399,18 +409,16 @@ define([ var perPositionHeight = array[startingIndex] === 1.0; if (!defined(result)) { - return new PolygonOutlineGeometry({ - polygonHierarchy : polygonHierarchy, - ellipsoid : ellipsoid, - height : height, - extrudedHeight : extrudedHeight, - granularity : granularity, - perPositionHeight : perPositionHeight - }); + 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; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); result._height = height; result._extrudedHeight = extrudedHeight; result._granularity = granularity; diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index 4de1479e0d53..026ee480ab76 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -133,10 +133,10 @@ 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; @@ -199,6 +199,19 @@ define([ 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. * @@ -231,10 +244,10 @@ define([ colors[i] = Color.unpack(array, startingIndex); } - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var width = array[startingIndex++]; @@ -243,22 +256,19 @@ define([ var granularity = array[startingIndex]; if (!defined(result)) { - return new PolylineGeometry({ - positions : positions, - colors : colors, - ellipsoid : ellipsoid, - vertexFormat : vertexFormat, - width : width, - perVertex : perVertex, - followSurface : followSurface, - granularity : granularity - }); + 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; - result._vertexFormat = vertexFormat; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); result._width = width; result._perVertex = perVertex; result._followSurface = followSurface; diff --git a/Source/Core/PolylineVolumeGeometry.js b/Source/Core/PolylineVolumeGeometry.js index 55369f1716db..e17a26928f34 100644 --- a/Source/Core/PolylineVolumeGeometry.js +++ b/Source/Core/PolylineVolumeGeometry.js @@ -187,7 +187,6 @@ define([ * @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. * @@ -230,10 +229,9 @@ 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'; @@ -244,7 +242,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 3; + this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 2; }; /** @@ -291,11 +289,21 @@ define([ VertexFormat.pack(value._vertexFormat, array, startingIndex); startingIndex += VertexFormat.packedLength; - array[startingIndex++] = value._height; 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. * @@ -328,33 +336,27 @@ define([ shape[i] = Cartesian2.unpack(array, startingIndex); } - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; - var height = array[startingIndex++]; var cornerType = array[startingIndex++]; var granularity = array[startingIndex]; if (!defined(result)) { - return new PolylineVolumeGeometry({ - polylinePositions : positions, - shapePositions : shape, - ellipsoid : ellipsoid, - vertexFormat : vertexFormat, - height : height, - cornerType : cornerType, - granularity : granularity - }); + 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; - result._vertexFormat = vertexFormat; - result._height = height; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat); result._cornerType = cornerType; result._granularity = granularity; diff --git a/Source/Core/PolylineVolumeOutlineGeometry.js b/Source/Core/PolylineVolumeOutlineGeometry.js index b4ac4187c30d..fa1a0226377e 100644 --- a/Source/Core/PolylineVolumeOutlineGeometry.js +++ b/Source/Core/PolylineVolumeOutlineGeometry.js @@ -144,7 +144,7 @@ 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'; @@ -204,6 +204,16 @@ define([ 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. * @@ -236,25 +246,23 @@ define([ shape[i] = Cartesian2.unpack(array, startingIndex); } - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; var cornerType = array[startingIndex++]; var granularity = array[startingIndex]; if (!defined(result)) { - return new PolylineVolumeOutlineGeometry({ - polylinePositions : positions, - shapePositions : shape, - ellipsoid : ellipsoid, - cornerType : cornerType, - granularity : granularity - }); + 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; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); result._cornerType = cornerType; result._granularity = granularity; diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 3c42745e820e..d27f0affc3cb 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -570,11 +570,11 @@ 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._vertexFormat = VertexFormat.clone(vertexFormat); this._extrudedHeight = defaultValue(extrudedHeight, 0.0); this._extrude = extrude; this._closeTop = closeTop; @@ -627,6 +627,22 @@ define([ 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. * @@ -643,13 +659,13 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var rectangle = Rectangle.unpack(array, startingIndex); + var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle); startingIndex += Rectangle.packedLength; - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var granularity = array[startingIndex++]; @@ -662,27 +678,24 @@ define([ var closeBottom = array[startingIndex] === 1.0; if (!defined(result)) { - return new RectangleGeometry({ - rectangle : rectangle, - ellipsoid : ellipsoid, - vertexFormat : vertexFormat, - granularity : granularity, - height : surfaceHeight, - rotation : rotation, - stRotation : stRotation, - extrudedHeight : extrude ? extrudedHeight : undefined, - closeTop : closeTop, - closeBottom : closeBottom - }); + 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; - result._ellipsoid = ellipsoid; - result._vertexFormat = vertexFormat; + 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 = extrudedHeight; + result._extrudedHeight = extrude ? extrudedHeight : undefined; result._extrude = extrude; result._closeTop = closeTop; result._closeBottom = closeBottom; diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index 44108e92ff92..d36637df5b8b 100644 --- a/Source/Core/RectangleOutlineGeometry.js +++ b/Source/Core/RectangleOutlineGeometry.js @@ -260,6 +260,17 @@ define([ 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. * @@ -276,31 +287,28 @@ define([ startingIndex = defaultValue(startingIndex, 0); - var rectangle = Rectangle.unpack(array, startingIndex); + var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle); startingIndex += Rectangle.packedLength; - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; var granularity = array[startingIndex++]; - var surfaceHeight = array[startingIndex++]; + var height = array[startingIndex++]; var rotation = array[startingIndex++]; var extrudedHeight = array[startingIndex]; if (!defined(result)) { - return new RectangleOutlineGeometry({ - rectangle : rectangle, - ellipsoid : ellipsoid, - granularity : granularity, - surfaceHeight : surfaceHeight, - rotation : rotation, - extrudedHeight : extrudedHeight - }); + scratchOptions.granularity = granularity; + scratchOptions.height = height; + scratchOptions.rotation = rotation; + scratchOptions.extrudedHeight = extrudedHeight; + return new RectangleOutlineGeometry(scratchOptions); } - result._rectangle = rectangle; - result._ellipsoid = ellipsoid; - result._surfaceHeight = surfaceHeight; + result._rectangle = Rectangle.clone(rectangle, result._rectangle); + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); + result._surfaceHeight = height; result._rotation = rotation; result._extrudedHeight = extrudedHeight; diff --git a/Source/Core/WallGeometry.js b/Source/Core/WallGeometry.js index 466da8a49b41..79bdf9a77925 100644 --- a/Source/Core/WallGeometry.js +++ b/Source/Core/WallGeometry.js @@ -106,9 +106,9 @@ 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; @@ -185,6 +185,17 @@ define([ 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. * @@ -230,30 +241,27 @@ define([ } } - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; - var vertexFormat = VertexFormat.unpack(array, startingIndex); + var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); startingIndex += VertexFormat.packedLength; var granularity = array[startingIndex]; if (!defined(result)) { - return new WallGeometry({ - positions : positions, - minimumHeights : minimumHeights, - maximumHeights : maximumHeights, - ellipsoid : ellipsoid, - vertexFormat : vertexFormat, - granularity : granularity - }); + 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; - result._vertexFormat = vertexFormat; + 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 f4035fe57f7d..4ebc9e0a6df4 100644 --- a/Source/Core/WallOutlineGeometry.js +++ b/Source/Core/WallOutlineGeometry.js @@ -97,7 +97,7 @@ 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; @@ -171,6 +171,15 @@ define([ 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. * @@ -216,25 +225,23 @@ define([ } } - var ellipsoid = Ellipsoid.unpack(array, startingIndex); + var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid); startingIndex += Ellipsoid.packedLength; var granularity = array[startingIndex]; if (!defined(result)) { - return new WallOutlineGeometry({ - positions : positions, - minimumHeights : minimumHeights, - maximumHeights : maximumHeights, - ellipsoid : ellipsoid, - granularity : granularity - }); + 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; + result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid); result._granularity = granularity; return result; diff --git a/Specs/Core/PolylineVolumeGeometrySpec.js b/Specs/Core/PolylineVolumeGeometrySpec.js index c11efbcb6372..2a4f9a38e09e 100644 --- a/Specs/Core/PolylineVolumeGeometrySpec.js +++ b/Specs/Core/PolylineVolumeGeometrySpec.js @@ -181,6 +181,6 @@ defineSuite([ 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, 0.0, 2.0, 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/RectangleGeometrySpec.js b/Specs/Core/RectangleGeometrySpec.js index 71fd1d65edd2..9305b8b7fb86 100644 --- a/Specs/Core/RectangleGeometrySpec.js +++ b/Specs/Core/RectangleGeometrySpec.js @@ -242,6 +242,6 @@ defineSuite([ 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, 1.0, 1.0]; + 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); }); From 4073f3824bf1fa4f4c4ded44e4540e8e61b78e94 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 5 Jan 2015 12:59:43 -0500 Subject: [PATCH 18/22] Remove the create*Geometry workers. Require geometries to implement packable and have a createGeometry function. --- Source/Core/BoxGeometry.js | 5 ++-- Source/Core/BoxOutlineGeometry.js | 5 ++-- Source/Core/CircleGeometry.js | 5 ++-- Source/Core/CircleOutlineGeometry.js | 5 ++-- Source/Core/CorridorGeometry.js | 5 ++-- Source/Core/CorridorOutlineGeometry.js | 5 ++-- Source/Core/CylinderGeometry.js | 5 ++-- Source/Core/CylinderOutlineGeometry.js | 5 ++-- Source/Core/EllipseGeometry.js | 5 ++-- Source/Core/EllipseOutlineGeometry.js | 5 ++-- Source/Core/EllipsoidGeometry.js | 5 ++-- Source/Core/EllipsoidOutlineGeometry.js | 5 ++-- Source/Core/PolygonGeometry.js | 5 ++-- Source/Core/PolygonOutlineGeometry.js | 5 ++-- Source/Core/PolylineGeometry.js | 5 ++-- Source/Core/PolylineVolumeGeometry.js | 5 ++-- Source/Core/PolylineVolumeOutlineGeometry.js | 5 ++-- Source/Core/RectangleGeometry.js | 5 ++-- Source/Core/RectangleOutlineGeometry.js | 5 ++-- Source/Core/SimplePolylineGeometry.js | 5 ++-- Source/Core/SphereGeometry.js | 5 ++-- Source/Core/SphereOutlineGeometry.js | 5 ++-- Source/Core/WallGeometry.js | 5 ++-- Source/Core/WallOutlineGeometry.js | 5 ++-- Source/Scene/Primitive.js | 8 ++++++- Source/Workers/createBoxGeometry.js | 16 ------------- Source/Workers/createBoxOutlineGeometry.js | 16 ------------- Source/Workers/createCircleGeometry.js | 24 ------------------- Source/Workers/createCircleOutlineGeometry.js | 24 ------------------- Source/Workers/createCorridorGeometry.js | 21 ---------------- .../Workers/createCorridorOutlineGeometry.js | 21 ---------------- Source/Workers/createCylinderGeometry.js | 16 ------------- .../Workers/createCylinderOutlineGeometry.js | 16 ------------- Source/Workers/createEllipseGeometry.js | 24 ------------------- .../Workers/createEllipseOutlineGeometry.js | 24 ------------------- Source/Workers/createEllipsoidGeometry.js | 16 ------------- .../Workers/createEllipsoidOutlineGeometry.js | 16 ------------- Source/Workers/createGeometry.js | 11 ++++++--- Source/Workers/createPolygonGeometry.js | 21 ---------------- .../Workers/createPolygonOutlineGeometry.js | 21 ---------------- Source/Workers/createPolylineGeometry.js | 21 ---------------- .../Workers/createPolylineVolumeGeometry.js | 21 ---------------- .../createPolylineVolumeOutlineGeometry.js | 21 ---------------- Source/Workers/createRectangleGeometry.js | 24 ------------------- .../Workers/createRectangleOutlineGeometry.js | 24 ------------------- .../Workers/createSimplePolylineGeometry.js | 21 ---------------- Source/Workers/createSphereGeometry.js | 16 ------------- Source/Workers/createSphereOutlineGeometry.js | 16 ------------- Source/Workers/createWallGeometry.js | 21 ---------------- Source/Workers/createWallOutlineGeometry.js | 21 ---------------- 50 files changed, 63 insertions(+), 558 deletions(-) delete mode 100644 Source/Workers/createBoxGeometry.js delete mode 100644 Source/Workers/createBoxOutlineGeometry.js delete mode 100644 Source/Workers/createCircleGeometry.js delete mode 100644 Source/Workers/createCircleOutlineGeometry.js delete mode 100644 Source/Workers/createCorridorGeometry.js delete mode 100644 Source/Workers/createCorridorOutlineGeometry.js delete mode 100644 Source/Workers/createCylinderGeometry.js delete mode 100644 Source/Workers/createCylinderOutlineGeometry.js delete mode 100644 Source/Workers/createEllipseGeometry.js delete mode 100644 Source/Workers/createEllipseOutlineGeometry.js delete mode 100644 Source/Workers/createEllipsoidGeometry.js delete mode 100644 Source/Workers/createEllipsoidOutlineGeometry.js delete mode 100644 Source/Workers/createPolygonGeometry.js delete mode 100644 Source/Workers/createPolygonOutlineGeometry.js delete mode 100644 Source/Workers/createPolylineGeometry.js delete mode 100644 Source/Workers/createPolylineVolumeGeometry.js delete mode 100644 Source/Workers/createPolylineVolumeOutlineGeometry.js delete mode 100644 Source/Workers/createRectangleGeometry.js delete mode 100644 Source/Workers/createRectangleOutlineGeometry.js delete mode 100644 Source/Workers/createSimplePolylineGeometry.js delete mode 100644 Source/Workers/createSphereGeometry.js delete mode 100644 Source/Workers/createSphereOutlineGeometry.js delete mode 100644 Source/Workers/createWallGeometry.js delete mode 100644 Source/Workers/createWallOutlineGeometry.js diff --git a/Source/Core/BoxGeometry.js b/Source/Core/BoxGeometry.js index 839a520262d1..b035aec1c1f4 100644 --- a/Source/Core/BoxGeometry.js +++ b/Source/Core/BoxGeometry.js @@ -52,7 +52,7 @@ define([ * }); * var geometry = Cesium.BoxGeometry.createGeometry(box); */ - var BoxGeometry = function(options) { + function BoxGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var min = options.minimumCorner; var max = options.maximumCorner; @@ -71,8 +71,7 @@ define([ this._minimumCorner = Cartesian3.clone(min); this._maximumCorner = Cartesian3.clone(max); this._vertexFormat = vertexFormat; - this._workerName = 'createBoxGeometry'; - }; + } /** * Creates a cube centered at the origin given its dimensions. diff --git a/Source/Core/BoxOutlineGeometry.js b/Source/Core/BoxOutlineGeometry.js index 8461d0a24d39..45fbcac139a1 100644 --- a/Source/Core/BoxOutlineGeometry.js +++ b/Source/Core/BoxOutlineGeometry.js @@ -47,7 +47,7 @@ define([ * }); * var geometry = Cesium.BoxOutlineGeometry.createGeometry(box); */ - var BoxOutlineGeometry = function(options) { + function BoxOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var min = options.minimumCorner; @@ -64,8 +64,7 @@ define([ this._min = Cartesian3.clone(min); this._max = Cartesian3.clone(max); - this._workerName = 'createBoxOutlineGeometry'; - }; + } /** * Creates an outline of a cube centered at the origin given its dimensions. diff --git a/Source/Core/CircleGeometry.js b/Source/Core/CircleGeometry.js index 1eb967557a95..4be0b5d39327 100644 --- a/Source/Core/CircleGeometry.js +++ b/Source/Core/CircleGeometry.js @@ -49,7 +49,7 @@ define([ * }); * var geometry = Cesium.CircleGeometry.createGeometry(circle); */ - var CircleGeometry = function(options) { + function CircleGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radius = options.radius; @@ -74,8 +74,7 @@ define([ stRotation : options.stRotation }; this._ellipseGeometry = new EllipseGeometry(ellipseGeometryOptions); - this._workerName = 'createCircleGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/CircleOutlineGeometry.js b/Source/Core/CircleOutlineGeometry.js index b43dca2f57b9..3ea44c16db26 100644 --- a/Source/Core/CircleOutlineGeometry.js +++ b/Source/Core/CircleOutlineGeometry.js @@ -46,7 +46,7 @@ define([ * }); * var geometry = Cesium.CircleOutlineGeometry.createGeometry(circle); */ - var CircleOutlineGeometry = function(options) { + function CircleOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radius = options.radius; @@ -70,8 +70,7 @@ define([ numberOfVerticalLines : options.numberOfVerticalLines }; this._ellipseGeometry = new EllipseOutlineGeometry(ellipseGeometryOptions); - this._workerName = 'createCircleOutlineGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index 184e2bdc167b..f1f582e4f566 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -648,7 +648,7 @@ define([ * width : 100000 * }); */ - var CorridorGeometry = function(options) { + function CorridorGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var width = options.width; @@ -670,14 +670,13 @@ define([ 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 = '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. diff --git a/Source/Core/CorridorOutlineGeometry.js b/Source/Core/CorridorOutlineGeometry.js index 851175437a9c..28b72944a9f8 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -325,7 +325,7 @@ define([ * width : 100000 * }); */ - var CorridorOutlineGeometry = function(options) { + function CorridorOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var width = options.width; @@ -346,14 +346,13 @@ define([ 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. diff --git a/Source/Core/CylinderGeometry.js b/Source/Core/CylinderGeometry.js index a6d76998523f..ced069257ded 100644 --- a/Source/Core/CylinderGeometry.js +++ b/Source/Core/CylinderGeometry.js @@ -72,7 +72,7 @@ define([ * }); * var geometry = Cesium.CylinderGeometry.createGeometry(cylinder); */ - var CylinderGeometry = function(options) { + function CylinderGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var length = options.length; @@ -104,8 +104,7 @@ define([ this._bottomRadius = bottomRadius; this._vertexFormat = VertexFormat.clone(vertexFormat); this._slices = slices; - this._workerName = 'createCylinderGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/CylinderOutlineGeometry.js b/Source/Core/CylinderOutlineGeometry.js index 89953caac132..b72203ba6993 100644 --- a/Source/Core/CylinderOutlineGeometry.js +++ b/Source/Core/CylinderOutlineGeometry.js @@ -63,7 +63,7 @@ define([ * }); * var geometry = Cesium.CylinderOutlineGeometry.createGeometry(cylinder); */ - var CylinderOutlineGeometry = function(options) { + function CylinderOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var length = options.length; @@ -95,8 +95,7 @@ define([ this._bottomRadius = bottomRadius; this._slices = slices; this._numberOfVerticalLines = numberOfVerticalLines; - this._workerName = 'createCylinderOutlineGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index e95ac358184b..fbe7c0790302 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -586,7 +586,7 @@ define([ * }); * var geometry = Cesium.EllipseGeometry.createGeometry(ellipse); */ - var EllipseGeometry = function(options) { + function EllipseGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var center = options.center; @@ -631,8 +631,7 @@ define([ 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. diff --git a/Source/Core/EllipseOutlineGeometry.js b/Source/Core/EllipseOutlineGeometry.js index f74f8cdfe6f4..c020fe5a06cf 100644 --- a/Source/Core/EllipseOutlineGeometry.js +++ b/Source/Core/EllipseOutlineGeometry.js @@ -161,7 +161,7 @@ define([ * }); * var geometry = Cesium.EllipseOutlineGeometry.createGeometry(ellipse); */ - var EllipseOutlineGeometry = function(options) { + function EllipseOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var center = options.center; @@ -204,8 +204,7 @@ define([ 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. diff --git a/Source/Core/EllipsoidGeometry.js b/Source/Core/EllipsoidGeometry.js index 571dcbef3ddc..d06f0ef054c3 100644 --- a/Source/Core/EllipsoidGeometry.js +++ b/Source/Core/EllipsoidGeometry.js @@ -69,7 +69,7 @@ define([ * }); * var geometry = Cesium.EllipsoidGeometry.createGeometry(ellipsoid); */ - var EllipsoidGeometry = function(options) { + function EllipsoidGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radii = defaultValue(options.radii, defaultRadii); @@ -90,8 +90,7 @@ define([ this._stackPartitions = stackPartitions; this._slicePartitions = slicePartitions; this._vertexFormat = VertexFormat.clone(vertexFormat); - this._workerName = 'createEllipsoidGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/EllipsoidOutlineGeometry.js b/Source/Core/EllipsoidOutlineGeometry.js index 70a523b743d0..491c302149b7 100644 --- a/Source/Core/EllipsoidOutlineGeometry.js +++ b/Source/Core/EllipsoidOutlineGeometry.js @@ -59,7 +59,7 @@ define([ * }); * var geometry = Cesium.EllipsoidOutlineGeometry.createGeometry(ellipsoid); */ - var EllipsoidOutlineGeometry = function(options) { + function EllipsoidOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radii = defaultValue(options.radii, defaultRadii); @@ -83,8 +83,7 @@ define([ this._stackPartitions = stackPartitions; this._slicePartitions = slicePartitions; this._subdivisions = subdivisions; - this._workerName = 'createEllipsoidOutlineGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index cd87fd4f4562..358480a6f4e2 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -603,7 +603,7 @@ define([ * }); * var geometry = Cesium.PolygonGeometry.createGeometry(extrudedPolygon); */ - var PolygonGeometry = function(options) { + function PolygonGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); @@ -637,14 +637,13 @@ define([ 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; - }; + } /** * A description of a polygon from an array of positions. diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index d7ae8bf92bc4..f5af844a14bc 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -298,7 +298,7 @@ define([ * }); * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(extrudedPolygon); */ - var PolygonOutlineGeometry = function(options) { + function PolygonOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); @@ -328,14 +328,13 @@ define([ 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. diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index 026ee480ab76..411fae19f2ca 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -110,7 +110,7 @@ define([ * }); * var geometry = Cesium.PolylineGeometry.createGeometry(polyline); */ - var PolylineGeometry = function(options) { + function PolylineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var colors = options.colors; @@ -137,7 +137,6 @@ define([ this._followSurface = defaultValue(options.followSurface, true); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); 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; @@ -147,7 +146,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 4; - }; + } /** * Stores the provided instance into the provided array. diff --git a/Source/Core/PolylineVolumeGeometry.js b/Source/Core/PolylineVolumeGeometry.js index e17a26928f34..c59619a299f2 100644 --- a/Source/Core/PolylineVolumeGeometry.js +++ b/Source/Core/PolylineVolumeGeometry.js @@ -213,7 +213,7 @@ define([ * shapePositions : computeCircle(100000.0) * }); */ - var PolylineVolumeGeometry = function(options) { + function PolylineVolumeGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.polylinePositions; var shape = options.shapePositions; @@ -233,7 +233,6 @@ define([ this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); 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; @@ -243,7 +242,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 2; - }; + } /** * Stores the provided instance into the provided array. diff --git a/Source/Core/PolylineVolumeOutlineGeometry.js b/Source/Core/PolylineVolumeOutlineGeometry.js index fa1a0226377e..280e10d62a44 100644 --- a/Source/Core/PolylineVolumeOutlineGeometry.js +++ b/Source/Core/PolylineVolumeOutlineGeometry.js @@ -128,7 +128,7 @@ define([ * shapePositions : computeCircle(100000.0) * }); */ - var PolylineVolumeOutlineGeometry = function(options) { + function PolylineVolumeOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.polylinePositions; var shape = options.shapePositions; @@ -147,7 +147,6 @@ define([ 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; @@ -157,7 +156,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + 2; - }; + } /** * Stores the provided instance into the provided array. diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index d27f0affc3cb..7d2f3ec5d5f5 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -543,7 +543,7 @@ define([ * }); * var geometry = Cesium.RectangleGeometry.createGeometry(rectangle); */ - var RectangleGeometry = function(options) { + function RectangleGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var rectangle = options.rectangle; @@ -579,8 +579,7 @@ define([ this._extrude = extrude; this._closeTop = closeTop; this._closeBottom = closeBottom; - this._workerName = 'createRectangleGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index d36637df5b8b..26051f5cbf05 100644 --- a/Source/Core/RectangleOutlineGeometry.js +++ b/Source/Core/RectangleOutlineGeometry.js @@ -193,7 +193,7 @@ define([ * }); * var geometry = Cesium.RectangleOutlineGeometry.createGeometry(rectangle); */ - var RectangleOutlineGeometry = function(options) { + function RectangleOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var rectangle = options.rectangle; @@ -219,8 +219,7 @@ define([ this._surfaceHeight = surfaceHeight; this._rotation = rotation; this._extrudedHeight = extrudedHeight; - this._workerName = 'createRectangleOutlineGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/SimplePolylineGeometry.js b/Source/Core/SimplePolylineGeometry.js index 203146b7a490..deec58558e0f 100644 --- a/Source/Core/SimplePolylineGeometry.js +++ b/Source/Core/SimplePolylineGeometry.js @@ -106,7 +106,7 @@ define([ * }); * var geometry = Cesium.SimplePolylineGeometry.createGeometry(polyline); */ - var SimplePolylineGeometry = function(options) { + function SimplePolylineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var colors = options.colors; @@ -127,7 +127,6 @@ define([ this._followSurface = defaultValue(options.followSurface, true); 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; @@ -137,7 +136,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + 3; - }; + } /** * Stores the provided instance into the provided array. diff --git a/Source/Core/SphereGeometry.js b/Source/Core/SphereGeometry.js index a54da65075fe..428d08683d53 100644 --- a/Source/Core/SphereGeometry.js +++ b/Source/Core/SphereGeometry.js @@ -41,7 +41,7 @@ define([ * }); * var geometry = Cesium.SphereGeometry.createGeometry(sphere); */ - var SphereGeometry = function(options) { + function SphereGeometry(options) { var radius = defaultValue(options.radius, 1.0); var radii = new Cartesian3(radius, radius, radius); var ellipsoidOptions = { @@ -52,8 +52,7 @@ define([ }; this._ellipsoidGeometry = new EllipsoidGeometry(ellipsoidOptions); - this._workerName = 'createSphereGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/SphereOutlineGeometry.js b/Source/Core/SphereOutlineGeometry.js index 748ab6b12949..61ef9dfa5712 100644 --- a/Source/Core/SphereOutlineGeometry.js +++ b/Source/Core/SphereOutlineGeometry.js @@ -39,7 +39,7 @@ define([ * }); * var geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere); */ - var SphereOutlineGeometry = function(options) { + function SphereOutlineGeometry(options) { var radius = defaultValue(options.radius, 1.0); var radii = new Cartesian3(radius, radius, radius); var ellipsoidOptions = { @@ -50,8 +50,7 @@ define([ }; this._ellipsoidGeometry = new EllipsoidOutlineGeometry(ellipsoidOptions); - this._workerName = 'createSphereOutlineGeometry'; - }; + } /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/WallGeometry.js b/Source/Core/WallGeometry.js index 79bdf9a77925..19e693a7e490 100644 --- a/Source/Core/WallGeometry.js +++ b/Source/Core/WallGeometry.js @@ -80,7 +80,7 @@ define([ * }); * var geometry = Cesium.WallGeometry.createGeometry(wall); */ - var WallGeometry = function(options) { + function WallGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var wallPositions = options.positions; @@ -109,7 +109,6 @@ define([ this._vertexFormat = VertexFormat.clone(vertexFormat); this._granularity = granularity; this._ellipsoid = Ellipsoid.clone(ellipsoid); - this._workerName = 'createWallGeometry'; var numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2; if (defined(minimumHeights)) { @@ -124,7 +123,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 1; - }; + } /** * Stores the provided instance into the provided array. diff --git a/Source/Core/WallOutlineGeometry.js b/Source/Core/WallOutlineGeometry.js index 4ebc9e0a6df4..eabe64972bc6 100644 --- a/Source/Core/WallOutlineGeometry.js +++ b/Source/Core/WallOutlineGeometry.js @@ -71,7 +71,7 @@ define([ * }); * var geometry = Cesium.WallOutlineGeometry.createGeometry(wall); */ - var WallOutlineGeometry = function(options) { + function WallOutlineGeometry(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var wallPositions = options.positions; @@ -98,7 +98,6 @@ define([ this._maximumHeights = maximumHeights; this._granularity = granularity; this._ellipsoid = Ellipsoid.clone(ellipsoid); - this._workerName = 'createWallOutlineGeometry'; var numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2; if (defined(minimumHeights)) { @@ -113,7 +112,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + 1; - }; + } /** * Stores the provided instance into the provided array. diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index aaa2b30b12e6..a29ecadfcfe3 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -731,8 +731,14 @@ define([ for (i = 0; i < length; ++i) { geometry = instances[i].geometry; instanceIds.push(instances[i].id); + + var moduleName = geometry.constructor.name; + if (moduleName === "Object") { + moduleName = undefined; + } + subTasks.push({ - moduleName : geometry._workerName, + moduleName : moduleName, geometry : geometry }); } diff --git a/Source/Workers/createBoxGeometry.js b/Source/Workers/createBoxGeometry.js deleted file mode 100644 index aaf24fbe30ee..000000000000 --- a/Source/Workers/createBoxGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/BoxGeometry', - '../Core/defined' - ], function( - BoxGeometry, - defined) { - "use strict"; - - 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 deleted file mode 100644 index 0c0ac8ae76c4..000000000000 --- a/Source/Workers/createBoxOutlineGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/BoxOutlineGeometry', - '../Core/defined' - ], function( - BoxOutlineGeometry, - defined) { - "use strict"; - - 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 deleted file mode 100644 index 3eba599f2d13..000000000000 --- a/Source/Workers/createCircleGeometry.js +++ /dev/null @@ -1,24 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/CircleGeometry', - '../Core/defined', - '../Core/Ellipsoid' - ], function( - Cartesian3, - CircleGeometry, - defined, - Ellipsoid) { - "use strict"; - - 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); - } - - return createCircleGeometry; -}); diff --git a/Source/Workers/createCircleOutlineGeometry.js b/Source/Workers/createCircleOutlineGeometry.js deleted file mode 100644 index 5df6cc94814f..000000000000 --- a/Source/Workers/createCircleOutlineGeometry.js +++ /dev/null @@ -1,24 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/CircleOutlineGeometry', - '../Core/defined', - '../Core/Ellipsoid' - ], function( - Cartesian3, - CircleOutlineGeometry, - defined, - Ellipsoid) { - "use strict"; - - 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); - } - - return createCircleOutlineGeometry; -}); diff --git a/Source/Workers/createCorridorGeometry.js b/Source/Workers/createCorridorGeometry.js deleted file mode 100644 index ba673a27f803..000000000000 --- a/Source/Workers/createCorridorGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/CorridorGeometry', - '../Core/defined', - '../Core/Ellipsoid' - ], function( - CorridorGeometry, - defined, - Ellipsoid) { - "use strict"; - - function createCorridorGeometry(corridorGeometry, offset) { - if (defined(offset)) { - corridorGeometry = CorridorGeometry.unpack(corridorGeometry, offset); - } - corridorGeometry._ellipsoid = Ellipsoid.clone(corridorGeometry._ellipsoid); - return CorridorGeometry.createGeometry(corridorGeometry); - } - - return createCorridorGeometry; -}); diff --git a/Source/Workers/createCorridorOutlineGeometry.js b/Source/Workers/createCorridorOutlineGeometry.js deleted file mode 100644 index 45cca03cbc43..000000000000 --- a/Source/Workers/createCorridorOutlineGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/CorridorOutlineGeometry', - '../Core/defined', - '../Core/Ellipsoid' - ], function( - CorridorOutlineGeometry, - defined, - Ellipsoid) { - "use strict"; - - function createCorridorOutlineGeometry(corridorOutlineGeometry, offset) { - if (defined(offset)) { - corridorOutlineGeometry = CorridorOutlineGeometry.unpack(corridorOutlineGeometry, offset); - } - corridorOutlineGeometry._ellipsoid = Ellipsoid.clone(corridorOutlineGeometry._ellipsoid); - return CorridorOutlineGeometry.createGeometry(corridorOutlineGeometry); - } - - return createCorridorOutlineGeometry; -}); diff --git a/Source/Workers/createCylinderGeometry.js b/Source/Workers/createCylinderGeometry.js deleted file mode 100644 index 309ea24cd175..000000000000 --- a/Source/Workers/createCylinderGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/CylinderGeometry', - '../Core/defined' - ], function( - CylinderGeometry, - defined) { - "use strict"; - - 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 deleted file mode 100644 index e17895dd6608..000000000000 --- a/Source/Workers/createCylinderOutlineGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/CylinderOutlineGeometry', - '../Core/defined' - ], function( - CylinderOutlineGeometry, - defined) { - "use strict"; - - 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 deleted file mode 100644 index 626e24e3dbb3..000000000000 --- a/Source/Workers/createEllipseGeometry.js +++ /dev/null @@ -1,24 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/defined', - '../Core/EllipseGeometry', - '../Core/Ellipsoid' - ], function( - Cartesian3, - defined, - EllipseGeometry, - Ellipsoid) { - "use strict"; - - 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); - } - - return createEllipseGeometry; -}); diff --git a/Source/Workers/createEllipseOutlineGeometry.js b/Source/Workers/createEllipseOutlineGeometry.js deleted file mode 100644 index 9a0ffe328e46..000000000000 --- a/Source/Workers/createEllipseOutlineGeometry.js +++ /dev/null @@ -1,24 +0,0 @@ -/*global define*/ -define([ - '../Core/Cartesian3', - '../Core/defined', - '../Core/EllipseOutlineGeometry', - '../Core/Ellipsoid' - ], function( - Cartesian3, - defined, - EllipseOutlineGeometry, - Ellipsoid) { - "use strict"; - - 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); - } - - return createEllipseOutlineGeometry; -}); diff --git a/Source/Workers/createEllipsoidGeometry.js b/Source/Workers/createEllipsoidGeometry.js deleted file mode 100644 index a5de0a49bc8d..000000000000 --- a/Source/Workers/createEllipsoidGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/EllipsoidGeometry' - ], function( - defined, - EllipsoidGeometry) { - "use strict"; - - 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 deleted file mode 100644 index 7f720a2df884..000000000000 --- a/Source/Workers/createEllipsoidOutlineGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/EllipsoidOutlineGeometry' - ], function( - defined, - EllipsoidOutlineGeometry) { - "use strict"; - - 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 24570db39d42..15d210b7a0da 100644 --- a/Source/Workers/createGeometry.js +++ b/Source/Workers/createGeometry.js @@ -17,9 +17,14 @@ define([ var module = moduleCache[moduleName]; if (!defined(module)) { // in web workers, require is synchronous - require(['./' + moduleName], function(f) { - module = f; - moduleCache[module] = f; + require(['../Core/' + moduleName], function(f) { + module = function(geometry, offset) { + if (defined(offset)) { + geometry = f.unpack(geometry, offset); + } + return f.createGeometry(geometry); + }; + moduleCache[moduleName] = module; }); } return module; diff --git a/Source/Workers/createPolygonGeometry.js b/Source/Workers/createPolygonGeometry.js deleted file mode 100644 index 1f03cc8386af..000000000000 --- a/Source/Workers/createPolygonGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/PolygonGeometry' - ], function( - defined, - Ellipsoid, - PolygonGeometry) { - "use strict"; - - function createPolygonGeometry(polygonGeometry, offset) { - if (defined(offset)) { - polygonGeometry = PolygonGeometry.unpack(polygonGeometry, offset); - } - polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); - return PolygonGeometry.createGeometry(polygonGeometry); - } - - return createPolygonGeometry; -}); diff --git a/Source/Workers/createPolygonOutlineGeometry.js b/Source/Workers/createPolygonOutlineGeometry.js deleted file mode 100644 index 1c298701111e..000000000000 --- a/Source/Workers/createPolygonOutlineGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/PolygonOutlineGeometry' - ], function( - defined, - Ellipsoid, - PolygonOutlineGeometry) { - "use strict"; - - function createPolygonOutlineGeometry(polygonGeometry, offset) { - if (defined(offset)) { - polygonGeometry = PolygonOutlineGeometry.unpack(polygonGeometry, offset); - } - polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); - return PolygonOutlineGeometry.createGeometry(polygonGeometry); - } - - return createPolygonOutlineGeometry; -}); diff --git a/Source/Workers/createPolylineGeometry.js b/Source/Workers/createPolylineGeometry.js deleted file mode 100644 index 4fb72ce64831..000000000000 --- a/Source/Workers/createPolylineGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/PolylineGeometry' - ], function( - defined, - Ellipsoid, - PolylineGeometry) { - "use strict"; - - function createPolylineGeometry(polylineGeometry, offset) { - if (defined(offset)) { - polylineGeometry = PolylineGeometry.unpack(polylineGeometry, offset); - } - polylineGeometry._ellipsoid = Ellipsoid.clone(polylineGeometry._ellipsoid); - return PolylineGeometry.createGeometry(polylineGeometry); - } - - return createPolylineGeometry; -}); diff --git a/Source/Workers/createPolylineVolumeGeometry.js b/Source/Workers/createPolylineVolumeGeometry.js deleted file mode 100644 index 914b710246e7..000000000000 --- a/Source/Workers/createPolylineVolumeGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/PolylineVolumeGeometry' - ], function( - defined, - Ellipsoid, - PolylineVolumeGeometry) { - "use strict"; - - function createPolylineVolumeGeometry(polylineVolumeGeometry, offset) { - if (defined(offset)) { - polylineVolumeGeometry = PolylineVolumeGeometry.unpack(polylineVolumeGeometry, offset); - } - polylineVolumeGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeGeometry._ellipsoid); - return PolylineVolumeGeometry.createGeometry(polylineVolumeGeometry); - } - - return createPolylineVolumeGeometry; -}); diff --git a/Source/Workers/createPolylineVolumeOutlineGeometry.js b/Source/Workers/createPolylineVolumeOutlineGeometry.js deleted file mode 100644 index 5ef898e172c2..000000000000 --- a/Source/Workers/createPolylineVolumeOutlineGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/PolylineVolumeOutlineGeometry' - ], function( - defined, - Ellipsoid, - PolylineVolumeOutlineGeometry) { - "use strict"; - - function createPolylineVolumeOutlineGeometry(polylineVolumeOutlineGeometry, offset) { - if (defined(offset)) { - polylineVolumeOutlineGeometry = PolylineVolumeOutlineGeometry.unpack(polylineVolumeOutlineGeometry, offset); - } - polylineVolumeOutlineGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeOutlineGeometry._ellipsoid); - return PolylineVolumeOutlineGeometry.createGeometry(polylineVolumeOutlineGeometry); - } - - return createPolylineVolumeOutlineGeometry; -}); diff --git a/Source/Workers/createRectangleGeometry.js b/Source/Workers/createRectangleGeometry.js deleted file mode 100644 index 13d87bffe571..000000000000 --- a/Source/Workers/createRectangleGeometry.js +++ /dev/null @@ -1,24 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/Rectangle', - '../Core/RectangleGeometry' - ], function( - defined, - Ellipsoid, - Rectangle, - RectangleGeometry) { - "use strict"; - - 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); - } - - return createRectangleGeometry; -}); diff --git a/Source/Workers/createRectangleOutlineGeometry.js b/Source/Workers/createRectangleOutlineGeometry.js deleted file mode 100644 index afa790575283..000000000000 --- a/Source/Workers/createRectangleOutlineGeometry.js +++ /dev/null @@ -1,24 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/Rectangle', - '../Core/RectangleOutlineGeometry' - ], function( - defined, - Ellipsoid, - Rectangle, - RectangleOutlineGeometry) { - "use strict"; - - 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); - } - - return createRectangleOutlineGeometry; -}); diff --git a/Source/Workers/createSimplePolylineGeometry.js b/Source/Workers/createSimplePolylineGeometry.js deleted file mode 100644 index 6ab03361b05e..000000000000 --- a/Source/Workers/createSimplePolylineGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/SimplePolylineGeometry' - ], function( - defined, - Ellipsoid, - SimplePolylineGeometry) { - "use strict"; - - function createSimplePolylineGeometry(simplePolylineGeometry, offset) { - if (defined(offset)) { - simplePolylineGeometry = SimplePolylineGeometry.unpack(simplePolylineGeometry, offset); - } - simplePolylineGeometry._ellipsoid = Ellipsoid.clone(simplePolylineGeometry._ellipsoid); - return SimplePolylineGeometry.createGeometry(simplePolylineGeometry); - } - - return createSimplePolylineGeometry; -}); diff --git a/Source/Workers/createSphereGeometry.js b/Source/Workers/createSphereGeometry.js deleted file mode 100644 index db749b945e19..000000000000 --- a/Source/Workers/createSphereGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/SphereGeometry' - ], function( - defined, - SphereGeometry) { - "use strict"; - - 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 deleted file mode 100644 index 144a2944cc2e..000000000000 --- a/Source/Workers/createSphereOutlineGeometry.js +++ /dev/null @@ -1,16 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/SphereOutlineGeometry' - ], function( - defined, - SphereOutlineGeometry) { - "use strict"; - - 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 deleted file mode 100644 index 8326b64f8e5f..000000000000 --- a/Source/Workers/createWallGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/WallGeometry' - ], function( - defined, - Ellipsoid, - WallGeometry) { - "use strict"; - - function createWallGeometry(wallGeometry, offset) { - if (defined(offset)) { - wallGeometry = WallGeometry.unpack(wallGeometry, offset); - } - wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); - return WallGeometry.createGeometry(wallGeometry); - } - - return createWallGeometry; -}); diff --git a/Source/Workers/createWallOutlineGeometry.js b/Source/Workers/createWallOutlineGeometry.js deleted file mode 100644 index fd555460b045..000000000000 --- a/Source/Workers/createWallOutlineGeometry.js +++ /dev/null @@ -1,21 +0,0 @@ -/*global define*/ -define([ - '../Core/defined', - '../Core/Ellipsoid', - '../Core/WallOutlineGeometry' - ], function( - defined, - Ellipsoid, - WallOutlineGeometry) { - "use strict"; - - function createWallOutlineGeometry(wallGeometry, offset) { - if (defined(offset)) { - wallGeometry = WallOutlineGeometry.unpack(wallGeometry, offset); - } - wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); - return WallOutlineGeometry.createGeometry(wallGeometry); - } - - return createWallOutlineGeometry; -}); From 0b78cbf12b8ca268d77d430d5119629143021c52 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 5 Jan 2015 13:07:24 -0500 Subject: [PATCH 19/22] Fix SphereGeometry and SphereOutlineGeometry unpack. --- Source/Core/SphereGeometry.js | 2 +- Source/Core/SphereOutlineGeometry.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/SphereGeometry.js b/Source/Core/SphereGeometry.js index 428d08683d53..20329ef3e75f 100644 --- a/Source/Core/SphereGeometry.js +++ b/Source/Core/SphereGeometry.js @@ -101,7 +101,7 @@ define([ scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions; if (!defined(result)) { - scratchOptions.radius = ellipsoidGeometry._radius; + scratchOptions.radius = ellipsoidGeometry._radii.x; return new SphereGeometry(scratchOptions); } diff --git a/Source/Core/SphereOutlineGeometry.js b/Source/Core/SphereOutlineGeometry.js index 61ef9dfa5712..cd02f3762895 100644 --- a/Source/Core/SphereOutlineGeometry.js +++ b/Source/Core/SphereOutlineGeometry.js @@ -99,7 +99,7 @@ define([ scratchOptions.subdivisions = ellipsoidGeometry._subdivisions; if (!defined(result)) { - scratchOptions.radius = ellipsoidGeometry._radius; + scratchOptions.radius = ellipsoidGeometry._radii.x; return new SphereOutlineGeometry(scratchOptions); } From a484adc8c2f726ae9983112d636b9d8abd5c8b49 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 5 Jan 2015 13:17:14 -0500 Subject: [PATCH 20/22] Add VertexFormat clone tests. --- Specs/Core/VertexFormatSpec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Specs/Core/VertexFormatSpec.js b/Specs/Core/VertexFormatSpec.js index 7bc4f4ba4e75..95e27689287c 100644 --- a/Specs/Core/VertexFormatSpec.js +++ b/Specs/Core/VertexFormatSpec.js @@ -8,5 +8,26 @@ defineSuite([ "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]); }); From 9e4f045277348a6f15619aa4fad5e7c5b644a3e8 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 5 Jan 2015 15:26:18 -0500 Subject: [PATCH 21/22] Revert "Remove the create*Geometry workers. Require geometries to implement packable and have a createGeometry function." This reverts commit 4073f3824bf1fa4f4c4ded44e4540e8e61b78e94. --- Source/Core/BoxGeometry.js | 5 ++-- Source/Core/BoxOutlineGeometry.js | 5 ++-- Source/Core/CircleGeometry.js | 5 ++-- Source/Core/CircleOutlineGeometry.js | 5 ++-- Source/Core/CorridorGeometry.js | 5 ++-- Source/Core/CorridorOutlineGeometry.js | 5 ++-- Source/Core/CylinderGeometry.js | 5 ++-- Source/Core/CylinderOutlineGeometry.js | 5 ++-- Source/Core/EllipseGeometry.js | 5 ++-- Source/Core/EllipseOutlineGeometry.js | 5 ++-- Source/Core/EllipsoidGeometry.js | 5 ++-- Source/Core/EllipsoidOutlineGeometry.js | 5 ++-- Source/Core/PolygonGeometry.js | 5 ++-- Source/Core/PolygonOutlineGeometry.js | 5 ++-- Source/Core/PolylineGeometry.js | 5 ++-- Source/Core/PolylineVolumeGeometry.js | 5 ++-- Source/Core/PolylineVolumeOutlineGeometry.js | 5 ++-- Source/Core/RectangleGeometry.js | 5 ++-- Source/Core/RectangleOutlineGeometry.js | 5 ++-- Source/Core/SimplePolylineGeometry.js | 5 ++-- Source/Core/SphereGeometry.js | 5 ++-- Source/Core/SphereOutlineGeometry.js | 5 ++-- Source/Core/WallGeometry.js | 5 ++-- Source/Core/WallOutlineGeometry.js | 5 ++-- Source/Scene/Primitive.js | 8 +------ Source/Workers/createBoxGeometry.js | 16 +++++++++++++ Source/Workers/createBoxOutlineGeometry.js | 16 +++++++++++++ Source/Workers/createCircleGeometry.js | 24 +++++++++++++++++++ Source/Workers/createCircleOutlineGeometry.js | 24 +++++++++++++++++++ Source/Workers/createCorridorGeometry.js | 21 ++++++++++++++++ .../Workers/createCorridorOutlineGeometry.js | 21 ++++++++++++++++ Source/Workers/createCylinderGeometry.js | 16 +++++++++++++ .../Workers/createCylinderOutlineGeometry.js | 16 +++++++++++++ Source/Workers/createEllipseGeometry.js | 24 +++++++++++++++++++ .../Workers/createEllipseOutlineGeometry.js | 24 +++++++++++++++++++ Source/Workers/createEllipsoidGeometry.js | 16 +++++++++++++ .../Workers/createEllipsoidOutlineGeometry.js | 16 +++++++++++++ Source/Workers/createGeometry.js | 11 +++------ Source/Workers/createPolygonGeometry.js | 21 ++++++++++++++++ .../Workers/createPolygonOutlineGeometry.js | 21 ++++++++++++++++ Source/Workers/createPolylineGeometry.js | 21 ++++++++++++++++ .../Workers/createPolylineVolumeGeometry.js | 21 ++++++++++++++++ .../createPolylineVolumeOutlineGeometry.js | 21 ++++++++++++++++ Source/Workers/createRectangleGeometry.js | 24 +++++++++++++++++++ .../Workers/createRectangleOutlineGeometry.js | 24 +++++++++++++++++++ .../Workers/createSimplePolylineGeometry.js | 21 ++++++++++++++++ Source/Workers/createSphereGeometry.js | 16 +++++++++++++ Source/Workers/createSphereOutlineGeometry.js | 16 +++++++++++++ Source/Workers/createWallGeometry.js | 21 ++++++++++++++++ Source/Workers/createWallOutlineGeometry.js | 21 ++++++++++++++++ 50 files changed, 558 insertions(+), 63 deletions(-) create mode 100644 Source/Workers/createBoxGeometry.js create mode 100644 Source/Workers/createBoxOutlineGeometry.js create mode 100644 Source/Workers/createCircleGeometry.js create mode 100644 Source/Workers/createCircleOutlineGeometry.js create mode 100644 Source/Workers/createCorridorGeometry.js create mode 100644 Source/Workers/createCorridorOutlineGeometry.js create mode 100644 Source/Workers/createCylinderGeometry.js create mode 100644 Source/Workers/createCylinderOutlineGeometry.js create mode 100644 Source/Workers/createEllipseGeometry.js create mode 100644 Source/Workers/createEllipseOutlineGeometry.js create mode 100644 Source/Workers/createEllipsoidGeometry.js create mode 100644 Source/Workers/createEllipsoidOutlineGeometry.js create mode 100644 Source/Workers/createPolygonGeometry.js create mode 100644 Source/Workers/createPolygonOutlineGeometry.js create mode 100644 Source/Workers/createPolylineGeometry.js create mode 100644 Source/Workers/createPolylineVolumeGeometry.js create mode 100644 Source/Workers/createPolylineVolumeOutlineGeometry.js create mode 100644 Source/Workers/createRectangleGeometry.js create mode 100644 Source/Workers/createRectangleOutlineGeometry.js create mode 100644 Source/Workers/createSimplePolylineGeometry.js create mode 100644 Source/Workers/createSphereGeometry.js create mode 100644 Source/Workers/createSphereOutlineGeometry.js create mode 100644 Source/Workers/createWallGeometry.js create mode 100644 Source/Workers/createWallOutlineGeometry.js diff --git a/Source/Core/BoxGeometry.js b/Source/Core/BoxGeometry.js index b035aec1c1f4..839a520262d1 100644 --- a/Source/Core/BoxGeometry.js +++ b/Source/Core/BoxGeometry.js @@ -52,7 +52,7 @@ define([ * }); * var geometry = Cesium.BoxGeometry.createGeometry(box); */ - function BoxGeometry(options) { + var BoxGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var min = options.minimumCorner; var max = options.maximumCorner; @@ -71,7 +71,8 @@ define([ this._minimumCorner = Cartesian3.clone(min); this._maximumCorner = Cartesian3.clone(max); this._vertexFormat = vertexFormat; - } + this._workerName = 'createBoxGeometry'; + }; /** * Creates a cube centered at the origin given its dimensions. diff --git a/Source/Core/BoxOutlineGeometry.js b/Source/Core/BoxOutlineGeometry.js index 45fbcac139a1..8461d0a24d39 100644 --- a/Source/Core/BoxOutlineGeometry.js +++ b/Source/Core/BoxOutlineGeometry.js @@ -47,7 +47,7 @@ define([ * }); * var geometry = Cesium.BoxOutlineGeometry.createGeometry(box); */ - function BoxOutlineGeometry(options) { + var BoxOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var min = options.minimumCorner; @@ -64,7 +64,8 @@ define([ this._min = Cartesian3.clone(min); this._max = Cartesian3.clone(max); - } + this._workerName = 'createBoxOutlineGeometry'; + }; /** * Creates an outline of a cube centered at the origin given its dimensions. diff --git a/Source/Core/CircleGeometry.js b/Source/Core/CircleGeometry.js index 4be0b5d39327..1eb967557a95 100644 --- a/Source/Core/CircleGeometry.js +++ b/Source/Core/CircleGeometry.js @@ -49,7 +49,7 @@ define([ * }); * var geometry = Cesium.CircleGeometry.createGeometry(circle); */ - function CircleGeometry(options) { + var CircleGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radius = options.radius; @@ -74,7 +74,8 @@ define([ stRotation : options.stRotation }; this._ellipseGeometry = new EllipseGeometry(ellipseGeometryOptions); - } + this._workerName = 'createCircleGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/CircleOutlineGeometry.js b/Source/Core/CircleOutlineGeometry.js index 3ea44c16db26..b43dca2f57b9 100644 --- a/Source/Core/CircleOutlineGeometry.js +++ b/Source/Core/CircleOutlineGeometry.js @@ -46,7 +46,7 @@ define([ * }); * var geometry = Cesium.CircleOutlineGeometry.createGeometry(circle); */ - function CircleOutlineGeometry(options) { + var CircleOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radius = options.radius; @@ -70,7 +70,8 @@ define([ numberOfVerticalLines : options.numberOfVerticalLines }; this._ellipseGeometry = new EllipseOutlineGeometry(ellipseGeometryOptions); - } + this._workerName = 'createCircleOutlineGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index f1f582e4f566..184e2bdc167b 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -648,7 +648,7 @@ define([ * width : 100000 * }); */ - function CorridorGeometry(options) { + var CorridorGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var width = options.width; @@ -670,13 +670,14 @@ define([ 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 = '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. diff --git a/Source/Core/CorridorOutlineGeometry.js b/Source/Core/CorridorOutlineGeometry.js index 28b72944a9f8..851175437a9c 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -325,7 +325,7 @@ define([ * width : 100000 * }); */ - function CorridorOutlineGeometry(options) { + var CorridorOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var width = options.width; @@ -346,13 +346,14 @@ define([ 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. diff --git a/Source/Core/CylinderGeometry.js b/Source/Core/CylinderGeometry.js index ced069257ded..a6d76998523f 100644 --- a/Source/Core/CylinderGeometry.js +++ b/Source/Core/CylinderGeometry.js @@ -72,7 +72,7 @@ define([ * }); * var geometry = Cesium.CylinderGeometry.createGeometry(cylinder); */ - function CylinderGeometry(options) { + var CylinderGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var length = options.length; @@ -104,7 +104,8 @@ define([ this._bottomRadius = bottomRadius; this._vertexFormat = VertexFormat.clone(vertexFormat); this._slices = slices; - } + this._workerName = 'createCylinderGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/CylinderOutlineGeometry.js b/Source/Core/CylinderOutlineGeometry.js index b72203ba6993..89953caac132 100644 --- a/Source/Core/CylinderOutlineGeometry.js +++ b/Source/Core/CylinderOutlineGeometry.js @@ -63,7 +63,7 @@ define([ * }); * var geometry = Cesium.CylinderOutlineGeometry.createGeometry(cylinder); */ - function CylinderOutlineGeometry(options) { + var CylinderOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var length = options.length; @@ -95,7 +95,8 @@ define([ this._bottomRadius = bottomRadius; this._slices = slices; this._numberOfVerticalLines = numberOfVerticalLines; - } + this._workerName = 'createCylinderOutlineGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index fbe7c0790302..e95ac358184b 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -586,7 +586,7 @@ define([ * }); * var geometry = Cesium.EllipseGeometry.createGeometry(ellipse); */ - function EllipseGeometry(options) { + var EllipseGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var center = options.center; @@ -631,7 +631,8 @@ define([ 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. diff --git a/Source/Core/EllipseOutlineGeometry.js b/Source/Core/EllipseOutlineGeometry.js index c020fe5a06cf..f74f8cdfe6f4 100644 --- a/Source/Core/EllipseOutlineGeometry.js +++ b/Source/Core/EllipseOutlineGeometry.js @@ -161,7 +161,7 @@ define([ * }); * var geometry = Cesium.EllipseOutlineGeometry.createGeometry(ellipse); */ - function EllipseOutlineGeometry(options) { + var EllipseOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var center = options.center; @@ -204,7 +204,8 @@ define([ 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. diff --git a/Source/Core/EllipsoidGeometry.js b/Source/Core/EllipsoidGeometry.js index d06f0ef054c3..571dcbef3ddc 100644 --- a/Source/Core/EllipsoidGeometry.js +++ b/Source/Core/EllipsoidGeometry.js @@ -69,7 +69,7 @@ define([ * }); * var geometry = Cesium.EllipsoidGeometry.createGeometry(ellipsoid); */ - function EllipsoidGeometry(options) { + var EllipsoidGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radii = defaultValue(options.radii, defaultRadii); @@ -90,7 +90,8 @@ define([ this._stackPartitions = stackPartitions; this._slicePartitions = slicePartitions; this._vertexFormat = VertexFormat.clone(vertexFormat); - } + this._workerName = 'createEllipsoidGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/EllipsoidOutlineGeometry.js b/Source/Core/EllipsoidOutlineGeometry.js index 491c302149b7..70a523b743d0 100644 --- a/Source/Core/EllipsoidOutlineGeometry.js +++ b/Source/Core/EllipsoidOutlineGeometry.js @@ -59,7 +59,7 @@ define([ * }); * var geometry = Cesium.EllipsoidOutlineGeometry.createGeometry(ellipsoid); */ - function EllipsoidOutlineGeometry(options) { + var EllipsoidOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var radii = defaultValue(options.radii, defaultRadii); @@ -83,7 +83,8 @@ define([ this._stackPartitions = stackPartitions; this._slicePartitions = slicePartitions; this._subdivisions = subdivisions; - } + this._workerName = 'createEllipsoidOutlineGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index 1968b8229045..25aea1ac76a5 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -603,7 +603,7 @@ define([ * }); * var geometry = Cesium.PolygonGeometry.createGeometry(extrudedPolygon); */ - function PolygonGeometry(options) { + var PolygonGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); @@ -637,13 +637,14 @@ define([ 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; - } + }; /** * A description of a polygon from an array of positions. diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index f5af844a14bc..d7ae8bf92bc4 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -298,7 +298,7 @@ define([ * }); * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(extrudedPolygon); */ - function PolygonOutlineGeometry(options) { + var PolygonOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); @@ -328,13 +328,14 @@ define([ 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. diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index 411fae19f2ca..026ee480ab76 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -110,7 +110,7 @@ define([ * }); * var geometry = Cesium.PolylineGeometry.createGeometry(polyline); */ - function PolylineGeometry(options) { + var PolylineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var colors = options.colors; @@ -137,6 +137,7 @@ define([ this._followSurface = defaultValue(options.followSurface, true); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); 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; @@ -146,7 +147,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 4; - } + }; /** * Stores the provided instance into the provided array. diff --git a/Source/Core/PolylineVolumeGeometry.js b/Source/Core/PolylineVolumeGeometry.js index c59619a299f2..e17a26928f34 100644 --- a/Source/Core/PolylineVolumeGeometry.js +++ b/Source/Core/PolylineVolumeGeometry.js @@ -213,7 +213,7 @@ define([ * shapePositions : computeCircle(100000.0) * }); */ - function PolylineVolumeGeometry(options) { + var PolylineVolumeGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.polylinePositions; var shape = options.shapePositions; @@ -233,6 +233,7 @@ define([ this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); 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; @@ -242,7 +243,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 2; - } + }; /** * Stores the provided instance into the provided array. diff --git a/Source/Core/PolylineVolumeOutlineGeometry.js b/Source/Core/PolylineVolumeOutlineGeometry.js index 280e10d62a44..fa1a0226377e 100644 --- a/Source/Core/PolylineVolumeOutlineGeometry.js +++ b/Source/Core/PolylineVolumeOutlineGeometry.js @@ -128,7 +128,7 @@ define([ * shapePositions : computeCircle(100000.0) * }); */ - function PolylineVolumeOutlineGeometry(options) { + var PolylineVolumeOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.polylinePositions; var shape = options.shapePositions; @@ -147,6 +147,7 @@ define([ 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; @@ -156,7 +157,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + 2; - } + }; /** * Stores the provided instance into the provided array. diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 7d2f3ec5d5f5..d27f0affc3cb 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -543,7 +543,7 @@ define([ * }); * var geometry = Cesium.RectangleGeometry.createGeometry(rectangle); */ - function RectangleGeometry(options) { + var RectangleGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var rectangle = options.rectangle; @@ -579,7 +579,8 @@ define([ this._extrude = extrude; this._closeTop = closeTop; this._closeBottom = closeBottom; - } + this._workerName = 'createRectangleGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index 26051f5cbf05..d36637df5b8b 100644 --- a/Source/Core/RectangleOutlineGeometry.js +++ b/Source/Core/RectangleOutlineGeometry.js @@ -193,7 +193,7 @@ define([ * }); * var geometry = Cesium.RectangleOutlineGeometry.createGeometry(rectangle); */ - function RectangleOutlineGeometry(options) { + var RectangleOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var rectangle = options.rectangle; @@ -219,7 +219,8 @@ define([ this._surfaceHeight = surfaceHeight; this._rotation = rotation; this._extrudedHeight = extrudedHeight; - } + this._workerName = 'createRectangleOutlineGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/SimplePolylineGeometry.js b/Source/Core/SimplePolylineGeometry.js index deec58558e0f..203146b7a490 100644 --- a/Source/Core/SimplePolylineGeometry.js +++ b/Source/Core/SimplePolylineGeometry.js @@ -106,7 +106,7 @@ define([ * }); * var geometry = Cesium.SimplePolylineGeometry.createGeometry(polyline); */ - function SimplePolylineGeometry(options) { + var SimplePolylineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var positions = options.positions; var colors = options.colors; @@ -127,6 +127,7 @@ define([ this._followSurface = defaultValue(options.followSurface, true); 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; @@ -136,7 +137,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + 3; - } + }; /** * Stores the provided instance into the provided array. diff --git a/Source/Core/SphereGeometry.js b/Source/Core/SphereGeometry.js index 20329ef3e75f..6e8b6e8bdd58 100644 --- a/Source/Core/SphereGeometry.js +++ b/Source/Core/SphereGeometry.js @@ -41,7 +41,7 @@ define([ * }); * var geometry = Cesium.SphereGeometry.createGeometry(sphere); */ - function SphereGeometry(options) { + var SphereGeometry = function(options) { var radius = defaultValue(options.radius, 1.0); var radii = new Cartesian3(radius, radius, radius); var ellipsoidOptions = { @@ -52,7 +52,8 @@ define([ }; this._ellipsoidGeometry = new EllipsoidGeometry(ellipsoidOptions); - } + this._workerName = 'createSphereGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/SphereOutlineGeometry.js b/Source/Core/SphereOutlineGeometry.js index cd02f3762895..739e3409a07c 100644 --- a/Source/Core/SphereOutlineGeometry.js +++ b/Source/Core/SphereOutlineGeometry.js @@ -39,7 +39,7 @@ define([ * }); * var geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere); */ - function SphereOutlineGeometry(options) { + var SphereOutlineGeometry = function(options) { var radius = defaultValue(options.radius, 1.0); var radii = new Cartesian3(radius, radius, radius); var ellipsoidOptions = { @@ -50,7 +50,8 @@ define([ }; this._ellipsoidGeometry = new EllipsoidOutlineGeometry(ellipsoidOptions); - } + this._workerName = 'createSphereOutlineGeometry'; + }; /** * The number of elements used to pack the object into an array. diff --git a/Source/Core/WallGeometry.js b/Source/Core/WallGeometry.js index 19e693a7e490..79bdf9a77925 100644 --- a/Source/Core/WallGeometry.js +++ b/Source/Core/WallGeometry.js @@ -80,7 +80,7 @@ define([ * }); * var geometry = Cesium.WallGeometry.createGeometry(wall); */ - function WallGeometry(options) { + var WallGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var wallPositions = options.positions; @@ -109,6 +109,7 @@ define([ this._vertexFormat = VertexFormat.clone(vertexFormat); this._granularity = granularity; this._ellipsoid = Ellipsoid.clone(ellipsoid); + this._workerName = 'createWallGeometry'; var numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2; if (defined(minimumHeights)) { @@ -123,7 +124,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 1; - } + }; /** * Stores the provided instance into the provided array. diff --git a/Source/Core/WallOutlineGeometry.js b/Source/Core/WallOutlineGeometry.js index eabe64972bc6..4ebc9e0a6df4 100644 --- a/Source/Core/WallOutlineGeometry.js +++ b/Source/Core/WallOutlineGeometry.js @@ -71,7 +71,7 @@ define([ * }); * var geometry = Cesium.WallOutlineGeometry.createGeometry(wall); */ - function WallOutlineGeometry(options) { + var WallOutlineGeometry = function(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); var wallPositions = options.positions; @@ -98,6 +98,7 @@ define([ this._maximumHeights = maximumHeights; this._granularity = granularity; this._ellipsoid = Ellipsoid.clone(ellipsoid); + this._workerName = 'createWallOutlineGeometry'; var numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2; if (defined(minimumHeights)) { @@ -112,7 +113,7 @@ define([ * @type {Number} */ this.packedLength = numComponents + Ellipsoid.packedLength + 1; - } + }; /** * Stores the provided instance into the provided array. diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index a29ecadfcfe3..aaa2b30b12e6 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -731,14 +731,8 @@ define([ for (i = 0; i < length; ++i) { geometry = instances[i].geometry; instanceIds.push(instances[i].id); - - var moduleName = geometry.constructor.name; - if (moduleName === "Object") { - moduleName = undefined; - } - subTasks.push({ - moduleName : moduleName, + moduleName : geometry._workerName, geometry : geometry }); } diff --git a/Source/Workers/createBoxGeometry.js b/Source/Workers/createBoxGeometry.js new file mode 100644 index 000000000000..aaf24fbe30ee --- /dev/null +++ b/Source/Workers/createBoxGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/BoxGeometry', + '../Core/defined' + ], function( + BoxGeometry, + defined) { + "use strict"; + + 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 new file mode 100644 index 000000000000..0c0ac8ae76c4 --- /dev/null +++ b/Source/Workers/createBoxOutlineGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/BoxOutlineGeometry', + '../Core/defined' + ], function( + BoxOutlineGeometry, + defined) { + "use strict"; + + 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 new file mode 100644 index 000000000000..3eba599f2d13 --- /dev/null +++ b/Source/Workers/createCircleGeometry.js @@ -0,0 +1,24 @@ +/*global define*/ +define([ + '../Core/Cartesian3', + '../Core/CircleGeometry', + '../Core/defined', + '../Core/Ellipsoid' + ], function( + Cartesian3, + CircleGeometry, + defined, + Ellipsoid) { + "use strict"; + + 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); + } + + return createCircleGeometry; +}); diff --git a/Source/Workers/createCircleOutlineGeometry.js b/Source/Workers/createCircleOutlineGeometry.js new file mode 100644 index 000000000000..5df6cc94814f --- /dev/null +++ b/Source/Workers/createCircleOutlineGeometry.js @@ -0,0 +1,24 @@ +/*global define*/ +define([ + '../Core/Cartesian3', + '../Core/CircleOutlineGeometry', + '../Core/defined', + '../Core/Ellipsoid' + ], function( + Cartesian3, + CircleOutlineGeometry, + defined, + Ellipsoid) { + "use strict"; + + 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); + } + + return createCircleOutlineGeometry; +}); diff --git a/Source/Workers/createCorridorGeometry.js b/Source/Workers/createCorridorGeometry.js new file mode 100644 index 000000000000..ba673a27f803 --- /dev/null +++ b/Source/Workers/createCorridorGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/CorridorGeometry', + '../Core/defined', + '../Core/Ellipsoid' + ], function( + CorridorGeometry, + defined, + Ellipsoid) { + "use strict"; + + function createCorridorGeometry(corridorGeometry, offset) { + if (defined(offset)) { + corridorGeometry = CorridorGeometry.unpack(corridorGeometry, offset); + } + corridorGeometry._ellipsoid = Ellipsoid.clone(corridorGeometry._ellipsoid); + return CorridorGeometry.createGeometry(corridorGeometry); + } + + return createCorridorGeometry; +}); diff --git a/Source/Workers/createCorridorOutlineGeometry.js b/Source/Workers/createCorridorOutlineGeometry.js new file mode 100644 index 000000000000..45cca03cbc43 --- /dev/null +++ b/Source/Workers/createCorridorOutlineGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/CorridorOutlineGeometry', + '../Core/defined', + '../Core/Ellipsoid' + ], function( + CorridorOutlineGeometry, + defined, + Ellipsoid) { + "use strict"; + + function createCorridorOutlineGeometry(corridorOutlineGeometry, offset) { + if (defined(offset)) { + corridorOutlineGeometry = CorridorOutlineGeometry.unpack(corridorOutlineGeometry, offset); + } + corridorOutlineGeometry._ellipsoid = Ellipsoid.clone(corridorOutlineGeometry._ellipsoid); + return CorridorOutlineGeometry.createGeometry(corridorOutlineGeometry); + } + + return createCorridorOutlineGeometry; +}); diff --git a/Source/Workers/createCylinderGeometry.js b/Source/Workers/createCylinderGeometry.js new file mode 100644 index 000000000000..309ea24cd175 --- /dev/null +++ b/Source/Workers/createCylinderGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/CylinderGeometry', + '../Core/defined' + ], function( + CylinderGeometry, + defined) { + "use strict"; + + 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 new file mode 100644 index 000000000000..e17895dd6608 --- /dev/null +++ b/Source/Workers/createCylinderOutlineGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/CylinderOutlineGeometry', + '../Core/defined' + ], function( + CylinderOutlineGeometry, + defined) { + "use strict"; + + 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 new file mode 100644 index 000000000000..626e24e3dbb3 --- /dev/null +++ b/Source/Workers/createEllipseGeometry.js @@ -0,0 +1,24 @@ +/*global define*/ +define([ + '../Core/Cartesian3', + '../Core/defined', + '../Core/EllipseGeometry', + '../Core/Ellipsoid' + ], function( + Cartesian3, + defined, + EllipseGeometry, + Ellipsoid) { + "use strict"; + + 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); + } + + return createEllipseGeometry; +}); diff --git a/Source/Workers/createEllipseOutlineGeometry.js b/Source/Workers/createEllipseOutlineGeometry.js new file mode 100644 index 000000000000..9a0ffe328e46 --- /dev/null +++ b/Source/Workers/createEllipseOutlineGeometry.js @@ -0,0 +1,24 @@ +/*global define*/ +define([ + '../Core/Cartesian3', + '../Core/defined', + '../Core/EllipseOutlineGeometry', + '../Core/Ellipsoid' + ], function( + Cartesian3, + defined, + EllipseOutlineGeometry, + Ellipsoid) { + "use strict"; + + 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); + } + + return createEllipseOutlineGeometry; +}); diff --git a/Source/Workers/createEllipsoidGeometry.js b/Source/Workers/createEllipsoidGeometry.js new file mode 100644 index 000000000000..a5de0a49bc8d --- /dev/null +++ b/Source/Workers/createEllipsoidGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/EllipsoidGeometry' + ], function( + defined, + EllipsoidGeometry) { + "use strict"; + + 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 new file mode 100644 index 000000000000..7f720a2df884 --- /dev/null +++ b/Source/Workers/createEllipsoidOutlineGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/EllipsoidOutlineGeometry' + ], function( + defined, + EllipsoidOutlineGeometry) { + "use strict"; + + 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 15d210b7a0da..24570db39d42 100644 --- a/Source/Workers/createGeometry.js +++ b/Source/Workers/createGeometry.js @@ -17,14 +17,9 @@ define([ var module = moduleCache[moduleName]; if (!defined(module)) { // in web workers, require is synchronous - require(['../Core/' + moduleName], function(f) { - module = function(geometry, offset) { - if (defined(offset)) { - geometry = f.unpack(geometry, offset); - } - return f.createGeometry(geometry); - }; - moduleCache[moduleName] = module; + require(['./' + moduleName], function(f) { + module = f; + moduleCache[module] = f; }); } return module; diff --git a/Source/Workers/createPolygonGeometry.js b/Source/Workers/createPolygonGeometry.js new file mode 100644 index 000000000000..1f03cc8386af --- /dev/null +++ b/Source/Workers/createPolygonGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/PolygonGeometry' + ], function( + defined, + Ellipsoid, + PolygonGeometry) { + "use strict"; + + function createPolygonGeometry(polygonGeometry, offset) { + if (defined(offset)) { + polygonGeometry = PolygonGeometry.unpack(polygonGeometry, offset); + } + polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); + return PolygonGeometry.createGeometry(polygonGeometry); + } + + return createPolygonGeometry; +}); diff --git a/Source/Workers/createPolygonOutlineGeometry.js b/Source/Workers/createPolygonOutlineGeometry.js new file mode 100644 index 000000000000..1c298701111e --- /dev/null +++ b/Source/Workers/createPolygonOutlineGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/PolygonOutlineGeometry' + ], function( + defined, + Ellipsoid, + PolygonOutlineGeometry) { + "use strict"; + + function createPolygonOutlineGeometry(polygonGeometry, offset) { + if (defined(offset)) { + polygonGeometry = PolygonOutlineGeometry.unpack(polygonGeometry, offset); + } + polygonGeometry._ellipsoid = Ellipsoid.clone(polygonGeometry._ellipsoid); + return PolygonOutlineGeometry.createGeometry(polygonGeometry); + } + + return createPolygonOutlineGeometry; +}); diff --git a/Source/Workers/createPolylineGeometry.js b/Source/Workers/createPolylineGeometry.js new file mode 100644 index 000000000000..4fb72ce64831 --- /dev/null +++ b/Source/Workers/createPolylineGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/PolylineGeometry' + ], function( + defined, + Ellipsoid, + PolylineGeometry) { + "use strict"; + + function createPolylineGeometry(polylineGeometry, offset) { + if (defined(offset)) { + polylineGeometry = PolylineGeometry.unpack(polylineGeometry, offset); + } + polylineGeometry._ellipsoid = Ellipsoid.clone(polylineGeometry._ellipsoid); + return PolylineGeometry.createGeometry(polylineGeometry); + } + + return createPolylineGeometry; +}); diff --git a/Source/Workers/createPolylineVolumeGeometry.js b/Source/Workers/createPolylineVolumeGeometry.js new file mode 100644 index 000000000000..914b710246e7 --- /dev/null +++ b/Source/Workers/createPolylineVolumeGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/PolylineVolumeGeometry' + ], function( + defined, + Ellipsoid, + PolylineVolumeGeometry) { + "use strict"; + + function createPolylineVolumeGeometry(polylineVolumeGeometry, offset) { + if (defined(offset)) { + polylineVolumeGeometry = PolylineVolumeGeometry.unpack(polylineVolumeGeometry, offset); + } + polylineVolumeGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeGeometry._ellipsoid); + return PolylineVolumeGeometry.createGeometry(polylineVolumeGeometry); + } + + return createPolylineVolumeGeometry; +}); diff --git a/Source/Workers/createPolylineVolumeOutlineGeometry.js b/Source/Workers/createPolylineVolumeOutlineGeometry.js new file mode 100644 index 000000000000..5ef898e172c2 --- /dev/null +++ b/Source/Workers/createPolylineVolumeOutlineGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/PolylineVolumeOutlineGeometry' + ], function( + defined, + Ellipsoid, + PolylineVolumeOutlineGeometry) { + "use strict"; + + function createPolylineVolumeOutlineGeometry(polylineVolumeOutlineGeometry, offset) { + if (defined(offset)) { + polylineVolumeOutlineGeometry = PolylineVolumeOutlineGeometry.unpack(polylineVolumeOutlineGeometry, offset); + } + polylineVolumeOutlineGeometry._ellipsoid = Ellipsoid.clone(polylineVolumeOutlineGeometry._ellipsoid); + return PolylineVolumeOutlineGeometry.createGeometry(polylineVolumeOutlineGeometry); + } + + return createPolylineVolumeOutlineGeometry; +}); diff --git a/Source/Workers/createRectangleGeometry.js b/Source/Workers/createRectangleGeometry.js new file mode 100644 index 000000000000..13d87bffe571 --- /dev/null +++ b/Source/Workers/createRectangleGeometry.js @@ -0,0 +1,24 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/Rectangle', + '../Core/RectangleGeometry' + ], function( + defined, + Ellipsoid, + Rectangle, + RectangleGeometry) { + "use strict"; + + 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); + } + + return createRectangleGeometry; +}); diff --git a/Source/Workers/createRectangleOutlineGeometry.js b/Source/Workers/createRectangleOutlineGeometry.js new file mode 100644 index 000000000000..afa790575283 --- /dev/null +++ b/Source/Workers/createRectangleOutlineGeometry.js @@ -0,0 +1,24 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/Rectangle', + '../Core/RectangleOutlineGeometry' + ], function( + defined, + Ellipsoid, + Rectangle, + RectangleOutlineGeometry) { + "use strict"; + + 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); + } + + return createRectangleOutlineGeometry; +}); diff --git a/Source/Workers/createSimplePolylineGeometry.js b/Source/Workers/createSimplePolylineGeometry.js new file mode 100644 index 000000000000..6ab03361b05e --- /dev/null +++ b/Source/Workers/createSimplePolylineGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/SimplePolylineGeometry' + ], function( + defined, + Ellipsoid, + SimplePolylineGeometry) { + "use strict"; + + function createSimplePolylineGeometry(simplePolylineGeometry, offset) { + if (defined(offset)) { + simplePolylineGeometry = SimplePolylineGeometry.unpack(simplePolylineGeometry, offset); + } + simplePolylineGeometry._ellipsoid = Ellipsoid.clone(simplePolylineGeometry._ellipsoid); + return SimplePolylineGeometry.createGeometry(simplePolylineGeometry); + } + + return createSimplePolylineGeometry; +}); diff --git a/Source/Workers/createSphereGeometry.js b/Source/Workers/createSphereGeometry.js new file mode 100644 index 000000000000..db749b945e19 --- /dev/null +++ b/Source/Workers/createSphereGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/SphereGeometry' + ], function( + defined, + SphereGeometry) { + "use strict"; + + 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 new file mode 100644 index 000000000000..144a2944cc2e --- /dev/null +++ b/Source/Workers/createSphereOutlineGeometry.js @@ -0,0 +1,16 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/SphereOutlineGeometry' + ], function( + defined, + SphereOutlineGeometry) { + "use strict"; + + 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 new file mode 100644 index 000000000000..8326b64f8e5f --- /dev/null +++ b/Source/Workers/createWallGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/WallGeometry' + ], function( + defined, + Ellipsoid, + WallGeometry) { + "use strict"; + + function createWallGeometry(wallGeometry, offset) { + if (defined(offset)) { + wallGeometry = WallGeometry.unpack(wallGeometry, offset); + } + wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); + return WallGeometry.createGeometry(wallGeometry); + } + + return createWallGeometry; +}); diff --git a/Source/Workers/createWallOutlineGeometry.js b/Source/Workers/createWallOutlineGeometry.js new file mode 100644 index 000000000000..fd555460b045 --- /dev/null +++ b/Source/Workers/createWallOutlineGeometry.js @@ -0,0 +1,21 @@ +/*global define*/ +define([ + '../Core/defined', + '../Core/Ellipsoid', + '../Core/WallOutlineGeometry' + ], function( + defined, + Ellipsoid, + WallOutlineGeometry) { + "use strict"; + + function createWallOutlineGeometry(wallGeometry, offset) { + if (defined(offset)) { + wallGeometry = WallOutlineGeometry.unpack(wallGeometry, offset); + } + wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid); + return WallOutlineGeometry.createGeometry(wallGeometry); + } + + return createWallOutlineGeometry; +}); From 376328458849193d2685e0c983bc312f093a64ae Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 7 Jan 2015 00:14:22 -0500 Subject: [PATCH 22/22] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) 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