migrate away from the deprecated FXRMotionControllerData in favor of FXRMotionControllerState and FXRHandTrackingState on UE 5.5+
This commit is contained in:
@@ -47,7 +47,6 @@
|
||||
#include "Runtime/Launch/Resources/Version.h"
|
||||
|
||||
#include "SenseGlove/Components/SGVirtualHandComponent.h"
|
||||
#include "SGLog/SGLog.h"
|
||||
|
||||
FSGVirtualHandAnimInstanceProxy::FSGVirtualHandAnimInstanceProxy()
|
||||
: FAnimInstanceProxy{}
|
||||
@@ -108,6 +107,16 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim
|
||||
return;
|
||||
}
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
const bool bGotHandTrackingState = VirtualHand->GetHandTrackingState(
|
||||
EXRSpaceType::UnrealWorldSpace, HandTrackingState);
|
||||
if (!bGotHandTrackingState || !HandTrackingState.bValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ensureAlwaysMsgf(HandTrackingState.HandKeyLocations.Num() == HandTrackingState.HandKeyRotations.Num(),
|
||||
TEXT("Mismatched hand tracking state locations and rotations!"));
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
const bool bGotMotionControllerData = VirtualHand->GetMotionControllerData(MotionControllerData);
|
||||
if (!bGotMotionControllerData || !MotionControllerData.bValid)
|
||||
{
|
||||
@@ -115,10 +124,18 @@ void FSGVirtualHandAnimInstanceProxy::PreEvaluateAnimation(UAnimInstance* InAnim
|
||||
}
|
||||
ensureAlwaysMsgf(MotionControllerData.HandKeyPositions.Num() == MotionControllerData.HandKeyRotations.Num(),
|
||||
TEXT("Mismatched motion controller data positions and rotations!"));
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
|
||||
BoneNamesMap.Empty();
|
||||
for (TArray<FQuat>::SizeType HandKeyIndex = 0;
|
||||
HandKeyIndex < MotionControllerData.HandKeyRotations.Num(); ++HandKeyIndex)
|
||||
HandKeyIndex <
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
HandTrackingState.HandKeyRotations.Num()
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
MotionControllerData.HandKeyRotations.Num()
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
; ++HandKeyIndex)
|
||||
{
|
||||
const FName& BoneName{VirtualHand->GetHandBoneName(HandKeyIndex)};
|
||||
BoneNamesMap.Add(HandKeyIndex, BoneName);
|
||||
@@ -136,10 +153,17 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output)
|
||||
return FAnimInstanceProxy::Evaluate(Output);
|
||||
}
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
if (!HandTrackingState.bValid)
|
||||
{
|
||||
return FAnimInstanceProxy::Evaluate(Output);
|
||||
}
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
if (!MotionControllerData.bValid)
|
||||
{
|
||||
return FAnimInstanceProxy::Evaluate(Output);
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
FComponentSpacePoseContext PoseContext{Output.AnimInstanceProxy};
|
||||
PoseContext.Pose.InitPose(Output.Pose);
|
||||
@@ -164,9 +188,16 @@ bool FSGVirtualHandAnimInstanceProxy::Evaluate(FPoseContext& Output)
|
||||
BoneReference.BoneIndex = BoneIndex;
|
||||
BoneReference.bUseSkeletonIndex = true;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
const FVector& HandKeyLocation{HandTrackingState.HandKeyLocations[HandKeyIndex]};
|
||||
const FQuat& HandKeyRotation{HandTrackingState.HandKeyRotations[HandKeyIndex]};
|
||||
const FTransform HandKeyTransform{HandKeyRotation, HandKeyLocation};
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
const FVector& HandKeyPosition{MotionControllerData.HandKeyPositions[HandKeyIndex]};
|
||||
const FQuat& HandKeyRotation{MotionControllerData.HandKeyRotations[HandKeyIndex]};
|
||||
const FTransform HandKeyTransform{HandKeyRotation, HandKeyPosition};
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
const FTransform BoneTransform{AnimationBoneCorrectionOffsetTransform * HandKeyTransform};
|
||||
FRotator BoneRotation{BoneTransform.GetRotation().Rotator()};
|
||||
|
||||
|
||||
@@ -452,8 +452,10 @@ bool USGVirtualHandComponent::GetMotionControllerData(FXRMotionControllerData& O
|
||||
OutMotionControllerData.bValid = false;
|
||||
|
||||
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
||||
const bool bGotMotionControllerData =
|
||||
FSGXRTracker::GetMotionControllerData(this, Hand, OutMotionControllerData);
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
||||
if (!bGotMotionControllerData || !OutMotionControllerData.bValid)
|
||||
{
|
||||
return false;
|
||||
@@ -462,6 +464,46 @@ bool USGVirtualHandComponent::GetMotionControllerData(FXRMotionControllerData& O
|
||||
return OutMotionControllerData.bValid;
|
||||
}
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
|
||||
bool USGVirtualHandComponent::GetMotionControllerState(
|
||||
const EXRSpaceType XRSpaceType, const EXRControllerPoseType XRControllerPoseType,
|
||||
FXRMotionControllerState& OutMotionControllerState)
|
||||
{
|
||||
OutMotionControllerState.bValid = false;
|
||||
|
||||
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
const bool bGotMotionControllerState =
|
||||
FSGXRTracker::GetMotionControllerState(
|
||||
this, XRSpaceType, Hand, XRControllerPoseType, OutMotionControllerState);
|
||||
if (!bGotMotionControllerState || !OutMotionControllerState.bValid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return OutMotionControllerState.bValid;
|
||||
}
|
||||
|
||||
bool USGVirtualHandComponent::GetHandTrackingState(
|
||||
const EXRSpaceType XRSpaceType,
|
||||
FXRHandTrackingState& OutHandTrackingState)
|
||||
{
|
||||
OutHandTrackingState.bValid = false;
|
||||
|
||||
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
const bool bGotHandTrackingState =
|
||||
FSGXRTracker::GetHandTrackingState(
|
||||
this, XRSpaceType, Hand, OutHandTrackingState);
|
||||
if (!bGotHandTrackingState || !OutHandTrackingState.bValid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return OutHandTrackingState.bValid;
|
||||
}
|
||||
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
const TArray<FName>& USGVirtualHandComponent::GetHandBoneNames() const
|
||||
{
|
||||
const TArray<FName>& Names{
|
||||
@@ -747,12 +789,25 @@ void USGVirtualHandComponent::FImpl::SetVisibility(const bool bInVisible)
|
||||
|
||||
void USGVirtualHandComponent::FImpl::UpdateVisibility()
|
||||
{
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
FXRHandTrackingState HandTrackingState;
|
||||
const bool bGotHandTrackingState =
|
||||
Owner->GetHandTrackingState(EXRSpaceType::UnrealWorldSpace, HandTrackingState);
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
FXRMotionControllerData MotionControllerData;
|
||||
const bool bGotMotionControllerData = Owner->GetMotionControllerData(MotionControllerData);
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
const bool bHandDataAvailable =
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
bGotHandTrackingState
|
||||
&& HandTrackingState.bValid
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
bGotMotionControllerData
|
||||
&& MotionControllerData.bValid
|
||||
&& MotionControllerData.DeviceVisualType == EXRVisualType::Hand;
|
||||
&& MotionControllerData.DeviceVisualType == EXRVisualType::Hand
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
;
|
||||
const bool bHandVisible = Owner->IsVisible();
|
||||
const bool bShouldBeVisibleWhenHandDataUnavailable =
|
||||
Owner->GetVirtualHandSettings().bVisibleWhenHandDataUnavailable;
|
||||
@@ -811,6 +866,16 @@ void USGVirtualHandComponent::FImpl::DrawDebugVirtualHand() const
|
||||
return;
|
||||
}
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
FXRHandTrackingState HandTrackingState;
|
||||
const bool bGotHandTrackingState = Owner->GetHandTrackingState(EXRSpaceType::UnrealWorldSpace, HandTrackingState);
|
||||
if (!bGotHandTrackingState || !HandTrackingState.bValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FSGDebugVirtualHand::Draw(World, HandTrackingState, Owner->GetVirtualHandSettings().DebuggingSettings);
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
FXRMotionControllerData MotionControllerData;
|
||||
const bool bGotMotionControllerData = Owner->GetMotionControllerData(MotionControllerData);
|
||||
if (!bGotMotionControllerData || !MotionControllerData.bValid)
|
||||
@@ -819,6 +884,7 @@ void USGVirtualHandComponent::FImpl::DrawDebugVirtualHand() const
|
||||
}
|
||||
|
||||
FSGDebugVirtualHand::Draw(World, MotionControllerData, Owner->GetVirtualHandSettings().DebuggingSettings);
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::FImpl::TriggerHandVisibilityChangedEvent(const bool bNewVisibility) const
|
||||
|
||||
@@ -246,8 +246,11 @@ bool USGWristTrackerComponent::GetMotionControllerData(FXRMotionControllerData&
|
||||
OutMotionControllerData.bValid = false;
|
||||
|
||||
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
||||
const bool bGotMotionControllerData =
|
||||
FSGXRTracker::GetMotionControllerData(this, Hand, OutMotionControllerData);
|
||||
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
||||
|
||||
if (!bGotMotionControllerData || !OutMotionControllerData.bValid)
|
||||
{
|
||||
return false;
|
||||
@@ -256,6 +259,46 @@ bool USGWristTrackerComponent::GetMotionControllerData(FXRMotionControllerData&
|
||||
return OutMotionControllerData.bValid;
|
||||
}
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
|
||||
bool USGWristTrackerComponent::GetMotionControllerState(
|
||||
const EXRSpaceType XRSpaceType, const EXRControllerPoseType XRControllerPoseType,
|
||||
FXRMotionControllerState& OutMotionControllerState)
|
||||
{
|
||||
OutMotionControllerState.bValid = false;
|
||||
|
||||
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
const bool bGotMotionControllerState =
|
||||
FSGXRTracker::GetMotionControllerState(
|
||||
this, XRSpaceType, Hand, XRControllerPoseType, OutMotionControllerState);
|
||||
if (!bGotMotionControllerState || !OutMotionControllerState.bValid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return OutMotionControllerState.bValid;
|
||||
}
|
||||
|
||||
bool USGWristTrackerComponent::GetHandTrackingState(
|
||||
const EXRSpaceType XRSpaceType,
|
||||
FXRHandTrackingState& OutHandTrackingState)
|
||||
{
|
||||
OutHandTrackingState.bValid = false;
|
||||
|
||||
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
|
||||
const bool bGotHandTrackingState =
|
||||
FSGXRTracker::GetHandTrackingState(
|
||||
this, XRSpaceType, Hand, OutHandTrackingState);
|
||||
if (!bGotHandTrackingState || !OutHandTrackingState.bValid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return OutHandTrackingState.bValid;
|
||||
}
|
||||
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
USGWristTrackerComponent::FImpl::FImpl(USGWristTrackerComponent* InOwner)
|
||||
: bOverridePluginSettingsPropertyAlreadyModified(false),
|
||||
Owner(InOwner)
|
||||
|
||||
@@ -67,7 +67,12 @@ private:
|
||||
bool bVirtualHandVisible;
|
||||
bool bMarkRenderStateDirty;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
FXRHandTrackingState HandTrackingState;
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
FXRMotionControllerData MotionControllerData;
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
TMap<TArray<FQuat>::SizeType, FName> BoneNamesMap;
|
||||
|
||||
FTransform AnimationBoneCorrectionOffsetTransform;
|
||||
@@ -103,10 +108,17 @@ protected:
|
||||
return bMarkRenderStateDirty;
|
||||
}
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
FORCEINLINE const FXRHandTrackingState& GetHandTrackingState() const
|
||||
{
|
||||
return HandTrackingState;
|
||||
}
|
||||
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
FORCEINLINE const FXRMotionControllerData& GetMotionControllerData() const
|
||||
{
|
||||
return MotionControllerData;
|
||||
}
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
FORCEINLINE const TMap<TArray<FQuat>::SizeType, FName>& GetBoneNamesMap() const
|
||||
{
|
||||
|
||||
@@ -175,8 +175,19 @@ protected:
|
||||
public:
|
||||
bool IsGloveConnected() const;
|
||||
USGHapticGlove* GetConnectedGlove() const;
|
||||
|
||||
UE_DEPRECATED(5.5, "Deprecated by UE 5.5 in favor of GetMotionControllerState and GetHandTrackingState")
|
||||
bool GetMotionControllerData(FXRMotionControllerData& OutMotionControllerData);
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
bool GetMotionControllerState(
|
||||
EXRSpaceType XRSpaceType, EXRControllerPoseType XRControllerPoseType,
|
||||
FXRMotionControllerState& OutMotionControllerState);
|
||||
bool GetHandTrackingState(
|
||||
EXRSpaceType XRSpaceType,
|
||||
FXRHandTrackingState& OutHandTrackingState);
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
|
||||
public:
|
||||
const TArray<FName>& GetHandBoneNames() const;
|
||||
const FName& GetHandBoneName(int32 Joint) const;
|
||||
|
||||
@@ -164,5 +164,15 @@ protected:
|
||||
FActorComponentTickFunction* ThisTickFunction);
|
||||
|
||||
public:
|
||||
UE_DEPRECATED(5.5, "Deprecated by UE 5.5 in favor of GetMotionControllerState and GetHandTrackingState")
|
||||
bool GetMotionControllerData(FXRMotionControllerData& OutMotionControllerData);
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
|
||||
bool GetMotionControllerState(
|
||||
EXRSpaceType XRSpaceType, EXRControllerPoseType XRControllerPoseType,
|
||||
FXRMotionControllerState& OutMotionControllerState);
|
||||
bool GetHandTrackingState(
|
||||
EXRSpaceType XRSpaceType,
|
||||
FXRHandTrackingState& OutHandTrackingState);
|
||||
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
|
||||
};
|
||||
Reference in New Issue
Block a user