8#include "AnimationRuntime.h"
9#include "DrawDebugHelpers.h"
11#include "Runtime/Engine/Public/Animation/AnimInstanceProxy.h"
12#include "BoneControllers/AnimNode_SkeletalControlBase.h"
28 Super::OnInitializeAnimInstance(InProxy, InAnimInstance);
38 Super::Initialize_AnyThread(Context);
43 Super::CacheBones_AnyThread(Context);
48 UObject* OwningAsset = RequiredBones.GetAsset();
57 USkeleton* AssetSkeleton = RequiredBones.GetSkeletonAsset();
68 TArray<FTransform> RefBones = AssetSkeleton->GetReferenceSkeleton().GetRefBonePose();
69 TArray<FMeshBoneInfo> RefBonesInfo = AssetSkeleton->GetReferenceSkeleton().GetRefBoneInfo();
77 BonePair.ReferenceToConstruct.Initialize(AssetSkeleton);
79 BonePair.ReferenceToConstruct.CachedCompactPoseIndex = BonePair.ReferenceToConstruct.GetCompactPoseIndex(RequiredBones);
81 if ((BonePair.ReferenceToConstruct.CachedCompactPoseIndex != INDEX_NONE))
84 BonePair.ParentReference = RequiredBones.GetParentBoneIndex(BonePair.ReferenceToConstruct.CachedCompactPoseIndex);
101 WristPair = BonePair;
105 IndexPair = BonePair;
109 PinkyPair = BonePair;
123 FVector BoneForwardVector = MiddleFingerPose.GetTranslation() - WristPose.GetTranslation();
125 BoneForwardVector.Normalize();
129 FVector BoneUpVector = IndexFingerPose.GetTranslation() - PinkyFingerPose.GetTranslation();
131 BoneUpVector.Normalize();
133 FVector BoneRightVector = FVector::CrossProduct(BoneUpVector, BoneForwardVector);
134 BoneRightVector.Normalize();
136 FQuat ForwardAdjustment = FQuat::FindBetweenNormals(FVector::ForwardVector, BoneForwardVector);
138 FVector NewRightVector = ForwardAdjustment * FVector::RightVector;
139 NewRightVector.Normalize();
141 FQuat TwistAdjustment = FQuat::FindBetweenNormals(NewRightVector, BoneRightVector);
153 if (WorldTransforms.Num() < EHandKeypointCount)
156 if (OutTransforms.Num() < WorldTransforms.Num())
158 OutTransforms.Empty(WorldTransforms.Num());
159 OutTransforms.AddUninitialized(WorldTransforms.Num());
163 int32 BoneParents[26] =
201 for (int32 Index = 0; Index < EHandKeypointCount; ++Index)
203 WorldTransforms[Index].NormalizeRotation();
205 if (bMirrorLeftRight)
207 WorldTransforms[Index].Mirror(EAxis::Y, EAxis::Y);
210 WorldTransforms[Index].ConcatenateRotation(AddTrans.GetRotation());
213 for (int32 Index = 0; Index < EHandKeypointCount; ++Index)
215 FTransform& BoneTransform = WorldTransforms[Index];
216 int32 ParentIndex = BoneParents[Index];
217 int32 ParentParent = -1;
220 if (bMergeMissingUE4Bones)
224 ParentParent = BoneParents[ParentIndex];
231 OutTransforms[Index] = BoneTransform;
236 if (bMergeMissingUE4Bones && ParentParent == 1)
238 OutTransforms[Index] = BoneTransform.GetRelativeTransform(WorldTransforms[ParentParent]);
242 OutTransforms[Index] = BoneTransform.GetRelativeTransform(WorldTransforms[ParentIndex]);
286 const float BlendWeight = FMath::Clamp<float>(ActualAlpha, 0.f, 1.f);
287 const FBoneContainer& BoneContainer = Output.Pose.GetPose().GetBoneContainer();
288 uint8 BoneTransIndex = 0;
289 uint8 NumBones = StoredActionInfoPtr ? StoredActionInfoPtr->
SkeletalTransforms.Num() : 0;
297 FTransform trans = FTransform::Identity;
299 TArray<FBoneTransform> TransBones;
302 FTransform TempTrans = FTransform::Identity;
303 FTransform ParentTrans = FTransform::Identity;
304 FTransform * ParentTransPtr =
nullptr;
308 TArray<FTransform> HandTransforms;
313 BoneTransIndex = (int8)BonePair.OpenXRBone;
314 ParentTrans = FTransform::Identity;
316 if (BoneTransIndex >= NumBones || BonePair.ReferenceToConstruct.CachedCompactPoseIndex == INDEX_NONE)
319 if (!BonePair.ReferenceToConstruct.IsValidToEvaluate(BoneContainer))
324 trans = Output.Pose.GetComponentSpaceTransform(BonePair.ReferenceToConstruct.CachedCompactPoseIndex);
326 if (BonePair.ParentReference != INDEX_NONE)
328 ParentTrans = Output.Pose.GetComponentSpaceTransform(BonePair.ParentReference);
329 ParentTrans.SetScale3D(FVector(1.f));
333 TempTrans = (HandTransforms[BoneTransIndex]);
343 TempTrans = TempTrans * ParentTrans;
346 trans.SetTranslation(TempTrans.GetTranslation());
348 trans.SetRotation(TempTrans.GetRotation());
350 TransBones.Add(FBoneTransform(BonePair.ReferenceToConstruct.CachedCompactPoseIndex, trans));
354 if (TransBones.Num())
356 Output.Pose.LocalBlendCSBoneTransforms(TransBones, BlendWeight);
EVRSkeletalHandIndex
UENUM(BlueprintType)
EXRHandJointType
UENUM(BlueprintType)
@ OXR_HAND_JOINT_INDEX_PROXIMAL_EXT
@ OXR_HAND_JOINT_WRIST_EXT
@ OXR_HAND_JOINT_LITTLE_PROXIMAL_EXT
@ OXR_HAND_JOINT_THUMB_PROXIMAL_EXT
@ OXR_SkeletonType_UE4Default_Right
UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
FTransform GetRefBoneInCS(TArray< FTransform > &RefBones, TArray< FMeshBoneInfo > &RefBonesInfo, int32 BoneIndex)
FAnimNode_ApplyOpenXRHandPose()
bool bSkipRootBone
UPROPERTY(EditAnywhere, Category = Skeletal, meta = (PinShownByDefault))
bool bOnlyApplyWristTransform
UPROPERTY(EditAnywhere, Category = Skeletal, meta = (PinShownByDefault))
EVROpenXRSkeletonType SkeletonType
UPROPERTY(EditAnywhere, Category = Skeletal, meta = (PinShownByDefault))
virtual void InitializeBoneReferences(const FBoneContainer &RequiredBones) override
void SetVectorToMaxElement(FVector &vec)
virtual bool IsValidToEvaluate(const USkeleton *Skeleton, const FBoneContainer &RequiredBones) override
virtual void CacheBones_AnyThread(const FAnimationCacheBonesContext &Context) override
virtual void EvaluateSkeletalControl_AnyThread(FComponentSpacePoseContext &Output, TArray< FBoneTransform > &OutBoneTransforms) override
void ConvertHandTransformsSpace(TArray< FTransform > &OutTransforms, TArray< FTransform > &WorldTransforms, FTransform AddTrans, bool bMirrorLeftRight, bool bMergeMissingUE4Bones)
FBPOpenXRSkeletalMappingData MappedBonePairs
UPROPERTY(EditAnywhere, Category = Skeletal, meta = (PinHiddenByDefault))
FBPOpenXRActionSkeletalData OptionalStoredActionInfo
UPROPERTY(EditAnywhere, Category = Skeletal, meta = (PinShownByDefault))
virtual void OnInitializeAnimInstance(const FAnimInstanceProxy *InProxy, const UAnimInstance *InAnimInstance) override
virtual void Initialize_AnyThread(const FAnimationInitializeContext &Context) override
bool bIsOpenInputAnimationInstance
USTRUCT(BlueprintType, Category = "VRExpansionFunctions|OpenXR|HandSkeleton")
TArray< FTransform > SkeletalTransforms
UPROPERTY(BlueprintReadOnly, NotReplicated, Transient, Category = Default)
bool bMirrorLeftRight
UPROPERTY(EditAnywhere, NotReplicated, BlueprintReadWrite, Category = Default)
bool bAllowDeformingMesh
UPROPERTY(EditAnywhere, NotReplicated, BlueprintReadWrite, Category = Default)
FTransform AdditionTransform
UPROPERTY(EditAnywhere, NotReplicated, BlueprintReadWrite, Category = Default)
void ConstructDefaultMappings(EVROpenXRSkeletonType SkeletonType, bool bSkipRootBone)
bool bMergeMissingBonesUE4
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Default")
TArray< FBPOpenXRSkeletalPair > BonePairs
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Default")
FName LastInitializedName
EVRSkeletalHandIndex TargetHand
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Default")
USTRUCT(BlueprintType, Category = "VRExpansionFunctions|SteamVR|HandSkeleton")
FBoneReference ReferenceToConstruct
TArray< FBPOpenXRActionSkeletalData > HandSkeletalActionData