2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-07-08 09:43:39 -04:00
|
|
|
|
|
|
|
|
#include "AnimGraphPrivatePCH.h"
|
|
|
|
|
#include "AnimGraphNode_BoneDrivenController.h"
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "A3Nodes"
|
|
|
|
|
|
2014-10-14 10:29:11 -04:00
|
|
|
UAnimGraphNode_BoneDrivenController::UAnimGraphNode_BoneDrivenController(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
:Super(ObjectInitializer)
|
2014-07-08 09:43:39 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 18:14:09 -04:00
|
|
|
FText UAnimGraphNode_BoneDrivenController::GetTooltipText() const
|
2014-07-08 09:43:39 -04:00
|
|
|
{
|
2014-09-03 18:14:09 -04:00
|
|
|
return LOCTEXT("UAnimGraphNode_BoneDrivenController_ToolTip", "Drives the transform of a bone using the transform of another");
|
2014-07-08 09:43:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FText UAnimGraphNode_BoneDrivenController::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
|
|
|
|
{
|
2014-09-16 15:01:38 -04:00
|
|
|
if ((Node.SourceBone.BoneName == NAME_None) && (Node.TargetBone.BoneName == NAME_None) && (TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle))
|
2014-07-08 09:43:39 -04:00
|
|
|
{
|
2014-09-04 11:25:05 -04:00
|
|
|
return GetControllerDescription();
|
|
|
|
|
}
|
2014-09-24 14:15:13 -04:00
|
|
|
// @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
|
2015-04-02 11:16:23 -04:00
|
|
|
else //if (!CachedNodeTitles.IsTitleCached(TitleType, this))
|
2014-09-04 11:25:05 -04:00
|
|
|
{
|
|
|
|
|
FFormatNamedArguments Args;
|
|
|
|
|
Args.Add(TEXT("ControllerDesc"), GetControllerDescription());
|
|
|
|
|
Args.Add(TEXT("SourceBone"), FText::FromName(Node.SourceBone.BoneName));
|
|
|
|
|
Args.Add(TEXT("TargetBone"), FText::FromName(Node.TargetBone.BoneName));
|
2014-08-21 18:50:33 -04:00
|
|
|
|
2014-09-16 15:01:38 -04:00
|
|
|
if (TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle)
|
2014-08-21 18:50:33 -04:00
|
|
|
{
|
2014-09-04 11:25:05 -04:00
|
|
|
Args.Add(TEXT("Delim"), FText::FromString(TEXT(" - ")));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Args.Add(TEXT("Delim"), FText::FromString(TEXT("\n")));
|
2014-08-21 18:50:33 -04:00
|
|
|
}
|
2014-07-08 09:43:39 -04:00
|
|
|
|
2014-09-04 11:25:05 -04:00
|
|
|
// FText::Format() is slow, so we cache this to save on performance
|
2015-04-02 11:16:23 -04:00
|
|
|
CachedNodeTitles.SetCachedTitle(TitleType, FText::Format(LOCTEXT("AnimGraphNode_BoneDrivenController_Title", "{ControllerDesc}{Delim}Driving Bone: {SourceBone}{Delim}Driven Bone: {TargetBone}"), Args), this);
|
2014-09-04 11:25:05 -04:00
|
|
|
}
|
|
|
|
|
return CachedNodeTitles[TitleType];
|
2014-07-08 09:43:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FText UAnimGraphNode_BoneDrivenController::GetControllerDescription() const
|
|
|
|
|
{
|
|
|
|
|
return LOCTEXT("BoneDrivenController", "Bone Driven Controller");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UAnimGraphNode_BoneDrivenController::Draw(FPrimitiveDrawInterface* PDI, USkeletalMeshComponent* SkelMeshComp) const
|
|
|
|
|
{
|
|
|
|
|
static const float ArrowHeadWidth = 5.0f;
|
|
|
|
|
static const float ArrowHeadHeight = 8.0f;
|
|
|
|
|
|
|
|
|
|
int32 SourceIdx = SkelMeshComp->GetBoneIndex(Node.SourceBone.BoneName);
|
|
|
|
|
int32 TargetIdx = SkelMeshComp->GetBoneIndex(Node.TargetBone.BoneName);
|
|
|
|
|
|
|
|
|
|
if(SourceIdx != INDEX_NONE && TargetIdx != INDEX_NONE)
|
|
|
|
|
{
|
2014-11-12 08:43:50 -05:00
|
|
|
FTransform SourceTM = SkelMeshComp->GetSpaceBases()[SourceIdx] * SkelMeshComp->ComponentToWorld;
|
|
|
|
|
FTransform TargetTM = SkelMeshComp->GetSpaceBases()[TargetIdx] * SkelMeshComp->ComponentToWorld;
|
2014-07-08 09:43:39 -04:00
|
|
|
|
|
|
|
|
PDI->DrawLine(TargetTM.GetLocation(), SourceTM.GetLocation(), FLinearColor(0.0f, 0.0f, 1.0f), SDPG_Foreground, 0.5f);
|
|
|
|
|
|
|
|
|
|
FVector ToTarget = TargetTM.GetTranslation() - SourceTM.GetTranslation();
|
|
|
|
|
FVector UnitToTarget = ToTarget;
|
|
|
|
|
UnitToTarget.Normalize();
|
|
|
|
|
FVector Midpoint = SourceTM.GetTranslation() + 0.5f * ToTarget + 0.5f * UnitToTarget * ArrowHeadHeight;
|
|
|
|
|
|
|
|
|
|
FVector YAxis;
|
|
|
|
|
FVector ZAxis;
|
|
|
|
|
UnitToTarget.FindBestAxisVectors(YAxis, ZAxis);
|
|
|
|
|
FMatrix ArrowMatrix(UnitToTarget, YAxis, ZAxis, Midpoint);
|
|
|
|
|
|
|
|
|
|
DrawConnectedArrow(PDI, ArrowMatrix, FLinearColor(0.0f, 1.0f, 0.0), ArrowHeadHeight, ArrowHeadWidth, SDPG_Foreground);
|
|
|
|
|
|
|
|
|
|
PDI->DrawPoint(SourceTM.GetTranslation(), FLinearColor(0.8f, 0.8f, 0.2f), 5.0f, SDPG_Foreground);
|
|
|
|
|
PDI->DrawPoint(SourceTM.GetTranslation() + ToTarget, FLinearColor(0.8f, 0.8f, 0.2f), 5.0f, SDPG_Foreground);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|