void CLipSyncProvider_TransitionQueue::StartLipSync(IEntityAudioProxy* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod) { CRY_ASSERT(pProxy); CRY_ASSERT(audioTriggerId != INVALID_AUDIO_CONTROL_ID); CRY_ASSERT((m_state == eS_Requested) || (m_state == eS_Unpaused)); if (lipSyncMethod != eLSM_None) { m_soundId = audioTriggerId; m_isSynchronized = false; if (ICharacterInstance* pChar = GetCharacterInstance()) { if (m_requestedAnimId >= 0) { ISkeletonAnim* skeletonAnimation = pChar->GetISkeletonAnim(); const bool success = skeletonAnimation->StartAnimationById(m_requestedAnimId, m_requestedAnimParams); if (success) { m_nCurrentAnimationToken = m_requestedAnimParams.m_nUserToken; SynchronizeAnimationToSound(audioTriggerId); } else { m_nCurrentAnimationToken = -1; } } } } m_state = eS_Started; }
//------------------------------------------------------------------------ void CVehiclePartAnimated::Reset() { CVehiclePartBase::Reset(); SetDrivingProxy(false); if (m_slot > -1 && m_pCharInstance) { ISkeletonAnim* pSkeletonAnim = m_pCharInstance->GetISkeletonAnim(); CRY_ASSERT(pSkeletonAnim); ISkeletonPose* pSkeletonPose = m_pCharInstance->GetISkeletonPose(); CRY_ASSERT(pSkeletonPose); IDefaultSkeleton &rIDefaultSkeleton = m_pCharInstance->GetIDefaultSkeleton(); pSkeletonAnim->StopAnimationsAllLayers(); pSkeletonPose->SetDefaultPose(); pSkeletonPose->SetForceSkeletonUpdate(0); for (int i = 0; i < rIDefaultSkeleton.GetJointCount(); ++i) { pSkeletonPose->SetMaterialOnJoint(i, NULL); } } m_iRotChangedFrameId = 0; }
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; }
CAnimation *CAnimationProxyDualCharacter::GetAnimation(IEntity *entity, int32 layer, uint32 token) { ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; ICharacterInstance* pICharacter = pIShadowCharacter ? pIShadowCharacter : entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); int nAnimsInFIFO = pISkeletonAnim->GetNumAnimsInFIFO(layer); if (nAnimsInFIFO == 0) { return NULL; } if (token == INVALID_ANIMATION_TOKEN) { return &pISkeletonAnim->GetAnimFromFIFO(layer, 0); } else { return pISkeletonAnim->FindAnimInFIFO(token, layer); } } return NULL; }
void CLivingEntitySample::ResetCharacterModel() { IEntity* pEntity = GetEntity(); const int slot = 0; const char* modelFilename = DEFAULT_MODEL_NAME; pEntity->LoadCharacter( slot, modelFilename ); ICharacterInstance* pCharacterInstance = pEntity->GetCharacter( slot ); if ( pCharacterInstance == NULL ) { return; } ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if ( pSkeletonAnim == NULL ) { return; } ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose(); if ( pSkeletonPose == NULL ) { return; } pSkeletonPose->SetFootAnchoring( 1 ); pSkeletonAnim->SetAnimationDrivenMotion( 1 ); // We will want to set motion parameters directly ourselves for this sample: pSkeletonAnim->SetCharEditMode( 1 ); }
void CLivingEntitySample::UpdateAnimationParams( const float frameTime ) { IEntity* pEntity = GetEntity(); const int slot = 0; ICharacterInstance* pCharacterInstance = pEntity->GetCharacter( slot ); if ( pCharacterInstance == NULL ) { return; } ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if ( pSkeletonAnim == NULL ) { return; } ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose(); if ( pSkeletonPose == NULL ) { return; } const Vec2 localVelocity( m_localEntityVelocity.x, m_localEntityVelocity.y ); const float speed = localVelocity.GetLength(); const float angle = atan2f( -localVelocity.x, localVelocity.y ); pSkeletonAnim->SetDesiredMotionParam( eMotionParamID_TravelSpeed, speed, frameTime ); pSkeletonAnim->SetDesiredMotionParam( eMotionParamID_TravelAngle, angle, frameTime ); }
void CActionScope::Pause() { if (!m_scopeContext.charInst) { return; } ISkeletonAnim *pSkeletonAnim = m_scopeContext.charInst->GetISkeletonAnim(); if (!pSkeletonAnim) { return; } for (int i = 0; i < m_numLayers; ++i) { SSequencer &sequencer = m_layerSequencers[i]; const int animationLayer = m_layer + i; const int animationsInLayer = pSkeletonAnim->GetNumAnimsInFIFO(animationLayer); if (animationsInLayer == 0) { sequencer.savedAnimNormalisedTime = -1; } else { const int lastAnimationIndex = animationsInLayer - 1; const CAnimation &animation = pSkeletonAnim->GetAnimFromFIFO(animationLayer, lastAnimationIndex); sequencer.savedAnimNormalisedTime = pSkeletonAnim->GetAnimationNormalizedTime(&animation); } } }
void CActionScope::StopAnimationOnLayer(uint32 layer, float blendTime) { CRY_ASSERT_MESSAGE(layer < m_numLayers, "Overrunning scope!"); ISkeletonAnim *pSkelAnim = m_scopeContext.charInst->GetISkeletonAnim(); const uint32 actualLayer = layer + m_layer; pSkelAnim->StopAnimationInLayer(actualLayer, blendTime); }
bool CActionScope::InstallAnimation(int animID, const CryCharAnimationParams &animParams) { ISkeletonAnim *pSkelAnim = m_scopeContext.charInst->GetISkeletonAnim(); const bool startAnimationSuccess = pSkelAnim->StartAnimationById(animID, animParams); pSkelAnim->SetLayerPlaybackScale(animParams.m_nLayerID, m_speedBias); pSkelAnim->SetLayerBlendWeight(animParams.m_nLayerID, m_animWeight); return startAnimationSuccess; }
void CMountedGunController::ReplayStopThirdPersonAnimations( ICharacterInstance* pCharacter ) { assert(pCharacter); ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); assert(pSkeletonAnim); pSkeletonAnim->StopAnimationInLayer(REPLAY_PLAYER_ANIMATION_LAYER_AIM_UP, 0.1f); pSkeletonAnim->StopAnimationInLayer(REPLAY_PLAYER_ANIMATION_LAYER_AIM_DOWN, 0.1f); }
void CScriptbind_Entity::StopAnimationInLayer(IEntity *pEntity, int slot, int layer, float blendOutTime) { ICharacterInstance *pCharacter = pEntity->GetCharacter(slot); if(!pCharacter) return; ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); if(!pSkeletonAnim) return; pSkeletonAnim->StopAnimationInLayer(layer, blendOutTime); }
void CScriptbind_Entity::StopAnimationsInAllLayers(IEntity *pEntity, int slot) { ICharacterInstance *pCharacter = pEntity->GetCharacter(slot); if(!pCharacter) return; ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); if(!pSkeletonAnim) return; pSkeletonAnim->StopAnimationsAllLayers(); }
bool CAnimationProxyDualCharacterUpper::RemoveAnimationInLayer(IEntity *entity, int32 nLayer, uint32 token) { ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; ICharacterInstance* pICharacter = pIShadowCharacter ? pIShadowCharacter : entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); if (pIShadowCharacter) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); int nAnimsInFIFO = pIShadowSkeletonAnim->GetNumAnimsInFIFO(nLayer); for (int i=0; i<nAnimsInFIFO; ++i) { const CAnimation& anim = pIShadowSkeletonAnim->GetAnimFromFIFO(nLayer, i); if (anim.HasUserToken(token)) { pIShadowSkeletonAnim->RemoveAnimFromFIFO(nLayer, i); } } } int nAnimsInFIFO = pISkeletonAnim->GetNumAnimsInFIFO(nLayer); for (int i=0; i<nAnimsInFIFO; ++i) { const CAnimation& anim = pISkeletonAnim->GetAnimFromFIFO(nLayer, i); if (anim.HasUserToken(token)) { return pISkeletonAnim->RemoveAnimFromFIFO(nLayer, i); } } } return false; }
CAnimation *CActionScope::GetTopAnim(int layer) { CAnimation *anim = NULL; if (m_scopeContext.charInst) { ISkeletonAnim *pISkeletonAnim = m_scopeContext.charInst->GetISkeletonAnim(); int nAnimsInFIFO = pISkeletonAnim->GetNumAnimsInFIFO(m_layer + layer); if (nAnimsInFIFO > 0) { anim = &pISkeletonAnim->GetAnimFromFIFO(m_layer + layer, nAnimsInFIFO-1); } } return anim; }
void CActionScope::Flush(EFlushMethod flushMethod) { ISkeletonAnim *pSkelAnim = m_scopeContext.charInst.get() ? m_scopeContext.charInst->GetISkeletonAnim() : NULL; for (uint32 i=0; i<m_numLayers; i++) { SSequencer &sequencer = m_layerSequencers[i]; //const uint32 numAnims = sequencer.sequence.size(); sequencer.sequence.resize(0); sequencer.installTime = -1.0f; sequencer.pos = 0; sequencer.flags = 0; //clear FIFO regardless of whether actionscope believes it has animations in the sequence or not //fixes issue where clearing a scope context wouldn't clear all animations because an empty fragment gets queued first clearing the sequencer if (/*(numAnims > 0) &&*/ pSkelAnim && (flushMethod != FM_NormalLeaveAnimations)) { pSkelAnim->ClearFIFOLayer(m_layer + i); } } const int numProcs = m_procSequencers.size(); for (uint32 i=0; i<numProcs; i++) { SProcSequencer &procSeq = m_procSequencers[i]; if (procSeq.proceduralClip) { switch(flushMethod) { case FM_Normal: case FM_NormalLeaveAnimations: procSeq.proceduralClip->OnExit(0.0f); break; case FM_Failure: procSeq.proceduralClip->OnFail(); break; default: CRY_ASSERT(false); } } } m_procSequencers.resize(0); m_lastFragmentID = FRAGMENT_ID_INVALID; m_fragmentTime = 0.0f; m_lastFragSelection = SFragmentSelection(); m_lastQueueTagState = SFragTagState(); m_sequenceFlags = 0; }
//------------------------------------------------------------------------ void CReplayActor::PlayUpperAnimation(int animId, const CryCharAnimationParams& params, float speedMultiplier, float animTime) { float adjustedLayerTime = 0; ICharacterInstance* pCharacterInstance = GetEntity()->GetCharacter(0); if (animTime == 0 || GetAdjustedLayerTime(pCharacterInstance, animId, params, speedMultiplier, animTime, adjustedLayerTime)) { m_animationProxyUpper.StartAnimationById(GetEntity(), animId, params, speedMultiplier); ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); pSkeletonAnim->SetLayerNormalizedTime(params.m_nLayerID, adjustedLayerTime); ICharacterInstance* pShadowCharacter = GetShadowCharacter(); if (pShadowCharacter) { pShadowCharacter->GetISkeletonAnim()->SetLayerNormalizedTime(params.m_nLayerID, adjustedLayerTime); } } }
//------------------------------------------------------------------------ int CVehiclePartAnimated::GetNextFreeLayer() { if (ICharacterInstance* pCharInstance = GetEntity()->GetCharacter(m_slot)) { ISkeletonAnim* pSkeletonAnim = pCharInstance->GetISkeletonAnim(); CRY_ASSERT(pSkeletonAnim); for (int i = 1; i < ISkeletonAnim::LayerCount; i++) { if (pSkeletonAnim->GetNumAnimsInFIFO(i) == 0) return i; } } return -1; }
const CAnimation *CAnimationProxyDualCharacter::GetAnimation(IEntity *entity, int32 layer) { ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; ICharacterInstance* pICharacter = pIShadowCharacter ? pIShadowCharacter : entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); int nAnimsInFIFO = pISkeletonAnim->GetNumAnimsInFIFO(layer); if (nAnimsInFIFO > 0) { return &pISkeletonAnim->GetAnimFromFIFO(layer, nAnimsInFIFO-1); } } return NULL; }
////////////////////////////////////////////////////////////////////////// /// Recording System Replay - This should work through mannequin void CMountedGunController::ReplayStartThirdPersonAnimations( ICharacterInstance* pCharacter, int upAnimId, int downAnimId ) { assert(pCharacter); ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); assert(pSkeletonAnim); CryCharAnimationParams animParams; animParams.m_nFlags = CA_LOOP_ANIMATION; animParams.m_fTransTime = 0.1f; animParams.m_nLayerID = REPLAY_PLAYER_ANIMATION_LAYER_AIM_UP; animParams.m_fPlaybackWeight = 0.0f; pSkeletonAnim->StartAnimationById(upAnimId, animParams); animParams.m_nLayerID = REPLAY_PLAYER_ANIMATION_LAYER_AIM_DOWN; animParams.m_fPlaybackWeight = 0.0f; pSkeletonAnim->StartAnimationById(downAnimId, animParams); }
void CActionScope::Update(float timePassed) { IAction * const pPlayingAction = GetPlayingAction().get(); if (pPlayingAction) { ISkeletonAnim *pSkelAnim = m_scopeContext.charInst ? m_scopeContext.charInst->GetISkeletonAnim() : NULL; const float newSpeedBias = pPlayingAction->GetSpeedBias(); const float newAnimWeight = pPlayingAction->GetAnimWeight(); if (m_speedBias != newSpeedBias) { m_speedBias = newSpeedBias; if(pSkelAnim) { for (uint32 layer=0; layer<m_numLayers; layer++) { pSkelAnim->SetLayerPlaybackScale(m_layer+layer, newSpeedBias); } } } if(m_animWeight != newAnimWeight) { m_animWeight = newAnimWeight; if(pSkelAnim) { for (uint32 layer=0; layer<m_numLayers; layer++) { pSkelAnim->SetLayerBlendWeight(m_layer+layer, newAnimWeight); } } } timePassed *= m_speedBias; m_fragmentTime += timePassed+m_timeIncrement; } UpdateSequencers(timePassed); }
bool CAnimationProxyDualCharacterUpper::StopAnimationInLayer(IEntity *entity, int32 nLayer, f32 BlendOutTime) { ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; if (pIShadowCharacter) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); pIShadowSkeletonAnim->StopAnimationInLayer(nLayer, BlendOutTime); } return pISkeletonAnim->StopAnimationInLayer(nLayer, BlendOutTime); } return false; }
void CMountedGunController::ReplayUpdateThirdPersonAnimations( ICharacterInstance* pCharacter, float aimRad, float aimUp, float aimDown, bool firstPerson /*= false*/) { if (pCharacter) { ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); assert(pSkeletonAnim); //Update manually animation time, to match current weapon orientation uint32 numAnimsLayer = pSkeletonAnim->GetNumAnimsInFIFO(REPLAY_PLAYER_ANIMATION_LAYER_BASE); for(uint32 i=0; i<numAnimsLayer; i++) { CAnimation &animation = pSkeletonAnim->GetAnimFromFIFO(REPLAY_PLAYER_ANIMATION_LAYER_BASE, i); if (animation.HasStaticFlag(CA_MANUAL_UPDATE)) { float time = CalculateAnimationTime(aimRad); pSkeletonAnim->SetAnimationNormalizedTime(&animation, time); animation.ClearStaticFlag( CA_DISABLE_MULTILAYER ); } } if (firstPerson) return; //Update additive weights for aiming up/down pSkeletonAnim->SetLayerBlendWeight(REPLAY_PLAYER_ANIMATION_LAYER_AIM_UP, aimUp); pSkeletonAnim->SetLayerBlendWeight(REPLAY_PLAYER_ANIMATION_LAYER_AIM_DOWN, aimDown); } }
//------------------------------------------------------------------------ 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 ); }
void CLipSyncProvider_TransitionQueue::StopLipSync(IEntityAudioProxy* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod) { CRY_ASSERT(pProxy); CRY_ASSERT(audioTriggerId != INVALID_AUDIO_CONTROL_ID); CRY_ASSERT((m_state == eS_Started) || (m_state == eS_Requested) || (m_state == eS_Unpaused) || (m_state == eS_Paused)); if (lipSyncMethod != eLSM_None) { if (m_state == eS_Requested) { CRY_ASSERT(m_soundId == INVALID_AUDIO_CONTROL_ID); } else { CRY_ASSERT(audioTriggerId == m_soundId); if (ICharacterInstance* pChar = GetCharacterInstance()) { if (m_requestedAnimId >= 0) { ISkeletonAnim* skeletonAnimation = pChar->GetISkeletonAnim(); // NOTE: there is no simple way to just stop the exact animation we started, but this should do too: bool success = skeletonAnimation->StopAnimationInLayer(m_nAnimLayer, LIPSYNC_STOP_TRANSITION_TIME); CRY_ASSERT(success); } } m_soundId = INVALID_AUDIO_CONTROL_ID; m_isSynchronized = false; } m_cachedAnim = CAutoResourceCache_CAF(); } m_state = eS_Stopped; }
//------------------------------------------------------------------------ void CVehicleSeatActionPassengerIK::Update(float frameTime) { if (!m_passengerId) return; IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(m_passengerId); if (!pActor) { CRY_ASSERT(!"Invalid entity id for the actor id, Actor System didn't know it"); return; } if (ICharacterInstance* pCharInstance = pActor->GetEntity()->GetCharacter(0)) { ISkeletonAnim* pSkeletonAnim = pCharInstance->GetISkeletonAnim(); CRY_ASSERT(pSkeletonAnim); if (pSkeletonAnim->GetNumAnimsInFIFO(0) >= 1) { const CAnimation& anim = pSkeletonAnim->GetAnimFromFIFO(0, 0); const uint16 loopCount = anim.GetLoop(); const f32 animationTime = pSkeletonAnim->GetAnimationNormalizedTime( &anim ); if (!m_waitShortlyBeforeStarting || (loopCount > 0 || animationTime > 0.9f)) { for (TIKLimbVector::iterator ite = m_ikLimbs.begin(); ite != m_ikLimbs.end(); ++ite) { const SIKLimb& limb = *ite; Vec3 helperPos = limb.pHelper->GetWorldSpaceTranslation(); pActor->SetIKPos(limb.limbName.c_str(), helperPos, 1); } } } } }
bool CAnimationProxyDualCharacterUpper::StartAnimationById(IEntity *entity, int animId, const CryCharAnimationParams& Params, float speedMultiplier) { ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; IAnimationSet* pAnimSet = pICharacter->GetIAnimationSet(); SPlayParams playParams; GetPlayParams(animId, speedMultiplier, pAnimSet, playParams); CryCharAnimationParams localParams = Params; bool startedMain = false; if (m_firstPersonMode) { localParams.m_fPlaybackSpeed *= playParams.speedFP; startedMain = pISkeletonAnim->StartAnimationById(playParams.animIDFP, localParams); } else { localParams.m_fPlaybackSpeed *= playParams.speedTP; startedMain = pISkeletonAnim->StartAnimationById(playParams.animIDTP, localParams); } if (startedMain) { pISkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } if (pIShadowCharacter != NULL && (Params.m_nLayerID != 0)) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); localParams.m_fPlaybackSpeed = Params.m_fPlaybackSpeed * playParams.speedTP; if (pIShadowSkeletonAnim->StartAnimationById(playParams.animIDTP, localParams)) { pIShadowSkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } } return startedMain; } return false; }
bool CAnimationProxyDualCharacter::StartAnimationById(IEntity *entity, int animId, const CryCharAnimationParams& Params, float speedMultiplier) { ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; IAnimationSet* pAnimSet = pICharacter->GetIAnimationSet(); SPlayParams playParams; GetPlayParams(animId, speedMultiplier, pAnimSet, playParams); bool shadowLocomotion = !(((Params.m_nFlags & CA_DISABLE_MULTILAYER) || (Params.m_nLayerID != 0)) || !m_killMixInFirst); bool bAnimStarted = false; bool bShouldPlayShadow = true; CryCharAnimationParams localParams = Params; if (!m_firstPersonMode || !shadowLocomotion) { localParams.m_fPlaybackSpeed *= m_firstPersonMode ? playParams.speedFP : playParams.speedTP; bAnimStarted = pISkeletonAnim->StartAnimationById(m_firstPersonMode ? playParams.animIDFP : playParams.animIDTP, localParams); if (bAnimStarted) { pISkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } else bShouldPlayShadow = false; } if (bShouldPlayShadow && pIShadowCharacter != NULL) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); localParams.m_fPlaybackSpeed = Params.m_fPlaybackSpeed * playParams.speedTP; if (pIShadowSkeletonAnim->StartAnimationById(playParams.animIDTP, localParams)) { bAnimStarted = true; pIShadowSkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } } if (bAnimStarted && (Params.m_nLayerID == 0)) { m_allowsMix = (Params.m_nFlags & CA_DISABLE_MULTILAYER) == 0; } return bAnimStarted; } return false; }
void CActionScope::UpdateSequencers(float timePassed) { ISkeletonAnim *pSkelAnim = m_scopeContext.charInst ? m_scopeContext.charInst->GetISkeletonAnim() : NULL; const bool hasIncrement = (m_timeIncrement != 0.0f); timePassed += m_timeIncrement; m_timeIncrement = 0.0f; const int k_MAX_INCREMENTS = 5; float queuedIncrements[k_MAX_INCREMENTS]; int numQueued = 0; if(pSkelAnim) { const CAnimation *pRootAnim = GetTopAnim(0); if (pRootAnim) { m_lastNormalisedTime = m_normalisedTime; m_normalisedTime = pRootAnim->GetCurrentSegmentNormalizedTime(); } for (uint32 i=0; i<m_numLayers; i++) { SSequencer &sequencer = m_layerSequencers[i]; float timeLeft = timePassed; while ((sequencer.flags & eSF_Queued) != 0) { const float timeTillInstall = sequencer.installTime; if (timeLeft >= timeTillInstall) { if (PlayPendingAnim(i, timeLeft - timeTillInstall)) { timeLeft -= timeTillInstall; if (numQueued < k_MAX_INCREMENTS) { queuedIncrements[numQueued++] = timeLeft; } if (sequencer.pos >= sequencer.sequence.size()) break; } } else { sequencer.installTime -= timeLeft; break; } } if (hasIncrement) { uint32 layer = m_layer + i; uint32 numAnims = pSkelAnim->GetNumAnimsInFIFO(layer); if (numAnims > 0) { for (uint32 anm=0; anm<numAnims; anm++) { int timeIncID = (anm + numQueued) - numAnims; float timeIncrement = (timeIncID >= 0) ? queuedIncrements[timeIncID] : timePassed; if (timeIncrement > 0.0f) { CAnimation &anim = pSkelAnim->GetAnimFromFIFO(layer, anm); float segDuration = m_scopeContext.charInst->GetIAnimationSet()->GetDuration_sec(anim.GetAnimationId()); if (segDuration > 0.0f) { const float segNormTime = anim.GetCurrentSegmentNormalizedTime(); const float newTime = (segNormTime * segDuration) + (timeIncrement * anim.GetPlaybackScale()); float newSegNormTime = newTime / segDuration; if (!anim.HasStaticFlag(CA_LOOP_ANIMATION)) { newSegNormTime = min(newSegNormTime, 1.0f); } else { newSegNormTime = newSegNormTime - (float)((int)(newSegNormTime)); } anim.SetCurrentSegmentNormalizedTime(newSegNormTime); } float transitionPriority = 0.0f; const float transitionTime = anim.GetTransitionTime(); if ((transitionTime == 0.0f) || (anm < numAnims-1)) { transitionPriority = 1.0f; } else { transitionPriority = min(anim.GetTransitionPriority() + (timeIncrement / transitionTime), 1.0f); } anim.SetTransitionPriority(transitionPriority); } } } } } } const uint32 numProcSequencers = m_procSequencers.size(); for (uint32 i=0; i<numProcSequencers; i++) { SProcSequencer &sequencer = m_procSequencers[i]; float timeLeft = timePassed; while ((sequencer.flags & eSF_Queued) != 0) { if (timeLeft >= sequencer.installTime) { timeLeft -= sequencer.installTime; sequencer.installTime = -1.0f; PlayPendingProc(i); } else { sequencer.installTime -= timeLeft; break; } } if (sequencer.proceduralClip) { sequencer.proceduralClip->Update(timeLeft); } } }