Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack Geometries before passing to a web worker #2342

Merged
merged 26 commits into from
Jan 7, 2015
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8db80fb
Make Ellipsoid and VertexFormat implement packable in order to make g…
bagnell Dec 19, 2014
5c976c6
Make box, circle, corridor, cylinder, and ellipse fill/outline geomet…
bagnell Dec 19, 2014
64aa675
Make ellipsoid and polygon fill/outline geometries implement packable.
bagnell Dec 19, 2014
2308c57
Make polyline, simple polyline, sphere and sphere outline geometries …
bagnell Dec 19, 2014
86eac13
Make Rectangle implement packable.
bagnell Dec 19, 2014
fb59f28
Make polyline volume, rectangle, and wall fill/outline geometries imp…
bagnell Dec 19, 2014
56e147d
Add packable tests for bounding sphere, ellipsoid and vertex format. …
bagnell Dec 22, 2014
30766ef
Add packable tests for corridor, cylinder, and ellipsoid fill/outline…
bagnell Dec 22, 2014
4053cf1
Add packable tests for polygon fill/outline geometries.
bagnell Dec 22, 2014
f4c6aec
Add packable tests for polyline, polyline volume and rectangle fill/o…
bagnell Dec 23, 2014
9f0745a
Add packable tests for simple polyline, sphere and wall fill/outline …
bagnell Dec 23, 2014
9af7036
Initial pack geometries before sending to web worker. Still needs web…
bagnell Dec 23, 2014
8fca16c
Pack geometries into an array when possible before passing to a web w…
bagnell Dec 23, 2014
e8c6034
Merge branch 'master' into geometry-web-worker
bagnell Dec 30, 2014
87fb766
Fix ellipse and rectangle geometry when extruded.
bagnell Dec 30, 2014
d042918
Pack geometries after they have been separated into sub-tasks.
bagnell Dec 30, 2014
382d342
Merge pull request #2365 from AnalyticalGraphicsInc/pack-subtasks
mramato Dec 31, 2014
d1ba164
Updates from review: Use scratch variables when unpacking box, circle…
bagnell Dec 31, 2014
e5d3f39
Updates from review: use scratch variables when unpacking corridor, c…
bagnell Dec 31, 2014
4073f38
Remove the create*Geometry workers. Require geometries to implement p…
bagnell Jan 5, 2015
0b78cbf
Fix SphereGeometry and SphereOutlineGeometry unpack.
bagnell Jan 5, 2015
a484adc
Add VertexFormat clone tests.
bagnell Jan 5, 2015
20c8d28
Merge branch 'master' into geometry-web-worker
bagnell Jan 5, 2015
9e4f045
Revert "Remove the create*Geometry workers. Require geometries to imp…
bagnell Jan 5, 2015
d263195
Merge branch 'master' into geometry-web-worker
bagnell Jan 6, 2015
3763284
Update CHANGES.md
mramato Jan 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
67 changes: 67 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,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using scratch result parameters for there, right now we end up creating a new Cartesian3 instance and then the BoxGeomtry constructor clones it (creating another new instance).

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

if (!defined(result)) {
return new BoxGeometry({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing my line of thought from the above, it would be good to cache this options object at the module scope as well, in order to avoid creating a new throw-away object for every geometry.

This comment (and the above) applies to every Geometry.unpack function in this PR. Ultimately, would would be better is for our Geometry API for let you avoid having to create an options object as all (and avoid unnecessary cloning); but that's outside of the scope of this PR.

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.
*
Expand Down
63 changes: 63 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,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._min, array, startingIndex);
Cartesian3.pack(value._max, 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._min = min;
result._max = max;

return result;
};

/**
* Computes the geometric representation of an outline of a box, including its vertices, indices, and a bounding sphere.
*
Expand Down
51 changes: 51 additions & 0 deletions Source/Core/CircleGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand Down Expand Up @@ -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.
*
Expand Down
50 changes: 50 additions & 0 deletions Source/Core/CircleOutlineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand Down Expand Up @@ -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.
*
Expand Down
Loading