This object contains a set of functions for converting from MathDevice objects to JavaScript arrays (returned by VMath function calls and JSON.parse) and vice versa. These functions should be used carefully as the conversion from MathDevice objects to VMath objects is a slow operation. In most cases it is best to use avoid conversion by continuing to use the same library.
Required scripts
The MathDeviceConvert object requires:
/*{{ javascript("jslib/utilities.js") }}*/
Converting from MathDevice objects to JavaScript Arrays
It is not required to call these functions when using MathDevice objects for arguments to VMath functions (see VMath compatibility with MathDevice objects).
Converting from JavaScript Arrays to MathDevice objects
You can convert from JavaScript arrays (returned by VMath function calls and JSON.parse) to MathDevice objects using apply. For example:
var jsV3 = VMath.v3Build(1, 2, 3);
var v3Build = mathDevice.v3Build;
v3 = v3Build.apply(mathDevice, jsV3);
This conversion will only work with JavaScript arrays (this will fail if jsV3 is actually a MathDevice object). If the argument is a MathDevice object then you should be using a copy function (mathDevice.v3Copy) instead. If a MathDevice destination object is available use:
var jsV3 = VMath.v3Build(1, 2, 3);
v3 = MathDeviceConvert.arrayToV3(mathDevice, jsV3, mathDeviceV3);
These conversions are slow operations and should be avoided where possible. For example, the examples above can be replaced with:
v3 = mathDevice.v3Build(1, 2, 3);
// or
v3 = mathDevice.v3Build(1, 2, 3, mathDeviceV3);
Summary
Returns a JavaScript array of length 2 with the values from a Vector2 object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.v2ToArray(vector);
Returns a JavaScript array object of length 2.
Summary
Returns a Vector2 object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToV2(mathDevice, jsVector, destination);
Returns a Vector2 object.
Summary
Returns a JavaScript array of length 3 with the values from a Vector3 object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.v3ToArray(vector);
Returns a JavaScript array object of length 3.
Summary
Returns a Vector3 object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToV3(mathDevice, jsVector, destination);
Returns a Vector3 object.
Summary
Returns a JavaScript array of length 4 with the values from a Vector4 object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.v4ToArray(vector);
Returns a JavaScript array object of length 4.
Summary
Returns a Vector4 object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToV4(mathDevice, jsVector, destination);
Returns a Vector4 object.
Summary
Returns a JavaScript array of length 4 with the values from a Quaternion object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.quatToArray(quat);
Returns a JavaScript array object of length 4.
Summary
Returns a Quat object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToQuat(mathDevice, jsQuat, destination);
Returns a Quat object.
Summary
Returns a JavaScript array of length 7 with the values from a QuatPos object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.quatPosToArray(quatPos);
Returns a JavaScript array object of length 7.
Summary
Returns a QuatPos object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToQuatPos(mathDevice, jsQuatPos, destination);
Returns a QuatPos object.
Summary
Returns a JavaScript array of length 6 with the values from an AABB object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.aabbToArray(aabb);
Returns a JavaScript array object of length 6.
Returns a JavaScript array object of length 7.
Summary
Returns a AABB object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToAABB(mathDevice, jsAABB, destination);
Returns a AABB object.
Summary
Returns a JavaScript array of length 9 with the values from an Matrix33 object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.m33ToArray(m33);
Returns a JavaScript array object of length 9.
Summary
Returns a Matrix33 object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToM33(mathDevice, jsM33, destination);
Returns a Matrix33 object.
Summary
Returns a JavaScript array of length 12 with the values from an Matrix43 object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.m43ToArray(m43);
Returns a JavaScript array object of length 12.
Summary
Returns a Matrix43 object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToM43(mathDevice, jsM43, destination);
Returns a Matrix43 object.
Summary
Returns a JavaScript array of length 12 with the values from an Matrix34 object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.m34ToArray(m34);
Returns a JavaScript array object of length 12.
Summary
Returns a JavaScript array of length 16 with the values from an Matrix44 object. This function is slow and its use should be avoided where possible.
Syntax
jsArray = MathDeviceConvert.m44ToArray(m44);
Returns a JavaScript array object of length 16.
Summary
Returns a Matrix44 object with the values from a JavaScript array. This function is slow and its use should be avoided where possible.
Syntax
destination = MathDeviceConvert.arrayToM44(mathDevice, jsM44, destination);
Returns a Matrix44 object.