Thursday, March 18, 2010

Some Maya Python Tips & Tricks

Some useful information I found online. Thanks to all these helpful people on the net! ;)

Ryan Trowbridge has pointed out a faster way of computing the deformations:
Most (if not all) of the devkit examples set the points positions one by one while iterating the mesh points, but this method is slower and since our deformation isn’t neighbor dependent or anything like that, we can set the points position all at once using MItGeometry.allPositions ().
In his own words: “The problem with this is that when the node goes to deform, it is iterating through x amount of vertices and each time it iterates it updates the scene using setPosition() So a 10,000 vertice mesh is updating the scene 10,000 times (…) The reason this one is faster is it get all the vertices and sets all the vertices at once“.

Well, to do this we need to create a MPointArray object to store the information we need. This line goes before the iteration loop:

allPoints = OpenMaya.MPointArray()

Now, inside the loop we can replace the setPosition line for this one:


This will insert each point value in the point array object, so we can pass on this big list all at once to the final command, that goes right outside the loop:


Maya API docs demystified for Python Users

No comments: