Beispiel #1
0
void CActionScope::Resume(float forcedBlendTime, uint32 resumeFlags)
{
	if (!m_scopeContext.pCharInst)
	{
		return;
	}

	IAnimationSet* pAnimSet = m_scopeContext.pCharInst->GetIAnimationSet();
	if (!pAnimSet)
	{
		return;
	}

	ISkeletonAnim &skeletonAnimation = *m_scopeContext.pCharInst->GetISkeletonAnim();

	const bool useDefaultBlendTime = (forcedBlendTime < 0);

	for (int i = 0; i < m_numLayers; ++i)
	{
		SSequencer &sequencer = m_layerSequencers[i];

		const int   animationLayer = m_layer + i;
		const float blendTime      = useDefaultBlendTime ? sequencer.blend.duration : forcedBlendTime;

		if (sequencer.savedAnimNormalisedTime < 0)
		{
			skeletonAnimation.StopAnimationInLayer(animationLayer, blendTime);
		}
		else
		{
			const uint32 pos = sequencer.pos - 1;
			if (pos < sequencer.sequence.size())
			{
				SAnimClip &clip   = sequencer.sequence[pos];
				const int  animID = pAnimSet->GetAnimIDByCRC(clip.animation.animRef.crc);
				if (0 <= animID)
				{
					CryCharAnimationParams params;
					InitAnimationParams(clip.animation, i, clip.blend, params);
					const bool installAnimationSuccess = InstallAnimation(animID, params);
					if (installAnimationSuccess)
					{
						const int animationsInLayer = skeletonAnimation.GetNumAnimsInFIFO(animationLayer);
						CRY_ASSERT(1 <= animationsInLayer);

						const bool   loopingAnimation                = ((clip.animation.flags & CA_LOOP_ANIMATION) != 0);
						const uint32 restoreAnimationTimeFlagToCheck = loopingAnimation ? IActionController::ERF_RestoreLoopingAnimationTime : IActionController::ERF_RestoreNonLoopingAnimationTime;
						const bool   restoreAnimationTime            = ((restoreAnimationTimeFlagToCheck & resumeFlags) != 0);
						if (restoreAnimationTime)
						{
							const int   lastAnimationIndex = animationsInLayer - 1;
							CAnimation &animation          = skeletonAnimation.GetAnimFromFIFO(animationLayer, lastAnimationIndex);
							skeletonAnimation.SetAnimationNormalizedTime(&animation, sequencer.savedAnimNormalisedTime);
						}
					}
				}
			}
		}
	}
}
Beispiel #2
0
float CActionScope::CalculateFragmentDuration(const CFragment &fragment) const
{
    IAnimationSet *pAnimSet = m_scopeContext.charInst ? m_scopeContext.charInst->GetIAnimationSet() : NULL;

    float ret = 0.0f;
    if (pAnimSet)
    {
        if (fragment.m_animLayers.size() > 0)
        {
            const TAnimClipSequence &animClipSeq = fragment.m_animLayers[0];

            uint32 numClips = animClipSeq.size();
            float lastDuration = 0.0f;
            for (uint32 i=0; i<numClips; i++)
            {
                const SAnimClip &animClip = animClipSeq[0];

                if (i > 0)
                {
                    if (animClip.blend.exitTime >= 0.0f)
                    {
                        ret += animClip.blend.exitTime;
                    }
                    else
                    {
                        ret += lastDuration;
                    }
                }
                lastDuration = 0.0f;
                if (!animClip.animation.IsEmpty() && !(animClip.animation.flags & CA_LOOP_ANIMATION) && (animClip.animation.playbackSpeed > 0.0f))
                {
                    int animID = pAnimSet->GetAnimIDByCRC(animClip.animation.animRef.crc);
                    if (animID >= 0)
                    {
                        lastDuration = (pAnimSet->GetDuration_sec(animID) / animClip.animation.playbackSpeed);
                    }
                }
            }

            ret += lastDuration;
        }
    }

    return ret;
}
void CAnimActionBlendFromRagdoll::GenerateAnimIDs()
{
	SFragTagState fragTagStateMatch;
	SFragTagState fragTagStateQuery( m_rootScope->GetContext().state.GetMask(), m_fragTagsTarget );
	int32 numOptions = m_rootScope->GetDatabase().FindBestMatchingTag(m_fragmentID, fragTagStateQuery, &fragTagStateMatch);

	IAnimationSet* piAnimSet = m_rootScope->GetEntity().GetCharacter(0)->GetIAnimationSet();

	m_animIds.reserve( numOptions );
	for (int32 i=0; i<numOptions; i++)
	{
		const CFragment *fragment = m_rootScope->GetDatabase().GetEntry(m_fragmentID, fragTagStateMatch, i);

		if( !fragment->m_animLayers.empty() && !fragment->m_animLayers[0].empty() )
		{
			const SAnimClip& animClip = fragment->m_animLayers[0][0];
			const uint animID = piAnimSet->GetAnimIDByCRC(animClip.animation.animRef.crc);
			m_animIds.push_back( animID );
		}
	}
}