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 23 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
77 changes: 74 additions & 3 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 All @@ -51,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;
Expand All @@ -70,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.
Expand Down Expand Up @@ -115,6 +115,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
72 changes: 69 additions & 3 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 All @@ -46,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;
Expand All @@ -63,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.
Expand Down Expand Up @@ -105,6 +105,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
83 changes: 79 additions & 4 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 All @@ -42,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;

Expand All @@ -67,7 +74,75 @@ define([
stRotation : options.stRotation
};
this._ellipseGeometry = new EllipseGeometry(ellipseGeometryOptions);
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;
};

/**
Expand Down
Loading