Skip to content

Commit

Permalink
Merge pull request #2342 from AnalyticalGraphicsInc/geometry-web-worker
Browse files Browse the repository at this point in the history
Pack Geometries before passing to a web worker
  • Loading branch information
mramato committed Jan 7, 2015
2 parents f4b785c + 3763284 commit 332bbaa
Show file tree
Hide file tree
Showing 85 changed files with 3,453 additions and 133 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/BoundingSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
72 changes: 72 additions & 0 deletions Source/Core/BoxGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand Down Expand Up @@ -115,6 +116,77 @@ define([
return new BoxGeometry(newOptions);
};

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
BoxGeometry.packedLength = 2 * Cartesian3.packedLength + VertexFormat.packedLength;

/**
* Stores the provided instance into the provided array.
* @function
*
* @param {Object} value The value to pack.
* @param {Number[]} array The array to pack into.
* @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
*/
BoxGeometry.pack = function(value, array, startingIndex) {
//>>includeStart('debug', pragmas.debug);
if (!defined(value)) {
throw new DeveloperError('value is required');
}
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

startingIndex = defaultValue(startingIndex, 0);

Cartesian3.pack(value._minimumCorner, array, startingIndex);
Cartesian3.pack(value._maximumCorner, array, startingIndex + Cartesian3.packedLength);
VertexFormat.pack(value._vertexFormat, array, startingIndex + 2 * Cartesian3.packedLength);
};

var scratchMin = new Cartesian3();
var scratchMax = new Cartesian3();
var scratchVertexFormat = new VertexFormat();
var scratchOptions = {
minimumCorner : scratchMin,
maximumCorner : scratchMax,
vertexFormat : scratchVertexFormat
};

/**
* Retrieves an instance from a packed array.
*
* @param {Number[]} array The packed array.
* @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {BoxGeometry} [result] The object into which to store the result.
*/
BoxGeometry.unpack = function(array, startingIndex, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

startingIndex = defaultValue(startingIndex, 0);

var min = Cartesian3.unpack(array, startingIndex, scratchMin);
var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength, scratchMax);
var vertexFormat = VertexFormat.unpack(array, startingIndex + 2 * Cartesian3.packedLength, scratchVertexFormat);

if (!defined(result)) {
return new BoxGeometry(scratchOptions);
}

result._minimumCorner = Cartesian3.clone(min, result._minimumCorner);
result._maximumCorner = Cartesian3.clone(max, result._maximumCorner);
result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);

return result;
};

/**
* Computes the geometric representation of a box, including its vertices, indices, and a bounding sphere.
*
Expand Down
67 changes: 67 additions & 0 deletions Source/Core/BoxOutlineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand Down Expand Up @@ -105,6 +106,72 @@ define([
return new BoxOutlineGeometry(newOptions);
};

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
BoxOutlineGeometry.packedLength = 2 * Cartesian3.packedLength;

/**
* Stores the provided instance into the provided array.
* @function
*
* @param {Object} value The value to pack.
* @param {Number[]} array The array to pack into.
* @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
*/
BoxOutlineGeometry.pack = function(value, array, startingIndex) {
//>>includeStart('debug', pragmas.debug);
if (!defined(value)) {
throw new DeveloperError('value is required');
}
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

startingIndex = defaultValue(startingIndex, 0);

Cartesian3.pack(value._min, array, startingIndex);
Cartesian3.pack(value._max, array, startingIndex + Cartesian3.packedLength);
};

var scratchMin = new Cartesian3();
var scratchMax = new Cartesian3();
var scratchOptions = {
minimumCorner : scratchMin,
maximumCorner : scratchMax
};

/**
* Retrieves an instance from a packed array.
*
* @param {Number[]} array The packed array.
* @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {BoxOutlineGeometry} [result] The object into which to store the result.
*/
BoxOutlineGeometry.unpack = function(array, startingIndex, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

startingIndex = defaultValue(startingIndex, 0);

var min = Cartesian3.unpack(array, startingIndex, scratchMin);
var max = Cartesian3.unpack(array, startingIndex + Cartesian3.packedLength, scratchMax);

if (!defined(result)) {
return new BoxOutlineGeometry(scratchOptions);
}

result._min = Cartesian3.clone(min, result._min);
result._max = Cartesian3.clone(max, result._max);

return result;
};

/**
* Computes the geometric representation of an outline of a box, including its vertices, indices, and a bounding sphere.
*
Expand Down
80 changes: 78 additions & 2 deletions Source/Core/CircleGeometry.js
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand All @@ -31,6 +37,7 @@ define([
* @exception {DeveloperError} granularity must be greater than zero.
*
* @see CircleGeometry.createGeometry
* @see Packable
*
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Circle.html|Cesium Sandcastle Circle Demo}
*
Expand Down Expand Up @@ -70,6 +77,75 @@ define([
this._workerName = 'createCircleGeometry';
};

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
CircleGeometry.packedLength = EllipseGeometry.packedLength;

/**
* Stores the provided instance into the provided array.
* @function
*
* @param {Object} value The value to pack.
* @param {Number[]} array The array to pack into.
* @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
*/
CircleGeometry.pack = function(value, array, startingIndex) {
//>>includeStart('debug', pragmas.debug);
if (!defined(value)) {
throw new DeveloperError('value is required');
}
//>>includeEnd('debug');
EllipseGeometry.pack(value._ellipseGeometry, array, startingIndex);
};

