Files
UnrealEngineUWP/Engine/Source/Editor/AnimGraph/Private/AnimGraphNode_PoseByName.cpp
Thomas Sarkanen 5419497f90 BlendSpace 2.0: Blendspace Graph Node
Added a new animation graph node that hosts its own UBlendSpaceBase. Modified UBlendSpaceBase to allow for pose links to be evaluated as the sample points.
The new blend space graphs can be spawned from existing UBlendSpace and UBlendSpace1D assets, or they can be created from scratch, or they can be converted from existing blendspace player nodes via the context menu.

Fixed anim node conversion functions so that their transactions work correctly.

Updated FBlueprintEditorUtils::IsGraphNameUnique to allow it to work with any object as the outer, not just UBlueprint. UBlueprint still has a special case for functions and events. This is to support GenerateUniqueGraphName within a scope (e.g. an outer graph).

Formalized the concept of 'node sub-graphs' (as well as the composite node pattern a little). Previously a number of known node types that contained sub-graphs (e.g. UK2Node_Composite) had special case logic for dealing with node/graph deletion etc. Now  any node can opt into this behaviour via the GetSubGraphs() override.

Added status bar readouts for the blendspace grid, so we dont have to stuff the prompts into the tooltip any more.

Moved anim BP related APIs out of FBlueprintEditor. They are always used via FAnimationBlueprintEditor.

Refactored graph title bar widget creation out into a function to allow other document tab factories to create it.

Altered breadcrumb trail click callbacks and SMyBlueprint::ExecuteAction to always JumpToHyperLink rather than calling OpenDocument directly. This allows unknown (to FBlueprintEditor) document types that reference objects to be correctly jumped to using the breadcrumb trail. Derived asset editors (i.e. FAnimationBlueprintEditor) can intercept the JumpToHyperlink call to ensure that the correct document is presented (i.e. the correct tab payload is generated).

Instead of making yet another bunch of duplicated code for handling the various alpha blend options, refactored this into FAnimGraphNodeAlphaOptions (for editor code) and FAnimNodeAlphaOptions (for runtime code).

Added OnCopyTermDefaultsToDefaultObject for per-node copying of default values from editor node to runtime node, rather than another special-case in the compiler.

#rb Jurre.deBaare,Phillip.Kavan

[CL 15177316 by Thomas Sarkanen in ue5-main branch]
2021-01-25 08:43:19 -04:00

