Matrix Array Commands

About

All you ever wanted to do with mMatrices in MEL.  Well, this description might be going a little too far, but proper mMatrix support is something that is missing in MEL and melfunctions gives you access to some of the hidden functionalities.  OK, there is a mMatrix datatype and you can retrieve a mMatrix from transforms using the “getAttr” and “xform” commands, but actually working with them is not really possible.  To overcome this limitation melfunctions has a bunch of commonly used mMatrix functions.  Most of them are just wrappers for the mMatrix functions provided by the Maya API.

Important conventions

A mMatrix in melfunctions is represented as an array of 16 floats.  The values are in row order (that means the first 4 values belong to the first row of the mMatrix, the next 4 to the second... and so on) All commands don’t change the actual data in place, but create a new output (that might change in the future).

Summary
All you ever wanted to do with mMatrices in MEL.
Create a matrix array
Get number of matrices in a matrix array
Append elements to the end of a matrix array
Get elements from a matrix array
Set elements in a matrix array, this function will not grow the matrix array, but error when you try to set an invalid array element!
Add two matrix arrays together elementwise
Subtract two matrix arrays from each other elementwise
Multiply matrix with matrix of arrays elementwise
Multiply matrix (array) with double (array) elementwise
Check if two mMatrices are exactly equal
Check if two mMatrices are exactly not equal
Check if elements of two matrix arrays are equivalent within a tolerance
Check if a matrices in an array are singular (do not have an inverse).
Get the inverse of a the elements of a matrix array.
Get the transpose of of the elements of a matrix array
Get the homogenized version o the elements of a matrix array
Get adjoint (or conjugate transpose) of the elements of a matrix array
Get 4x4 determinant of the elements of an matrix array.
Get 3x3 (upper right) determinant of a mMatrix.
Get matrix component at specified row and columns within a matrix array.
Set a single component of an entry in a matrix array.

Functions

mMatCreate

#define mel mMatCreate(int $count,
float $template[16])

Create a matrix array

Parameters

nonereturn the identity matrix or
countreturn count identity matrices or
countthe number of matrix elements to create
templatethe template matrix which will be used for creation

Returns

The matrix array of as a float array of its elements

mMatSize

#define mel int mMatSize(float $matrixArrayA[])

Get number of matrices in a matrix array

Parameters

matrixArrayAmatrix array Returns:

The size of the matrix array

mMatAppend

#define mel mMatAppend(float $matrixArrayA[],
float $matrixArrayB[])

Append elements to the end of a matrix array

Parameters

matrixArrayAmatrix array to extract elements to
matrixArrayBmatrix array to append Returns:

The new matrix array of as a float array of its elements

mMatGet

#define mel mMatGet(float $matrixArrayA[],
int $id[],
float $matrixArrayB[])

Get elements from a matrix array

Parameters

matrixArrayAmatrix array to extract elements from
idsint array of ids to extraxt from the matrix array optional
matrixArrayBmatrix array that will be used as a substitution if an id does not exist in array A, must be 1 or same size than id array Returns:

The matrix array of as a float array of its elements

mMatSet

#define mel mMatSet(float $matrixArrayA[],
int $id[],
float $matrixArrayB[])

Set elements in a matrix array, this function will not grow the matrix array, but error when you try to set an invalid array element!

Parameters

matrixArrayAbase matrix array
idsint array of ids defining where in A to insert B
matrixArrayBmatrix array of elements to be inserted into A, must be size 1 or same size than id array Returns:

The matrix arrayA with elements inserted of of as a float array of its elements

mMatAdd

#define mel mMatAdd(float[] $matArrayArrayA,
float[] $matArrayArrayB)

Add two matrix arrays together elementwise

Parameters

$matArrayAthe first matrix array
$matArrayBthe second matrix array

Returns

$matArrayA + $maArrayB, the sum of the two matrix arrays elementswise as a float[]

mMatSub

#define mel mMatSub(float[] $matArrayArrayA,
float[] $matArrayArrayB)

Subtract two matrix arrays from each other elementwise

Parameters

$matArrayAthe first matrix array
$matArrayBthe second matrix array

Returns

$matArrayA + $maArrayB, the difference of the two matrix arrays elementswise as a float[]

mMatMult

#define mel mMatMult(float[] $matArrayArrayA,
float[] $matArrayArrayB)

Multiply matrix with matrix of arrays elementwise

Parameters

$matArrayAthe first matrix array
$matArrayBthe second matrix array

Returns

$matArrayA[] * $matArrayB[], the result of the matrix multiplication as a float[]

mMatDblMult

#define mel mMatDblMult(float[] $matArray,
float[] $dblArray)

Multiply matrix (array) with double (array) elementwise

Parameters

$matArraythe matrix array
$dblArraythe double array

Returns

$matArray[] * $dblArray[], the result of the multiplication as a float[]

mMatIsEqual

#define mel mMatIsEqual(float[] $matArrayArrayA,
float[] $matArrayArrayB)

Check if two mMatrices are exactly equal

Parameters

$matArrayArrayAthe first matrix array
$matArrayArrayBthe second matrix array

Returns

$matArrayArrayA == $matArrayArrayB, the result of the elementwise comparison as a float[] of (0,1)

mMatIsNotEqual

#define mel mMatIsNotEqual(float[] $matArrayArrayA,
float[] $matArrayArrayB)

Check if two mMatrices are exactly not equal

Parameters

$matArrayArrayAthe first matrix array
$matArrayArrayBthe second matrix array

Returns

$matArrayArrayA != $matArrayArrayB, the result of the elementwise comparison as a float[] of (0,1)

mMatIsEquivalent

#define mel mMatIsEquivalent(float[] $matArrayArrayA,
float[] $matArrayArrayB), float[] $toleranceArray)

