View Full Version : How to access each vertex of a polyCube and move it randomly??

 FireSkull06 June 2009, 12:23 PMHi MEL Masters, I have a query for all MEL experts. I am new to MEL, so I am in a learning phase right now. The problem is that I have created a polyCube in Maya. Like all cubes, it has 8 vertices. What I'm trying to do is that I want each and every vertex of the polyCube to move at a random X,Y,Z position thereby creating a deformed cube. The solution in my mind is that first i create three variables as; float \$Xpos = rand(-12,12) float \$Ypos = rand(-12,12) float \$Zpos = rand(-12,12) and then assign these variables as X,Y,Z position of each vertex like; move \$Xpos \$Ypos \$Zpos; I understand that for this I have to use the for() loop so that each time a distorted cube is created it will have a different shape. Finally i will make a procedure that will accept the number of distorted cubes as input form the user and gives the result. Something like; global proc CreateDistortedCubes(int \$NoOfCubes) If anyone can write me a MEL for this or at least give me a clue in the form of a chunk of code, i'll be greatful. I can handle the for() loop on my own. I just want to know how to access each vertex of a polyCube through MEL, and move each vertex dynamically through rand() command. Thank you.
mlefevre
06 June 2009, 09:40 AM
Hi,

Here's a crude example.

You might want to mess about with the move command flag, -relative & -absolute.
You could also load the procedure into memory, and place distortObj(-1, 1) in an expression to
get some random animation going.
Should work for any number of objects selected.

global proc distortObj(float \$randomA, float \$randomB)
{
float \$Xpos;
float \$Ypos;
float \$Zpos;
string \$sel[] = `ls -sl`;
int \$vtxCount[];
int \$k = 0;
for (\$each in \$sel)
{
int \$vtxInfo[] = `polyEvaluate -vertex \$each`;
\$vtxCount[\$k] = \$vtxInfo[0];
\$k++;
}
for (\$i=0;\$i<size(\$vtxCount);\$i++)
{
for(\$j=0;\$j<(\$vtxCount[\$i]);\$j++)
{
\$Xpos = rand(\$randomA, \$randomB);
\$Ypos = rand(\$randomA, \$randomB);
\$Zpos = rand(\$randomA, \$randomB);
move -r \$Xpos \$Ypos \$Zpos (\$sel[\$i] + ".vtx["+\$j+"]");
}
}
}

//example
distortObj(-1, 1)

Hope that helps.

FireSkull
06 June 2009, 10:41 AM
Hey it worked. Thank you so much. I owe you bro.. :buttrock: