2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "AnimGraphPrivatePCH.h"
2014-04-24 14:34:01 -04:00
# include "AnimGraphNode_SkeletalControlBase.h"
# include "AnimationGraphSchema.h"
2014-03-14 14:13:41 -04:00
/////////////////////////////////////////////////////
// UAnimGraphNode_SkeletalControlBase
2014-04-23 18:30:37 -04:00
# define LOCTEXT_NAMESPACE "A3Nodes"
2014-10-14 10:29:11 -04:00
UAnimGraphNode_SkeletalControlBase : : UAnimGraphNode_SkeletalControlBase ( const FObjectInitializer & ObjectInitializer )
: Super ( ObjectInitializer )
2014-03-14 14:13:41 -04:00
{
}
2014-11-14 10:55:42 -05:00
// returns int32 instead of EWidgetMode because of compiling issue on Mac
int32 UAnimGraphNode_SkeletalControlBase : : GetWidgetMode ( const USkeletalMeshComponent * SkelComp )
{
return ( int32 ) FWidget : : EWidgetMode : : WM_None ;
}
2014-12-01 21:27:36 -05:00
int32 UAnimGraphNode_SkeletalControlBase : : ChangeToNextWidgetMode ( const USkeletalMeshComponent * SkelComp , int32 CurWidgetMode )
2014-11-14 10:55:42 -05:00
{
return GetWidgetMode ( SkelComp ) ;
}
//
FName UAnimGraphNode_SkeletalControlBase : : FindSelectedBone ( )
{
return NAME_None ;
}
2014-03-14 14:13:41 -04:00
FLinearColor UAnimGraphNode_SkeletalControlBase : : GetNodeTitleColor ( ) const
{
return FLinearColor ( 0.75f , 0.75f , 0.10f ) ;
}
FString UAnimGraphNode_SkeletalControlBase : : GetNodeCategory ( ) const
{
return TEXT ( " Skeletal Controls " ) ;
}
2014-04-23 18:30:37 -04:00
FText UAnimGraphNode_SkeletalControlBase : : GetControllerDescription ( ) const
2014-03-14 14:13:41 -04:00
{
2014-04-23 18:30:37 -04:00
return LOCTEXT ( " ImplementMe " , " Implement me " ) ;
2014-03-14 14:13:41 -04:00
}
2014-09-03 18:14:09 -04:00
FText UAnimGraphNode_SkeletalControlBase : : GetTooltipText ( ) const
2014-03-14 14:13:41 -04:00
{
2014-09-03 18:14:09 -04:00
return GetControllerDescription ( ) ;
2014-03-14 14:13:41 -04:00
}
void UAnimGraphNode_SkeletalControlBase : : CreateOutputPins ( )
{
const UAnimationGraphSchema * Schema = GetDefault < UAnimationGraphSchema > ( ) ;
CreatePin ( EGPD_Output , Schema - > PC_Struct , TEXT ( " " ) , FComponentSpacePoseLink : : StaticStruct ( ) , /*bIsArray=*/ false , /*bIsReference=*/ false , TEXT ( " Pose " ) ) ;
}
2014-11-14 05:00:37 -05:00
void UAnimGraphNode_SkeletalControlBase : : ConvertToComponentSpaceTransform ( const USkeletalMeshComponent * SkelComp , const FTransform & InTransform , FTransform & OutCSTransform , int32 BoneIndex , EBoneControlSpace Space ) const
{
USkeleton * Skeleton = SkelComp - > SkeletalMesh - > Skeleton ;
switch ( Space )
{
case BCS_WorldSpace :
{
OutCSTransform = InTransform ;
OutCSTransform . SetToRelativeTransform ( SkelComp - > ComponentToWorld ) ;
}
break ;
case BCS_ComponentSpace :
{
// Component Space, no change.
OutCSTransform = InTransform ;
}
break ;
case BCS_ParentBoneSpace :
if ( BoneIndex ! = INDEX_NONE )
{
const int32 ParentIndex = Skeleton - > GetReferenceSkeleton ( ) . GetParentIndex ( BoneIndex ) ;
if ( ParentIndex ! = INDEX_NONE )
{
const int32 MeshParentIndex = Skeleton - > GetMeshBoneIndexFromSkeletonBoneIndex ( SkelComp - > SkeletalMesh , ParentIndex ) ;
if ( MeshParentIndex ! = INDEX_NONE )
{
const FTransform ParentTM = SkelComp - > GetBoneTransform ( MeshParentIndex ) ;
OutCSTransform = InTransform * ParentTM ;
}
else
{
OutCSTransform = InTransform ;
}
}
}
break ;
case BCS_BoneSpace :
if ( BoneIndex ! = INDEX_NONE )
{
const int32 MeshBoneIndex = Skeleton - > GetMeshBoneIndexFromSkeletonBoneIndex ( SkelComp - > SkeletalMesh , BoneIndex ) ;
if ( MeshBoneIndex ! = INDEX_NONE )
{
const FTransform BoneTM = SkelComp - > GetBoneTransform ( MeshBoneIndex ) ;
OutCSTransform = InTransform * BoneTM ;
}
else
{
OutCSTransform = InTransform ;
}
}
break ;
default :
if ( SkelComp - > SkeletalMesh )
{
UE_LOG ( LogAnimation , Warning , TEXT ( " ConvertToComponentSpaceTransform: Unknown BoneSpace %d for Mesh: %s " ) , ( uint8 ) Space , * SkelComp - > SkeletalMesh - > GetFName ( ) . ToString ( ) ) ;
}
else
{
UE_LOG ( LogAnimation , Warning , TEXT ( " ConvertToComponentSpaceTransform: Unknown BoneSpace %d for Skeleton: %s " ) , ( uint8 ) Space , * Skeleton - > GetFName ( ) . ToString ( ) ) ;
}
break ;
}
}
FVector UAnimGraphNode_SkeletalControlBase : : ConvertCSVectorToBoneSpace ( const USkeletalMeshComponent * SkelComp , FVector & InCSVector , FA2CSPose & MeshBases , const FName & BoneName , const EBoneControlSpace Space )
{
FVector OutVector = InCSVector ;
if ( MeshBases . IsValid ( ) )
{
int32 MeshBoneIndex = SkelComp - > GetBoneIndex ( BoneName ) ;
switch ( Space )
{
// World Space, no change in preview window
case BCS_WorldSpace :
case BCS_ComponentSpace :
// Component Space, no change.
break ;
case BCS_ParentBoneSpace :
{
const int32 ParentIndex = MeshBases . GetParentBoneIndex ( MeshBoneIndex ) ;
if ( ParentIndex ! = INDEX_NONE )
{
FTransform ParentTM = MeshBases . GetComponentSpaceTransform ( ParentIndex ) ;
OutVector = ParentTM . InverseTransformVector ( InCSVector ) ;
}
}
break ;
case BCS_BoneSpace :
{
FTransform BoneTM = MeshBases . GetComponentSpaceTransform ( MeshBoneIndex ) ;
OutVector = BoneTM . InverseTransformVector ( InCSVector ) ;
}
break ;
}
}
return OutVector ;
}
FQuat UAnimGraphNode_SkeletalControlBase : : ConvertCSRotationToBoneSpace ( const USkeletalMeshComponent * SkelComp , FRotator & InCSRotator , FA2CSPose & MeshBases , const FName & BoneName , const EBoneControlSpace Space )
{
FQuat OutQuat = FQuat : : Identity ;
if ( MeshBases . IsValid ( ) )
{
int32 MeshBoneIndex = SkelComp - > GetBoneIndex ( BoneName ) ;
FVector RotAxis ;
float RotAngle ;
InCSRotator . Quaternion ( ) . ToAxisAndAngle ( RotAxis , RotAngle ) ;
switch ( Space )
{
// World Space, no change in preview window
case BCS_WorldSpace :
case BCS_ComponentSpace :
// Component Space, no change.
OutQuat = InCSRotator . Quaternion ( ) ;
break ;
case BCS_ParentBoneSpace :
{
const int32 ParentIndex = MeshBases . GetParentBoneIndex ( MeshBoneIndex ) ;
if ( ParentIndex ! = INDEX_NONE )
{
FTransform ParentTM = MeshBases . GetComponentSpaceTransform ( ParentIndex ) ;
ParentTM = ParentTM . Inverse ( ) ;
//Calculate the new delta rotation
FVector4 BoneSpaceAxis = ParentTM . TransformVector ( RotAxis ) ;
FQuat DeltaQuat ( BoneSpaceAxis , RotAngle ) ;
DeltaQuat . Normalize ( ) ;
OutQuat = DeltaQuat ;
}
}
break ;
case BCS_BoneSpace :
{
FTransform BoneTM = MeshBases . GetComponentSpaceTransform ( MeshBoneIndex ) ;
BoneTM = BoneTM . Inverse ( ) ;
FVector4 BoneSpaceAxis = BoneTM . TransformVector ( RotAxis ) ;
//Calculate the new delta rotation
FQuat DeltaQuat ( BoneSpaceAxis , RotAngle ) ;
DeltaQuat . Normalize ( ) ;
OutQuat = DeltaQuat ;
}
break ;
}
}
return OutQuat ;
}
FVector UAnimGraphNode_SkeletalControlBase : : ConvertWidgetLocation ( const USkeletalMeshComponent * SkelComp , FA2CSPose & MeshBases , const FName & BoneName , const FVector & Location , const EBoneControlSpace Space )
{
FVector WidgetLoc = FVector : : ZeroVector ;
if ( MeshBases . IsValid ( ) )
{
USkeleton * Skeleton = SkelComp - > SkeletalMesh - > Skeleton ;
int32 MeshBoneIndex = SkelComp - > GetBoneIndex ( BoneName ) ;
switch ( Space )
{
// ComponentToWorld must be Identity in preview window so same as ComponentSpace
case BCS_WorldSpace :
case BCS_ComponentSpace :
{
// Component Space, no change.
WidgetLoc = Location ;
}
break ;
case BCS_ParentBoneSpace :
if ( MeshBoneIndex ! = INDEX_NONE )
{
const int32 MeshParentIndex = MeshBases . GetParentBoneIndex ( MeshBoneIndex ) ;
if ( MeshParentIndex ! = INDEX_NONE )
{
const FTransform ParentTM = MeshBases . GetComponentSpaceTransform ( MeshParentIndex ) ;
WidgetLoc = ParentTM . TransformPosition ( Location ) ;
}
}
break ;
case BCS_BoneSpace :
if ( MeshBoneIndex ! = INDEX_NONE )
{
FTransform BoneTM = MeshBases . GetComponentSpaceTransform ( MeshBoneIndex ) ;
WidgetLoc = BoneTM . TransformPosition ( Location ) ;
}
}
}
return WidgetLoc ;
}
2015-02-18 03:59:11 -05:00
void UAnimGraphNode_SkeletalControlBase : : GetDefaultValue ( const FString & UpdateDefaultValueName , FVector & OutVec )
2014-11-14 05:00:37 -05:00
{
for ( UEdGraphPin * Pin : Pins )
{
if ( Pin - > PinName = = UpdateDefaultValueName )
{
if ( GetSchema ( ) - > IsCurrentPinDefaultValid ( Pin ) . IsEmpty ( ) )
{
2015-02-18 03:59:11 -05:00
FString DefaultString = Pin - > GetDefaultAsString ( ) ;
2015-03-06 16:33:54 -05:00
// Existing nodes (from older versions) might have an empty default value string; in that case we just fall through and return the zero vector below (which is the default value in that case).
if ( ! DefaultString . IsEmpty ( ) )
{
TArray < FString > ResultString ;
2015-02-18 03:59:11 -05:00
2015-03-06 16:33:54 -05:00
//Parse string to split its contents separated by ','
DefaultString . Trim ( ) ;
DefaultString . TrimTrailing ( ) ;
DefaultString . ParseIntoArray ( ResultString , TEXT ( " , " ) , true ) ;
2015-02-18 03:59:11 -05:00
2015-03-06 16:33:54 -05:00
check ( ResultString . Num ( ) = = 3 ) ;
OutVec . Set (
FCString : : Atof ( * ResultString [ 0 ] ) ,
FCString : : Atof ( * ResultString [ 1 ] ) ,
FCString : : Atof ( * ResultString [ 2 ] )
) ;
return ;
}
2015-02-18 03:59:11 -05:00
}
}
}
OutVec = FVector : : ZeroVector ;
}
void UAnimGraphNode_SkeletalControlBase : : SetDefaultValue ( const FString & UpdateDefaultValueName , const FVector & Value )
{
for ( UEdGraphPin * Pin : Pins )
{
if ( Pin - > PinName = = UpdateDefaultValueName )
{
if ( GetSchema ( ) - > IsCurrentPinDefaultValid ( Pin ) . IsEmpty ( ) )
{
FString Str = FString : : Printf ( TEXT ( " %.3f,%.3f,%.3f " ) , Value . X , Value . Y , Value . Z ) ;
2014-11-14 05:00:37 -05:00
if ( Pin - > DefaultValue ! = Str )
{
PreEditChange ( NULL ) ;
GetSchema ( ) - > TrySetDefaultValue ( * Pin , Str ) ;
PostEditChange ( ) ;
break ;
}
}
}
}
}
2015-02-18 03:59:11 -05:00
bool UAnimGraphNode_SkeletalControlBase : : IsPinShown ( const FString & PinName ) const
{
for ( const FOptionalPinFromProperty & Pin : ShowPinForProperties )
{
if ( Pin . PropertyName . ToString ( ) = = PinName )
{
return Pin . bShowPin ;
}
}
return false ;
}
2014-04-23 18:30:37 -04:00
# undef LOCTEXT_NAMESPACE