181 lines
5.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "AnimGraphNode_PoseByName.h"
#include "ToolMenus.h"
#include "Kismet2/CompilerResultsLog.h"
#include "AnimGraphCommands.h"
/////////////////////////////////////////////////////
// UAnimGraphNode_PoseByName
#define LOCTEXT_NAMESPACE "A3Nodes"
UAnimGraphNode_PoseByName::UAnimGraphNode_PoseByName(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
void UAnimGraphNode_PoseByName::PreloadRequiredAssets()
{
PreloadObject(Node.PoseAsset);
Super::PreloadRequiredAssets();
}
void UAnimGraphNode_PoseByName::GetAllAnimationSequencesReferred(TArray<UAnimationAsset*>& AnimationAssets) const
{
if(Node.PoseAsset)
{
HandleAnimReferenceCollection(Node.PoseAsset, AnimationAssets);
}
}
void UAnimGraphNode_PoseByName::ReplaceReferredAnimations(const TMap<UAnimationAsset*, UAnimationAsset*>& AnimAssetReplacementMap)
{
HandleAnimReferenceReplacement(Node.PoseAsset, AnimAssetReplacementMap);
}
FText UAnimGraphNode_PoseByName::GetTooltipText() const
{
// FText::Format() is slow, so we utilize the cached list title
return GetNodeTitle(ENodeTitleType::ListView);
}
FText UAnimGraphNode_PoseByName::GetMenuCategory() const
{
return LOCTEXT("PoseAssetCategory_Label", "Poses");
}
FText UAnimGraphNode_PoseByName::GetNodeTitleForPoseAsset(ENodeTitleType::Type TitleType, UPoseAsset* InPoseAsset) const
{
FFormatNamedArguments Args;
Args.Add(TEXT("PoseAssetName"), FText::FromString(InPoseAsset->GetName()));
Args.Add(TEXT("PoseName"), FText::FromString(Node.PoseName.ToString()));
// FText::Format() is slow, so we cache this to save on performance
CachedNodeTitle.SetCachedText(FText::Format(LOCTEXT("PoseByName_Title", "{PoseAssetName} : {PoseName}"), Args), this);
return CachedNodeTitle;
}
FText UAnimGraphNode_PoseByName::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
if (Node.PoseAsset == nullptr)
{
// we may have a valid variable connected or default pin value
UEdGraphPin* PosePin = FindPin(GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_PoseByName, PoseAsset));
if (PosePin && PosePin->LinkedTo.Num() > 0)
{
return LOCTEXT("PoseByName_TitleVariable", "Pose");
}
else if (PosePin && PosePin->DefaultObject != nullptr)
{
return GetNodeTitleForPoseAsset(TitleType, CastChecked<UPoseAsset>(PosePin->DefaultObject));
}
else
{
return LOCTEXT("PoseByName_TitleNONE", "Pose (None)");
}
}
// @TODO: don't know enough about this node type to comfortably assert that
// the CacheName won't change after the node has spawned... until
// then, we'll leave this optimization off
else //if (CachedNodeTitle.IsOutOfDate(this))
{
return GetNodeTitleForPoseAsset(TitleType, Node.PoseAsset);
}
}
// void UAnimGraphNode_PoseByName::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
// {
// // Intentionally empty; you can drop down a regular sequence player and convert into a sequence evaluator in the right-click menu.
// }
void UAnimGraphNode_PoseByName::SetAnimationAsset(UAnimationAsset* Asset)
{
if (UPoseAsset* PoseAsset = Cast<UPoseAsset>(Asset))
{
Node.PoseAsset = PoseAsset;
}
}
void UAnimGraphNode_PoseByName::ValidateAnimNodeDuringCompilation(class USkeleton* ForSkeleton, class FCompilerResultsLog& MessageLog)
{
Super::ValidateAnimNodeDuringCompilation(ForSkeleton, MessageLog);
UPoseAsset* PoseAssetToCheck = Node.PoseAsset;
UEdGraphPin* PoseAssetPin = FindPin(GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_PoseByName, PoseAsset));
if (PoseAssetPin != nullptr && PoseAssetToCheck == nullptr)
{
PoseAssetToCheck = Cast<UPoseAsset>(PoseAssetPin->DefaultObject);
}
if (PoseAssetToCheck == nullptr)
{
// we may have a connected node
if (PoseAssetPin == nullptr || PoseAssetPin->LinkedTo.Num() == 0)
{
MessageLog.Error(TEXT("@@ references an unknown pose asset"), this);
}
}
else
{
USkeleton* SeqSkeleton = PoseAssetToCheck->GetSkeleton();
if (SeqSkeleton&& // if anim sequence doesn't have skeleton, it might be due to anim sequence not loaded yet, @todo: wait with anim blueprint compilation until all assets are loaded?
!SeqSkeleton->IsCompatible(ForSkeleton))
{
MessageLog.Error(TEXT("@@ references sequence that uses different skeleton @@"), this, SeqSkeleton);
}
}
}
bool UAnimGraphNode_PoseByName::DoesSupportTimeForTransitionGetter() const
{
return false;
}
UAnimationAsset* UAnimGraphNode_PoseByName::GetAnimationAsset() const
{
UPoseAsset* PoseAsset = Node.PoseAsset;
UEdGraphPin* PoseAssetPin = FindPin(GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_PoseByName, PoseAsset));
if (PoseAssetPin != nullptr && PoseAsset == nullptr)
{
PoseAsset = Cast<UPoseAsset>(PoseAssetPin->DefaultObject);
}
return PoseAsset;
}
void UAnimGraphNode_PoseByName::GetNodeContextMenuActions(UToolMenu* Menu, UGraphNodeContextMenuContext* Context) const
{
if (!Context->bIsDebugging)
{
// add an option to convert to single frame
{
FToolMenuSection& Section = Menu->AddSection("AnimGraphNodePoseByName", LOCTEXT("PoseByNameHeading", "Pose By Name"));
Section.AddMenuEntry(FAnimGraphCommands::Get().ConvertToPoseBlender);
}
}
}
void UAnimGraphNode_PoseByName::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
{
// Intentionally empty; you can drop down a regular pose blend node and convert into a poseasset by name in the right-click menu.
}
EAnimAssetHandlerType UAnimGraphNode_PoseByName::SupportsAssetClass(const UClass* AssetClass) const
{
if (AssetClass->IsChildOf(UPoseAsset::StaticClass()))
{
return EAnimAssetHandlerType::Supported;
}
else
{
return EAnimAssetHandlerType::NotSupported;
}
}
#undef LOCTEXT_NAMESPACE