var scratchEllipseGeometry = new EllipseGeometry({
center : new Cartesian3(),
semiMajorAxis : 1.0,
semiMinorAxis : 1.0
});
var scratchOptions = {
center : new Cartesian3(),
radius : undefined,
ellipsoid : Ellipsoid.clone(Ellipsoid.UNIT_SPHERE),
height : undefined,
extrudedHeight : undefined,
granularity : undefined,
vertexFormat : new VertexFormat(),
stRotation : undefined,
semiMajorAxis : undefined,
semiMinorAxis : undefined
};

/**
* Retrieves an instance from a packed array.
*
* @param {Number[]} array The packed array.
* @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {CircleGeometry} [result] The object into which to store the result.
*/
CircleGeometry.unpack = function(array, startingIndex, result) {
var ellipseGeometry = EllipseGeometry.unpack(array, startingIndex, scratchEllipseGeometry);
scratchOptions.center = Cartesian3.clone(ellipseGeometry._center, scratchOptions.center);
scratchOptions.ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid);
scratchOptions.height = ellipseGeometry._height;
scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
scratchOptions.granularity = ellipseGeometry._granularity;
scratchOptions.vertexFormat = VertexFormat.clone(ellipseGeometry._vertexFormat, scratchOptions.vertexFormat);
scratchOptions.stRotation = ellipseGeometry._stRotation;

if (!defined(result)) {
scratchOptions.radius = ellipseGeometry._semiMajorAxis;
return new CircleGeometry(scratchOptions);
}

scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
result._ellipseGeometry = new EllipseGeometry(scratchOptions);
return result;
};

/**
* Computes the geometric representation of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
*
Expand Down
76 changes: 74 additions & 2 deletions Source/Core/CircleOutlineGeometry.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/*global define*/
define([
'./Cartesian3',
'./defaultValue',
'./defined',
'./DeveloperError',
'./EllipseOutlineGeometry'
'./EllipseOutlineGeometry',
'./Ellipsoid'
], function(
Cartesian3,
defaultValue,
defined,
DeveloperError,
EllipseOutlineGeometry) {
EllipseOutlineGeometry,
Ellipsoid) {
"use strict";

/**
Expand All @@ -30,6 +34,7 @@ define([
* @exception {DeveloperError} granularity must be greater than zero.
*
* @see CircleOutlineGeometry.createGeometry
* @see Packable
*
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Circle%20Outline.html|Cesium Sandcastle Circle Outline Demo}
*
Expand Down Expand Up @@ -68,6 +73,73 @@ define([
this._workerName = 'createCircleOutlineGeometry';
};

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
CircleOutlineGeometry.packedLength = EllipseOutlineGeometry.packedLength;

/**
* Stores the provided instance into the provided array.
* @function
*
* @param {Object} value The value to pack.
* @param {Number[]} array The array to pack into.
* @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
*/
CircleOutlineGeometry.pack = function(value, array, startingIndex) {
//>>includeStart('debug', pragmas.debug);
if (!defined(value)) {
throw new DeveloperError('value is required');
}
//>>includeEnd('debug');
EllipseOutlineGeometry.pack(value._ellipseGeometry, array, startingIndex);
};

var scratchEllipseGeometry = new EllipseOutlineGeometry({
center : new Cartesian3(),
semiMajorAxis : 1.0,
semiMinorAxis : 1.0
});
var scratchOptions = {
center : new Cartesian3(),
radius : undefined,
ellipsoid : Ellipsoid.clone(Ellipsoid.UNIT_SPHERE),
height : undefined,
extrudedHeight : undefined,
granularity : undefined,
numberOfVerticalLines : undefined,
semiMajorAxis : undefined,
semiMinorAxis : undefined
};

/**
* Retrieves an instance from a packed array.
*
* @param {Number[]} array The packed array.
* @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {CircleOutlineGeometry} [result] The object into which to store the result.
*/
CircleOutlineGeometry.unpack = function(array, startingIndex, result) {
var ellipseGeometry = EllipseOutlineGeometry.unpack(array, startingIndex, scratchEllipseGeometry);
scratchOptions.center = Cartesian3.clone(ellipseGeometry._center, scratchOptions.center);
scratchOptions.ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid);
scratchOptions.height = ellipseGeometry._height;
scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
scratchOptions.granularity = ellipseGeometry._granularity;
scratchOptions.numberOfVerticalLines = ellipseGeometry._numberOfVerticalLines;

if (!defined(result)) {
scratchOptions.radius = ellipseGeometry._semiMajorAxis;
return new CircleOutlineGeometry(scratchOptions);
}

scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
result._ellipseGeometry = new EllipseOutlineGeometry(scratchOptions);
return result;
};

/**
* Computes the geometric representation of an outline of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
*
Expand Down
Loading

0 comments on commit 332bbaa

Please sign in to comment.