i have question regarding matrices in MEL. i want to store vertex color information for a mesh in a matrix. as i don't know the size of the matrix, i need to query the vertcount, which will define the dimension of the matrix. somehow MEL does not support variables to define matrix sizes like this example:
int $a = 1; int $b = 2;
matrix $myMatrix [$a][$b];
anybody knows a solution for this?
Replies
If you need to store the color of each vertex of a variable size mesh, the best solution, in my opinion, is to use an array of arrays. It means you create an array as big as vertex count if in Maya you must specify its size on definition, then fill it with 3 or 4 values arrays (depending on the data you need to stor RGB or RGBA) each of which represents the color of the corresponding vertex. I guess you can get access to them in MEL by the double subscript operator: vertColors[vertIndex][channel], or simply by vertColors[vertIndex] to get the corresponding vertex color array.
I hope this helps, anyway.
right. that's what i'm doing right now. i don't want to mix two problems here, but if i do this i have problems returning the data from an procedure. as far as i know, i just can return one variable from a procedure. if i store my vert data into four float arrays, i have four variables to return, which is something i couldn't get to work in MEL yet. correct me if i'm wrong.
i'm still mainly an artist, just doing some scripting for supporting our workflow, so sorry for lack of knowledge here and there.
Why do you have to return a single channel value from your procedure? Cannot you return the full color array for a selected vertex - it would be like a single value, or the whole array of arrays? In any language I know, that's possible, usually by pointer or reference (even if I don't know if MEL uses such addressing, should be feasible too).
If MEL does support structures or classes (it should), you could create a class to store the data types to be returned by the procedure, then use an instance to return needed values, but this could be a little more daunting and not really needed if the script is simple and data is not much complex, like RGBA values.
Any MEL master would be of great help at this point, I've stretched to the limit of my guessing knowledge on this
but that's not working in mel. when i try to set the matrix size with a variable, maya gives me an error. it just let's me define the matrix with absolute numbers, like matrix $myMatrix [10][3]. of course i can't set the size, before i query the vert count of my mesh.
if you want the 312th vert's colour - $colArray[3* 312 +0], $colArray[3* 312 +1], $colArray[3* 312 +2]
Or use vectors, which is easier:
vector $vecArray[$numVerts];
vecArray[123] = <<colour.r, colour.g, colour.b>>;
Doing this off the top of my head, so the syntax might be off
good to hear that matrices are limited in mel. in this case it wasn't my lack of knowledge.
and those ideas for a workaround are great. i think to store eveything in one array is best, as i can pass the alpha, too...thanks a lot.
Whargoul's suggestion is pretty much what I end up doing every time I want to do "multi-dimensional arrays" in MEL now. Really makes me miss maxscript for having structs and the capability of having arrays as elements in another array. Could make stuff so much easier.
Might be worth looking into Python instead?