Files
UnrealEngineUWP/Engine/Source/Runtime/AnimGraphRuntime/Private/BoneControllers/AnimNode_ObserveBone.cpp
ryan durand 0f0464a30e Updating copyright for Engine Runtime.
#rnx
#rb none


#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869210 via CL 10869511 via CL 10869900
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870549 by ryan durand in Main branch]
2019-12-26 14:45:42 -05:00

69 lines
2.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "BoneControllers/AnimNode_ObserveBone.h"
#include "AnimationRuntime.h"
#include "Animation/AnimInstanceProxy.h"
#include "Animation/AnimTrace.h"
/////////////////////////////////////////////////////
// FAnimNode_ObserveBone
FAnimNode_ObserveBone::FAnimNode_ObserveBone()
: DisplaySpace(BCS_ComponentSpace)
, bRelativeToRefPose(false)
, Translation(FVector::ZeroVector)
, Rotation(FRotator::ZeroRotator)
, Scale(FVector(1.0f))
{
}
void FAnimNode_ObserveBone::GatherDebugData(FNodeDebugData& DebugData)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(GatherDebugData)
const FString DebugLine = FString::Printf(TEXT("(Bone: %s has T(%s), R(%s), S(%s))"), *BoneToObserve.BoneName.ToString(), *Translation.ToString(), *Rotation.Euler().ToString(), *Scale.ToString());
DebugData.AddDebugItem(DebugLine);
ComponentPose.GatherDebugData(DebugData);
}
void FAnimNode_ObserveBone::EvaluateSkeletalControl_AnyThread(FComponentSpacePoseContext& Output, TArray<FBoneTransform>& OutBoneTransforms)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(EvaluateSkeletalControl_AnyThread)
const FBoneContainer& BoneContainer = Output.Pose.GetPose().GetBoneContainer();
const FCompactPoseBoneIndex BoneIndex = BoneToObserve.GetCompactPoseIndex(BoneContainer);
FTransform BoneTM = Output.Pose.GetComponentSpaceTransform(BoneIndex);
// Convert to the specific display space if necessary
FAnimationRuntime::ConvertCSTransformToBoneSpace(Output.AnimInstanceProxy->GetComponentTransform(), Output.Pose, BoneTM, BoneIndex, DisplaySpace);
// Convert to be relative to the ref pose if necessary
if (bRelativeToRefPose)
{
const FTransform& SourceOrigRef = BoneContainer.GetRefPoseArray()[BoneToObserve.BoneIndex];
BoneTM = BoneTM.GetRelativeTransform(SourceOrigRef);
}
// Cache off the values for display
Translation = BoneTM.GetTranslation();
Rotation = BoneTM.GetRotation().Rotator();
Scale = BoneTM.GetScale3D();
TRACE_ANIM_NODE_VALUE(Output, TEXT("Bone"), BoneToObserve.BoneName);
TRACE_ANIM_NODE_VALUE(Output, TEXT("Translation"), Translation);
TRACE_ANIM_NODE_VALUE(Output, TEXT("Rotation"), Rotation.Euler());
TRACE_ANIM_NODE_VALUE(Output, TEXT("Scale"), Scale);
}
bool FAnimNode_ObserveBone::IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones)
{
return (BoneToObserve.IsValidToEvaluate(RequiredBones));
}
void FAnimNode_ObserveBone::InitializeBoneReferences(const FBoneContainer& RequiredBones)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(InitializeBoneReferences)
BoneToObserve.Initialize(RequiredBones);
}