-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Changes from 13 commits
8db80fb
5c976c6
64aa675
2308c57
86eac13
fb59f28
56e147d
30766ef
4053cf1
f4c6aec
9f0745a
9af7036
8fca16c
e8c6034
87fb766
d042918
382d342
d1ba164
e5d3f39
4073f38
0b78cbf
a484adc
20c8d28
9e4f045
d263195
3763284
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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. | ||
* | ||
|
There was a problem hiding this comment.
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).