Sign in to follow this  

[Maya API] Check if Animation curve is between frames

Recommended Posts

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:

bool NodeHasAnimationCurve(MObject& object)
MTime currentTime = MAnimControl::currentTime(); // Get current key time, in PAL format
MPlugArray connectedPlugs;
MFnDependencyNode fnDepNode(object);
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();
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;

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