Showing posts with label Maya Python. Show all posts
Showing posts with label Maya Python. Show all posts

Monday, April 12, 2010

Maya Python - smSoftIK plugin node

Finally had my first try at Maya Python API. Surprisingly (because I'm so used to the C++ way), implementing plugins using Maya Python API is really fast and easy. Took some time to get used to it, but really loving it now. :)

Demo of the softIK plugin node I created over the weekend:
  • Reduce the "popping" of IK rigs when the joint chain straightens
  • Ability to adjust and animate the soft limit
  • AutoStretchiness already built into the plugin node, thus saving a bunch of multiplyDivide, plusMinusAverage or condition nodes in the rig

All thanks to the theory shared by Andy Nicholas!
http://www.xsi-blog.com/archives/109

Saturday, April 10, 2010

Maya Python - Getting Points & Normals from MItGeometry all at once

From Adam Mechtley in Maya-Python mailing list:

Yes—it stores the result in the object you pass as a parameter, since it is passed by reference. As per my example:

meshIter0 = OpenMaya.MItGeometry(dag1)

points = OpenMaya.MPointArray()

meshIter0.allPositions(points, ObjectSpace)

# all the points are now stored in the points object

normals = OpenMaya.MVectorArray()

meshIter1.getNormals(normals, ObjectSpace)

# all the normals are now stored in the normals object

Thursday, March 18, 2010

Some Maya Python Tips & Tricks

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

From http://riggerman.animationblogspot.com
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:

allPoints.append(point+normalVec)

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:

geomIter.setAllPositions(allPoints)



Maya API docs demystified for Python Users