PDA

View Full Version : Baking out vertex positions


LordMcGoat
11-08-2005, 09:25 PM
Hi,
I'm trying to write a script to keyframe all the vertex positions of an object for animation. The trouble is, the script also needs to hand move all the vertices to a given position before keyframing, and needs to do this for everyframe.

I can't seem to write anything that won't crash my computer if done for more than a few frames. What I have at the moment is:

proc bakeVerts()

{

int $i,$j;

int $finTime = 200;

currentTime -edit 0;

for($i=0;$i<$finTime;$i++)

{

geomMove();

for($j=0;$j<$maxVerts;$j++)

{

setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 polySurface31.vtx[$j];

}

currentTime -edit ($i+1);

}

}



Where the geomMove function is:

proc geomMove()

{

float $location[2];

for($i=0;$i<=$maxVerts;$i++)

{

$location = `pointPosition ("locator"+($i+1))`;

select -r polySurface31.vtx[$i];

move $location[0] $location[1] $location[2];

}

}



Any ideas on how I can do this better? I mean I don't mind it being slow, since it has to key every vertex for every frame (incidentally, there are 1616 verts on the mesh im applying the script to), as long as it doesn't crash my computer.

Thanks

seven6ty
11-08-2005, 09:53 PM
Seems like this would be better to tackle in C++ or something, no?

mhovland
11-08-2005, 10:12 PM
I don't see anywhere in the code where you are getting a value for $maxVerts.

Are these the complete scripts?

LordMcGoat
11-09-2005, 10:20 AM
I don't see anywhere in the code where you are getting a value for $maxVerts.

Are these the complete scripts?

Sorry yea slightly wrong version in as much as $maxVerts should be passed into both functions. It's just an integer holding the amount of vertices in the mesh, which in the case I'm trying to get working is 1616. Other than that they are complete scripts - or they would be if they didn't crash my computer :)

Seven6ty, you're right I may have to take it into C++, was just wondering if I was missing anything that could make it work in mel.

Thanks for the responses.

harmless
11-09-2005, 02:54 PM
You need to optimize your script.
Notice that you loop through all of your vertices to move them THEN loop through all of your vertices to keyframe them, per frame. That means that if you have 10000 vertices over 100 frames you are looping through 20000 vertices over 100 frames, or 2,000,000 operations rather than 1,000,000 if you were to move the vertex then keyframe it. Do the move and the keyframe in the same loop.

Doing them in the same loop also means getting rid of the extra function call jump. There is no need to break out the function that move the vertices or than prettiness. It slows things down and you need speed. Get rid of the function that moves vertices.

There are other things you can optimize as well. I saw a "select" command in there. You shouldn't be selecting objects! You can get all of the values you need without telling maya to do something with the GUI!

Another thing that comes to mind is the undos. I would suspect that maya handles the undos for your script. This means the max size of undos is determined by your preferences. Try running the optimized script with undos set to 1.

Scripting is your friend. Just tighten up that script :)

LordMcGoat
11-09-2005, 03:36 PM
Cracking, thanks a lot :)

CGTalk Moderation
11-09-2005, 03:36 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.