even more optimal fxrmotioncontroller data calculations that considers mesh when outputting senseglove data

This commit is contained in:
Mamadou Babaei
2024-08-16 18:02:05 +02:00
parent 714307e92c
commit 4881c88dc3
3 changed files with 157 additions and 250 deletions
@@ -46,8 +46,7 @@ FSGVirtualHandTrackingSettings::FSGVirtualHandTrackingSettings()
2.4f, 2.4f,
2.4f, 2.4f,
2.4f, 2.4f,
FRotator{0.0f, -90.0f, 0.0f}, FRotator{0.0f, -90.0f, 0.0f})
FRotator{0.0f, 180.0f, 90.0f})
{ {
} }
@@ -59,8 +58,7 @@ FSGVirtualHandTrackingSettings::FSGVirtualHandTrackingSettings(
const float InMiddleDistalPhalanxLength, const float InMiddleDistalPhalanxLength,
const float InRingDistalPhalanxLength, const float InRingDistalPhalanxLength,
const float InLittleDistalPhalanxLength, const float InLittleDistalPhalanxLength,
const FRotator& InHandMeshToOpenXRRootBoneRotationCorrection, const FRotator& InRootBoneRotationCorrection)
const FRotator& InHandMeshToSenseGloveRootBoneRotationCorrection)
: LeftHandReferenceMesh(InLeftHandReferenceMesh), : LeftHandReferenceMesh(InLeftHandReferenceMesh),
RightHandReferenceMesh(InRightHandReferenceMesh), RightHandReferenceMesh(InRightHandReferenceMesh),
ThumbDistalPhalanxLength(InThumbDistalPhalanxLength), ThumbDistalPhalanxLength(InThumbDistalPhalanxLength),
@@ -68,8 +66,7 @@ FSGVirtualHandTrackingSettings::FSGVirtualHandTrackingSettings(
MiddleDistalPhalanxLength(InMiddleDistalPhalanxLength), MiddleDistalPhalanxLength(InMiddleDistalPhalanxLength),
RingDistalPhalanxLength(InRingDistalPhalanxLength), RingDistalPhalanxLength(InRingDistalPhalanxLength),
LittleDistalPhalanxLength(InLittleDistalPhalanxLength), LittleDistalPhalanxLength(InLittleDistalPhalanxLength),
HandMeshToOpenXRRootBoneRotationCorrection(InHandMeshToOpenXRRootBoneRotationCorrection), RootBoneRotationCorrection(InRootBoneRotationCorrection),
HandMeshToSenseGloveRootBoneRotationCorrection(InHandMeshToSenseGloveRootBoneRotationCorrection),
LeftHandDefaultReferenceBoneTransforms{ LeftHandDefaultReferenceBoneTransforms{
TPair<FName, FTransform>{ TPair<FName, FTransform>{
FName{TEXT("hand_l")}, FName{TEXT("hand_l")},
@@ -73,10 +73,7 @@ public:
float LittleDistalPhalanxLength; float LittleDistalPhalanxLength;
UPROPERTY(Config, EditDefaultsOnly, Category="Virtual Hand") UPROPERTY(Config, EditDefaultsOnly, Category="Virtual Hand")
FRotator HandMeshToOpenXRRootBoneRotationCorrection; FRotator RootBoneRotationCorrection;
UPROPERTY(Config, EditDefaultsOnly, Category="Virtual Hand")
FRotator HandMeshToSenseGloveRootBoneRotationCorrection;
UPROPERTY(Config, VisibleDefaultsOnly, Category="Virtual Hand") UPROPERTY(Config, VisibleDefaultsOnly, Category="Virtual Hand")
TMap<FName, FTransform> LeftHandDefaultReferenceBoneTransforms; TMap<FName, FTransform> LeftHandDefaultReferenceBoneTransforms;
@@ -101,7 +98,5 @@ public:
float InMiddleDistalPhalanxLength, float InMiddleDistalPhalanxLength,
float InRingDistalPhalanxLength, float InRingDistalPhalanxLength,
float InLittleDistalPhalanxLength, float InLittleDistalPhalanxLength,
const FRotator& InHandMeshToOpenXRRootBoneRotationCorrection, const FRotator& InRootBoneRotationCorrection);
const FRotator& InHandMeshToSenseGloveRootBoneRotationCorrection);
}; };
@@ -210,6 +210,7 @@ struct FSGXRTracker::FImpl
float DistalPhalanxLength); float DistalPhalanxLength);
static TArray<TArray<float>> GetFingerLengths(bool bRight); static TArray<TArray<float>> GetFingerLengths(bool bRight);
static TArray<FTransform> GetFingerStartTransforms(bool bRight);
static TArray<FVector> GetFingerStartPositions(bool bRight); static TArray<FVector> GetFingerStartPositions(bool bRight);
static TArray<FQuat> GetFingerStartRotations(bool bRight); static TArray<FQuat> GetFingerStartRotations(bool bRight);
static USGBasicHandModel* GetHandModel(bool bRight); static USGBasicHandModel* GetHandModel(bool bRight);
@@ -280,126 +281,128 @@ struct FSGXRTracker::FImpl
return Name; return Name;
} }
static const FTransform& GetRawMeshBoneRefTransform(bool bRight, const FName& BoneName); static const FTransform& GetMeshRawBoneRefTransform(bool bRight, const FName& BoneName);
FORCEINLINE static const FTransform& GetRawMeshBoneRefTransform(const bool bRight, const int32 JointIndex) FORCEINLINE static const FTransform& GetMeshRawBoneRefTransform(const bool bRight, const int32 JointIndex)
{ {
const FName& BoneName{GetMeshBoneName(bRight, JointIndex)}; const FName& BoneName{GetMeshBoneName(bRight, JointIndex)};
const FTransform& Transform{GetRawMeshBoneRefTransform(bRight, BoneName)}; const FTransform& Transform{GetMeshRawBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
FORCEINLINE static const FTransform& GetRawMeshBoneRefTransform(const bool bRight, const EHandKeypoint Keypoint) FORCEINLINE static const FTransform& GetMeshRawBoneRefTransform(const bool bRight, const EHandKeypoint Keypoint)
{ {
const FName& BoneName{GetMeshBoneName(bRight, Keypoint)}; const FName& BoneName{GetMeshBoneName(bRight, Keypoint)};
const FTransform& Transform{GetRawMeshBoneRefTransform(bRight, BoneName)}; const FTransform& Transform{GetMeshRawBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
FORCEINLINE static const FTransform& GetRawMeshBoneRefTransform(const EControllerHand Hand, const FName& BoneName) FORCEINLINE static const FTransform& GetMeshRawBoneRefTransform(const EControllerHand Hand, const FName& BoneName)
{ {
const bool bRight = Hand == EControllerHand::Right; const bool bRight = Hand == EControllerHand::Right;
const FTransform& Transform{GetRawMeshBoneRefTransform(bRight, BoneName)}; const FTransform& Transform{GetMeshRawBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
FORCEINLINE static const FTransform& GetRawMeshBoneRefTransform(const EControllerHand Hand, const int32 JointIndex) FORCEINLINE static const FTransform& GetMeshRawBoneRefTransform(const EControllerHand Hand, const int32 JointIndex)
{ {
const bool bRight = Hand == EControllerHand::Right; const bool bRight = Hand == EControllerHand::Right;
const FName& BoneName{GetMeshBoneName(bRight, JointIndex)}; const FName& BoneName{GetMeshBoneName(bRight, JointIndex)};
const FTransform& Transform{GetRawMeshBoneRefTransform(bRight, BoneName)}; const FTransform& Transform{GetMeshRawBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
FORCEINLINE static const FTransform& GetRawMeshBoneRefTransform( FORCEINLINE static const FTransform& GetMeshRawBoneRefTransform(
const EControllerHand Hand, const EHandKeypoint Keypoint) const EControllerHand Hand, const EHandKeypoint Keypoint)
{ {
const bool bRight = Hand == EControllerHand::Right; const bool bRight = Hand == EControllerHand::Right;
const FName& BoneName{GetMeshBoneName(bRight, Keypoint)}; const FName& BoneName{GetMeshBoneName(bRight, Keypoint)};
const FTransform& Transform{GetRawMeshBoneRefTransform(bRight, BoneName)}; const FTransform& Transform{GetMeshRawBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
static FTransform GetOpenXRMeshBoneRefTransform(bool bRight, const FName& BoneName); static FTransform GetMeshWristChildBoneRefTransform(bool bRight, const FName& BoneName);
FORCEINLINE static FTransform GetOpenXRMeshBoneRefTransform(const bool bRight, const int32 JointIndex) FORCEINLINE static FTransform GetMeshWristChildBoneRefTransform(
{
const FName& BoneName{GetMeshBoneName(bRight, JointIndex)};
const FTransform Transform{GetOpenXRMeshBoneRefTransform(bRight, BoneName)};
return Transform;
}
FORCEINLINE static FTransform GetOpenXRMeshBoneRefTransform(
const bool bRight, const EHandKeypoint Keypoint)
{
const FName& BoneName{GetMeshBoneName(bRight, Keypoint)};
const FTransform Transform{GetOpenXRMeshBoneRefTransform(bRight, BoneName)};
return Transform;
}
FORCEINLINE static FTransform GetOpenXRMeshBoneRefTransform(
const EControllerHand Hand, const FName& BoneName)
{
const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetOpenXRMeshBoneRefTransform(bRight, BoneName)};
return Transform;
}
FORCEINLINE static FTransform GetOpenXRMeshBoneRefTransform(
const EControllerHand Hand, const int32 JointIndex)
{
const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetOpenXRMeshBoneRefTransform(bRight, JointIndex)};
return Transform;
}
FORCEINLINE static FTransform GetOpenXRMeshBoneRefTransform(
const EControllerHand Hand, const EHandKeypoint Keypoint)
{
const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetOpenXRMeshBoneRefTransform(bRight, Keypoint)};
return Transform;
}
static FTransform GetSGMeshMetacarpalBoneRefTransform(bool bRight, const FName& BoneName);
FORCEINLINE static FTransform GetSGMeshMetacarpalBoneRefTransform(
const bool bRight, const int32 JointIndex) const bool bRight, const int32 JointIndex)
{ {
const FName& BoneName{GetMeshBoneName(bRight, JointIndex)}; const FName& BoneName{GetMeshBoneName(bRight, JointIndex)};
const FTransform Transform{GetSGMeshMetacarpalBoneRefTransform(bRight, BoneName)}; const FTransform Transform{GetMeshWristChildBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
FORCEINLINE static FTransform GetSGMeshMetacarpalBoneRefTransform( FORCEINLINE static FTransform GetMeshWristChildBoneRefTransform(
const bool bRight, const EHandKeypoint Keypoint) const bool bRight, const EHandKeypoint Keypoint)
{ {
const FName& BoneName{GetMeshBoneName(bRight, Keypoint)}; const FName& BoneName{GetMeshBoneName(bRight, Keypoint)};
const FTransform Transform{GetSGMeshMetacarpalBoneRefTransform(bRight, BoneName)}; const FTransform Transform{GetMeshWristChildBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
FORCEINLINE static FTransform GetSGMeshMetacarpalBoneRefTransform( FORCEINLINE static FTransform GetMeshWristChildBoneRefTransform(
const EControllerHand Hand, const FName& BoneName) const EControllerHand Hand, const FName& BoneName)
{ {
const bool bRight = Hand == EControllerHand::Right; const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetSGMeshMetacarpalBoneRefTransform(bRight, BoneName)}; const FTransform Transform{GetMeshWristChildBoneRefTransform(bRight, BoneName)};
return Transform; return Transform;
} }
FORCEINLINE static FTransform GetSGMeshMetacarpalBoneRefTransform( FORCEINLINE static FTransform GetMeshWristChildBoneRefTransform(
const EControllerHand Hand, const int32 JointIndex) const EControllerHand Hand, const int32 JointIndex)
{ {
const bool bRight = Hand == EControllerHand::Right; const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetSGMeshMetacarpalBoneRefTransform(bRight, JointIndex)}; const FTransform Transform{GetMeshWristChildBoneRefTransform(bRight, JointIndex)};
return Transform; return Transform;
} }
FORCEINLINE static FTransform GetSGMeshMetacarpalBoneRefTransform( FORCEINLINE static FTransform GetMeshWristChildBoneRefTransform(
const EControllerHand Hand, const EHandKeypoint Keypoint) const EControllerHand Hand, const EHandKeypoint Keypoint)
{ {
const bool bRight = Hand == EControllerHand::Right; const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetSGMeshMetacarpalBoneRefTransform(bRight, Keypoint)}; const FTransform Transform{GetMeshWristChildBoneRefTransform(bRight, Keypoint)};
return Transform;
}
static FTransform GetMeshFingerStartBoneRefTransform(
bool bRight, EHandKeypoint Parent, const FName& BoneName);
FORCEINLINE static FTransform GetMeshFingerStartBoneRefTransform(
const bool bRight, const EHandKeypoint Parent, const int32 JointIndex)
{
const FName& BoneName{GetMeshBoneName(bRight, JointIndex)};
const FTransform Transform{GetMeshFingerStartBoneRefTransform(bRight, Parent, BoneName)};
return Transform;
}
FORCEINLINE static FTransform GetMeshFingerStartBoneRefTransform(
const bool bRight, const EHandKeypoint Parent, const EHandKeypoint Keypoint)
{
const FName& BoneName{GetMeshBoneName(bRight, Keypoint)};
const FTransform Transform{GetMeshFingerStartBoneRefTransform(bRight, Parent, BoneName)};
return Transform;
}
FORCEINLINE static FTransform GetMeshFingerStartBoneRefTransform(
const EControllerHand Hand, const EHandKeypoint Parent, const FName& BoneName)
{
const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetMeshFingerStartBoneRefTransform(bRight, Parent, BoneName)};
return Transform;
}
FORCEINLINE static FTransform GetMeshFingerStartBoneRefTransform(
const EControllerHand Hand, const EHandKeypoint Parent, const int32 JointIndex)
{
const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetMeshFingerStartBoneRefTransform(bRight, Parent, JointIndex)};
return Transform;
}
FORCEINLINE static FTransform GetMeshFingerStartBoneRefTransform(
const EControllerHand Hand, const EHandKeypoint Parent, const EHandKeypoint Keypoint)
{
const bool bRight = Hand == EControllerHand::Right;
const FTransform Transform{GetMeshFingerStartBoneRefTransform(bRight, Parent, Keypoint)};
return Transform; return Transform;
} }
@@ -637,9 +640,9 @@ TArray<float> FSGXRTracker::FImpl::GetFingerLengths(
const EHandKeypoint Joint2nd, const EHandKeypoint Joint3rd, const EHandKeypoint Joint2nd, const EHandKeypoint Joint3rd,
const float DistalPhalanxLength) const float DistalPhalanxLength)
{ {
const FTransform& Joint2ndTransform{GetOpenXRMeshBoneRefTransform(bRight, Joint2nd)}; const FTransform& Joint2ndTransform{GetMeshRawBoneRefTransform(bRight, Joint2nd)};
const FVector& Joint2ndLocation{Joint2ndTransform.GetLocation()}; const FVector& Joint2ndLocation{Joint2ndTransform.GetLocation()};
const FTransform& Joint3rdTransform{GetOpenXRMeshBoneRefTransform(bRight, Joint3rd)}; const FTransform& Joint3rdTransform{GetMeshRawBoneRefTransform(bRight, Joint3rd)};
const FVector& Joint3rdLocation{Joint3rdTransform.GetLocation()}; const FVector& Joint3rdLocation{Joint3rdTransform.GetLocation()};
const float PhalanxLength1st = static_cast<float>(Joint2ndLocation.Size()); const float PhalanxLength1st = static_cast<float>(Joint2ndLocation.Size());
@@ -684,74 +687,51 @@ TArray<TArray<float>> FSGXRTracker::FImpl::GetFingerLengths(const bool bRight)
return Lengths; return Lengths;
} }
TArray<FTransform> FSGXRTracker::FImpl::GetFingerStartTransforms(const bool bRight)
{
FTransform ThumbStartTransform{
GetMeshWristChildBoneRefTransform(bRight, EHandKeypoint::ThumbMetacarpal).GetLocation()
};
FTransform IndexStartTransform{
GetMeshFingerStartBoneRefTransform(bRight, EHandKeypoint::IndexMetacarpal, EHandKeypoint::IndexProximal)
};
FTransform MiddleStartTransform{
GetMeshFingerStartBoneRefTransform(bRight, EHandKeypoint::MiddleMetacarpal, EHandKeypoint::MiddleProximal)
};
FTransform RingStartTransform{
GetMeshFingerStartBoneRefTransform(bRight, EHandKeypoint::RingMetacarpal, EHandKeypoint::RingProximal)
};
FTransform LittleStartTransform{
GetMeshFingerStartBoneRefTransform(bRight, EHandKeypoint::LittleMetacarpal, EHandKeypoint::LittleProximal)
};
TArray<FTransform> Transforms{
MoveTemp(ThumbStartTransform),
MoveTemp(IndexStartTransform),
MoveTemp(MiddleStartTransform),
MoveTemp(RingStartTransform),
MoveTemp(LittleStartTransform),
};
return Transforms;
}
TArray<FVector> FSGXRTracker::FImpl::GetFingerStartPositions(const bool bRight) TArray<FVector> FSGXRTracker::FImpl::GetFingerStartPositions(const bool bRight)
{ {
const FVector WristPosition{GetRawMeshBoneRefTransform(bRight, EHandKeypoint::Wrist).GetLocation()}; const TArray<FTransform> StartTransforms{GetFingerStartTransforms(bRight)};
const FQuat RootRotationCorrection{
GetVirtualHandTrackingSettings().HandMeshToOpenXRRootBoneRotationCorrection.Quaternion()
};
FTransform RootBoneRefTransform{GetRawMeshBoneRefTransform(bRight, EHandKeypoint::Wrist)};
RootBoneRefTransform.SetRotation(RootRotationCorrection * RootBoneRefTransform.GetRotation());
FVector ThumbStartPosition{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::ThumbMetacarpal).GetLocation()
};
FTransform IndexMetacarpalTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::IndexMetacarpal)
};
FTransform IndexStartTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::IndexProximal)
};
FVector IndexStartPositionUncorrected = IndexMetacarpalTransform.GetLocation() + (IndexMetacarpalTransform.
GetRotation() * IndexStartTransform.GetLocation());
FVector IndexStartPosition = RootBoneRefTransform.GetRotation() * IndexStartPositionUncorrected;
FTransform MiddleMetacarpalTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::MiddleMetacarpal)
};
FTransform MiddleStartTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::MiddleProximal)
};
FVector MiddleStartPositionUncorrected = MiddleMetacarpalTransform.GetLocation() + (MiddleMetacarpalTransform.
GetRotation() * MiddleStartTransform.GetLocation());
FVector MiddleStartPosition = RootBoneRefTransform.GetRotation() * MiddleStartPositionUncorrected;
FTransform RingMetacarpalTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::RingMetacarpal)
};
FTransform RingStartTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::RingProximal)
};
FVector RingStartPositionUncorrected = RingMetacarpalTransform.GetLocation() + (RingMetacarpalTransform.
GetRotation() * RingStartTransform.GetLocation());
FVector RingStartPosition = RootBoneRefTransform.GetRotation() * RingStartPositionUncorrected;
FTransform LittleMetacarpalTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::LittleMetacarpal)
};
FTransform LittleStartTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::LittleProximal)
};
FVector LittleStartPositionUncorrected = LittleMetacarpalTransform.GetLocation() + (LittleMetacarpalTransform.
GetRotation() * LittleStartTransform.GetLocation());
FVector LittleStartPosition = RootBoneRefTransform.GetRotation() * LittleStartPositionUncorrected;
ensureAlwaysMsgf(StartTransforms.Num() == 5, TEXT("Invalid number of finger start transforms!"));
const TArray<FVector> StartPositions{ const TArray<FVector> StartPositions{
ThumbStartPosition, StartTransforms[0].GetLocation(),
IndexStartPosition, StartTransforms[1].GetLocation(),
MiddleStartPosition, StartTransforms[2].GetLocation(),
RingStartPosition, StartTransforms[3].GetLocation(),
LittleStartPosition, StartTransforms[4].GetLocation(),
}; };
return StartPositions; return StartPositions;
@@ -759,78 +739,16 @@ TArray<FVector> FSGXRTracker::FImpl::GetFingerStartPositions(const bool bRight)
TArray<FQuat> FSGXRTracker::FImpl::GetFingerStartRotations(const bool bRight) TArray<FQuat> FSGXRTracker::FImpl::GetFingerStartRotations(const bool bRight)
{ {
// const FQuat ThumbStartRotation{ const TArray<FTransform> StartTransforms{GetFingerStartTransforms(bRight)};
// GetSGMeshMetacarpalBoneRefTransform(bRight, EHandKeypoint::ThumbMetacarpal).GetRotation()
// };
//
// const FQuat IndexMetacarpalRotation{
// GetSGMeshMetacarpalBoneRefTransform(bRight, EHandKeypoint::IndexMetacarpal).GetRotation()
// };
// const FQuat IndexStartRotation{
// GetRawMeshBoneRefTransform(bRight, EHandKeypoint::IndexProximal).GetRotation() * IndexMetacarpalRotation
// };
//
// const FQuat MiddleMetacarpalRotation{
// GetSGMeshMetacarpalBoneRefTransform(bRight, EHandKeypoint::MiddleMetacarpal).GetRotation()
// };
// const FQuat MiddleStartRotation{
// GetRawMeshBoneRefTransform(bRight, EHandKeypoint::MiddleProximal).GetRotation() * MiddleMetacarpalRotation
// };
//
// const FQuat RingMetacarpalRotation{
// GetSGMeshMetacarpalBoneRefTransform(bRight, EHandKeypoint::RingMetacarpal).GetRotation()
// };
// const FQuat RingStartRotation{
// GetRawMeshBoneRefTransform(bRight, EHandKeypoint::RingProximal).GetRotation() * RingMetacarpalRotation
// };
//
// const FQuat LittleMetacarpalRotation{
// GetSGMeshMetacarpalBoneRefTransform(bRight, EHandKeypoint::LittleMetacarpal).GetRotation()
// };
// const FQuat LittleStartRotation{
// GetRawMeshBoneRefTransform(bRight, EHandKeypoint::LittleProximal).GetRotation() * LittleMetacarpalRotation
// };
const FQuat ThumbStartRotation{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::ThumbMetacarpal).GetRotation()
};
const FQuat RootRotationCorrection{
GetVirtualHandTrackingSettings().HandMeshToSenseGloveRootBoneRotationCorrection.Quaternion()
};
FTransform RootBoneRefTransform{GetRawMeshBoneRefTransform(bRight, EHandKeypoint::Wrist)};
RootBoneRefTransform.SetRotation(RootRotationCorrection * RootBoneRefTransform.GetRotation());
const FTransform IndexMetacarpalTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::IndexMetacarpal)
};
const FTransform IndexProximalTransform{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::IndexProximal)
};
const FQuat IndexStartRotation{IndexProximalTransform.GetRotation() * RootBoneRefTransform.GetRotation()};
const FQuat MiddleStartRotation{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::MiddleProximal).GetRotation()
};
const FQuat RingStartRotation{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::RingProximal).GetRotation()
};
const FQuat LittleStartRotation{
GetRawMeshBoneRefTransform(bRight, EHandKeypoint::LittleProximal).GetRotation()
};
ensureAlwaysMsgf(StartTransforms.Num() == 5, TEXT("Invalid number of finger start transforms!"));
const TArray<FQuat> StartRotations{ const TArray<FQuat> StartRotations{
// ThumbStartRotation, // StartTransforms[0].GetRotation(),
// IndexStartRotation, // StartTransforms[1].GetRotation(),
// MiddleStartRotation, // StartTransforms[2].GetRotation(),
// RingStartRotation, // StartTransforms[3].GetRotation(),
// LittleStartRotation, // StartTransforms[4].GetRotation(),
FQuat::Identity, FQuat::Identity,
FQuat::Identity, FQuat::Identity,
FQuat::Identity, FQuat::Identity,
@@ -877,7 +795,7 @@ USGHandPose* FSGXRTracker::FImpl::GetHandPose(const bool bRight)
return HandPose; return HandPose;
} }
const FTransform& FSGXRTracker::FImpl::GetRawMeshBoneRefTransform(const bool bRight, const FName& BoneName) const FTransform& FSGXRTracker::FImpl::GetMeshRawBoneRefTransform(const bool bRight, const FName& BoneName)
{ {
const TSoftObjectPtr<USkeletalMesh>& HandMesh{ const TSoftObjectPtr<USkeletalMesh>& HandMesh{
bRight bRight
@@ -919,30 +837,37 @@ const FTransform& FSGXRTracker::FImpl::GetRawMeshBoneRefTransform(const bool bRi
return Transform; return Transform;
} }
FTransform FSGXRTracker::FImpl::GetOpenXRMeshBoneRefTransform( FTransform FSGXRTracker::FImpl::GetMeshWristChildBoneRefTransform(const bool bRight, const FName& BoneName)
const bool bRight, const FName& BoneName)
{ {
const FQuat RootRotationCorrection{ FQuat RootRotationCorrection{
GetVirtualHandTrackingSettings().HandMeshToOpenXRRootBoneRotationCorrection.Quaternion() GetVirtualHandTrackingSettings().RootBoneRotationCorrection
}; };
const FTransform& RootBoneRefTransform{GetMeshRawBoneRefTransform(bRight, EHandKeypoint::Wrist)};
const FTransform& RawTransform{GetMeshRawBoneRefTransform(bRight, BoneName)};
FQuat CorrectedRootBoneRefRotation{MoveTemp(RootRotationCorrection) * RootBoneRefTransform.GetRotation()};
FVector CorrectedLocation{MoveTemp(CorrectedRootBoneRefRotation) * RawTransform.GetLocation()};
FTransform RootBoneRefTransform{GetRawMeshBoneRefTransform(bRight, EHandKeypoint::Wrist)}; const FTransform Transform{RawTransform.GetRotation(), MoveTemp(CorrectedLocation)};
RootBoneRefTransform.SetRotation(RootRotationCorrection * RootBoneRefTransform.GetRotation());
const FTransform Transform{GetRawMeshBoneRefTransform(bRight, BoneName) * RootBoneRefTransform};
return Transform; return Transform;
} }
FTransform FSGXRTracker::FImpl::GetSGMeshMetacarpalBoneRefTransform(const bool bRight, const FName& BoneName) FTransform FSGXRTracker::FImpl::GetMeshFingerStartBoneRefTransform(
const bool bRight, const EHandKeypoint Parent, const FName& BoneName)
{ {
const FQuat RootRotationCorrection{ FQuat RootRotationCorrection{
GetVirtualHandTrackingSettings().HandMeshToSenseGloveRootBoneRotationCorrection.Quaternion() GetVirtualHandTrackingSettings().RootBoneRotationCorrection
};
const FTransform& RootBoneRefTransform{GetMeshRawBoneRefTransform(bRight, EHandKeypoint::Wrist)};
FQuat CorrectedRootBoneRefRotation{MoveTemp(RootRotationCorrection) * RootBoneRefTransform.GetRotation()};
FTransform CorrectedRootBoneRefTransform {
MoveTemp(CorrectedRootBoneRefRotation), RootBoneRefTransform.GetLocation()
}; };
FTransform RootBoneRefTransform{GetRawMeshBoneRefTransform(bRight, EHandKeypoint::Wrist)}; FTransform ParentBoneRefTransform{
RootBoneRefTransform.SetRotation(RootRotationCorrection * RootBoneRefTransform.GetRotation()); GetMeshRawBoneRefTransform(bRight, Parent) * MoveTemp(CorrectedRootBoneRefTransform)
const FTransform Transform{RootBoneRefTransform * GetRawMeshBoneRefTransform(bRight, BoneName)}; };
const FTransform Transform{GetMeshRawBoneRefTransform(bRight, BoneName) * MoveTemp(ParentBoneRefTransform)};
return Transform; return Transform;
} }
@@ -1852,11 +1777,9 @@ bool FSGXRTracker::FImpl::UpdateSGPalmJointData(
return false; return false;
} }
const FTransform JointTransform{GetOpenXRMeshBoneRefTransform(DeviceHand, EHandKeypoint::Palm)}; const FTransform JointTransform{GetMeshWristChildBoneRefTransform(DeviceHand, EHandKeypoint::Palm)};
// FVector JointLocation{JointTransform.GetLocation()}; FVector JointLocation{JointTransform.GetLocation()};
// FQuat JointRotation{JointTransform.GetRotation()}; FQuat JointRotation{JointTransform.GetRotation()};
FVector JointLocation{4.967f, 0.090f, -0.132f};
FQuat JointRotation{0.000000000f, 0.000000000f, 0.000000000f, 0.999999829f};
if (!UpdateSGJointData(OutHandState, EHandKeypoint::Palm, if (!UpdateSGJointData(OutHandState, EHandKeypoint::Palm,
MoveTemp(JointLocation), MoveTemp(JointRotation), WristLocation, WristRotation, MoveTemp(JointLocation), MoveTemp(JointRotation), WristLocation, WristRotation,
@@ -1945,12 +1868,10 @@ bool FSGXRTracker::FImpl::UpdateSGIndexJointData(
static constexpr int32 IndexTipJointIndex = 3; static constexpr int32 IndexTipJointIndex = 3;
const FTransform& IndexMetacarpalTransform{ const FTransform& IndexMetacarpalTransform{
GetOpenXRMeshBoneRefTransform(DeviceHand, EHandKeypoint::IndexMetacarpal) GetMeshWristChildBoneRefTransform(DeviceHand, EHandKeypoint::IndexMetacarpal)
}; };
// FVector IndexMetacarpalLocation{IndexMetacarpalTransform.GetLocation()}; FVector IndexMetacarpalLocation{IndexMetacarpalTransform.GetLocation()};
// FQuat IndexMetacarpalRotation{IndexMetacarpalTransform.GetRotation()}; FQuat IndexMetacarpalRotation{IndexMetacarpalTransform.GetRotation()};
FVector IndexMetacarpalLocation{3.759f, 2.089f, -0.932f};
FQuat IndexMetacarpalRotation{0.000000000f, 0.000000000f, 0.000000000f, 0.999999829f};
const FVector& IndexProximalLocation{JointLocations[IndexFingerIndex][IndexProximalJointIndex]}; const FVector& IndexProximalLocation{JointLocations[IndexFingerIndex][IndexProximalJointIndex]};
const FVector& IndexIntermediateLocation{JointLocations[IndexFingerIndex][IndexIntermediateJointIndex]}; const FVector& IndexIntermediateLocation{JointLocations[IndexFingerIndex][IndexIntermediateJointIndex]};
@@ -2026,12 +1947,10 @@ bool FSGXRTracker::FImpl::UpdateSGMiddleJointData(
static constexpr int32 MiddleTipJointMiddle = 3; static constexpr int32 MiddleTipJointMiddle = 3;
const FTransform& MiddleMetacarpalTransform{ const FTransform& MiddleMetacarpalTransform{
GetOpenXRMeshBoneRefTransform(DeviceHand, EHandKeypoint::MiddleMetacarpal) GetMeshWristChildBoneRefTransform(DeviceHand, EHandKeypoint::MiddleMetacarpal)
}; };
// FVector MiddleMetacarpalLocation{MiddleMetacarpalTransform.GetLocation()}; FVector MiddleMetacarpalLocation{MiddleMetacarpalTransform.GetLocation()};
// FQuat MiddleMetacarpalRotation{MiddleMetacarpalTransform.GetRotation()}; FQuat MiddleMetacarpalRotation{MiddleMetacarpalTransform.GetRotation()};
FVector MiddleMetacarpalLocation{3.534f, 0.405f, -0.767f};
FQuat MiddleMetacarpalRotation{0.000000000f, 0.000000000f, 0.000000000f, 0.999999829f};
const FVector& MiddleProximalLocation{JointLocations[MiddleFingerMiddle][MiddleProximalJointMiddle]}; const FVector& MiddleProximalLocation{JointLocations[MiddleFingerMiddle][MiddleProximalJointMiddle]};
const FVector& MiddleIntermediateLocation{JointLocations[MiddleFingerMiddle][MiddleIntermediateJointMiddle]}; const FVector& MiddleIntermediateLocation{JointLocations[MiddleFingerMiddle][MiddleIntermediateJointMiddle]};
@@ -2107,12 +2026,10 @@ bool FSGXRTracker::FImpl::UpdateSGRingJointData(
static constexpr int32 RingTipJointRing = 3; static constexpr int32 RingTipJointRing = 3;
const FTransform& RingMetacarpalTransform{ const FTransform& RingMetacarpalTransform{
GetOpenXRMeshBoneRefTransform(DeviceHand, EHandKeypoint::RingMetacarpal) GetMeshWristChildBoneRefTransform(DeviceHand, EHandKeypoint::RingMetacarpal)
}; };
// FVector RingMetacarpalLocation{RingMetacarpalTransform.GetLocation()}; FVector RingMetacarpalLocation{RingMetacarpalTransform.GetLocation()};
// FQuat RingMetacarpalRotation{RingMetacarpalTransform.GetRotation()}; FQuat RingMetacarpalRotation{RingMetacarpalTransform.GetRotation()};
FVector RingMetacarpalLocation{3.612f, -1.557f, -0.625f};
FQuat RingMetacarpalRotation{0.000000000f, 0.000000000f, 0.000000000f, 0.999999829f};
const FVector& RingProximalLocation{JointLocations[RingFingerRing][RingProximalJointRing]}; const FVector& RingProximalLocation{JointLocations[RingFingerRing][RingProximalJointRing]};
const FVector& RingIntermediateLocation{JointLocations[RingFingerRing][RingIntermediateJointRing]}; const FVector& RingIntermediateLocation{JointLocations[RingFingerRing][RingIntermediateJointRing]};
@@ -2188,12 +2105,10 @@ bool FSGXRTracker::FImpl::UpdateSGLittleJointData(
static constexpr int32 LittleTipJointLittle = 3; static constexpr int32 LittleTipJointLittle = 3;
const FTransform& LittleMetacarpalTransform{ const FTransform& LittleMetacarpalTransform{
GetOpenXRMeshBoneRefTransform(DeviceHand, EHandKeypoint::LittleMetacarpal) GetMeshWristChildBoneRefTransform(DeviceHand, EHandKeypoint::LittleMetacarpal)
}; };
// FVector LittleMetacarpalLocation{LittleMetacarpalTransform.GetLocation()}; FVector LittleMetacarpalLocation{LittleMetacarpalTransform.GetLocation()};
// FQuat LittleMetacarpalRotation{LittleMetacarpalTransform.GetRotation()}; FQuat LittleMetacarpalRotation{LittleMetacarpalTransform.GetRotation()};
FVector LittleMetacarpalLocation{3.539f, -2.389f, -0.978f};
FQuat LittleMetacarpalRotation{0.207036002f, 0.018311810f, -0.140342834f, 0.968041580f};
const FVector& LittleProximalLocation{JointLocations[LittleFingerLittle][LittleProximalJointLittle]}; const FVector& LittleProximalLocation{JointLocations[LittleFingerLittle][LittleProximalJointLittle]};
const FVector& LittleIntermediateLocation{JointLocations[LittleFingerLittle][LittleIntermediateJointLittle]}; const FVector& LittleIntermediateLocation{JointLocations[LittleFingerLittle][LittleIntermediateJointLittle]};