utilize UXRDeviceVisualizationComponent to display meshes on UE 5.2 onwards

This commit is contained in:
Mamadou Babaei
2024-03-22 21:03:56 +01:00
parent 43232ba110
commit b2861b0068
8 changed files with 90 additions and 3 deletions
@@ -39,7 +39,9 @@
#include "Components/PrimitiveComponent.h"
#include "Components/SphereComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "Runtime/Launch/Resources/Version.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"
@@ -173,6 +175,15 @@ 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());
HandLeft->SetCanEverAffectNavigation(false);
@@ -391,6 +402,15 @@ 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());
HandRight->SetCanEverAffectNavigation(false);
@@ -46,6 +46,7 @@
#include "TimerManager.h"
#include "SenseGlove/Components/SGTouchComponent.h"
#include "SenseGlove/Components/SGVirtualHandComponent.h"
#include "SenseGlove/GameFramework/SGPawn.h"
#include "SenseGlove/Haptics/SGGrabState.h"
#include "SenseGlove/Haptics/SGTouchState.h"
@@ -37,7 +37,7 @@
#include "Containers/Array.h"
#include "GameFramework/Pawn.h"
#include "SenseGlove/Components/SGVirtualHandComponent.h"
#include "Runtime/Launch/Resources/Version.h"
#include "Templates/UniquePtr.h"
#include "SenseGlove/Haptics/SGGrabState.h"
@@ -48,6 +48,7 @@
class UCameraComponent;
class UPrimitiveComponent;
class USphereComponent;
class UXRDeviceVisualizationComponent;
class USGVirtualHandComponent;
class USGWristTrackerComponent;
@@ -129,6 +130,9 @@ private:
UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
USGWristTrackerComponent* WristTrackerLeft;
UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
UXRDeviceVisualizationComponent* ControllerVisualizerLeft;
UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
USGVirtualHandComponent* HandLeft;
@@ -162,6 +166,9 @@ private:
UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
USGWristTrackerComponent* WristTrackerRight;
UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
UXRDeviceVisualizationComponent* ControllerVisualizerRight;
UPROPERTY(VisibleAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
USGVirtualHandComponent* HandRight;
@@ -244,6 +251,13 @@ 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
{
return HandLeft;
@@ -299,6 +313,13 @@ 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
{
return HandRight;
+8 -1
View File
@@ -57,6 +57,13 @@ public class SenseGlove : ModuleRules
"Engine",
"HeadMountedDisplay",
"InputCore",
// NOTE
// UE 5.3+ provides UXRDeviceVisualizationComponent as part of the XRBase plugin.
// UE 5.2 provides UXRDeviceVisualizationComponent as part of the HeadMountDisplay module.
// UE 5.1 does not provide the UXRDeviceVisualizationComponent type.
#if UE_5_3_OR_LATER
"XRBase",
#endif
"SenseGloveBackend",
"SenseGloveConnect",
"SenseGloveCore",
@@ -74,4 +81,4 @@ public class SenseGlove : ModuleRules
}
);
}
}
}
@@ -35,8 +35,13 @@
#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"
@@ -52,6 +57,15 @@ USGWristTrackerComponent* UPawnKismetLibrary::GetWristTrackerLeft(const ASGPawn*
return Pawn->GetWristTrackerLeft();
}
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)
{
return Pawn->GetHandLeft();
@@ -107,6 +121,15 @@ USGWristTrackerComponent* UPawnKismetLibrary::GetWristTrackerRight(const ASGPawn
return Pawn->GetWristTrackerRight();
}
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)
{
return Pawn->GetHandRight();
@@ -51,6 +51,7 @@
class UCameraComponent;
class USphereComponent;
class UXRDeviceVisualizationComponent;
class ASGPawn;
class USGVirtualHandComponent;
@@ -68,6 +69,9 @@ public:
UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn")
static USGWristTrackerComponent* GetWristTrackerLeft(const ASGPawn* Pawn);
UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn")
static UXRDeviceVisualizationComponent* GetControllerVisualizerLeft(const ASGPawn* Pawn);
UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn")
static USGVirtualHandComponent* GetHandLeft(const ASGPawn* Pawn);
@@ -101,6 +105,9 @@ public:
UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn")
static USGWristTrackerComponent* GetWristTrackerRight(const ASGPawn* Pawn);
UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn")
static UXRDeviceVisualizationComponent* GetControllerVisualizerRight(const ASGPawn* Pawn);
UFUNCTION(BlueprintPure, Category="SenseGlove | Game Framework | Pawn")
static USGVirtualHandComponent* GetHandRight(const ASGPawn* Pawn);
@@ -55,6 +55,13 @@ public class SenseGloveKismet : ModuleRules
"CoreUObject",
"Engine",
"HeadMountedDisplay",
// NOTE
// UE 5.3+ provides UXRDeviceVisualizationComponent as part of the XRBase plugin.
// UE 5.2 provides UXRDeviceVisualizationComponent as part of the HeadMountDisplay module.
// UE 5.1 does not provide the UXRDeviceVisualizationComponent type.
#if UE_5_3_OR_LATER
"XRBase",
#endif
"SenseGlove",
"SenseGloveCore",
"SenseGloveLog",