[Not an Issue] CSkinnedMesh incorrect AnimationFrames count

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
luthyr
Posts: 69
Joined: Wed Dec 30, 2009 5:47 pm

[Not an Issue] CSkinnedMesh incorrect AnimationFrames count

Post by luthyr »

Because of the optimization that removes duplicate frames, the following section incorrectly sets the wrong amount for AnimationFrames which leads to returning the wrong frame count in GetFrameCount(). Right now I have an animation that stops at frame 40 instead of playing out to frame 91 because of several keys that get optimized out because they are duplicates.

Code: Select all

 
void CSkinnedMesh::checkForAnimation()
{
    ..................
   if (HasAnimation)
    {
        //--- Find the length of the animation ---
        AnimationFrames=0;
        for(i=0;i<AllJoints.size();++i)
        {
            if (AllJoints[i]->UseAnimationFrom)
            {
                if (AllJoints[i]->UseAnimationFrom->PositionKeys.size())
                    if (AllJoints[i]->UseAnimationFrom->PositionKeys.size()+1 > AnimationFrames)
                        AnimationFrames=AllJoints[i]->UseAnimationFrom->PositionKeys.size()+1;
 
                if (AllJoints[i]->UseAnimationFrom->ScaleKeys.size())
                    if (AllJoints[i]->UseAnimationFrom->ScaleKeys.size()+1 > AnimationFrames)
                        AnimationFrames=AllJoints[i]->UseAnimationFrom->ScaleKeys.size()+1;
 
                if (AllJoints[i]->UseAnimationFrom->RotationKeys.size())
                    if (AllJoints[i]->UseAnimationFrom->RotationKeys.size()+1 > AnimationFrames)
                        AnimationFrames=AllJoints[i]->UseAnimationFrom->RotationKeys.size()+1;
            }
        }
    }
}
 
I think it should be something like:

Code: Select all

    if (HasAnimation)
    {
        //--- Find the length of the animation ---
        AnimationFrames=0;
        for(i=0;i<AllJoints.size();++i)
        {
            if (AllJoints[i]->UseAnimationFrom)
            {
                if (AllJoints[i]->UseAnimationFrom->PositionKeys.size())
                    if (AllJoints[i]->UseAnimationFrom->PositionKeys[AllJoints[i]->UseAnimationFrom->PositionKeys.size()-1].frame+1 > AnimationFrames)
                        AnimationFrames=AllJoints[i]->UseAnimationFrom->PositionKeys[AllJoints[i]->UseAnimationFrom->PositionKeys.size()-1].frame+1;
 
                if (AllJoints[i]->UseAnimationFrom->ScaleKeys.size())
               if (AllJoints[i]->UseAnimationFrom->ScaleKeys[AllJoints[i]->UseAnimationFrom->ScaleKeys.size()-1].frame+1 > AnimationFrames)
                  AnimationFrames=AllJoints[i]->UseAnimationFrom->ScaleKeys[AllJoints[i]->UseAnimationFrom->ScaleKeys.size()-1].frame+1;
 
                if (AllJoints[i]->UseAnimationFrom->RotationKeys.size())
               if (AllJoints[i]->UseAnimationFrom->RotationKeys[AllJoints[i]->UseAnimationFrom->RotationKeys.size()-1].frame+1 > AnimationFrames)
                  AnimationFrames=AllJoints[i]->UseAnimationFrom->RotationKeys[AllJoints[i]->UseAnimationFrom->RotationKeys.size()-1].frame+1;
            }
        }
    }
Here is an example model if you want to check it out.
Last edited by luthyr on Wed Feb 06, 2013 3:56 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CSkinnedMesh can have incorrect AnimationFrames count

Post by CuteAlien »

Hm, I've checked all versions from trunk back to even Irrlicht 1.4 and just can't find the wrong code in any of them. Which Irrlicht version are you using?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
luthyr
Posts: 69
Joined: Wed Dec 30, 2009 5:47 pm

Re: CSkinnedMesh can have incorrect AnimationFrames count

Post by luthyr »

You're right, sorry. I don't know how this was changed on our side. :oops:
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [Not an Issue] CSkinnedMesh incorrect AnimationFrames co

Post by CuteAlien »

No problem :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply