Extracting Animation Data
Getting animation information out of Maya involves a little trickery also. Essentially you want to extract information out of the DG at a given time, and then you want to alter the time parameter for each frame. There are several problems. First is how to determine where the keyframes are. Your data will either
I can only help you with the first two ways. The following code will find all the key frames, and the length of an animation:
maxKeyTime holds the last keyframe time, and the length of an animation. storeKeyTime is a call to your own code to store a given keyframe time so you can evaluate the animation at that time later. Remember that probably many duplicate times will be inserted into that array. There are quite likely many MFnAnimCurve nodes in the DG with the same keyframe times to animate different parts of the model. You can either chose to use the keyframe times as they are stored, or you can chose to use the last maxKeyTime and iterate over fixed steps from 0 to that time. This is something you should probably discuss with those people responsible for making the animations.void findFrames()
{
MItDag dagIter( MItDag::kBreadthFirst, MFn::kInvalid, &stat );
MTime maxKeyTime = 0;
for ( ; !dagIter.isDone(); dagIter.next())
{
MDagPath dagPath;
stat = dagIter.getPath( dagPath );
MFnDagNode dn( dagPath );
// find all the motion nodes
MItDependencyGraph dgIter( dagPath.node(),
MFn::kAnimCurve,
MItDependencyGraph::kUpstream,
MItDependencyGraph::kBreadthFirst,
MItDependencyGraph::kNodeLevel,
&stat );
if ( stat )
{
// get all the keyframe times
for ( ; !dgIter.isDone(); dgIter.next())
{
MObject anim = dgIter.thisNode( &stat );
MFnAnimCurve animCurve( anim, &stat );
// found some keyframe information
if ( MS::kSuccess == stat )
{
u32 numKeys = animCurve.numKeyframes( &stat );
for ( u32 currKey = 0; currKey < numKeys; currKey++ )
{
// Truncating values here...
MTime keyTime = animCurve.time( currKey, &stat );
// store this key frame time somewhere.
storeKeyTime( keyTime );
// and store the maximum frame time
if ( time > maxKeyTime )
maxKeyTime = time;
}
}
}
}
}
}
The last part of the problem is how to evaluate a model at a given time, to extract all the vertices, or transforms for a given animation. For this you use the handy MAnimControl object, like so:
void processAnimationFrame( MTime& time )And there you have it, everything you need to know to extract basic model information out of Maya.{
// create a Dag iterator
MStatus stat;
MItDag dagIter( MItDag::kBreadthFirst, MFn::kInvalid, &stat );
// here is the magic animation time setting object. Set it to the
// desired time, and presto...
MAnimControl animctrl;
animctrl.setCurrentTime( time );
for ( ; !dagIter.isDone(); dagIter.next())
{
MDagPath dagPath;
stat = dagIter.getPath( dagPath );
if ( stat )
{
MFnDagNode dagNode( dagPath, &stat );
if ( dagNode.isIntermediateObject()) continue;
if ( !dagPath.hasFn( MFn::kMesh )) continue;
if ( dagPath.hasFn( MFn::kTransform )) continue;
// your mesh object... and it should be
MFnMesh fnMesh( dagPath );
// get the vertices that are part of the current mesh
MPointArray vertexList;
fnMesh.getPoints( vertexList, MSpace::kWorld );
// iterate through all the vertices
for ( u32 i = 0; i < vertexList.length(); i++ )
{
vertexList[i].cartesianize();
MPoint point = vertexList[i];
// here is your data, but this time it should be different
// for each time at which you evaluate it. You should be
// able to get tranform information over time in a similar
// way.
processVertex( point.x, point.y, point.z );
}
}
}
}
Here are some other Maya programming tutorials:
Author: admin
Submitted: 2006-11-02 20:40:49 UTC
Tags:
Software: Maya
Views: 46,268
Related Items
-
.40 S&W Cartridge 3D Model
$25.00 (USD) -
Animated Olympic Fire 2014 (Maya) 3D Model
$69.00 (USD) -
Elephant 3d textured model 3ds max and maya scene files 3D Model
$30.00 (USD) -
"Rapid Rig: Poser" for Maya for Maya 2.0.9 (maya script)
$20.00 (USD) -
Nick-Maya Rig With Advance Facial Setup for Maya 0.1.0
$20.00 (USD) -
Pamela Maya (2013) Rig for Maya 0.0.1
$20.00 (USD) -
The Alchemy Tools for Maya for Maya 1.0.0 (maya script)
$20.00 (USD) -
Arab Rig for Maya with Ncloth simulation for Maya 0.0.1
$99.00 (USD) -
Poly Tools for Maya for Maya 0.4.2 (maya script)
$20.00 (USD)






