A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
OpenXRExpansionFunctionLibrary.cpp
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
3//#include "EngineMinimal.h"
4#include "Engine/Engine.h"
5#include <openxr/openxr.h>
6#include "CoreMinimal.h"
7#include "IXRTrackingSystem.h"
8
9//General Log
10DEFINE_LOG_CATEGORY(OpenXRExpansionFunctionLibraryLog);
11
12UOpenXRExpansionFunctionLibrary::UOpenXRExpansionFunctionLibrary(const FObjectInitializer& ObjectInitializer)
13 : Super(ObjectInitializer)
14{
15}
16
17//=============================================================================
22
24{
27
28 if (FOpenXRHMD* pOpenXRHMD = GetOpenXRHMD())
29 {
30 XrInstance XRInstance = pOpenXRHMD->GetInstance();
31 XrSystemId XRSysID = pOpenXRHMD->GetSystem();
32
33 if (XRSysID && XRInstance)
34 {
35 XrSystemProperties systemProperties{ XR_TYPE_SYSTEM_PROPERTIES };
36 systemProperties.next = nullptr;
37
38 if (xrGetSystemProperties(XRInstance, XRSysID, &systemProperties) == XR_SUCCESS)
39 {
40 XrSession XRSesh = pOpenXRHMD->GetSession();
41
42 if (XRSesh)
43 {
44 XrPath myPath;
45 XrResult PathResult = xrStringToPath(XRInstance, "/user/hand/left", &myPath);
46 XrInteractionProfileState interactionProfile{ XR_TYPE_INTERACTION_PROFILE_STATE };
47 interactionProfile.next = nullptr;
48
49 XrResult QueryResult = xrGetCurrentInteractionProfile(XRSesh, myPath, &interactionProfile);
50 if (QueryResult == XR_SUCCESS)
51 {
52 char myPathy[XR_MAX_SYSTEM_NAME_SIZE];
53 uint32_t outputsize;
54 xrPathToString(XRInstance, interactionProfile.interactionProfile, XR_MAX_SYSTEM_NAME_SIZE, &outputsize, myPathy);
55
56 if (outputsize < 1)
57 return;
58
59 FString InteractionName(ANSI_TO_TCHAR(myPathy));
60 if (InteractionName.Len() < 1)
61 return;
62
63 /*
64 * Interaction profile paths [6.4]
65 An interaction profile identifies a collection of buttons and
66 other input sources, and is of the form:
67 /interaction_profiles/<vendor_name>/<type_name>
68 Paths supported in the core 1.0 release
69 /interaction_profiles/khr/simple_control
70 /interaction_profiles/khr/simple_controller
71 /interaction_profiles/google/daydream_controller
72 /interaction_profiles/htc/vive_controller
73 /interaction_profiles/htc/vive_pro
74 /interaction_profiles/microsoft/motion_controller
75 /interaction_profiles/microsoft/xbox_controller
76 /interaction_profiles/oculus/go_controller
77 /interaction_profiles/oculus/touch_controller
78 /interaction_profiles/valve/index_controller
79 */
80
81 // Not working currently?
82 /*XrInputSourceLocalizedNameGetInfo InputSourceInfo{ XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO };
83 InputSourceInfo.next = nullptr;
84 InputSourceInfo.whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_INTERACTION_PROFILE_BIT;
85 InputSourceInfo.sourcePath = interactionProfile.interactionProfile;
86
87 char buffer[XR_MAX_SYSTEM_NAME_SIZE];
88 uint32_t usedBufferCount = 0;
89 if (xrGetInputSourceLocalizedName(XRSesh, &InputSourceInfo, XR_MAX_SYSTEM_NAME_SIZE, &usedBufferCount, (char*)&buffer) == XR_SUCCESS)
90 {
91 int g = 0;
92 }*/
93
94
95 if (InteractionName.Find("touch_controller", ESearchCase::IgnoreCase) != INDEX_NONE)
96 {
98 }
99 else if (InteractionName.Contains("index_controller", ESearchCase::IgnoreCase))
100 {
102 }
103 else if (InteractionName.Find("vive_controller", ESearchCase::IgnoreCase) != INDEX_NONE)
104 {
106 }
107 else if (InteractionName.Find("vive_pro", ESearchCase::IgnoreCase) != INDEX_NONE)
108 {
110 }
111 else if (InteractionName.Find("simple_controller", ESearchCase::IgnoreCase) != INDEX_NONE)
112 {
114 }
115 else if (InteractionName.Find("daydream_controller", ESearchCase::IgnoreCase) != INDEX_NONE)
116 {
118 }
119 else if (InteractionName.Find("motion_controller", ESearchCase::IgnoreCase) != INDEX_NONE)
120 {
122 }
123 else if (InteractionName.Find("xbox_controller", ESearchCase::IgnoreCase) != INDEX_NONE)
124 {
126 }
127 else if (InteractionName.Find("go_controller", ESearchCase::IgnoreCase) != INDEX_NONE)
128 {
130 }
131 else
132 {
133 UE_LOG(OpenXRExpansionFunctionLibraryLog, Warning, TEXT("UNKNOWN OpenXR Interaction profile detected!!!: %s"), *InteractionName);
135 }
136
138 }
139
140 TrackingSystemName = FString(ANSI_TO_TCHAR(systemProperties.systemName));// , XR_MAX_SYSTEM_NAME_SIZE);
141 //VendorID = systemProperties.vendorId;
142 return;
143 }
144 }
145 }
146 }
147
148 TrackingSystemName.Empty();
149 return;
150}
DEFINE_LOG_CATEGORY(OpenXRExpansionFunctionLibraryLog)
EBPOpenXRControllerDeviceType
UENUM(Blueprintable)
EBPXRResultSwitch
UENUM()
UOpenXRExpansionFunctionLibrary(const FObjectInitializer &ObjectInitializer)
static void GetXRMotionControllerType(FString &TrackingSystemName, EBPOpenXRControllerDeviceType &DeviceType, EBPXRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|OpenXR", meta = (bIgnoreSelf = "true",...