Files
UnrealEngineUWP/Engine/Source/Runtime/AnimGraphRuntime/Private/AnimNodes/AnimNode_PoseHandler.cpp
Thomas Sarkanen 16eee0289d Anim node data/compiler refactor
Per-node constant data is now held on a generated struct as part of sparse class data.
Per-node mutable data (i.e. pin links/property access mappings) is now held on a generated 'mutable data' struct that is compiled as part of the generated class.

The anim BP compiler is now extended more conventionally using UAnimBlueprintExtension, derived from UBlueprintExtension. This directly replaces the older 'compiler handler' pattern that was added in an emergency fashion for 4.26. Anim graph nodes now request their required extensions and these are held on the UAnimBlueprint in the UBlueprint::Extensions array. The Extensions array is potentially refreshed with any node addition or removal. The Extensions array is force-refreshed each time an anim BP is compiled for the first time to deal with newly added or removed requirements.

Const-corrected a bunch of UAnimInstance/FAnimInstanceProxy APIs that rely on (now truly) const data.
Added a split state/constant version of FInputScaleBiasClamp to allow some of its data to be split into constants.
Tweaked alignment/ordering of FPoseLinkBase to save a few bytes per pose link.
Deprecated FAnimNode_Base::OverrideAsset in favor of a more UAnimGraphNode_Base-based approach. Individual nodes can still have runtime overrides via specific accessors. The new approach will also give us the oppurtunity to override multiple assets per node if required in the future.

Moved property access into Engine module & removed event support from it - this was never used.
Reworked property access compilation API a little - construction/lifetime was a bit confusing previously.

Optimized path used to create UK2Node_StructMemberSet nodes in per-node custom events. When using mutable data, the structure used is large and very sparsely connected (i.e. only a few properties are written) so we only create pins that are actually going to be used, rather than creating all of them and conly connecting a few.

Patched the following nodes to use the new data approach:

- Asset players (sequences, blendspaces, aim offsets)
- Blend lists
- Ref poses
- Roots

#rb Jurre.deBaare, Martin.Wilson, Keith.Yerex

[CL 16090510 by Thomas Sarkanen in ue5-main branch]
2021-04-22 04:57:09 -04:00

108 lines
3.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "AnimNodes/AnimNode_PoseHandler.h"
#include "Animation/AnimInstanceProxy.h"
#include "Animation/AnimTrace.h"
/////////////////////////////////////////////////////
// FAnimPoseByNameNode
void FAnimNode_PoseHandler::Initialize_AnyThread(const FAnimationInitializeContext& Context)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(Initialize_AnyThread)
FAnimNode_AssetPlayerBase::Initialize_AnyThread(Context);
UpdatePoseAssetProperty(Context.AnimInstanceProxy);
}
void FAnimNode_PoseHandler::CacheBones_AnyThread(const FAnimationCacheBonesContext& Context)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(CacheBones_AnyThread)
FAnimNode_AssetPlayerBase::CacheBones_AnyThread(Context);
BoneBlendWeights.Reset();
// this has to update bone blending weight
if (CurrentPoseAsset.IsValid())
{
const UPoseAsset* CurrentAsset = CurrentPoseAsset.Get();
const TArray<FName>& TrackNames = CurrentAsset->GetTrackNames();
const FBoneContainer& BoneContainer = Context.AnimInstanceProxy->GetRequiredBones();
const TArray<FBoneIndexType>& RequiredBoneIndices = BoneContainer.GetBoneIndicesArray();
BoneBlendWeights.AddZeroed(RequiredBoneIndices.Num());
for (const auto& TrackName : TrackNames)
{
int32 MeshBoneIndex = BoneContainer.GetPoseBoneIndexForBoneName(TrackName);
FCompactPoseBoneIndex CompactBoneIndex = BoneContainer.MakeCompactPoseIndex(FMeshPoseBoneIndex(MeshBoneIndex));
if (CompactBoneIndex != INDEX_NONE)
{
BoneBlendWeights[CompactBoneIndex.GetInt()] = 1.f;
}
}
RebuildPoseList(BoneContainer, CurrentAsset);
}
else
{
PoseExtractContext.PoseCurves.Reset();
}
}
void FAnimNode_PoseHandler::RebuildPoseList(const FBoneContainer& InBoneContainer, const UPoseAsset* InPoseAsset)
{
PoseExtractContext.PoseCurves.Reset();
const TArray<FSmartName>& PoseNames = InPoseAsset->GetPoseNames();
const int32 TotalPoseNum = PoseNames.Num();
if (TotalPoseNum > 0)
{
TArray<uint16> const& LUTIndex = InBoneContainer.GetUIDToArrayLookupTable();
for (int32 PoseIndex = 0; PoseIndex < PoseNames.Num(); ++PoseIndex)
{
const FSmartName& PoseName = PoseNames[PoseIndex];
if (LUTIndex.IsValidIndex(PoseName.UID) && LUTIndex[PoseName.UID] != MAX_uint16)
{
// we keep pose index as that is the fastest way to search when extracting pose asset
PoseExtractContext.PoseCurves.Add(FPoseCurve(PoseIndex, PoseName.UID, 0.f));
}
}
}
}
void FAnimNode_PoseHandler::UpdateAssetPlayer(const FAnimationUpdateContext& Context)
{
GetEvaluateGraphExposedInputs().Execute(Context);
// update pose asset if it's not valid
if (CurrentPoseAsset.IsValid() == false || CurrentPoseAsset.Get() != PoseAsset)
{
UpdatePoseAssetProperty(Context.AnimInstanceProxy);
}
TRACE_ANIM_NODE_VALUE(Context, TEXT("Name"), CurrentPoseAsset.IsValid() ? *CurrentPoseAsset.Get()->GetName() : TEXT("None"));
TRACE_ANIM_NODE_VALUE(Context, TEXT("Pose Asset"), CurrentPoseAsset.IsValid() ? *CurrentPoseAsset.Get()->GetName() : TEXT("None"));
}
#if WITH_EDITORONLY_DATA
void FAnimNode_PoseHandler::SetPoseAsset(UPoseAsset* InPoseAsset)
{
PoseAsset = InPoseAsset;
}
#endif
void FAnimNode_PoseHandler::GatherDebugData(FNodeDebugData& DebugData)
{
DECLARE_SCOPE_HIERARCHICAL_COUNTER_ANIMNODE(GatherDebugData)
FString DebugLine = DebugData.GetNodeName(this);
DebugLine += FString::Printf(TEXT("('%s')"), *GetNameSafe(PoseAsset));
DebugData.AddDebugItem(DebugLine, true);
}
void FAnimNode_PoseHandler::UpdatePoseAssetProperty(struct FAnimInstanceProxy* InstanceProxy)
{
CurrentPoseAsset = PoseAsset;
CacheBones_AnyThread(FAnimationCacheBonesContext(InstanceProxy));
}