Files
UnrealEngineUWP/Engine/Source/Runtime/AnimGraphRuntime/Private/AnimNodes/AnimNode_ApplyAdditive.cpp
Thomas Sarkanen 2878a344ae Anim Blueprint compiler can now access member variables directly instead of thunking to the VM
Optimization is enabled by default but is an engine setting in case it needs to be disabled (bOptimizeAnimBlueprintMemberVariableAccess).
Expanded FExposedValueHandler to also contain an array of source & dest properties (copy records) to copy between. These are resolved to read/write addresses on init & a simple memcpy at runtime instead of calling the usual generated custom event.
Custom events are not added at all if all properties use copy records. The event may still be added & called however as mixed-mode access is still supported (i.e. a thunk and a memcpy to different pin properties).
Unfortunately this required initialization of all ExposedValueHandlers (as I didnt want to add the branch overhead of lazy init) so all the anim nodes have needed a small change to call their base class Initialize().

[CL 2678504 by Thomas Sarkanen in Main branch]
2015-09-03 09:55:41 -04:00

70 lines
1.9 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "AnimGraphRuntimePrivatePCH.h"
#include "AnimNodes/AnimNode_ApplyAdditive.h"
/////////////////////////////////////////////////////
// FAnimNode_ApplyAdditive
void FAnimNode_ApplyAdditive::Initialize(const FAnimationInitializeContext& Context)
{
FAnimNode_Base::Initialize(Context);
Base.Initialize(Context);
Additive.Initialize(Context);
}
void FAnimNode_ApplyAdditive::CacheBones(const FAnimationCacheBonesContext& Context)
{
Base.CacheBones(Context);
Additive.CacheBones(Context);
}
void FAnimNode_ApplyAdditive::Update(const FAnimationUpdateContext& Context)
{
EvaluateGraphExposedInputs.Execute(Context);
Base.Update(Context);
const float ActualAlpha = AlphaScaleBias.ApplyTo(Alpha);
if (ActualAlpha > ZERO_ANIMWEIGHT_THRESH)
{
Additive.Update(Context.FractionalWeight(ActualAlpha));
}
}
void FAnimNode_ApplyAdditive::Evaluate(FPoseContext& Output)
{
//@TODO: Could evaluate Base into Output and save a copy
const float ActualAlpha = AlphaScaleBias.ApplyTo(Alpha);
if (ActualAlpha > ZERO_ANIMWEIGHT_THRESH)
{
FPoseContext AdditiveEvalContext(Output);
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)
{
}
void FAnimNode_ApplyAdditive::GatherDebugData(FNodeDebugData& DebugData)
{
const float ActualAlpha = AlphaScaleBias.ApplyTo(Alpha);
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));
}