Matrix Array CommandsAboutAll 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 conventionsA 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. | | | | | | 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. |
mMatCreate| #define mel mMatCreate( | int | $count, | | float | $template[16] | ) |
|
Create a matrix array Parameters| none | return the identity matrix or | | count | return count identity matrices or | | count | the number of matrix elements to create | | template | the template matrix which will be used for creation |
ReturnsThe 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| matrixArrayA | matrix 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| matrixArrayA | matrix array to extract elements to | | matrixArrayB | matrix 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| matrixArrayA | matrix array to extract elements from | | ids | int array of ids to extraxt from the matrix array optional | | matrixArrayB | matrix 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| matrixArrayA | base matrix array | | ids | int array of ids defining where in A to insert B | | matrixArrayB | matrix 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| $matArrayA | the first matrix array | | $matArrayB | the 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| $matArrayA | the first matrix array | | $matArrayB | the 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| $matArrayA | the first matrix array | | $matArrayB | the 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| $matArray | the matrix array | | $dblArray | the 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| $matArrayArrayA | the first matrix array | | $matArrayArrayB | the 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| $matArrayArrayA | the first matrix array | | $matArrayArrayB | the 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| $matArrayArrayA | the first matrix array | | $matArrayArrayB | the second matrix array | | $toleranceArray | the maximum amount of error allowed |
Returnsthe 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| $matArrayArrayA | the matrix array |
Returnsa 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| $matArrayA | the matrix array |
Returnsthe 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 ParametersReturnsthe 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 ParametersReturnsthe 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 ParametersReturnsadjoint 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. ParametersReturnsthe determinant as a float
mMatDet3x3| #define mel mMatDet3x3( | float[] | $matArrayA | ) |
|
Get 3x3 (upper right) determinant of a mMatrix. ParametersReturnsthe 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| $matArrayA | the matrix array | | $row | the row index [0-3] as an int array | | $column | the column index [0-3] as an int array |
Returnsthe 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| $matArray | the matrix array | | $row | the row index [0-3] as an int array | | $column | the column index [0-3] as an int array | | $value | the value to insert as an float array |
Returnsthe matrix rray with the newly inserted value at [row][column] as a float[]
|