Getting joint animation data for skeletal animation(Pymel)

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  05 May 2013
Getting joint animation data for skeletal animation(Pymel)

I'm a bit stuck with a Pymel animation exporter I'm writing for my game. Seems to work with a single bone, but complex rigs get rotations at weird angles.

I'm a bit unsure about how the SRT data is supposed to be used for skeletal. Whether in relative space or not.

    key = array("f")
    		for i in range (minTime,maxTime):
    			print ' *********** frame:' + str(i)
   		    #for each Joint get rotation quat and transform vector.
    			for s in influences:
    			   newJoint= PyNode(s)
    			   rotationQuat = newJoint.getRotation(quaternion=True)
    			   parents = listRelatives(newJoint, parent=True)
    			   trans = newJoint.getTranslation()
    			   if(len(parents) != 0 ):
    				   if(type(parents[0]) is nt.Joint ):
    					   parentWorldMatrix = parents[0].attr("worldInverseMatrix").get()
    					   jointWorldMatrix = newJoint.attr("worldMatrix").get()
    					   #Get the joints local space transformation
    					   transMat =  jointWorldMatrix * parentWorldMatrix
    					   rotationQuat = Quaternion((transMat))
    					   translation = transMat.translate.get()
    					   print "reltrans:" + str(trans)
    			   print "rotQuat" + str(rotationQuat)		  
    			   key.extend( translation )

Any suggestions would be a real help. I touch on Maya scripting so little that I do things a bit backwards.
__________________ Linkedin Twitter

Last edited by Simon : 05 May 2013 at 09:54 PM.
  05 May 2013
Hi there,

This may help, or maybe not...

I once had to construct a matrix from joint attributes using the Maya C++ API. You may be able to translate this to pymel. The important thing is to factor in the orientation attribute.

Apologies if I missed the point.

MStatus getJointMat( const MObject & dagNode, MMatrix & mat ) {
   MStatus st;
   MFnIkJoint jointFn(dagNode, &st  );
   if (st.error()) return st; 

   // build the matrix which represents the joint in it's current angle
   MTransformationMatrix::RotationOrder rOrder = jointFn.rotationOrder(&st);
   double3 scale ;
   st = jointFn.getScale(scale);
   double3 scaleOrientation ;
   st = jointFn.getScaleOrientation(scaleOrientation,rOrde  r) ;
   double3 rotation;
   st = jointFn.getRotation(rotation,rOrder); ert;
   double3 orientation;
   st = jointFn.getOrientation(orientation, rOrder);
   // changed from translation due to deprecation
   MVector trans = jointFn.getTranslation(MSpace::kTransform ,&st);

   MTransformationMatrix mtxmat;
   MMatrix Smat;
   MMatrix ROmat;
   MMatrix Rmat;
   MMatrix JOmat;
   MMatrix Tmat;
   Smat(0,0) = scale[0];
   Smat(1,1) = scale[1];
   Smat(2,2) = scale[2];
   mtxmat.setRotation(scaleOrientation , rOrder);
   ROmat = mtxmat.asMatrix();
   mtxmat.setRotation(rotation , rOrder);
   Rmat = mtxmat.asMatrix();
   mtxmat.setRotation(orientation, rOrder);
   JOmat = mtxmat.asMatrix();
   Tmat(3,0) = trans.x;
   Tmat(3,1) = trans.y;
   Tmat(3,2) = trans.z;
   mat = Smat*ROmat*Rmat*JOmat*Tmat;
   return MS::kSuccess; 
  05 May 2013
Maybe a better way to get those transforms is to point and orient constrain locators to each joint and then query the transforms of the locators for every frame. Or even use the xform command.

  05 May 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 04:57 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.