bool CBoidObject::PlayAnimation( const char *animation, bool bLooped, float fBlendTime ) { bool playing = false; if (m_object) { ISkeletonAnim* pSkeleton = m_object->GetISkeletonAnim(); assert(pSkeleton); CryCharAnimationParams animParams; if (bLooped) animParams.m_nFlags |= CA_LOOP_ANIMATION; animParams.m_fTransTime = fBlendTime; const int amountAnimationsInFIFO = pSkeleton->GetNumAnimsInFIFO(0); const uint32 maxAnimationsAllowedInQueue = 2; if(amountAnimationsInFIFO >= maxAnimationsAllowedInQueue) { animParams.m_nFlags |= CA_REMOVE_FROM_FIFO; } playing = pSkeleton->StartAnimation( animation, animParams ); assert(pSkeleton->GetNumAnimsInFIFO(0) <= maxAnimationsAllowedInQueue); m_object->SetPlaybackScale( 1.0f ); } return playing; }
//------------------------------------------------------------------------ void CItem::PlayAnimationEx(const char* animationName, int slot, int layer, bool loop, float blend, float speed, uint32 flags) { bool start=true; ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot); if (!pCharacter && slot==eIGS_FirstPerson && ((m_stats.viewmode&eIVM_FirstPerson)==0)) { start=false; int idx = 0; if (m_stats.hand == eIH_Right) idx = 1; else if (m_stats.hand == eIH_Left) idx = 2; if (m_fpgeometry[idx].name.empty()) idx = 0; pCharacter = m_pItemSystem->GetCachedCharacter(m_fpgeometry[idx].name.c_str()); } if (pCharacter && animationName) { ISkeletonAnim* pSkeletonAnim = pCharacter->GetISkeletonAnim(); if (flags&eIPAF_CleanBlending) { while(pSkeletonAnim->GetNumAnimsInFIFO(layer)>1) { if (!pSkeletonAnim->RemoveAnimFromFIFO(layer, pSkeletonAnim->GetNumAnimsInFIFO(layer)-1)) break; } } if (flags&eIPAF_NoBlend) blend = 0.0f; if (start) { CryCharAnimationParams params; params.m_fTransTime = blend; params.m_nLayerID = layer; params.m_nFlags = (loop?CA_LOOP_ANIMATION:0)|(flags&eIPAF_RestartAnimation?CA_ALLOW_ANIM_RESTART:0)|(flags&eIPAF_RepeatLastFrame?CA_REPEAT_LAST_KEY:0); pSkeletonAnim->StartAnimation(animationName, params); pSkeletonAnim->SetLayerUpdateMultiplier(layer, speed); //pCharacter->GetISkeleton()->SetDebugging( true ); } float duration=0.0f; int animationId = pCharacter->GetIAnimationSet()->GetAnimIDByName(animationName); if (animationId>=0) duration = pCharacter->GetIAnimationSet()->GetDuration_sec(animationId); m_animationTime[slot] = (uint32)(duration*1000.0f/speed); m_animationEnd[slot] = (uint32)(gEnv->pTimer->GetCurrTime()*1000.0f)+m_animationTime[slot]; m_animationSpeed[slot] = speed; } }
void CScriptbind_Entity::PlayAnimation(IEntity *pEntity, mono::string animationName, int slot, int layer, float blend, float speed, EAnimationFlags flags) { // Animation graph input /*if(IGameObject *pGameObject = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetGameObject(pEntity->GetId())) { if(IAnimatedCharacter *pAniamtedCharacter = static_cast<IAnimatedCharacter*>(pGameObject->AcquireExtension("AnimatedCharacter"))) { pAniamtedCharacter->GetAnimationGraphState()->SetInput("Action / "Signal" } }*/ ICharacterInstance *pCharacter = pEntity->GetCharacter(slot); if(!pCharacter) return; ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); if(!pSkeletonAnim) return; if(flags & EAnimFlag_CleanBending) { while(pSkeletonAnim->GetNumAnimsInFIFO(layer)>1) { if (!pSkeletonAnim->RemoveAnimFromFIFO(layer, pSkeletonAnim->GetNumAnimsInFIFO(layer)-1)) break; } } if (flags & EAnimFlag_NoBlend) blend = 0.0f; CryCharAnimationParams params; params.m_fTransTime = blend; params.m_nLayerID = layer; params.m_fPlaybackSpeed = speed; params.m_nFlags = (flags & EAnimFlag_Loop ? CA_LOOP_ANIMATION : 0) | (flags & EAnimFlag_RestartAnimation ? CA_ALLOW_ANIM_RESTART : 0) | (flags & EAnimFlag_RepeatLastFrame ? CA_REPEAT_LAST_KEY : 0); pSkeletonAnim->StartAnimation(ToCryString(animationName), params); }
void CLivingEntitySample::StartAnimationForCurrentAnimationState() { IEntity* pEntity = GetEntity(); const int slot = 0; ICharacterInstance* pCharacterInstance = pEntity->GetCharacter( slot ); if ( pCharacterInstance == NULL ) { return; } ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if ( pSkeletonAnim == NULL ) { return; } CryCharAnimationParams animationParams; animationParams.m_nFlags |= CA_LOOP_ANIMATION; animationParams.m_nLayerID = 0; animationParams.m_fTransTime = 0.3f; const char* animationName = IDLE_ANIMATION_NAME; switch ( m_animationState ) { case None: case Idle: animationName = IDLE_ANIMATION_NAME; break; case Walk: animationName = WALK_ANIMATION_NAME; break; } pSkeletonAnim->StartAnimation( animationName, animationParams ); }