From 5dfe41da0e0c26a1e564228cc77f4fc6d5038469 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 12 Apr 2024 07:31:37 +0200 Subject: [PATCH] check hmd auto-detection against various identifiers as the names returns from the engine is not reliable --- .../Private/SenseGlove/SGHeadMountDisplay.cpp | 105 ++++++++++++++++-- .../Public/SenseGlove/SGHeadMountDisplay.h | 20 +--- h -f | 30 ----- 3 files changed, 97 insertions(+), 58 deletions(-) delete mode 100644 h -f diff --git a/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp b/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp index 2ee3a192..176dbea5 100644 --- a/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp +++ b/Source/SenseGlove/Private/SenseGlove/SGHeadMountDisplay.cpp @@ -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 */ } diff --git a/Source/SenseGlove/Public/SenseGlove/SGHeadMountDisplay.h b/Source/SenseGlove/Public/SenseGlove/SGHeadMountDisplay.h index d70c9834..af09406f 100644 --- a/Source/SenseGlove/Public/SenseGlove/SGHeadMountDisplay.h +++ b/Source/SenseGlove/Public/SenseGlove/SGHeadMountDisplay.h @@ -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(); diff --git a/h -f b/h -f deleted file mode 100644 index 30e126ea..00000000 --- a/h -f +++ /dev/null @@ -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;