Check if elements of two matrix arrays are equivalent within a tolerance

Parameters

$matArrayArrayAthe first matrix array
$matArrayArrayBthe second matrix array
$toleranceArraythe maximum amount of error allowed

Returns

the result of the comparison as a float array of (0,1)

mMatIsSingular

#define mel mMatIsSingular(float[] $matArrayArrayA)

Check if a matrices in an array are singular (do not have an inverse).

Parameters

$matArrayArrayAthe matrix array

Returns

a float array (0,1) indicating wether the element of a matrix array is singular or not // get the arguments MDoubleArray dblA, dblB, dblC; unsigned int incA, incB,incC, count; MStatus stat = getArgMatMat(args, dblA, dblB, dblC, incA, incB, incC,count); ERROR_FAIL(stat);

mMatInverse

#define mel mMatInverse(float[] $matArrayA)

Get the inverse of a the elements of a matrix array.

Parameters

$matArrayAthe matrix array

Returns

the inverse of the elements of a matrix array as a float[]

mMatTranspose

#define mel mMatTranspose(float[] $matArrayA)

Get the transpose of of the elements of a matrix array

Parameters

$matArrayAthe mMatrix

Returns

the transpose of the elements of a matrix array as a float[]

mMatHomogenize

#define mel mMatHomogenize(float[] $matArrayA)

Get the homogenized version o the elements of a matrix array

Parameters

$matArrayAthe mMatrix

Returns

the homogenized elements of a matrix array as a float[]

mMatAdjoint

#define mel mMatAdjoint(float[] $matArrayA)

Get adjoint (or conjugate transpose) of the elements of a matrix array

Parameters

$matArrayAthe mMatrix

Returns

adjoint of the elements of a matrix array as a float[]

mMatDet4x4

#define mel mMatDet4x4(float[] $matArrayA)

Get 4x4 determinant of the elements of an matrix array.

Parameters

$matArrayAthe mMatrix

Returns

the determinant as a float

mMatDet3x3

#define mel mMatDet3x3(float[] $matArrayA)

Get 3x3 (upper right) determinant of a mMatrix.

Parameters

$matArrayAthe mMatrix

Returns

the determinant as a float

mMatGetComponent

#define mel mMatGetComponent(float[] $matArrayA,
int[] $row,
int[] $column)

Get matrix component at specified row and columns within a matrix array.

Parameters

$matArrayAthe matrix array
$rowthe row index [0-3] as an int array
$columnthe column index [0-3] as an int array

Returns

the element at mat[row][column] as a float array

mMatSetComponent

#define mel mMatSetComponent(float[] $matArrayA,
int[] $row,
int[] $column,
float[] $value)

Set a single component of an entry in a matrix array.

Parameters

$matArraythe matrix array
$rowthe row index [0-3] as an int array
$columnthe column index [0-3] as an int array
$valuethe value to insert as an float array

Returns

the matrix rray with the newly inserted value at [row][column] as a float[]

#define mel mMatCreate(int $count,
float $template[16])
Create a matrix array
#define mel int mMatSize(float $matrixArrayA[])
Get number of matrices in a matrix array
#define mel mMatAppend(float $matrixArrayA[],
float $matrixArrayB[])
Append elements to the end of a matrix array
#define mel mMatGet(float $matrixArrayA[],
int $id[],
float $matrixArrayB[])
Get elements from a matrix array
#define mel mMatSet(float $matrixArrayA[],
int $id[],
float $matrixArrayB[])
Set elements in a matrix array, this function will not grow the matrix array, but error when you try to set an invalid array element!
#define mel mMatAdd(float[] $matArrayArrayA,
float[] $matArrayArrayB)
Add two matrix arrays together elementwise
#define mel mMatSub(float[] $matArrayArrayA,
float[] $matArrayArrayB)
Subtract two matrix arrays from each other elementwise
#define mel mMatMult(float[] $matArrayArrayA,
float[] $matArrayArrayB)
Multiply matrix with matrix of arrays elementwise
#define mel mMatDblMult(float[] $matArray,
float[] $dblArray)
Multiply matrix (array) with double (array) elementwise
#define mel mMatIsEqual(float[] $matArrayArrayA,
float[] $matArrayArrayB)
Check if two mMatrices are exactly equal
#define mel mMatIsNotEqual(float[] $matArrayArrayA,
float[] $matArrayArrayB)
Check if two mMatrices are exactly not equal
#define mel mMatIsEquivalent(float[] $matArrayArrayA,
float[] $matArrayArrayB), float[] $toleranceArray)
Check if elements of two matrix arrays are equivalent within a tolerance
#define mel mMatIsSingular(float[] $matArrayArrayA)
Check if a matrices in an array are singular (do not have an inverse).
#define mel mMatInverse(float[] $matArrayA)
Get the inverse of a the elements of a matrix array.
#define mel mMatTranspose(float[] $matArrayA)
Get the transpose of of the elements of a matrix array
#define mel mMatHomogenize(float[] $matArrayA)
Get the homogenized version o the elements of a matrix array
#define mel mMatAdjoint(float[] $matArrayA)
Get adjoint (or conjugate transpose) of the elements of a matrix array
#define mel mMatDet4x4(float[] $matArrayA)
Get 4x4 determinant of the elements of an matrix array.
#define mel mMatDet3x3(float[] $matArrayA)
Get 3x3 (upper right) determinant of a mMatrix.
#define mel mMatGetComponent(float[] $matArrayA,
int[] $row,
int[] $column)
Get matrix component at specified row and columns within a matrix array.
#define mel mMatSetComponent(float[] $matArrayA,
int[] $row,
int[] $column,
float[] $value)
Set a single component of an entry in a matrix array.