2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-07-22 14:37:24 -04:00
|
|
|
#include "AnimNodes/AnimNode_RotateRootBone.h"
|
2019-12-13 11:07:03 -05:00
|
|
|
#include "Animation/AnimTrace.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
|
// FAnimNode_RotateRootBone
|
|
|
|
|
|
2017-06-21 10:25:35 -04:00
|
|
|
void FAnimNode_RotateRootBone::Initialize_AnyThread(const FAnimationInitializeContext& Context)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2019-07-16 11:49:59 -04:00
|
|
|
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Initialize_AnyThread)
|
2017-06-21 10:25:35 -04:00
|
|
|
FAnimNode_Base::Initialize_AnyThread(Context);
|
2015-09-03 09:55:41 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
BasePose.Initialize(Context);
|
2018-05-23 21:04:31 -04:00
|
|
|
|
|
|
|
|
PitchScaleBiasClamp.Reinitialize();
|
|
|
|
|
YawScaleBiasClamp.Reinitialize();
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-16 11:49:59 -04:00
|
|
|
void FAnimNode_RotateRootBone::CacheBones_AnyThread(const FAnimationCacheBonesContext& Context)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2019-07-16 11:49:59 -04:00
|
|
|
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(CacheBones_AnyThread)
|
2014-03-14 14:13:41 -04:00
|
|
|
BasePose.CacheBones(Context);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-21 10:25:35 -04:00
|
|
|
void FAnimNode_RotateRootBone::Update_AnyThread(const FAnimationUpdateContext& Context)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2019-07-16 11:49:59 -04:00
|
|
|
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Update_AnyThread)
|
2018-11-14 19:05:13 -05:00
|
|
|
GetEvaluateGraphExposedInputs().Execute(Context);
|
2014-03-14 14:13:41 -04:00
|
|
|
BasePose.Update(Context);
|
2018-05-23 21:04:31 -04:00
|
|
|
|
|
|
|
|
ActualPitch = PitchScaleBiasClamp.ApplyTo(Pitch, Context.GetDeltaTime());
|
|
|
|
|
ActualYaw = YawScaleBiasClamp.ApplyTo(Yaw, Context.GetDeltaTime());
|
2019-12-13 11:07:03 -05:00
|
|
|
|
|
|
|
|
TRACE_ANIM_NODE_VALUE(Context, TEXT("Pitch"), ActualPitch);
|
|
|
|
|
TRACE_ANIM_NODE_VALUE(Context, TEXT("Yaw"), ActualYaw);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2017-06-21 10:25:35 -04:00
|
|
|
void FAnimNode_RotateRootBone::Evaluate_AnyThread(FPoseContext& Output)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2019-07-16 11:49:59 -04:00
|
|
|
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Evaluate_AnyThread)
|
2014-03-14 14:13:41 -04:00
|
|
|
// Evaluate the input
|
|
|
|
|
BasePose.Evaluate(Output);
|
|
|
|
|
|
2018-02-22 11:25:06 -05:00
|
|
|
checkSlow(!FMath::IsNaN(ActualYaw) && FMath::IsFinite(ActualYaw));
|
|
|
|
|
checkSlow(!FMath::IsNaN(ActualPitch) && FMath::IsFinite(ActualPitch));
|
|
|
|
|
|
|
|
|
|
if (!FMath::IsNearlyZero(ActualPitch, KINDA_SMALL_NUMBER) || !FMath::IsNearlyZero(ActualYaw, KINDA_SMALL_NUMBER))
|
2015-05-29 16:09:13 -04:00
|
|
|
{
|
|
|
|
|
// Build our desired rotation
|
2018-02-22 11:25:06 -05:00
|
|
|
const FRotator DeltaRotation(ActualPitch, ActualYaw, 0.f);
|
2015-05-29 16:09:13 -04:00
|
|
|
const FQuat DeltaQuat(DeltaRotation);
|
|
|
|
|
const FQuat MeshToComponentQuat(MeshToComponent);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-05-29 16:09:13 -04:00
|
|
|
// Convert our rotation from Component Space to Mesh Space.
|
|
|
|
|
const FQuat MeshSpaceDeltaQuat = MeshToComponentQuat.Inverse() * DeltaQuat * MeshToComponentQuat;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2015-05-29 16:09:13 -04:00
|
|
|
// Apply rotation to root bone.
|
2015-10-28 19:18:20 -04:00
|
|
|
FCompactPoseBoneIndex RootBoneIndex(0);
|
|
|
|
|
Output.Pose[RootBoneIndex].SetRotation(Output.Pose[RootBoneIndex].GetRotation() * MeshSpaceDeltaQuat);
|
|
|
|
|
Output.Pose[RootBoneIndex].NormalizeRotation();
|
2015-05-29 16:09:13 -04:00
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-04-23 18:35:21 -04:00
|
|
|
|
|
|
|
|
void FAnimNode_RotateRootBone::GatherDebugData(FNodeDebugData& DebugData)
|
|
|
|
|
{
|
2019-07-16 11:49:59 -04:00
|
|
|
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(GatherDebugData)
|
2014-04-23 18:35:21 -04:00
|
|
|
FString DebugLine = DebugData.GetNodeName(this);
|
2018-02-22 11:25:06 -05:00
|
|
|
|
|
|
|
|
DebugLine += FString::Printf(TEXT("Pitch(%.2f) Yaw(%.2f)"), ActualPitch, ActualYaw);
|
2014-04-23 18:35:21 -04:00
|
|
|
DebugData.AddDebugItem(DebugLine);
|
|
|
|
|
|
|
|
|
|
BasePose.GatherDebugData(DebugData);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
FAnimNode_RotateRootBone::FAnimNode_RotateRootBone()
|
|
|
|
|
: Pitch(0.0f)
|
|
|
|
|
, Yaw(0.0f)
|
|
|
|
|
, MeshToComponent(FRotator::ZeroRotator)
|
2018-05-23 21:04:31 -04:00
|
|
|
, ActualPitch(0.f)
|
|
|
|
|
, ActualYaw(0.f)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
}
|