check hmd auto-detection against various identifiers as the names returns from the engine is not reliable

This commit is contained in:
Mamadou Babaei
2024-04-12 07:39:26 +02:00
parent ade7afac88
commit e9ffa1e43d
3 changed files with 97 additions and 58 deletions
@@ -54,12 +54,83 @@ FName FSGHeadMountDisplay::GetDeviceName()
return NAME_None;
}
bool FSGHeadMountDisplay::IsMetaQuest2()
{
static const FName MetaQuest2DeviceIdentifier{TEXT("Meta Quest 2")};
static const FName OculusQuest2DeviceIdentifier{TEXT("Oculus Quest2")};
static const FString Quest2DeviceIdentifier1{TEXT("Quest 2")};
static const FString Quest2DeviceIdentifier2{TEXT("Quest2")};
const FName DeviceName{GetDeviceName()};
bool bMatched = DeviceName == MetaQuest2DeviceIdentifier || DeviceName == OculusQuest2DeviceIdentifier;
if (!bMatched)
{
const FString DeviceNameString{GetDeviceName().ToString()};
bMatched = DeviceNameString.Contains(Quest2DeviceIdentifier1)
|| DeviceNameString.Contains(Quest2DeviceIdentifier2);
}
return bMatched;
}
bool FSGHeadMountDisplay::IsMetaQuestPro()
{
static const FName MetaQuestProDeviceIdentifier{TEXT("Meta Quest Pro")};
static const FName OculusQuestProDeviceIdentifier{TEXT("Oculus QuestPro")};
static const FString QuestProDeviceIdentifier1{TEXT("Quest Pro")};
static const FString QuestProDeviceIdentifier2{TEXT("QuestPro")};
const FName DeviceName{GetDeviceName()};
bool bMatched = DeviceName == MetaQuestProDeviceIdentifier || DeviceName == OculusQuestProDeviceIdentifier;
if (!bMatched)
{
const FString DeviceNameString{GetDeviceName().ToString()};
bMatched = DeviceNameString.Contains(QuestProDeviceIdentifier1)
|| DeviceNameString.Contains(QuestProDeviceIdentifier2);
}
return bMatched;
}
bool FSGHeadMountDisplay::IsMetaQuest3()
{
static const FName MetaQuest3DeviceIdentifier{TEXT("Meta Quest 3")};
static const FName OculusQuest3DeviceIdentifier{TEXT("Oculus Quest3")};
static const FString Quest3DeviceIdentifier1{TEXT("Quest 3")};
static const FString Quest3DeviceIdentifier2{TEXT("Quest3")};
const FName DeviceName{GetDeviceName()};
bool bMatched = DeviceName == MetaQuest3DeviceIdentifier || DeviceName == OculusQuest3DeviceIdentifier;
if (!bMatched)
{
const FString DeviceNameString{GetDeviceName().ToString()};
bMatched = DeviceNameString.Contains(Quest3DeviceIdentifier1)
|| DeviceNameString.Contains(Quest3DeviceIdentifier2);
}
return bMatched;
}
bool FSGHeadMountDisplay::IsHtcVivePro()
{
#if !PLATFORM_ANDROID
#if PLATFORM_ANDROID
return false;
#else /* PLATFORM_ANDROID */
static const FName DeviceIdentifier{TEXT("Vive OpenXR: Vive SRanipal")};
const bool bIdentifierMatches = GetDeviceName() == DeviceIdentifier;
if (bIdentifierMatches)
static const FString ViveDeviceIdentifier{TEXT("Vive")};
static const FString SRanipalDeviceIdentifier{TEXT("SRanipal")};
const FName DeviceName{GetDeviceName()};
bool bMatched = DeviceName == DeviceIdentifier;
if (!bMatched)
{
const FString DeviceNameString{GetDeviceName().ToString()};
bMatched = DeviceNameString.Contains(ViveDeviceIdentifier)
|| DeviceNameString.Contains(SRanipalDeviceIdentifier);
}
if (bMatched)
{
if (GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowed())
{
@@ -78,25 +149,37 @@ bool FSGHeadMountDisplay::IsHtcVivePro()
// - Unreal OpenXR Resolution: 5016 x 2508
if (HmdMonitorInfo.ResolutionX < 5000 && HmdMonitorInfo.ResolutionY > 2700)
{
return true;
bMatched = true;
}
}
}
}
#endif /* !PLATFORM_ANDROID */
return false;
return bMatched;
#endif /* PLATFORM_ANDROID */
}
bool FSGHeadMountDisplay::IsHtcViveFocus3()
{
static const FName DeviceIdentifier{TEXT("Vive OpenXR: Vive SRanipal")};
const bool bIdentifierMatches = GetDeviceName() == DeviceIdentifier;
static const FString ViveDeviceIdentifier{TEXT("Vive")};
static const FString SRanipalDeviceIdentifier{TEXT("SRanipal")};
const FName DeviceName{GetDeviceName()};
bool bMatched = DeviceName == DeviceIdentifier;
if (!bMatched)
{
const FString DeviceNameString{GetDeviceName().ToString()};
bMatched = DeviceNameString.Contains(ViveDeviceIdentifier)
|| DeviceNameString.Contains(SRanipalDeviceIdentifier);
}
#if PLATFORM_ANDROID
return bIdentifierMatches;
return bMatched;
#else /* PLATFORM_ANDROID */
if (bIdentifierMatches)
if (bMatched)
{
if (GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowed())
{
@@ -116,13 +199,13 @@ bool FSGHeadMountDisplay::IsHtcViveFocus3()
if (HmdMonitorInfo.ResolutionX > 5000
&& (HmdMonitorInfo.ResolutionY > 2500 && HmdMonitorInfo.ResolutionY < 2700))
{
return true;
bMatched = true;
}
}
}
}
return false;
return bMatched;
#endif /* PLATFORM_ANDROID */
}
@@ -54,23 +54,9 @@ struct SENSEGLOVE_API FSGHeadMountDisplay
public:
static FName GetDeviceName();
FORCEINLINE static bool IsMetaQuest2()
{
static const FName DeviceIdentifier{TEXT("Meta Quest 2")};
return GetDeviceName() == DeviceIdentifier;
}
FORCEINLINE static bool IsMetaQuestPro()
{
static const FName DeviceIdentifier{TEXT("Meta Quest Pro")};
return GetDeviceName() == DeviceIdentifier;
}
FORCEINLINE static bool IsMetaQuest3()
{
static const FName DeviceIdentifier{TEXT("Meta Quest 3")};
return GetDeviceName() == DeviceIdentifier;
}
static bool IsMetaQuest2();
static bool IsMetaQuestPro();
static bool IsMetaQuest3();
static bool IsHtcVivePro();
static bool IsHtcViveFocus3();
-30
View File
@@ -1,30 +0,0 @@
diff --git a/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp b/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp
index bc65ea56..1bda9233 100644
--- a/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp
+++ b/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp
@@ -38,6 +38,7 @@
#include "Engine/Engine.h"
#include "IHeadMountedDisplay.h"
#include "IXRTrackingSystem.h"
+#include "SGLog/SGLog.h"

FName FSGHeadMountDisplay::GetDeviceName()
{
@@ -52,6 +53,17 @@ FName FSGHeadMountDisplay::GetDeviceName()

ESGHeadMountDisplayDevice FSGHeadMountDisplay::GetDeviceType()
{
+ if (GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowed())
+ {
+ IHeadMountedDisplay::MonitorInfo HmdMonitorInfo;
+ IHeadMountedDisplay* Device{GEngine->XRSystem->GetHMDDevice()};
+ Device->GetHMDMonitorInfo(HmdMonitorInfo);
+ const int32 ResX = HmdMonitorInfo.ResolutionX;
+ const int32 ResY = HmdMonitorInfo.ResolutionY;
+ SGLOG(HmdMonitorInfo.MonitorName, ResX, ResY, HmdMonitorInfo.DesktopX, HmdMonitorInfo.DesktopY,
+ HmdMonitorInfo.WindowSizeX, HmdMonitorInfo.WindowSizeY);
+ }
+
if (IsMetaQuest2())
{
return ESGHeadMountDisplayDevice::MetaQuest2;