251 lines
8.9 KiB
C++
251 lines
8.9 KiB
C++
// VRM4U Copyright (c) 2021-2024 Haruyoshi Yamamoto. This software is released under the MIT License.
|
|
|
|
#include "AnimGraphNode_VrmSpringBone.h"
|
|
#include "Misc/EngineVersionComparison.h"
|
|
#include "UnrealWidget.h"
|
|
#include "AnimNodeEditModes.h"
|
|
#include "AnimationRuntime.h"
|
|
#include "Animation/AnimInstance.h"
|
|
#include "Kismet2/CompilerResultsLog.h"
|
|
#include "Components/SkeletalMeshComponent.h"
|
|
#include "VrmMetaObject.h"
|
|
#include "VrmUtil.h"
|
|
|
|
/////////////////////////////////////////////////////
|
|
// UAnimGraphNode_ModifyBone
|
|
|
|
#define LOCTEXT_NAMESPACE "A3Nodesaaaa"
|
|
////////////////////
|
|
|
|
const FEditorModeID FVrmSpringBoneEditMode::VrmSpringBone("AnimGraph.SkeletalControl.VrmSpringBone");
|
|
|
|
/*
|
|
void FVrmSpringBoneEditMode::EnterMode(class UAnimGraphNode_Base* InEditorNode, struct FAnimNode_Base* InRuntimeNode)
|
|
{
|
|
RuntimeNode = static_cast<FAnimNode_VrmSpringBone*>(InRuntimeNode);
|
|
GraphNode = CastChecked<UAnimGraphNode_VrmSpringBone>(InEditorNode);
|
|
|
|
FAnimNodeEditMode::EnterMode(InEditorNode, InRuntimeNode);
|
|
}
|
|
|
|
void FVrmSpringBoneEditMode::ExitMode()
|
|
{
|
|
RuntimeNode = nullptr;
|
|
GraphNode = nullptr;
|
|
|
|
FAnimNodeEditMode::ExitMode();
|
|
}
|
|
|
|
FVector FVrmSpringBoneEditMode::GetWidgetLocation() const
|
|
{
|
|
//USkeletalMeshComponent* SkelComp = GetAnimPreviewScene().GetPreviewMeshComponent();
|
|
|
|
//FBoneSocketTarget& Target = RuntimeNode->EffectorTarget;
|
|
//FVector Location = RuntimeNode->EffectorTransform.GetLocation();
|
|
//EBoneControlSpace Space = RuntimeNode->EffectorTransformSpace;
|
|
FVector WidgetLoc;// = ConvertWidgetLocation(SkelComp, RuntimeNode->ForwardedPose, Target, Location, Space);
|
|
return WidgetLoc;
|
|
}
|
|
|
|
FWidget::EWidgetMode FVrmSpringBoneEditMode::GetWidgetMode() const
|
|
{
|
|
// allow translation all the time for effectot target
|
|
return FWidget::WM_Translate;
|
|
}
|
|
|
|
void FVrmSpringBoneEditMode::DoTranslation(FVector& InTranslation)
|
|
{
|
|
//USkeletalMeshComponent* SkelComp = GetAnimPreviewScene().GetPreviewMeshComponent();
|
|
//FVector Offset = ConvertCSVectorToBoneSpace(SkelComp, InTranslation, RuntimeNode->ForwardedPose, RuntimeNode->EffectorTarget, RuntimeNode->EffectorTransformSpace);
|
|
|
|
//RuntimeNode->EffectorTransform.AddToTranslation(Offset);
|
|
//GraphNode->Node.EffectorTransform.SetTranslation(RuntimeNode->EffectorTransform.GetTranslation());
|
|
}
|
|
*/
|
|
|
|
////////////////////
|
|
|
|
|
|
UAnimGraphNode_VrmSpringBone::UAnimGraphNode_VrmSpringBone(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
#if UE_VERSION_OLDER_THAN(5,0,0)
|
|
CurWidgetMode = (int32)FWidget::WM_Rotate;
|
|
#else
|
|
CurWidgetMode = UE::Widget::EWidgetMode::WM_Rotate;
|
|
#endif
|
|
}
|
|
|
|
void UAnimGraphNode_VrmSpringBone::ValidateAnimNodePostCompile(FCompilerResultsLog& MessageLog, UAnimBlueprintGeneratedClass* CompiledClass, int32 CompiledNodeIndex) {
|
|
|
|
if (Node.VrmMetaObject_Internal == nullptr) {
|
|
//MessageLog.Warning(*LOCTEXT("VrmNoMetaObject", "@@ - You must set VrmMetaObject").ToString(), this);
|
|
} else {
|
|
auto *targetSkeleton = CompiledClass->GetTargetSkeleton();
|
|
if (targetSkeleton) {
|
|
if (Node.VrmMetaObject_Internal->SkeletalMesh) {
|
|
if (VRMGetSkeleton(Node.VrmMetaObject_Internal->SkeletalMesh) != targetSkeleton) {
|
|
MessageLog.Warning(*LOCTEXT("VrmDifferentSkeleton", "@@ - You must set VrmMetaObject has same skeleton").ToString(), this);
|
|
}
|
|
}
|
|
if (targetSkeleton->GetReferenceSkeleton().GetRawBoneNum() <= 0) {
|
|
MessageLog.Warning(*LOCTEXT("VrmNoBone", "@@ - Skeleton bad data").ToString(), this);
|
|
}
|
|
}
|
|
else {
|
|
//MessageLog.Warning(*LOCTEXT("VrmNoBone", "@@ - no target skeleton").ToString(), this);
|
|
}
|
|
}
|
|
|
|
Super::ValidateAnimNodePostCompile(MessageLog, CompiledClass, CompiledNodeIndex);
|
|
}
|
|
|
|
void UAnimGraphNode_VrmSpringBone::ValidateAnimNodeDuringCompilation(USkeleton* ForSkeleton, FCompilerResultsLog& MessageLog)
|
|
{
|
|
// Temporary fix where skeleton is not fully loaded during AnimBP compilation and thus virtual bone name check is invalid UE-39499 (NEED FIX)
|
|
if (ForSkeleton && !ForSkeleton->HasAnyFlags(RF_NeedPostLoad))
|
|
{
|
|
if (Node.VrmMetaObject_Internal == nullptr) {
|
|
//MessageLog.Warning(*LOCTEXT("VrmNoMetaObject", "@@ - You must set VrmMetaObject").ToString(), this);
|
|
} else {
|
|
if (Node.VrmMetaObject_Internal->SkeletalMesh){
|
|
if (VRMGetSkeleton(Node.VrmMetaObject_Internal->SkeletalMesh) != ForSkeleton) {
|
|
// MessageLog.Warning(*LOCTEXT("VrmDifferentSkeleton", "@@ - You must set VrmMetaObject has same skeleton").ToString(), this);
|
|
}
|
|
}
|
|
if (ForSkeleton->GetReferenceSkeleton().GetRawBoneNum() <= 0) {
|
|
// MessageLog.Warning(*LOCTEXT("VrmNoBone", "@@ - Skeleton bad data").ToString(), this);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
//if (ForSkeleton->GetReferenceSkeleton().FindBoneIndex(Node.BoneToModify.BoneName) == INDEX_NONE)
|
|
if (ForSkeleton->GetReferenceSkeleton().FindBoneIndex(Node.BoneNameToModify) == INDEX_NONE)
|
|
{
|
|
//if (Node.BoneToModify.BoneName == NAME_None)
|
|
if (Node.BoneNameToModify == NAME_None)
|
|
{
|
|
MessageLog.Warning(*LOCTEXT("NoBoneSelectedToModify", "@@ - You must pick a bone to modify").ToString(), this);
|
|
}
|
|
else
|
|
{
|
|
FFormatNamedArguments Args;
|
|
//Args.Add(TEXT("BoneName"), FText::FromName(Node.BoneToModify.BoneName));
|
|
Args.Add(TEXT("BoneName"), FText::FromName(Node.BoneNameToModify));
|
|
|
|
FText Msg = FText::Format(LOCTEXT("NoBoneFoundToModify", "@@ - Bone {BoneName} not found in Skeleton"), Args);
|
|
|
|
MessageLog.Warning(*Msg.ToString(), this);
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
|
|
//if ((Node.TranslationMode == BMM_Ignore) && (Node.RotationMode == BMM_Ignore) && (Node.ScaleMode == BMM_Ignore))
|
|
{
|
|
// MessageLog.Warning(*LOCTEXT("NothingToModify", "@@ - No components to modify selected. Either Rotation, Translation, or Scale should be set to something other than Ignore").ToString(), this);
|
|
}
|
|
|
|
Super::ValidateAnimNodeDuringCompilation(ForSkeleton, MessageLog);
|
|
}
|
|
|
|
FText UAnimGraphNode_VrmSpringBone::GetControllerDescription() const
|
|
{
|
|
if (Node.EnableAutoSearchMetaData) {
|
|
return LOCTEXT("VrmSpringBone", "VrmSpringBone(auto)");
|
|
}else {
|
|
return LOCTEXT("VrmSpringBone", "VrmSpringBone");
|
|
}
|
|
}
|
|
|
|
FText UAnimGraphNode_VrmSpringBone::GetTooltipText() const
|
|
{
|
|
return LOCTEXT("AnimGraphNode_VrmSpringBone_Tooltip", "VrmCopyHandBone");
|
|
}
|
|
|
|
FText UAnimGraphNode_VrmSpringBone::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
|
{
|
|
//if ((TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle) && (Node.BoneToModify.BoneName == NAME_None))
|
|
//if ((TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle) && (Node.BoneNameToModify == NAME_None))
|
|
//{
|
|
return GetControllerDescription();
|
|
//}
|
|
// @TODO: the bone can be altered in the property editor, so we have to
|
|
// choose to mark this dirty when that happens for this to properly work
|
|
/*
|
|
else //if (!CachedNodeTitles.IsTitleCached(TitleType, this))
|
|
{
|
|
FFormatNamedArguments Args;
|
|
Args.Add(TEXT("ControllerDescription"), GetControllerDescription());
|
|
//Args.Add(TEXT("BoneName"), FText::FromName(Node.BoneToModify.BoneName));
|
|
Args.Add(TEXT("BoneName"), FText::FromName(Node.BoneNameToModify));
|
|
|
|
// FText::Format() is slow, so we cache this to save on performance
|
|
if (TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle)
|
|
{
|
|
CachedNodeTitles.SetCachedTitle(TitleType, FText::Format(LOCTEXT("AnimGraphNode_ModifyBone_ListTitle", "{ControllerDescription} - Bone: {BoneName}"), Args), this);
|
|
}
|
|
else
|
|
{
|
|
CachedNodeTitles.SetCachedTitle(TitleType, FText::Format(LOCTEXT("AnimGraphNode_ModifyBone_Title", "{ControllerDescription}\nBone: {BoneName}"), Args), this);
|
|
}
|
|
}
|
|
return CachedNodeTitles[TitleType];
|
|
*/
|
|
}
|
|
|
|
void UAnimGraphNode_VrmSpringBone::CopyNodeDataToPreviewNode(FAnimNode_Base* InPreviewNode)
|
|
{
|
|
FAnimNode_VrmSpringBone* node = static_cast<FAnimNode_VrmSpringBone*>(InPreviewNode);
|
|
|
|
// no copy
|
|
}
|
|
|
|
FEditorModeID UAnimGraphNode_VrmSpringBone::GetEditorMode() const
|
|
{
|
|
return Super::GetEditorMode();
|
|
//return FVrmSpringBoneEditMode::VrmSpringBone;
|
|
}
|
|
|
|
void UAnimGraphNode_VrmSpringBone::Draw(FPrimitiveDrawInterface* PDI, USkeletalMeshComponent * PreviewSkelMeshComp) const
|
|
{
|
|
if (PreviewSkelMeshComp)
|
|
{
|
|
/*
|
|
if (FAnimNode_VrmSpringBone* ActiveNode = GetActiveInstanceNode<FAnimNode_VrmSpringBone>(PreviewSkelMeshComp->GetAnimInstance()))
|
|
{
|
|
if (bPreviewLive) {
|
|
ActiveNode->ConditionalDebugDraw(PDI, PreviewSkelMeshComp, bPreviewForeground);
|
|
}
|
|
}
|
|
*/
|
|
if (bPreviewLive) {
|
|
Node.ConditionalDebugDraw(PDI, PreviewSkelMeshComp, bPreviewForeground);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void UAnimGraphNode_VrmSpringBone::CopyPinDefaultsToNodeData(UEdGraphPin* InPin)
|
|
{
|
|
/*
|
|
if (InPin->GetName() == GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_ModifyBone, Translation))
|
|
{
|
|
GetDefaultValue(GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_ModifyBone, Translation), Node.Translation);
|
|
}
|
|
else if (InPin->GetName() == GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_ModifyBone, Rotation))
|
|
{
|
|
GetDefaultValue(GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_ModifyBone, Rotation), Node.Rotation);
|
|
}
|
|
else if (InPin->GetName() == GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_ModifyBone, Scale))
|
|
{
|
|
GetDefaultValue(GET_MEMBER_NAME_STRING_CHECKED(FAnimNode_ModifyBone, Scale), Node.Scale);
|
|
}
|
|
*/
|
|
}
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|