XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : Baking out vertex positions

11-08-2005, 10:25 PM
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;






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];



$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.


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

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

Are these the complete scripts?

11-09-2005, 11: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.

11-09-2005, 03: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 :)

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

CGTalk Moderation
11-09-2005, 04: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.