Pages

Thursday, 25 November 2010

python hermite function

as Maya doesn`t have python command version of its hermite MEL command, I found this example of the very basic curve interpolation description. What is cool, you can pass both floats or MVectors from OpenMaya module. Both work.


import maya.OpenMaya

p0 = maya.OpenMaya.MVector( 0,0,0 )
p1 = maya.OpenMaya.MVector( 10,0,0 )
r0 = maya.OpenMaya.MVector( 0,4,0 )
r1 = maya.OpenMaya.MVector( 0,-4,0 )

def hermite(p0, p1, r0, r1, t):

t2 = t * t
t3 = t2 * t
_3t2 = 3.0 * t2
_2t3 = 2.0 * t3

return (p0*(_2t3-_3t2+1) + p1*(-_2t3+_3t2) + r0*(t3-2.0*t2+t) + r1*(t3-t2))

res = hermite(p0, p1, r0, r1, t)



taken from Autodesk API examples:

http://download.autodesk.com/us/maya/2010help/api/torus_field_8py-example.html

No comments: