MFnTransform usage confusion

python
maya

#1

I am trying to use OpenMaya to copy rotations from the Bound Joints of a full IK/FK anim rig, to a Skeleton Rig for use in a game engine. Trying to automate the process to save people time.

I’ve reached the stupidest roadblock right now.

I create two lists/arrays of the bound joints in the Anim Rig and Skeleton Rig from the DAG hierarchy in the scene.

    # Check whether the name contains the Bound Joint String Indicator
    if aBind in dagNodeFn.name():          
        # If so, check whether the name contains the Rig Type Indicator
        if aRig in dagNodeFn.name():
            jointList.append(dagObject)

Those lists are passed to the Copy Script, which uses simple name-matching.
I want to just copy the blooming rotations from like-named-joint to like-named-joint.

                if(animJointName == skelJointName):
                print 'Copy from ' + animJointName + ' to ' + skelJointName
                animJTransformFN = OpenMaya.MFnTransform(animJ)
                print 'Transform: ' + str(animJTransformFN)
                animRotation = animJTransformFN.getRotation()
                print 'Rotation: ' + str(animRotation)
                skelDagNodeFn.setRotation(animRotation)
                break

But I am told by Maya that I have the wrong number or type of arguments for getRotation()

These are the suggested solutions. Am I just totally misunderstanding the syntax of what I am trying to do?

getRotation(MFnTransform const *,MQuaternion &,MSpace::Space)
getRotation(MFnTransform const *,MEulerRotation &)
getRotation(MFnTransform const *,double [3],MTransformationMatrix::RotationOrder &)
getRotation(MFnTransform const *,double [3],MTransformationMatrix::RotationOrder &,MSpace::Space)

Can anyone enlighten me? If I am not passing the Joint Transform to the getRotation() function? If not how do I access it?


#2

For API 1.0 (maya.OpenMaya), you need to create a rotation object to receive the value by reference, kinda like this:

if(animJointName == skelJointName):
      print 'Copy from ' + animJointName + ' to ' + skelJointName
      animJTransformFN = OpenMaya.MFnTransform(animJ)
      print 'Transform: ' + str(animJTransformFN)
      animRotation = OpenMaya.MEulerRotation()
      animJTransformFN.getRotation(animRotation)
      print 'Rotation: ' + str(animRotation)
      skelDagNodeFn.setRotation(animRotation)

In API 2.0 (maya.api.OpenMaya), you can get return values directly out of api functions…

import maya.api.OpenMaya as om2
node = om2.MSelectionList().add('locator1').getDependNode(0)
nodeRotation = om2.MFnTransform(node).rotation()

node2 = om2.MSelectionList().add('locator2').getDependNode(0)
om2.MFnTransform(node2).setRotation(nodeRotation,om2.MSpace.kTransform)

#3

Thanks @katz,

I did finally work it out like so:

                animJTransformFN.getRotation(animRotation)
                skelJTransformFN = OpenMaya.MFnTransform(skelJ)
                skelJTransformFN.setRotation(animRotation)

Now I’d love to know if you have any insight on how to key the rotations I’ve just copied over?

Am I correct that I have to create three AnimCurve nodes, and key each of them at Current Time with Current Rot Values?

There’s no simpler solution whereby I can call something like “KeyTransform(Now, Rotation)”, which would be amazing.