Accessing Sampled Animation Data [MEL]


 

 

As mentioned in the Animation Curve section, maya stores all of it's animation data as animation curves. Whilst this works well for maya, it usually doesn't work too well in games.

For simplicity, it is usually easier to read back animation data by reading sampled transforms at a fixed time interval. Some people may decide to only export rotational data.

It may be worth pointing out that animators occasionally make use of influence objects to enhance the deformation of knees, elbows and other tricky to skin places. Influence objects are usually transforms, added into the bone hierarchy, and usually use scale and translation to deform the object rather than rotations.

If you want to keep your animators happy then it may be worth exporting scale and translational animation data as well. It should be fairly easy to strip out redundant keyframes, so it shouldn't add too much to your animation code.

Generally the process for sampling the data is as follows.

  1. Build a list of all useful transforms you wish to sample. This is generally best done as an array of MDagPaths, this process is explained here
  2. use the MAnimControl class to find the range for the animation
  3. step through the animation frames outputting each transform value for that frame

You may find that at some point you have a single animated attribute that may be better suited to gathering animation curves. One example is blend shape weight values.

 

 

 

 

 

Determining the time range

The MAnimControl class can be used to find the time range for the animation. This then simply outputs the start and end time for the animation in frames (25fps).

 

 

 


#include<maya/MAnimControl.h>
#include<maya/MTime.h>

MTime Start = MAnimControl::animationStartTime();
MTime End = MAnimControl::animationEndTime();

// output the start time
cout <<"start "
<<Start.as(MTime::kPALFrame)
<<endl;

// output the end time

cout <<"end "
<<End.as(MTime::kPALFrame)
<<endl;


 

Stepping Through The Animation timeline.

 

Normally when you write an exporter, you try to ensure that you only output transforms that have an affect on your final model.

This implies that before you write any transform or animation data to the file, you must have first determine a set of transforms to write to the file.

Usually this list of important transforms will be held as an MDagPathArray. MObjects unfortunately can become invalidated when the frame changes, so generally storing DagPaths is the way to go.

To output the animation we can use the MAnimControl class once again to step between the first and last frames. Each frame we can sample the joints transform and output it. This example simply outputs the rotation, however you could also output the translation and scale for the joints.

 


#include<maya/MAnimControl.h>
#include<maya/MFnTransform.h>
#include<maya/MQuaternion.h>
#include<maya/MDagPath.h>
#include<maya/MTime.h>

bool OutputBoneAnimation(MDagPath& bone,int sf,int ef)
{
 

// loop through all frames in this animation cycle.
//

for(int i=sf;i<ef;++i) {

 

// set the current frame
MAnimControl::setCurrentTime(MTime(i,MTime::kPALFrame));

// attach the function set to the object
MFnTransform
fn(bone);

// get the rotation for the bone this frame
MQuaternion
Rotation;

fn.getRotation(Rotation);

// write out the animation key
// you may want more animation data, in which case
// have a look at the transform section.

cout << "rotation "
<< Rotation.x << " "
<< Rotation.y << " "
<< Rotation.z << " "
<< Rotation.w << endl;

}

}



 

 

What Next?

Material Data

Transformation Data

Blend Shape Deformers

Soft Skinned Surfaces

Rigid Skinned Surfaces

Lattice Deformers

index

Rob Bateman [2004]


[HOME] [MEL] [API]