implement bHandTrackingVisualizationAllowed

This commit is contained in:
Mamadou Babaei
2024-08-16 18:00:53 +02:00
parent c132a967f3
commit 9cb77cafa5
12 changed files with 144 additions and 53 deletions
+5 -2
View File
@@ -21,11 +21,14 @@ This is a minor release focusing mainly on bringing OpenXR-compatible hand track
- Added FSGVirtualHandAnimInstanceProxy::GetMotionControllerData usable only by child classes.
- USGVirtualHandComponent introduced new uproperties AnimationBoneRotationCorrectionOffset and bAnimationShouldApplyBoneLocation with their equivalent getters and setters.
- Added USGVirtualHandComponent::GetMotionControllerData().
- Added the SenseGloveDebugKismet module in order to allow drawing of debug gizmos and virtual hands from Blueprint.
- Added a new static Draw() method overload to DebugGizmo which allows passing a FQuat instead of a FRotator.
- Added USGWristTrackerComponent::GetMotionControllerData().
- Added USGWristTrackerComponent::OnWristDeviceVisualTypeChanged event in order to be able to notify other components/actors whenever the wrist-tracking device switches between hand tracking or motion controllers.
- Added the SenseGloveDebugKismet module in order to allow drawing of debugging gizmos and virtual hands from Blueprint.
- Added a new static Draw() method overload to DebugGizmo which allows passing an FQuat instead of a FRotator.
### Changed
- The SGSettings has been fully revamped with more customizations added and categorized in a different manner.
- The SGSettings constructor visibility has been changed from public to private.
- The SenseGlove libraries have been updated to v2.103.0-4a8bd81d.
- GetHandPose() has been replaced by GetMotionControllerData inside USGVirtualHandComponent (see the relevant entry in the Added and Removed sections).
@@ -387,7 +387,7 @@ bool USGVirtualHandComponent::GetMotionControllerData(FXRMotionControllerData& O
if (GEngine)
{
IXRTrackingSystem* XrtTrackingSystem = GEngine->XRSystem.Get();
IXRTrackingSystem* XrtTrackingSystem{GEngine->XRSystem.Get()};
if (XrtTrackingSystem)
{
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
@@ -38,6 +38,7 @@
#include "Animation/Skeleton.h"
#include "Components/SkeletalMeshComponent.h"
#include "Engine/SkeletalMesh.h"
#include "IXRTrackingSystem.h"
#include "UObject/ConstructorHelpers.h"
#include "SGDebug/SGDebugGizmo.h"
@@ -104,6 +105,7 @@ USGWristTrackerComponent::USGWristTrackerComponent(const FObjectInitializer& Obj
bRight = true;
DeviceVisualType = EXRVisualType::Controller;
WristLocation = FVector::ZeroVector;
WristRotation = FRotator::ZeroRotator;
}
@@ -200,6 +202,23 @@ void USGWristTrackerComponent::EditorTick(
Pimpl->UpdateWristTrackingData();
}
bool USGWristTrackerComponent::GetMotionControllerData(FXRMotionControllerData& OutMotionControllerData)
{
OutMotionControllerData.bValid = false;
if (GEngine)
{
IXRTrackingSystem* XrtTrackingSystem{GEngine->XRSystem.Get()};
if (XrtTrackingSystem)
{
const EControllerHand Hand = IsRight() ? EControllerHand::Right : EControllerHand::Left;
XrtTrackingSystem->GetMotionControllerData(this, Hand, OutMotionControllerData);
}
}
return OutMotionControllerData.bValid;
}
USGWristTrackerComponent::FImpl::FImpl(USGWristTrackerComponent* InOwner)
: Owner(InOwner)
{
@@ -230,6 +249,22 @@ void USGWristTrackerComponent::FImpl::UpdateMotionSource() const
void USGWristTrackerComponent::FImpl::UpdateWristTrackingData() const
{
FXRMotionControllerData MotionControllerData;
const bool bGotMotionControllerData = Owner->GetMotionControllerData(MotionControllerData);
if (bGotMotionControllerData)
{
const bool bDeviceVisualTypeUpdated = Owner->DeviceVisualType != MotionControllerData.DeviceVisualType;
if (bDeviceVisualTypeUpdated)
{
Owner->DeviceVisualType = MotionControllerData.DeviceVisualType;
if (Owner->WristDeviceVisualTypeChangedEvent.IsBound())
{
Owner->WristDeviceVisualTypeChangedEvent.Broadcast(Owner->DeviceVisualType);
}
}
}
FVector NewWristLocation{Owner->GetComponentLocation()};
FRotator NewWristRotation{Owner->GetComponentRotation()};
@@ -39,9 +39,7 @@
#include "Components/PrimitiveComponent.h"
#include "Components/SphereComponent.h"
#include "Kismet/KismetMathLibrary.h"
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
#include "XRDeviceVisualizationComponent.h"
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
#include "UObject/UObjectGlobals.h"
#include "SenseGlove/Components/SGGrabComponent.h"
@@ -93,9 +91,21 @@ struct ASGPawn::FImpl
void SetVisibility(USceneComponent* SceneComponent, const bool bVisibility) const;
void UpdateHandLocation(const bool bRight, const FVector& Location, const bool bUpdateVirtualHand);
void UpdateLeftHandLocation(const FVector& Location, const bool bUpdateVirtualHand);
void UpdateRightHandLocation(const FVector& Location, const bool bUpdateVirtualHand);
void UpdateWristTrackerVisualization(const bool bRight, const EXRVisualType VisualType) const;
FORCEINLINE void UpdateLeftWristTrackerVisualization(const EXRVisualType VisualType) const
{
UpdateWristTrackerVisualization(false, VisualType);
}
FORCEINLINE void UpdateRightWristTrackerVisualization(const EXRVisualType VisualType) const
{
UpdateWristTrackerVisualization(true, VisualType);
}
void UpdateHandLocation(const bool bRight, const FVector& Location, const bool bUpdateVirtualHand) const;
void UpdateLeftHandLocation(const FVector& Location, const bool bUpdateVirtualHand) const;
void UpdateRightHandLocation(const FVector& Location, const bool bUpdateVirtualHand) const;
void UpdateHandRotation(const bool bRight, const FRotator& Rotation, const bool bUpdateVirtualHand);
void UpdateLeftHandRotation(const FRotator& Rotation, const bool bUpdateVirtualHand);
@@ -177,14 +187,10 @@ ASGPawn::ASGPawn(const FObjectInitializer& ObjectInitializer)
WristTrackerLeft->SetupAttachment(GetRootComponent());
WristTrackerLeft->SetRight(false);
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
ControllerVisualizerLeft = ObjectInitializer.CreateDefaultSubobject<UXRDeviceVisualizationComponent>(
this, TEXT("ControllerVisualizerLeft"));
ControllerVisualizerLeft->SetupAttachment(WristTrackerLeft);
ControllerVisualizerLeft->SetDisplayModelSource(FName("OpenXR"));
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
WristTrackerLeft->SetDisplayModelSource(FName("OpenXR"));
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
HandLeft = ObjectInitializer.CreateDefaultSubobject<USGVirtualHandComponent>(this, TEXT("HandLeft"));
HandLeft->SetupAttachment(GetRootComponent());
@@ -403,14 +409,10 @@ ASGPawn::ASGPawn(const FObjectInitializer& ObjectInitializer)
WristTrackerRight->SetupAttachment(GetRootComponent());
WristTrackerRight->SetRight(true);
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
ControllerVisualizerRight = ObjectInitializer.CreateDefaultSubobject<UXRDeviceVisualizationComponent>(
this, TEXT("ControllerVisualizerRight"));
ControllerVisualizerRight->SetupAttachment(WristTrackerRight);
ControllerVisualizerRight->SetDisplayModelSource(FName("OpenXR"));
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
WristTrackerRight->SetDisplayModelSource(FName("OpenXR"));
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
HandRight = ObjectInitializer.CreateDefaultSubobject<USGVirtualHandComponent>(this, TEXT("HandRight"));
HandRight->SetupAttachment(GetRootComponent());
@@ -668,6 +670,18 @@ void ASGPawn::BeginPlay()
WristTrackerRight->IsRight() && HandRight->IsRight(),
TEXT("The right hand and the right wrist do not track the right hand!"));
WristTrackerLeft->OnWristDeviceVisualTypeChanged().AddWeakLambda(
this, [&](const EXRVisualType VisualType) -> void
{
Pimpl->UpdateLeftWristTrackerVisualization(VisualType);
});
WristTrackerLeft->OnWristDeviceVisualTypeChanged().AddWeakLambda(
this, [&](const EXRVisualType VisualType) -> void
{
Pimpl->UpdateRightWristTrackerVisualization(VisualType);
});
WristTrackerLeft->OnWristLocationChanged().AddWeakLambda(this, [&](const FVector& Location)-> void
{
Pimpl->UpdateLeftHandLocation(Location, !Pimpl->IsLeftHandOverlappingWithAnyActor());
@@ -1507,7 +1521,6 @@ void ASGPawn::Grab(USGVirtualHandComponent* Hand, AActor* Actor)
Pimpl->UnregisterLeftHandOverlappedActor(Actor);
}
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
const bool bAttached = Actor->AttachToComponent(Hand, MoveTemp(AttachmentRules), SocketName);
if (bAttached)
{
@@ -1531,17 +1544,6 @@ void ASGPawn::Grab(USGVirtualHandComponent* Hand, AActor* Actor)
SGLOG_ERROR("Failed to grab the actor with the left hand!", Actor, SocketName);
}
}
#else
Actor->AttachToComponent(Hand, MoveTemp(AttachmentRules), SocketName);
if (Hand->IsRight())
{
Pimpl->SetRightHandGrabbedActor(Actor);
}
else
{
Pimpl->SetLeftHandGrabbedActor(Actor);
}
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
Pimpl->TriggerActorGrabbedEvent(Hand, Actor);
}
@@ -1785,7 +1787,31 @@ void ASGPawn::FImpl::SetVisibility(USceneComponent* SceneComponent, const bool b
SceneComponent->SetVisibility(bVisibility);
}
void ASGPawn::FImpl::UpdateHandLocation(const bool bRight, const FVector& Location, const bool bUpdateVirtualHand)
void ASGPawn::FImpl::UpdateWristTrackerVisualization(const bool bRight, const EXRVisualType VisualType) const
{
const USGWristTrackerComponent* WristTracker{bRight ? Owner->WristTrackerRight : Owner->WristTrackerLeft};
if (!IsValid(WristTracker))
{
return;
}
const FSGWristTrackingSettings& Settings{WristTracker->GetWristTrackingSettings()};
const bool bIsVisualizationActive = VisualType == EXRVisualType::Controller
|| !!Settings.bHandTrackingVisualizationAllowed;
UXRDeviceVisualizationComponent* ControllerVisualizer{
bRight ? Owner->ControllerVisualizerLeft : Owner->ControllerVisualizerRight
};
if (!IsValid(ControllerVisualizer))
{
return;
}
ControllerVisualizer->SetIsVisualizationActive(bIsVisualizationActive);
}
void ASGPawn::FImpl::UpdateHandLocation(const bool bRight, const FVector& Location, const bool bUpdateVirtualHand) const
{
if (bRight)
{
@@ -1797,7 +1823,7 @@ void ASGPawn::FImpl::UpdateHandLocation(const bool bRight, const FVector& Locati
}
}
void ASGPawn::FImpl::UpdateLeftHandLocation(const FVector& Location, const bool bUpdateVirtualHand)
void ASGPawn::FImpl::UpdateLeftHandLocation(const FVector& Location, const bool bUpdateVirtualHand) const
{
if (bUpdateVirtualHand)
{
@@ -1806,7 +1832,7 @@ void ASGPawn::FImpl::UpdateLeftHandLocation(const FVector& Location, const bool
Owner->RealHandLeft->SetWorldLocation(Location);
}
void ASGPawn::FImpl::UpdateRightHandLocation(const FVector& Location, const bool bUpdateVirtualHand)
void ASGPawn::FImpl::UpdateRightHandLocation(const FVector& Location, const bool bUpdateVirtualHand) const
{
if (bUpdateVirtualHand)
{
@@ -36,13 +36,7 @@
#include "SenseGlove/GameFramework/SGPlayerController.h"
#include "Runtime/Launch/Resources/Version.h"
#if ENGINE_MAJOR_VERSION > 5 || ( ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 2 )
#include "Engine/TimerHandle.h"
#else /* ENGINE_MAJOR_VERSION > 5 || ( ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 2 ) */
#include "Engine/EngineTypes.h"
#endif /* ENGINE_MAJOR_VERSION > 5 || ( ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 2 ) */
#include "TimerManager.h"
#include "SenseGlove/Components/SGTouchComponent.h"
@@ -36,6 +36,7 @@
#pragma once
#include "GameFramework/Actor.h"
#include "HeadMountedDisplayTypes.h"
#include "Math/Rotator.h"
#include "Math/Vector.h"
#include "MotionControllerComponent.h"
@@ -51,6 +52,13 @@ class SENSEGLOVE_API USGWristTrackerComponent : public UMotionControllerComponen
GENERATED_UCLASS_BODY()
public:
DECLARE_EVENT_OneParam(USGWristTrackerComponent, FWristDeviceVisualTypeChangedEvent, EXRVisualType)
FWristDeviceVisualTypeChangedEvent& OnWristDeviceVisualTypeChanged()
{
return WristDeviceVisualTypeChangedEvent;
};
DECLARE_EVENT_OneParam(USGWristTrackerComponent, FWristLocationChangedEvent, const FVector&)
FWristLocationChangedEvent& OnWristLocationChanged()
@@ -74,6 +82,7 @@ public:
};
private:
FWristDeviceVisualTypeChangedEvent WristDeviceVisualTypeChangedEvent;
FWristLocationChangedEvent WristLocationChangedEvent;
FWristRotationChangedEvent WristRotationChangedEvent;
FWristLocationAndRotationChangedEvent WristLocationAndRotationChangedEvent;
@@ -107,6 +116,9 @@ private:
FSGWristTrackingSettings WristTrackingSettings;
private:
UPROPERTY(Transient)
EXRVisualType DeviceVisualType;
UPROPERTY(Transient)
FVector WristLocation;
@@ -139,6 +151,11 @@ public:
const FSGWristTrackingSettings& GetWristTrackingSettings() const;
void SetWristTrackingSettings(const FSGWristTrackingSettings& InWristTrackingSettings);
FORCEINLINE EXRVisualType GetDeviceVisualType() const
{
return DeviceVisualType;
}
FORCEINLINE const FVector& GetWristLocation() const
{
return WristLocation;
@@ -166,4 +183,7 @@ protected:
virtual void EditorTick(float DeltaTime,
enum ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction);
public:
bool GetMotionControllerData(FXRMotionControllerData& OutMotionControllerData);
};
@@ -251,12 +251,10 @@ public:
return WristTrackerLeft;
}
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
FORCEINLINE UXRDeviceVisualizationComponent* GetControllerVisualizerLeft() const
{
return ControllerVisualizerLeft;
}
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
FORCEINLINE USGVirtualHandComponent* GetHandLeft() const
{
@@ -313,12 +311,10 @@ public:
return WristTrackerRight;
}
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
FORCEINLINE UXRDeviceVisualizationComponent* GetControllerVisualizerRight() const
{
return ControllerVisualizerLeft;
}
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
FORCEINLINE USGVirtualHandComponent* GetHandRight() const
{
@@ -36,12 +36,9 @@
#include "SGKismet/SGPawnKismetLibrary.h"
#include "Runtime/Launch/Resources/Version.h"
#include "Camera/CameraComponent.h"
#include "Components/SphereComponent.h"
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
#include "XRDeviceVisualizationComponent.h"
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
#include "SenseGlove/Components/SGVirtualHandComponent.h"
#include "SenseGlove/Components/SGWristTrackerComponent.h"
@@ -59,11 +56,7 @@ USGWristTrackerComponent* UPawnKismetLibrary::GetWristTrackerLeft(const ASGPawn*
UXRDeviceVisualizationComponent* UPawnKismetLibrary::GetControllerVisualizerLeft(const ASGPawn* Pawn)
{
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
return Pawn->GetControllerVisualizerLeft();
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
return nullptr;
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
}
USGVirtualHandComponent* UPawnKismetLibrary::GetHandLeft(const ASGPawn* Pawn)
@@ -123,11 +116,7 @@ USGWristTrackerComponent* UPawnKismetLibrary::GetWristTrackerRight(const ASGPawn
UXRDeviceVisualizationComponent* UPawnKismetLibrary::GetControllerVisualizerRight(const ASGPawn* Pawn)
{
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
return Pawn->GetControllerVisualizerRight();
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
return nullptr;
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2 */
}
USGVirtualHandComponent* UPawnKismetLibrary::GetHandRight(const ASGPawn* Pawn)
@@ -78,6 +78,12 @@ void UWristTrackerComponentKismetLibrary::SetRight(
WristTrackerComponent->SetRight(bInRight);
}
EXRVisualType UWristTrackerComponentKismetLibrary::GetDeviceVisualType(
const USGWristTrackerComponent* WristTrackerComponent)
{
return WristTrackerComponent->GetDeviceVisualType();
}
const FVector& UWristTrackerComponentKismetLibrary::GetWristLocation(
const USGWristTrackerComponent* WristTrackerComponent)
{
@@ -88,4 +94,10 @@ const FRotator& UWristTrackerComponentKismetLibrary::GetWristRotation(
const USGWristTrackerComponent* WristTrackerComponent)
{
return WristTrackerComponent->GetWristRotation();
}
bool UWristTrackerComponentKismetLibrary::GetMotionControllerData(
USGWristTrackerComponent* WristTrackerComponent, FXRMotionControllerData& OutMotionControllerData)
{
return WristTrackerComponent->GetMotionControllerData(OutMotionControllerData);
}
@@ -35,6 +35,8 @@
#pragma once
#include "HeadMountedDisplayTypes.h"
#include "SGKismet/SGBlueprintFunctionLibrary.h"
#include "SGSettings/SGWristTrackingSettings.h"
@@ -74,9 +76,16 @@ public:
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static void SetRight(UPARAM(ref) USGWristTrackerComponent* WristTrackerComponent, bool bInRight);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static EXRVisualType GetDeviceVisualType(const USGWristTrackerComponent* WristTrackerComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static const FVector& GetWristLocation(const USGWristTrackerComponent* WristTrackerComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static const FRotator& GetWristRotation(const USGWristTrackerComponent* WristTrackerComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Wrist Tracker Component")
static bool GetMotionControllerData(UPARAM(ref) USGWristTrackerComponent* WristTrackerComponent,
FXRMotionControllerData& OutMotionControllerData);
};
@@ -37,6 +37,7 @@
FSGWristTrackingSettings::FSGWristTrackingSettings()
: FSGWristTrackingSettings(
false,
ESGPositionalTrackingHardware::None,
FVector::ZeroVector,
FVector::ZeroVector,
@@ -50,6 +51,7 @@ FSGWristTrackingSettings::FSGWristTrackingSettings()
}
FSGWristTrackingSettings::FSGWristTrackingSettings(
const bool bInHandTrackingVisualizationAllowed,
const ESGPositionalTrackingHardware InTrackingHardware,
const FVector& InTrackingHardwareLocationOffsetLeftHand,
const FVector& InTrackingHardwareLocationOffsetRightHand,
@@ -59,7 +61,8 @@ FSGWristTrackingSettings::FSGWristTrackingSettings(
const EControllerHand InRightHandMotionSource,
const bool bInDrawDebugGizmo,
const FSGDebugGizmoSettings& InDebugGizmoSettings)
: TrackingHardware(InTrackingHardware),
: bHandTrackingVisualizationAllowed(bInHandTrackingVisualizationAllowed),
TrackingHardware(InTrackingHardware),
TrackingHardwareLocationOffsetLeftHand(InTrackingHardwareLocationOffsetLeftHand),
TrackingHardwareLocationOffsetRightHand(InTrackingHardwareLocationOffsetRightHand),
TrackingHardwareRotationOffsetLeftHand(InTrackingHardwareRotationOffsetLeftHand),
@@ -49,6 +49,9 @@ struct SENSEGLOVESETTINGS_API FSGWristTrackingSettings
GENERATED_USTRUCT_BODY()
public:
UPROPERTY(Config, EditDefaultsOnly, Category = "Wrist Tracking")
uint8 bHandTrackingVisualizationAllowed : 1;
/**
* If set to Custom, any desired location and rotation can be specified.
*/
@@ -114,6 +117,7 @@ public:
FSGWristTrackingSettings();
FSGWristTrackingSettings(
bool bInHandTrackingVisualizationAllowed,
ESGPositionalTrackingHardware InTrackingHardware,
const FVector& InTrackingHardwareLocationOffsetLeftHand,
const FVector& InTrackingHardwareLocationOffsetRightHand,