Files
UnrealEngineUWP/Engine/Source/Runtime/AnimGraphRuntime/Private/AnimNodes/AnimNode_ApplyAdditive.cpp
Ryan Vance 7c51ff94af Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
CL 1 of 8
#rb integration

[CL 4748712 by Ryan Vance in Dev-VR branch]
2019-01-17 18:54:05 -05:00

100 lines
2.9 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "AnimNodes/AnimNode_ApplyAdditive.h"
#include "AnimationRuntime.h"
#include "Animation/AnimInstanceProxy.h"
/////////////////////////////////////////////////////
// FAnimNode_ApplyAdditive
void FAnimNode_ApplyAdditive::Initialize_AnyThread(const FAnimationInitializeContext& Context)
{
FAnimNode_Base::Initialize_AnyThread(Context);
Base.Initialize(Context);
Additive.Initialize(Context);
AlphaBoolBlend.Reinitialize();
AlphaScaleBiasClamp.Reinitialize();
}
void FAnimNode_ApplyAdditive::CacheBones_AnyThread(const FAnimationCacheBonesContext& Context)
{
Base.CacheBones(Context);
Additive.CacheBones(Context);
}
void FAnimNode_ApplyAdditive::Update_AnyThread(const FAnimationUpdateContext& Context)
{
Base.Update(Context);
ActualAlpha = 0.f;
if (IsLODEnabled(Context.AnimInstanceProxy))
{
// @note: If you derive from this class, and if you have input that you rely on for base
// this is not going to work
GetEvaluateGraphExposedInputs().Execute(Context);
switch (AlphaInputType)
{
case EAnimAlphaInputType::Float:
ActualAlpha = AlphaScaleBias.ApplyTo(AlphaScaleBiasClamp.ApplyTo(Alpha, Context.GetDeltaTime()));
break;
case EAnimAlphaInputType::Bool:
ActualAlpha = AlphaBoolBlend.ApplyTo(bAlphaBoolEnabled, Context.GetDeltaTime());
break;
case EAnimAlphaInputType::Curve:
if (UAnimInstance* AnimInstance = Cast<UAnimInstance>(Context.AnimInstanceProxy->GetAnimInstanceObject()))
{
ActualAlpha = AlphaScaleBiasClamp.ApplyTo(AnimInstance->GetCurveValue(AlphaCurveName), Context.GetDeltaTime());
}
break;
};
if (FAnimWeight::IsRelevant(ActualAlpha))
{
Additive.Update(Context.FractionalWeight(ActualAlpha));
}
}
}
void FAnimNode_ApplyAdditive::Evaluate_AnyThread(FPoseContext& Output)
{
//@TODO: Could evaluate Base into Output and save a copy
if (FAnimWeight::IsRelevant(ActualAlpha))
{
const bool bExpectsAdditivePose = true;
FPoseContext AdditiveEvalContext(Output, bExpectsAdditivePose);
Base.Evaluate(Output);
Additive.Evaluate(AdditiveEvalContext);
FAnimationRuntime::AccumulateAdditivePose(Output.Pose, AdditiveEvalContext.Pose, Output.Curve, AdditiveEvalContext.Curve, ActualAlpha, AAT_LocalSpaceBase);
Output.Pose.NormalizeRotations();
}
else
{
Base.Evaluate(Output);
}
}
FAnimNode_ApplyAdditive::FAnimNode_ApplyAdditive()
: Alpha(1.0f)
, LODThreshold(INDEX_NONE)
, AlphaCurveName(NAME_None)
, ActualAlpha(0.f)
, AlphaInputType(EAnimAlphaInputType::Float)
, bAlphaBoolEnabled(true)
{
}
void FAnimNode_ApplyAdditive::GatherDebugData(FNodeDebugData& DebugData)
{
FString DebugLine = DebugData.GetNodeName(this);
DebugLine += FString::Printf(TEXT("(Alpha: %.1f%%)"), ActualAlpha*100.f);
DebugData.AddDebugItem(DebugLine);
Base.GatherDebugData(DebugData.BranchFlow(1.f));
Additive.GatherDebugData(DebugData.BranchFlow(ActualAlpha));
}