You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
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]
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "AnimGraphRuntimePrivatePCH.h"
|
|
#include "BoneControllers/AnimNode_SkeletalControlBase.h"
|
|
#include "AnimationUtils.h"
|
|
#include "AnimationRuntime.h"
|
|
|
|
/////////////////////////////////////////////////////
|
|
// FAnimNode_SkeletalControlBase
|
|
|
|
void FAnimNode_SkeletalControlBase::Initialize(const FAnimationInitializeContext& Context)
|
|
{
|
|
FAnimNode_Base::Initialize(Context);
|
|
|
|
ComponentPose.Initialize(Context);
|
|
}
|
|
|
|
void FAnimNode_SkeletalControlBase::CacheBones(const FAnimationCacheBonesContext& Context)
|
|
{
|
|
InitializeBoneReferences(Context.AnimInstance->RequiredBones);
|
|
ComponentPose.CacheBones(Context);
|
|
}
|
|
|
|
void FAnimNode_SkeletalControlBase::Update(const FAnimationUpdateContext& Context)
|
|
{
|
|
ComponentPose.Update(Context);
|
|
EvaluateGraphExposedInputs.Execute(Context);
|
|
}
|
|
|
|
bool ContainsNaN(const TArray<FBoneTransform> & BoneTransforms)
|
|
{
|
|
for (int32 i = 0; i < BoneTransforms.Num(); ++i)
|
|
{
|
|
if (BoneTransforms[i].Transform.ContainsNaN())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void FAnimNode_SkeletalControlBase::EvaluateComponentSpace(FComponentSpacePoseContext& Output)
|
|
{
|
|
// Evaluate the input
|
|
ComponentPose.EvaluateComponentSpace(Output);
|
|
|
|
// Apply the skeletal control if it's valid
|
|
const float ActualAlpha = AlphaScaleBias.ApplyTo(Alpha);
|
|
if ((ActualAlpha >= ZERO_ANIMWEIGHT_THRESH) && IsValidToEvaluate(Output.AnimInstance->CurrentSkeleton, Output.AnimInstance->RequiredBones))
|
|
{
|
|
USkeletalMeshComponent* Component = Output.AnimInstance->GetSkelMeshComponent();
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
// save current pose before applying skeletal control to compute the exact gizmo location in AnimGraphNode
|
|
ForwardedPose = Output.Pose;
|
|
#endif // #if WITH_EDITORONLY_DATA
|
|
|
|
TArray<FBoneTransform> BoneTransforms;
|
|
EvaluateBoneTransforms(Component, Output.Pose, BoneTransforms);
|
|
|
|
checkSlow(!ContainsNaN(BoneTransforms));
|
|
|
|
if (BoneTransforms.Num() > 0)
|
|
{
|
|
const float BlendWeight = FMath::Clamp<float>(ActualAlpha, 0.f, 1.f);
|
|
Output.Pose.LocalBlendCSBoneTransforms(BoneTransforms, BlendWeight);
|
|
}
|
|
}
|
|
}
|
|
|
|
void FAnimNode_SkeletalControlBase::AddDebugNodeData(FString& OutDebugData)
|
|
{
|
|
const float ActualAlpha = AlphaScaleBias.ApplyTo(Alpha);
|
|
OutDebugData += FString::Printf(TEXT("Alpha: %.1f%%"), ActualAlpha*100.f);
|
|
} |