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++ ) {
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
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.
There are several reasons why you want to avoid your version inside an expression:
It breaks undo!
Its slow
State is not stable, makes rendering frames again impossible*
Non referencable, the name is carved in stone; object does not duplicate well even with construction history copy
Its working against mayas evaluation graph so theres no trigger when values change -> unneccesery evaluations where not needed and missing eveluations where needeed.
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.