import maya.cmds as cmds
# I named both my objects in maya scene 'tgt' and 'src' repsectively. tgtObj= 'tgt'
aimObj = 'src'
# definition for a worldSpacePosition matrix.
def getWorldPos( object ):
# utils needed to be imported for converting from a list to a matrix product. util = om.MScriptUtil()
xform = cmds.xform( object, ws=1, m=1, q=1 )
util.createFromList( xform, 16 )
return om.MMatrix( util.asFloat4Ptr() )
# get the worldSpacePosition of both objects.
aimM = getWorldPos( aimObj )
tgtM = getWorldPos( tgtObj )
# gets a pointMatrix product.
aimOrig = om.MPoint(0.0,0.0,0.0)
tgtOrig = om.MPoint(0.0,0.0,0.0)
aimOrig *= getWorldPos( aimObj )
tgtOrig *= getWorldPos( tgtObj )
#v = aimOrig * aimM.transpose()
#print v.x, v.y, v.z
print aimOrig.x, aimOrig.y, aimOrig.z
v = aimOrig - tgtOrig
print v.x, v.y, v.z
No comments:
Post a Comment