hkaDefaultAnimationControl maxCycles

hkaDefaultAnimationControl maxCycles

Bild des Benutzers Stephane L.

Hi,

I am either experiencing a bug or most likely am miusing the hkaDefaultAnimationControl.

  • If I load an animation with a maxCycles of 1, it does not play.
  • If I load an animation with a maxCycles of 2, it plays twice.

Basically I am trying to play one cycle of an animation. I am able to hack this problem by setting my maxCycles to 2 and then setting the local time to 0.51f, but this is just wrong.

 

Scenario: When the user press space-bar, I want him to jump and play the jump animation once. Whenever he presses it again, I stop the jump animation(at least for now) and I want to restart the animation from 0 and play it again.

Here is part of my code (any suggestions well accepted):

void

AnimComponent::AddAnimation(ANIM::TYPE type,conststd::string &animName,
                                 hkReal easeInTime,
                                 hkReal easeOutTime,
                                 hkReal masterWeight,
                                

boolblendable,
                                

boolwaitForFadeOut,
                                

floatanimationSpeedFactor,
                                

intcategory)
{
    assert(m_skeletonInstance);
    AnimationClip* anim = AnimationManager::GetInstance().GetAnimationClip(type, animName);
    assert(anim);
   
    idens_.push_back(AnimationIdentifier(animName, m_skeletonInstance->getNumAnimationControls(),
                                         masterWeight, category,
                                         blendable, waitForFadeOut,
                                         animationSpeedFactor, easeInTime, easeOutTime));
    hkaDefaultAnimationControl* control =

newhkaDefaultAnimationControl(anim->GetBinding(), anim->StartEasedIn(), anim->MaxCycles());
   

if(anim->StartEasedIn())
        control->setMasterWeight(1);
   

else
        control->setMasterWeight(0);
    control->setPlaybackSpeed( 1 );
    control->setEaseInCurve(anim->EaseInCurveY0(), anim->EaseInCurveY1(), anim->EaseInCurveY2(), anim->EaseInCurveY3());
    control->setEaseOutCurve(anim->EaseOutCurveY0(), anim->EaseOutCurveY1(), anim->EaseOutCurveY2(), anim->EaseOutCurveY3());
    control->setLocalTime(1);
    control->setCropStartAmountLocalTime(anim->StartCropTime());
    control->setCropEndAmountLocalTime(anim->EndCropTime());
    m_skeletonInstance->addAnimationControl(control);
    control->removeReference();
}
 
void

AnimComponent::SetCurrentAnimation(conststd::string &animName)
{
    IdenControl iden = findIdentifierAndControl(animName);
   

for(inti = 0; i < m_skeletonInstance->getNumAnimationControls(); ++i)
    {
        hkaDefaultAnimationControl* control =

static_cast<hkaDefaultAnimationControl*>(m_skeletonInstance->getAnimationControl(i));
        hkaDefaultAnimationControl::EaseStatus status = control->getEaseStatus();
       

if(i == iden.GetIdentifier().GetIndex())
        {
           

if(status == hkaDefaultAnimationControl::EASED_OUT ||
               status == hkaDefaultAnimationControl::EASING_OUT)
            {
                control->setPlaybackSpeed( iden.GetIdentifier().GetAnimationSpeedFactor() );
                control->setMasterWeight(iden.GetIdentifier().GetMasterWeight());
                control->setOverflowCount(0);
                control->setUnderflowCount(0);
                control->easeIn(iden.GetIdentifier().EaseInTime());
            }
           

elseif(status == hkaDefaultAnimationControl::EASED_IN)
            {
                control->setPlaybackSpeed( iden.GetIdentifier().GetAnimationSpeedFactor() );
                control->setMasterWeight(iden.GetIdentifier().GetMasterWeight());
                control->setOverflowCount(0);
                control->setUnderflowCount(0);
                control->easeIn(iden.GetIdentifier().EaseInTime());
                control->setLocalTime(0.51f);
            }
        }
       

else
        {
           

if(status == hkaDefaultAnimationControl::EASED_IN ||
               status == hkaDefaultAnimationControl::EASING_IN)
            {
                control->easeOut(iden.GetIdentifier().EaseOutTime());
            }
        }
       
    }
}

 

Thank you.

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers HavokTim

Hi Stephane--

Make sure that you're passing an integer value rather than a float for your max cycles to ensure that you're not encountering a rounding error. It's hard to tell what values and types you're passing around since you've included a lot of undefined functions and custom code, but I suggest you compare the values you set against those in the "Control" animation demo provided with PC XS (you can find it in Animation/Api/Playback/Control). Use example 5 (see "// 5 cycle once only.") as a reference, as it achieves one-shot animation by setting max cycles to 1. Also, one suspicious line of code I do see is the place where you set the local time to a non-zero value:

control->setPlaybackSpeed( 1 );

What is your purpose for doing this? This might be the source of your problem. If none of those tips help, I suggest that you simplify your usage by commenting out the code in which you set eas-in/ease-out curves and use constant values rather than variables to try to pinpoint the source of your bad data. Please let me know whether any of these suggestions works for you - thanks!

--Tim

Melden Sie sich an, um einen Kommentar zu hinterlassen.