Skip to content

Commit

Permalink
Fixes left hand not animating correctly when not mirrored
Browse files Browse the repository at this point in the history
  • Loading branch information
mordentral committed Jun 1, 2024
1 parent aa9e169 commit 883efb9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,28 @@ void FAnimNode_ApplyOpenXRHandPose::OnInitializeAnimInstance(const FAnimInstance
{
Super::OnInitializeAnimInstance(InProxy, InAnimInstance);

if (const UOpenXRAnimInstance * animInst = Cast<UOpenXRAnimInstance>(InAnimInstance))
if (const UOpenXRAnimInstance * OpenXRAnimInstance = Cast<UOpenXRAnimInstance>(InAnimInstance))
{
bIsOpenInputAnimationInstance = true;

if (OpenXRAnimInstance->AnimInstanceProxy.HandSkeletalActionData.Num())
{
for (int i = 0; i < OpenXRAnimInstance->AnimInstanceProxy.HandSkeletalActionData.Num(); ++i)
{
EVRSkeletalHandIndex TargetHand = OpenXRAnimInstance->AnimInstanceProxy.HandSkeletalActionData[i].TargetHand;

if (OpenXRAnimInstance->AnimInstanceProxy.HandSkeletalActionData[i].bMirrorLeftRight)
{
TargetHand = (TargetHand == EVRSkeletalHandIndex::EActionHandIndex_Left) ? EVRSkeletalHandIndex::EActionHandIndex_Right : EVRSkeletalHandIndex::EActionHandIndex_Left;
}

if (TargetHand == MappedBonePairs.TargetHand)
{
bIsMirroringHand = OpenXRAnimInstance->AnimInstanceProxy.HandSkeletalActionData[i].bMirrorLeftRight;
break;
}
}
}
}
}

Expand Down Expand Up @@ -168,7 +187,16 @@ void FAnimNode_ApplyOpenXRHandPose::CalculateOpenXRAdjustment()

// Side direction
// Do I need to flip this for left hand?
static FVector OpenXRSideDirection = FVector(0.f, 1.f, 0.f);

bool bUseLeftHandOffsets = false;
if ((!bIsMirroringHand && MappedBonePairs.TargetHand == EVRSkeletalHandIndex::EActionHandIndex_Left) ||
(bIsMirroringHand && MappedBonePairs.TargetHand == EVRSkeletalHandIndex::EActionHandIndex_Right))
{
bUseLeftHandOffsets = true;
}

//static FVector OpenXRSideDirection = FVector(0.f, 1.f, 0.f);
FVector OpenXRSideDirection = bUseLeftHandOffsets ? FVector(0.f, -1.f, 0.f) : FVector(0.f, 1.f, 0.f);

// Align forward vectors, openXR once in engine is X+ forward
FQuat AlignmentRot = FQuat::FindBetweenNormals(WristForwardLS_UE, OpenXRForwardDirection);
Expand Down Expand Up @@ -380,9 +408,6 @@ void FAnimNode_ApplyOpenXRHandPose::EvaluateSkeletalControl_AnyThread(FComponent
return;
}




FTransform trans = FTransform::Identity;
OutBoneTransforms.Reserve(MappedBonePairs.BonePairs.Num());
TArray<FBoneTransform> TransBones;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ struct OPENXREXPANSIONPLUGIN_API FAnimNode_ApplyOpenXRHandPose : public FAnimNod
UPROPERTY(EditAnywhere, Category = Skeletal, meta = (PinHiddenByDefault))
FBPOpenXRSkeletalMappingData MappedBonePairs;

bool bIsOpenInputAnimationInstance;
bool bIsOpenInputAnimationInstance = false;
bool bIsMirroringHand = false;

void ConvertHandTransformsSpace(TArray<FTransform>& OutTransforms, const TArray<FTransform>& WorldTransforms, FTransform AddTrans, bool bMirrorLeftRight, bool bMergeMissingUE4Bones);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct OPENXREXPANSIONPLUGIN_API FBPOpenXRActionSkeletalData
UPROPERTY(EditAnywhere, NotReplicated, BlueprintReadWrite, Category = Default)
bool bAllowDeformingMesh;

// If true then the bones will be mirrored from left/right, to allow you to swap a hand mesh or apply to a full body mesh
// If true then the bones will be mirrored from left/right, to allow you to swap a hand mesh to the other hand
UPROPERTY(EditAnywhere, NotReplicated, BlueprintReadWrite, Category = Default)
bool bMirrorLeftRight;

Expand Down

0 comments on commit 883efb9

Please sign in to comment.