// VRM4U Copyright (c) 2021-2024 Haruyoshi Yamamoto. This software is released under the MIT License. #include "AnimGraphNode_VrmModifyBoneDynamic.h" #include "Misc/EngineVersionComparison.h" #include "UnrealWidget.h" #include "AnimNodeEditModes.h" #include "Kismet2/CompilerResultsLog.h" ///////////////////////////////////////////////////// // UAnimGraphNode_ModifyBone #define LOCTEXT_NAMESPACE "A3Nodesaaaa" UAnimGraphNode_VrmModifyBoneDynamic::UAnimGraphNode_VrmModifyBoneDynamic(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_VrmModifyBoneDynamic::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 (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_VrmModifyBoneDynamic::GetControllerDescription() const { return LOCTEXT("VrmTransformModifyBoneDynamic", "VrmTransform (Modify) BoneDynamic"); } FText UAnimGraphNode_VrmModifyBoneDynamic::GetTooltipText() const { return LOCTEXT("AnimGraphNode_ModifyBone_Tooltip", "The Transform Bone node alters the transform - i.e. Translation, Rotation, or Scale - of the bone"); } FText UAnimGraphNode_VrmModifyBoneDynamic::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_VrmModifyBoneDynamic::CopyNodeDataToPreviewNode(FAnimNode_Base* InPreviewNode) { FAnimNode_VrmModifyBoneDynamic* ModifyBone = static_cast(InPreviewNode); // copies Pin values from the internal node to get data which are not compiled yet ModifyBone->Translation = Node.Translation; ModifyBone->Rotation = Node.Rotation; ModifyBone->Scale = Node.Scale; // copies Modes ModifyBone->TranslationMode = Node.TranslationMode; ModifyBone->RotationMode = Node.RotationMode; ModifyBone->ScaleMode = Node.ScaleMode; // copies Spaces ModifyBone->TranslationSpace = Node.TranslationSpace; ModifyBone->RotationSpace = Node.RotationSpace; ModifyBone->ScaleSpace = Node.ScaleSpace; } //FEditorModeID UAnimGraphNode_VrmModifyBoneDynamic::GetEditorMode() const //{ // return AnimNodeEditModes::ModifyBone; //} void UAnimGraphNode_VrmModifyBoneDynamic::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