Table Of Contents

Previous topic

21.29. The Material Object

Next topic

21.31. The NetworkLatencyBehavior Object

This Page

21.30. The MathDeviceConvert Object

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);

21.30.1. Methods

21.30.1.1. v2ToArray

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);
vector
A Vector2 object. The MathDevice object to convert.

Returns a JavaScript array object of length 2.

21.30.1.2. arrayToV2

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);
mathDevice
A MathDevice object.
jsVector
A JavaScript array of length 2.
destination (Optional)
A Vector2 object.

Returns a Vector2 object.

21.30.1.3. v3ToArray

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);
vector
A Vector3 object. The MathDevice object to convert.

Returns a JavaScript array object of length 3.

21.30.1.4. arrayToV3

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);
mathDevice
A MathDevice object.
jsVector
A JavaScript array of length 3.
destination (Optional)
A Vector3 object.

Returns a Vector3 object.

21.30.1.5. v4ToArray

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);
vector
A Vector4 object. The MathDevice object to convert.

Returns a JavaScript array object of length 4.

21.30.1.6. arrayToV4

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);
mathDevice
A MathDevice object.
jsVector
A JavaScript array of length 4.
destination (Optional)
A Vector4 object.

Returns a Vector4 object.

21.30.1.7. quatToArray

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);
quat
A Quaternion object. The MathDevice object to convert.

Returns a JavaScript array object of length 4.

21.30.1.8. arrayToQuat

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);
mathDevice
A MathDevice object.
jsQuat
A JavaScript array of length 4.
destination (Optional)
A Quat object.

Returns a Quat object.

21.30.1.9. quatPosToArray

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);
quatPos
A QuatPos object. The MathDevice object to convert.

Returns a JavaScript array object of length 7.

21.30.1.10. arrayToQuatPos

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);
mathDevice
A MathDevice object.
jsQuatPos
A JavaScript array of length 7.
destination (Optional)
A QuatPos object.

Returns a QuatPos object.

21.30.1.11. aabbToArray

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);
aabb
An AABB object. The MathDevice object to convert.

Returns a JavaScript array object of length 6.

Returns a JavaScript array object of length 7.

21.30.1.12. arrayToAABB

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);
mathDevice
A MathDevice object.
jsAABB
A JavaScript array of length 6.
destination (Optional)
A AABB object.

Returns a AABB object.

21.30.1.13. m33ToArray

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);
m33
An Matrix33 object. The MathDevice object to convert.

Returns a JavaScript array object of length 9.

21.30.1.14. arrayToM33

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);
mathDevice
A MathDevice object.
jsM33
A JavaScript array of length 9.
destination (Optional)
A Matrix33 object.

Returns a Matrix33 object.

21.30.1.15. m43ToArray

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);
m43
An Matrix43 object. The MathDevice object to convert.

Returns a JavaScript array object of length 12.

21.30.1.16. arrayToM43

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);
mathDevice
A MathDevice object.
jsM43
A JavaScript array of length 12.
destination (Optional)
A Matrix43 object.

Returns a Matrix43 object.

21.30.1.17. m34ToArray

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);
m34
An Matrix34 object. The MathDevice object to convert.

Returns a JavaScript array object of length 12.

21.30.1.18. m44ToArray

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);
m44
An Matrix34 object. The MathDevice object to convert.

Returns a JavaScript array object of length 16.

21.30.1.19. arrayToM44

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);
mathDevice
A MathDevice object.
jsM44
A JavaScript array of length 16.
destination (Optional)
A Matrix44 object.

Returns a Matrix44 object.