Get rotation from tangent information…motionPath like
- November 29th, 2010
- Posted in Maya Python
- Write comment
I’m meking a test for a custom node thats take the tangent, normal and binormal and transform in rotation information…This code is only for analysis…
Thanks for Fernando Soares and Richard Kazuo for the suport!
##
##
import maya.cmds as cmds
import maya.OpenMaya as om
import math as math
def tanCons(upVec, frontAxis, par):
sel = cmds.ls(sl=True)
curveObj = sel[0]
obj = sel[1]
#Ensure a valid up-vector. Use Y-up as default if input is bogus.
if upVec.length() < 0.001:
upVec = om.MVector(0.0, 1.0, 0.0)
#Ensure up-vector is normalized.
upVec.normalize()
#Query the position and tangent
p = cmds.pointOnCurve(curveObj, ch=False, top=True, pr=par, p=True)
t = cmds.pointOnCurve(curveObj, ch=False, top=True, pr=par, nt=True)
tan = om.MVector(t[0], t[1], t[2])
tan.normalize()
#Calculate a normal using the Y-up vector as the binormal.
norm = tan^upVec
#Calculate the orthogonal binormal.
bi = tan^norm
#If the binormal is pointing the wrong way,
#negate it and the normal.
if upVec*bi < 0.0:
bi = -bi
norm = -norm
#Normalize our vector.
norm.normalize()
bi.normalize()
#Create a matrix, using normal for the X axis and
#tangent for the Z axis.
if frontAxis == (1,0,0):
m = [(tan.x, tan.y, tan.z, 0.0), # X axis
(bi.x, bi.y, bi.z, 0.0),# Y axis
(norm.x, norm.y, norm.z, 0.0),# Z axis
(p[0], p[1], p[2], 1.0)]
elif frontAxis == (0,1,0):
m = [(norm.x, norm.y, norm.z, 0.0), # X axis
(tan.x, tan.y, tan.z, 0.0),# Y axis
(bi.x, bi.y, bi.z, 0.0),# Z axis
(p[0], p[1], p[2], 1.0)]
else:
m = [(norm.x, norm.y, norm.z, 0.0), # X axis
(bi.x, bi.y, bi.z, 0.0),# Y axis
(tan.x, tan.y, tan.z, 0.0),# Z axis
(p[0], p[1], p[2], 1.0)]
cmds.xform(obj, ws=True, m=((m[0][0], m[0][1], m[0][2], m[0][3],
m[1][0], m[1][1], m[1][2], m[1][3],
m[2][0], m[2][1], m[2][2], m[2][3],
m[3][0], m[3][1], m[3][2], m[3][3])),
p=True)
cmds.scale(1,1,1,obj)
frontAxis = (0,1,0)
upVec = om.MVector(0,1,0)
tanCons(upVec, frontAxis, .5)
##
##
