| Item | Quantity | Price |
|---|
| Your cart is empty. Check out our collection of 3d models! |
Prices in:
Clear Cart
Well yes, its easy actually.* Anyway, this is a perfect example of missunderstanding completely how one should approach mel or in fact any maya scriping tasks for that matter.
What you do is, you manually do the work. While instead you should arrange nodes to do tasks for you. Its a very different thing. Also dont select the verices pass a selection to move.
So what you do is you use a particle node as a softbody to do the change.
*unfortunately i dont sit in front of a computer capable of running maya so you need to either figure it out of my hint (it is sraightforward). Or wait till i get home and get the kids asleep
Sorry someting came up.
Im simplifyiong a bit and assume WITH NO ERRORCHEKING that you select some vertices in only one node.
1 | { |
As you see its a bit more involved thinking
Thanks, it's helpful to see how different people approach the same problem. Unfortunately, this has the same effect as my original code. In order to get the randomness to animate, I put the code in an expression instead of a script. I'm going to try something along those lines.
Stop, right there. It does animate, its just not animated which is a different thing.
The object now has 3 extra attributes roughness, offset and frequency. Animate any one of those and it animates the noise.
Oh, cool! That works great! I tried the following, which is probably a roundabout way of doing something similar:
{
float $Xpos;
float $Ypos;
float $Zpos;
int $vtxCount[];
float $randomness = .1;
string $refObject = "pCube1";
string $tarObject = "pCube2";
$vtxCount = `polyEvaluate -vertex $tarObject`;
for($i=0;$i<$vtxCount[0];$i++)
{
// reads a point
float $vtxPos[3] = `xform -q -ws -t ($refObject + ".vtx[" + $i + "]")`;
print $vtxPos;
// determines random XYZ
$Xpos = ( $vtxPos[0] + rand(-$randomness,$randomness) );
$Ypos = ( $vtxPos[1] + rand(-$randomness,$randomness) );
$Zpos = ( $vtxPos[2] + rand(-$randomness,$randomness) );
// moves a point
xform -a -ws -t $Xpos $Ypos $Zpos ($tarObject + ".vtx[" + $i + "]");
}
}
There are several reasons why you want to avoid your version inside an expression:
1. It breaks undo!
2. Its slow
3. State is not stable, makes rendering frames again impossible*
4. Non referencable, the name is carved in stone; object does not duplicate well even with construction history copy
5. Its working against mayas evaluation graph so theres no trigger when values change -> unneccesery evaluations where not needed and missing eveluations where needeed.
6. Non graceful exit
Really the reason i do it in way that looks whacked form a coding perspective is that im teaching a node to do this and NOT program the act. If you wish to keep the same worldview you have now you should start developing nodes instead. In mel you have little choice.
There is clear evidence your doing something that's not node centric if you have a for loop that loops over components. Its fine if you intend to do it once however.
* noise was developed for this and few other reasons back in the 1980's by Ken Perlin, noise is the 3D artists version of rand for most things. And Ken later got a technical Oscar for hos work on noise in 1997, read more here.
I've created the following script to roughen the vertexes of selected shapes. I'd like this script to create history that could be animated - it would be like a 3D static if I could change the way the vertexes were roughened in time. Any ideas how that could be approached?
Thanks!
{
float $roughness = .1;
string $allObjects[];
string $obj;
int $vertexCount[];
float $x;
float $y;
float $z;
$allObjects = `ls -selection`;
// process each shape
for ( $obj in $allObjects ) {
// select next object
select -r $obj;
// get the number of vertices used in the mesh
$vertexCount = `polyEvaluate -v`;
// process each vertex
for ( $i=0 ; $i < $vertexCount[0] ; $i++ )
{
// select next vertex
select -r ( $obj + ".vtx[" + $i + "]") ;
$x = rand(-$roughness,$roughness);
$y = rand(-$roughness,$roughness);
$z = rand(-$roughness,$roughness);
move -r $x $y $z ;
}
}
// re-select initial object selection
select -r $allObjects;
}