Sign in to follow this  
wiegje85

[Maya API] Check if Animation curve is between frames

Recommended Posts

wiegje85    151
A good evening once again.

Now that my joint animation is nicely working, I am having trouble with a small issue: how to check if the scene node that I am exporting on Frame N has an animation curve that has a start and ending frame that start before frame N and end after frame N, i.e. "is this node being animated on this frame?"

How do I check for that? What I do right now is I get the start key frame and end key frame and then retrieve the current time of the MAnimControl class. Then do a simple comparison for those 3 values. However, this doesn't seem to work as I get all these random values. I reference the MFnAnimCurve the way Rob The Bloke does it on his website: http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/index.html

[source]
bool NodeHasAnimationCurve(MObject& object)
{
MTime currentTime = MAnimControl::currentTime(); // Get current key time, in PAL format
MPlugArray connectedPlugs;
MFnDependencyNode fnDepNode(object);
fnDepNode.getConnections(connectedPlugs);
for(unsigned int c = 0; c < connectedPlugs.length(); ++c)
{
MPlug& plug = connectedPlugs[c];
MPlugArray connectedConnections;
plug.connectedTo(connectedConnections, true, false);
for(unsigned int i = 0; i < connectedConnections.length(); ++i)
{
MObject connected = connectedConnections[i].node();
const char* connectedType = connected.apiTypeStr();
if(connected.hasFn(MFn::kAnimCurve))
{
MFnAnimCurve fnAnim(connected);
for(unsigned int t = 0; t < fnAnim.numKeys(); ++t)
{
MTime keyTime = fnAnim.time(t); // This returns crazy values (PAL)
if(keyTime < currentTime || keyTime > currentTime)
{
return false;
}
}

return true;
}
}
}

return false;
}
[/source]

So right now I'm exporting all nodes, even those that are not animated for the currently selected frame, (i.e. don't have an animation curve attached for frame N).

How does one fix this? Thank you in advance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this