A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
OpenVRExpansionFunctionLibrary.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 "CoreMinimal.h"
6#include "Engine/Texture.h"
7#include "Engine/Texture2D.h"
8#include "Rendering/Texture2DResource.h"
9#include "RenderUtils.h"
10#include "IXRTrackingSystem.h"
11#include "IHeadMountedDisplay.h"
12
13#if WITH_EDITOR
14#include "Editor/UnrealEd/Classes/Editor/EditorEngine.h"
15#endif
16
17//General Log
18DEFINE_LOG_CATEGORY(OpenVRExpansionFunctionLibraryLog);
19
20#if STEAMVR_SUPPORTED_PLATFORM
21
22//pVRGetGenericInterface UOpenVRExpansionFunctionLibrary::VRGetGenericInterfaceFn = nullptr;
23FBPOpenVRCameraHandle UOpenVRExpansionFunctionLibrary::OpenCamera = FBPOpenVRCameraHandle();
24#endif
25
26UOpenVRExpansionFunctionLibrary::UOpenVRExpansionFunctionLibrary(const FObjectInitializer& ObjectInitializer)
27 : Super(ObjectInitializer)
28{
29}
30
31//=============================================================================
33{
34#if STEAMVR_SUPPORTED_PLATFORM
35 //if(VRGetGenericInterfaceFn)
36 // UnloadOpenVRModule();
37#endif
38}
39
41{
42
44
45 if (GEngine && GEngine->XRSystem.IsValid())
46 {
47 // Already declared in some of our includes here
48 //static const FName SteamVRSysName(TEXT("SteamVR"));
49 static const FName OculusSystemName(TEXT("OculusHMD"));
50 //static const FName OSVRSystemName(TEXT("OSVR"));
51
52 FName DeviceName(NAME_None);
53 DeviceName = GEngine->XRSystem->GetSystemName();
54
55
56 if (DeviceName == SteamVRSystemName)
58 else if (DeviceName == OculusSystemName)
60 //else if (DeviceName == OSVRSystemName)
61 //DeviceType = EBPOpenVRHMDDeviceType::DT_OSVR;
62 }
63
64#if !STEAMVR_SUPPORTED_PLATFORM
65 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Get OpenVRHMDType returning default value as this is not a steamvr supported platform!!!"));
66 return DeviceType;
67#else
68
69 // If not, will early out with the type (OSVR / OculusHMD)
70 if (DeviceType == EBPOpenVRHMDDeviceType::DT_SteamVR)
71 {
72 FString DeviceModelNumber;
73 EBPOVRResultSwitch Result;
74
75 // Using index 0 as it is always HMD
78 {
79 //UE_LOG(OpenVRExpansionFunctionLibraryLog, Display, TEXT("OpenVRDeviceType - Prop_ModelNumber_String_1001: %s"), *DeviceModelNumber);
80
81 //#TODO: Screw this eventually, need it to be actual string value comparisons for each model
82 // This is the hacky workaround for now
83 /*
84 "Vive MV";
85 "Vive Cosmos"
86 "VIVE_Pro MV"
87 "Vive Focus"
88 "Oculus Rift CV1";
89 "Lenovo Explorer";
90 "HP Windows Mixed Reality Headset";
91 "Samsung Windows Mixed Reality 800ZAA";
92 "Acer AH100";
93 */
94
95 // Manufacturer name
96 /*WindowsMR*/
97
98 if (DeviceModelNumber.Find("index", ESearchCase::IgnoreCase) != INDEX_NONE)
99 {
101 }
102 else if (DeviceModelNumber.Find("vive_cosmos", ESearchCase::IgnoreCase) != INDEX_NONE)
103 {
105 }
106 else if (DeviceModelNumber.Find("vive", ESearchCase::IgnoreCase) != INDEX_NONE)
107 {
108 if (DeviceModelNumber.Find("focus3", ESearchCase::IgnoreCase) != INDEX_NONE)
109 {
111 }
112 else if (DeviceModelNumber.Find("focus", ESearchCase::IgnoreCase) != INDEX_NONE)
113 {
115 }
116 else if (DeviceModelNumber.Find("Pico Neo3", ESearchCase::IgnoreCase) != INDEX_NONE)
117 {
119 }
120 else
121 {
123 }
124 }
125 else if ((DeviceModelNumber.Find("oculus quest", ESearchCase::IgnoreCase) != INDEX_NONE) ||
126 (DeviceModelNumber.Find("miramar", ESearchCase::IgnoreCase) != INDEX_NONE))
127 {
129 }
130 else if (DeviceModelNumber.Find("oculus", ESearchCase::IgnoreCase) != INDEX_NONE)
131 {
133 }
134 else if (
135 DeviceModelNumber.Find("Mixed Reality", ESearchCase::IgnoreCase) != INDEX_NONE ||
136 DeviceModelNumber.Find("Acer", ESearchCase::IgnoreCase) != INDEX_NONE ||
137 DeviceModelNumber.Find("Lenovo", ESearchCase::IgnoreCase) != INDEX_NONE
138 )
139 {
141 }
142 else
143 {
144 // Check for manufacturer name for windows MR
147 {
148 if (DeviceModelNumber.Find("WindowsMR", ESearchCase::IgnoreCase) != INDEX_NONE)
149 {
151 }
152 }
153 else
154 {
156#if WITH_EDITOR
157 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Tell VRE about unhandled HMD model type: %s !!!"), *DeviceModelNumber);
158#endif
159 }
160 }
161 }
162 else
163 {
164 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Get OpenVRHMDType failed to get the OpenVR property string!!!"));
165 }
166 }
167
168 return DeviceType;
169#endif
170}
171
173{
174
176
177#if !STEAMVR_SUPPORTED_PLATFORM
178 return DeviceType;
179#else
180
181 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
182 {
183 return DeviceType;
184 }
185
186 vr::IVRSystem* VRSystem = vr::VRSystem();
187
188 if (!VRSystem)
189 {
190 return DeviceType;
191 }
192
193 int32 DeviceIndexOut = INDEX_NONE;
194 int32 FallbackIndex = INDEX_NONE;
195
196 for (uint32 DeviceIndex = 0; DeviceIndex < vr::k_unMaxTrackedDeviceCount; ++DeviceIndex)
197 {
198 const vr::ETrackedDeviceClass DeviceClass = VRSystem->GetTrackedDeviceClass(DeviceIndex);
199 if (DeviceClass == vr::ETrackedDeviceClass::TrackedDeviceClass_Controller)
200 {
201 // NOTE: GetControllerRoleForTrackedDeviceIndex() only seems to return a valid role if the device is on and being tracked
202 const vr::ETrackedControllerRole ControllerRole = VRSystem->GetControllerRoleForTrackedDeviceIndex(DeviceIndex);
203 if (ControllerRole != vr::TrackedControllerRole_LeftHand && ControllerRole != vr::TrackedControllerRole_RightHand)
204 {
205 continue;
206 }
207
208 DeviceIndexOut = DeviceIndex;
209 break;
210 }
211 }
212
213 if (DeviceIndexOut == INDEX_NONE)
214 {
215 return DeviceType;
216 }
217
218 EBPOVRResultSwitch Result;
219
220 FString DeviceModelNumber;
223 {
224 if (DeviceModelNumber.Find("knuckles", ESearchCase::IgnoreCase) != INDEX_NONE || DeviceModelNumber.Find("index", ESearchCase::IgnoreCase) != INDEX_NONE)
225 {
227 }
228 else if (DeviceModelNumber.Find("cosmos", ESearchCase::IgnoreCase) != INDEX_NONE)
229 {
231 }
232 else if (DeviceModelNumber.Find("VIVE", ESearchCase::IgnoreCase) != INDEX_NONE) // Vive Wand
233 {
235 }
236 else if ((DeviceModelNumber.Find("oculus quest", ESearchCase::IgnoreCase) != INDEX_NONE) ||
237 (DeviceModelNumber.Find("miramar", ESearchCase::IgnoreCase) != INDEX_NONE))
238 {
240 }
241 else if (DeviceModelNumber.Find("oculus rift cv1", ESearchCase::IgnoreCase) != INDEX_NONE) // Oculus Rift CV1
242 {
244 }
245 else if (DeviceModelNumber.Find("oculus rift s", ESearchCase::IgnoreCase) != INDEX_NONE) // Oculus Rift CV1
246 {
248 }
249 else if (DeviceModelNumber.Find("windowsmr", ESearchCase::IgnoreCase) != INDEX_NONE) // Oculus Rift CV1
250 {
252 }
253 else if (DeviceModelNumber.Find("Pico Neo3 Controller", ESearchCase::IgnoreCase) != INDEX_NONE) // PicoNeo3
254 {
256 }
257 else
258 {
259#if WITH_EDITOR
260 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Tell VRE about unhandled controller model type: %s !!!"), *DeviceModelNumber);
261 // Add other controllers here
262#endif
263 }
264 }
265
266 return DeviceType;
267#endif
268}
269
271{
272#if !STEAMVR_SUPPORTED_PLATFORM
273 return false;
274#else
275 Width = 0;
276 Height = 0;
277
278 //if (!VRGetGenericInterfaceFn)
279 // return false;
280
281 // Don't run anything if no HMD and if the HMD is not a steam type
282 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
283 return false;
284
285 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
286
287
288 if (!VRCamera)
289 return false;
290
291 bool pHasCamera;
292 vr::EVRTrackedCameraError CamError = VRCamera->HasCamera(vr::k_unTrackedDeviceIndex_Hmd, &pHasCamera);
293
294 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None)
295 return false;
296
297 uint32 WidthOut;
298 uint32 HeightOut;
299 uint32 FrameBufferSize;
300 CamError = VRCamera->GetCameraFrameSize(vr::k_unTrackedDeviceIndex_Hmd, (vr::EVRTrackedCameraFrameType)FrameType, &WidthOut, &HeightOut, &FrameBufferSize);
301
302 Width = WidthOut;
303 Height = HeightOut;
304
305 return pHasCamera;
306
307#endif
308}
309
311{
312#if !STEAMVR_SUPPORTED_PLATFORM
314 return;
315#else
316
317 // Don't run anything if no HMD and if the HMD is not a steam type
318 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
319 {
321 return;
322 }
323
324 // If already have a valid camera handle
325 if (OpenCamera.IsValid())
326 {
327 CameraHandle = OpenCamera;
329 return;
330 }
331
332 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
333
334 if (!VRCamera)
335 {
337 return;
338 }
339
340 vr::EVRTrackedCameraError CamError = VRCamera->AcquireVideoStreamingService(vr::k_unTrackedDeviceIndex_Hmd, &CameraHandle.pCameraHandle);
341
342 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None)
343 CameraHandle.pCameraHandle = INVALID_TRACKED_CAMERA_HANDLE;
344
345 if (CameraHandle.pCameraHandle == INVALID_TRACKED_CAMERA_HANDLE)
346 {
348 return;
349 }
350
351 OpenCamera = CameraHandle;
353 return;
354#endif
355}
356
358{
359#if !STEAMVR_SUPPORTED_PLATFORM
361 return;
362#else
363
364 // Don't run anything if no HMD and if the HMD is not a steam type
365 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
366 {
368 return;
369 }
370
371 if (!CameraHandle.IsValid())
372 {
374 return;
375 }
376
377
378 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
379
380 if (!VRCamera)
381 {
383 return;
384 }
385
386 vr::EVRTrackedCameraError CamError = VRCamera->ReleaseVideoStreamingService(CameraHandle.pCameraHandle);
387 CameraHandle.pCameraHandle = INVALID_TRACKED_CAMERA_HANDLE;
388
389 OpenCamera = CameraHandle;
391 return;
392
393#endif
394}
395
397{
398 return (CameraHandle.IsValid());
399}
400
401
403{
404#if !STEAMVR_SUPPORTED_PLATFORM
406 return nullptr;
407#else
408
409 // Don't run anything if no HMD and if the HMD is not a steam type
410 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
411 {
413 return nullptr;
414 }
415
416 if (!CameraHandle.IsValid() || !FApp::CanEverRender())
417 {
419 return nullptr;
420 }
421
422 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
423
424 if (!VRCamera)
425 {
427 return nullptr;
428 }
429
430 uint32 Width;
431 uint32 Height;
432 uint32 FrameBufferSize;
433 vr::EVRTrackedCameraError CamError = VRCamera->GetCameraFrameSize(vr::k_unTrackedDeviceIndex_Hmd, (vr::EVRTrackedCameraFrameType)FrameType, &Width, &Height, &FrameBufferSize);
434
435 if (Width > 0 && Height > 0)
436 {
437
438 UTexture2D * NewRenderTarget2D = UTexture2D::CreateTransient(Width, Height, EPixelFormat::PF_R8G8B8A8);//NewObject<UTexture2D>(GetWorld());
439 check(NewRenderTarget2D);
440
441 //Setting some Parameters for the Texture and finally returning it
442 NewRenderTarget2D->PlatformData->SetNumSlices(1);
443 NewRenderTarget2D->NeverStream = true;
444 NewRenderTarget2D->UpdateResource();
445
447 return NewRenderTarget2D;
448 }
449
451 return nullptr;
452#endif
453}
454
455void UOpenVRExpansionFunctionLibrary::GetVRCameraFrame(UPARAM(ref) FBPOpenVRCameraHandle & CameraHandle, EOpenVRCameraFrameType FrameType, EBPOVRResultSwitch & Result, UTexture2D * TargetRenderTarget)
456{
457#if !STEAMVR_SUPPORTED_PLATFORM
459 return;
460#else
461
462 // Don't run anything if no HMD and if the HMD is not a steam type
463 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
464 {
466 return;
467 }
468
469 if (!TargetRenderTarget || !CameraHandle.IsValid())
470 {
472 return;
473 }
474
475 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
476
477 if (!VRCamera)
478 {
480 return;
481 }
482
483 uint32 Width;
484 uint32 Height;
485 uint32 FrameBufferSize;
486 vr::EVRTrackedCameraError CamError = VRCamera->GetCameraFrameSize(vr::k_unTrackedDeviceIndex_Hmd, (vr::EVRTrackedCameraFrameType)FrameType, &Width, &Height, &FrameBufferSize);
487
488 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None || Width <= 0 || Height <= 0)
489 {
491 return;
492 }
493
494 // Make sure formats are correct
495 check(FrameBufferSize == (Width * Height * GPixelFormats[EPixelFormat::PF_R8G8B8A8].BlockBytes));
496
497
498 // Need to bring this back after moving from render target to this
499 // Update the format if required, this is in case someone made a new render target NOT with my custom function
500 // Enforces correct buffer size for the camera feed
501 if (TargetRenderTarget->GetSizeX() != Width || TargetRenderTarget->GetSizeY() != Height || TargetRenderTarget->GetPixelFormat() != EPixelFormat::PF_R8G8B8A8)
502 {
503 TargetRenderTarget->PlatformData->SizeX = Width;
504 TargetRenderTarget->PlatformData->SizeY = Height;
505 TargetRenderTarget->PlatformData->PixelFormat = EPixelFormat::PF_R8G8B8A8;
506
507 // Allocate first mipmap.
508 int32 NumBlocksX = Width / GPixelFormats[EPixelFormat::PF_R8G8B8A8].BlockSizeX;
509 int32 NumBlocksY = Height / GPixelFormats[EPixelFormat::PF_R8G8B8A8].BlockSizeY;
510
511 TargetRenderTarget->PlatformData->Mips[0].SizeX = Width;
512 TargetRenderTarget->PlatformData->Mips[0].SizeY = Height;
513 TargetRenderTarget->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
514 TargetRenderTarget->PlatformData->Mips[0].BulkData.Realloc(NumBlocksX * NumBlocksY * GPixelFormats[EPixelFormat::PF_R8G8B8A8].BlockBytes);
515 TargetRenderTarget->PlatformData->Mips[0].BulkData.Unlock();
516 }
517
518 vr::CameraVideoStreamFrameHeader_t CamHeader;
519 uint8* pData = new uint8[FrameBufferSize];
520
521 CamError = VRCamera->GetVideoStreamFrameBuffer(CameraHandle.pCameraHandle, (vr::EVRTrackedCameraFrameType)FrameType, pData, FrameBufferSize, &CamHeader, sizeof(vr::CameraVideoStreamFrameHeader_t));
522
523 // No frame available = still on spin / wake up
524 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None || CamError == vr::EVRTrackedCameraError::VRTrackedCameraError_NoFrameAvailable)
525 {
526 delete[] pData;
528 return;
529 }
530
531 /*ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
532 UpdateDynamicTextureCode,
533 UTexture2D*, pTexture, TargetRenderTarget,
534 const uint8*, pData, pData,
535 {
536 FUpdateTextureRegion2D region;
537 region.SrcX = 0;
538 region.SrcY = 0;
539 region.DestX = 0;
540 region.DestY = 0;
541 region.Width = pTexture->GetSizeX();// TEX_WIDTH;
542 region.Height = pTexture->GetSizeY();//TEX_HEIGHT;
543
544 FTexture2DResource* resource = (FTexture2DResource*)pTexture->Resource;
545 RHIUpdateTexture2D(resource->GetTexture2DRHI(), 0, region, region.Width * GPixelFormats[pTexture->GetPixelFormat()].BlockBytes, pData);
546 delete[] pData;
547 });*/
548
549 UTexture2D* TexturePtr = TargetRenderTarget;
550 const uint8* TextureData = pData;
551 ENQUEUE_RENDER_COMMAND(OpenVRExpansionPlugin_GetVRCameraFrame)(
552 [TexturePtr, TextureData](FRHICommandList& RHICmdList)
553 {
554 FUpdateTextureRegion2D region;
555 region.SrcX = 0;
556 region.SrcY = 0;
557 region.DestX = 0;
558 region.DestY = 0;
559 region.Width = TexturePtr->GetSizeX();// TEX_WIDTH;
560 region.Height = TexturePtr->GetSizeY();//TEX_HEIGHT;
561
562 FTexture2DResource* resource = (FTexture2DResource*)TexturePtr->Resource;
563 RHIUpdateTexture2D(resource->GetTexture2DRHI(), 0, region, region.Width * GPixelFormats[TexturePtr->GetPixelFormat()].BlockBytes/*TEX_PIXEL_SIZE_IN_BYTES*/, TextureData);
564 delete[] TextureData;
565 });
566
567 // Letting the enqueued command free the memory
569 return;
570#endif
571}
572
573void UOpenVRExpansionFunctionLibrary::GetVRDevicePropertyString(EVRDeviceProperty_String PropertyToRetrieve, int32 DeviceID, FString & StringValue, EBPOVRResultSwitch & Result)
574{
575
576#if !STEAMVR_SUPPORTED_PLATFORM
578 return;
579#else
580
581 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
582 {
584 return;
585 }
586
587 vr::IVRSystem* VRSystem = vr::VRSystem();
588
589 if (!VRSystem)
590 {
592 return;
593 }
594
595 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
596
597 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT("EVRDeviceProperty_String"), static_cast<uint8>(PropertyToRetrieve));
598 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
599 {
601 return;
602 }
603
604 char charvalue[vr::k_unMaxPropertyStringSize];
605 uint32_t buffersize = vr::k_unMaxPropertyStringSize;
606 uint32_t ret = VRSystem->GetStringTrackedDeviceProperty(DeviceID, EnumPropertyValue, charvalue, buffersize, &pError);
607
608 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
609 {
611 return;
612 }
613
614 StringValue = FString(ANSI_TO_TCHAR(charvalue));
616 return;
617
618#endif
619}
620
622{
623#if !STEAMVR_SUPPORTED_PLATFORM
625 return;
626#else
627
628 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
629 {
631 return;
632 }
633
634 vr::IVRSystem* VRSystem = vr::VRSystem();
635
636 if (!VRSystem)
637 {
639 return;
640 }
641
642 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
643
644 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT("EVRDeviceProperty_Bool"), static_cast<uint8>(PropertyToRetrieve));
645 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
646 {
648 return;
649 }
650
651 bool ret = VRSystem->GetBoolTrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
652
653 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
654 {
656 return;
657 }
658
659 BoolValue = ret;
661 return;
662
663#endif
664}
665
667{
668#if !STEAMVR_SUPPORTED_PLATFORM
670 return;
671#else
672
673 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
674 {
676 return;
677 }
678
679 vr::IVRSystem* VRSystem = vr::VRSystem();
680
681 if (!VRSystem)
682 {
684 return;
685 }
686
687 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
688
689 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT("EVRDeviceProperty_Float"), static_cast<uint8>(PropertyToRetrieve));
690 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
691 {
693 return;
694 }
695
696 float ret = VRSystem->GetFloatTrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
697
698 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
699 {
701 return;
702 }
703
704 FloatValue = ret;
706 return;
707
708#endif
709}
710
712{
713#if !STEAMVR_SUPPORTED_PLATFORM
715 return;
716#else
717
718 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
719 {
721 return;
722 }
723
724 vr::IVRSystem* VRSystem = vr::VRSystem();
725
726 if (!VRSystem)
727 {
729 return;
730 }
731
732 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
733
734 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT("EVRDeviceProperty_Int32"), static_cast<uint8>(PropertyToRetrieve));
735 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
736 {
738 return;
739 }
740
741 int32 ret = VRSystem->GetInt32TrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
742
743 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
744 {
746 return;
747 }
748
749 IntValue = ret;
751 return;
752
753#endif
754}
755
756void UOpenVRExpansionFunctionLibrary::GetVRDevicePropertyUInt64(EVRDeviceProperty_UInt64 PropertyToRetrieve, int32 DeviceID, FString & UInt64Value, EBPOVRResultSwitch & Result)
757{
758#if !STEAMVR_SUPPORTED_PLATFORM
760 return;
761#else
762
763 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
764 {
766 return;
767 }
768
769 vr::IVRSystem* VRSystem = vr::VRSystem();
770
771 if (!VRSystem)
772 {
774 return;
775 }
776
777 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
778
779 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT("EVRDeviceProperty_UInt64"), static_cast<uint8>(PropertyToRetrieve));
780 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
781 {
783 return;
784 }
785
786 uint64 ret = VRSystem->GetUint64TrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
787
788 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
789 {
791 return;
792 }
793
794 UInt64Value = FString::Printf(TEXT("%llu"), ret);
796 return;
797
798#endif
799}
800
801void UOpenVRExpansionFunctionLibrary::GetVRDevicePropertyMatrix34AsTransform(EVRDeviceProperty_Matrix34 PropertyToRetrieve, int32 DeviceID, FTransform & TransformValue, EBPOVRResultSwitch & Result)
802{
803#if !STEAMVR_SUPPORTED_PLATFORM
805 return;
806#else
807
808 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() != SteamVRSystemName))
809 {
811 return;
812 }
813
814 vr::IVRSystem* VRSystem = vr::VRSystem();
815
816 if (!VRSystem)
817 {
819 return;
820 }
821
822 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
823
824 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT("EVRDeviceProperty_Matrix34"), static_cast<uint8>(PropertyToRetrieve));
825 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
826 {
828 return;
829 }
830
831 vr::HmdMatrix34_t ret = VRSystem->GetMatrix34TrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
832
833 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
834 {
836 return;
837 }
838
839 TransformValue = FTransform(ToFMatrix(ret));
841 return;
842
843#endif
844}
845
846
848{
849#if !STEAMVR_SUPPORTED_PLATFORM
851#else
852
853 if (OpenVRDeviceIndex < 0 || OpenVRDeviceIndex > (vr::k_unMaxTrackedDeviceCount - 1))
855
856 vr::IVRSystem* VRSystem = vr::VRSystem();
857
858 if (!VRSystem)
859 {
860 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VRSystem InterfaceErrored in GetOpenVRDevices"));
862 }
863
864 return (EBPOpenVRTrackedDeviceClass)VRSystem->GetTrackedDeviceClass(OpenVRDeviceIndex);
865#endif
866}
867
868void UOpenVRExpansionFunctionLibrary::GetOpenVRDevices(TArray<EBPOpenVRTrackedDeviceClass> &FoundDevices)
869{
870#if !STEAMVR_SUPPORTED_PLATFORM
871#else
872
873 vr::IVRSystem* VRSystem = vr::VRSystem();
874
875 if (!VRSystem)
876 {
877 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VRSystem InterfaceErrored in GetOpenVRDevices"));
878 return;
879 }
880
881 vr::ETrackedDeviceClass DeviceClass = vr::ETrackedDeviceClass::TrackedDeviceClass_Invalid;
882 for (vr::TrackedDeviceIndex_t deviceIndex = vr::k_unTrackedDeviceIndex_Hmd; deviceIndex < vr::k_unMaxTrackedDeviceCount; ++deviceIndex)
883 {
884 DeviceClass = VRSystem->GetTrackedDeviceClass(deviceIndex);
885
886 if (VRSystem->GetTrackedDeviceClass(deviceIndex) != vr::ETrackedDeviceClass::TrackedDeviceClass_Invalid)
887 FoundDevices.Add((EBPOpenVRTrackedDeviceClass)DeviceClass);
888 }
889#endif
890}
891
893{
894#if !STEAMVR_SUPPORTED_PLATFORM
895#else
896
897 vr::IVRSystem* VRSystem = vr::VRSystem();
898
899 if (!VRSystem)
900 {
901 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VRSystem InterfaceErrored in GetOpenVRDevices"));
902 return;
903 }
904
905 for (vr::TrackedDeviceIndex_t deviceIndex = vr::k_unTrackedDeviceIndex_Hmd; deviceIndex < vr::k_unMaxTrackedDeviceCount; ++deviceIndex)
906 {
907 if (VRSystem->GetTrackedDeviceClass(deviceIndex) == (vr::ETrackedDeviceClass)TypeToRetreive)
908 FoundIndexs.Add(deviceIndex);
909 }
910#endif
911}
912
914{
915#if !STEAMVR_SUPPORTED_PLATFORM
916 return false;
917#else
918
919 vr::IVRSystem* VRSystem = vr::VRSystem();
920
921 if (!VRSystem)
922 {
923 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VRSystem InterfaceErrored in IsOpenVRDeviceConnected"));
924 return false;
925 }
926
927 return VRSystem->IsTrackedDeviceConnected(OpenVRDeviceIndex);
928
929#endif
930}
931
932UTexture2D * UOpenVRExpansionFunctionLibrary::GetVRDeviceModelAndTexture(UObject* WorldContextObject, FString RenderModelNameOverride, FString& RenderModelNameOut, EBPOpenVRTrackedDeviceClass DeviceType, TArray<UProceduralMeshComponent *> ProceduralMeshComponentsToFill, bool bCreateCollision, EAsyncBlueprintResultSwitch &Result, int32 OverrideDeviceID)
933{
934
935#if !STEAMVR_SUPPORTED_PLATFORM
936 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
938 return NULL;
939#else
940
941 vr::IVRSystem* VRSystem = vr::VRSystem();
942
943 if (!VRSystem)
944 {
945 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VRSystem InterfaceErrored"));
946 }
947
948 vr::IVRRenderModels* VRRenderModels = vr::VRRenderModels();
949
950 if (!VRRenderModels)
951 {
952 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Render Models Errored"));
953 }
954
955
956 if (!VRSystem || !VRRenderModels)
957 {
958 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Couldn't Get Interfaces!!"));
960 return nullptr;
961 }
962
963 char RenderModelName[vr::k_unMaxPropertyStringSize];
964 FMemory::Memzero(&RenderModelName, vr::k_unMaxPropertyStringSize);
965
966 if (!RenderModelNameOverride.IsEmpty())
967 {
968 int len = RenderModelNameOverride.Len();
969 FMemory::Memcpy(&RenderModelName, TCHAR_TO_ANSI(*RenderModelNameOverride), len > vr::k_unMaxPropertyStringSize ? vr::k_unMaxPropertyStringSize : len);
970 RenderModelNameOut = RenderModelNameOverride;
971 }
972 else
973 {
974 int32 DeviceID = 0;
975 if (OverrideDeviceID != -1)
976 {
977 DeviceID = (uint32)OverrideDeviceID;
978 if (OverrideDeviceID > (vr::k_unMaxTrackedDeviceCount - 1) || VRSystem->GetTrackedDeviceClass(DeviceID) == vr::k_unTrackedDeviceIndexInvalid)
979 {
980 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Override Tracked Device Was Missing!!"));
982 return nullptr;
983 }
984 }
985 else
986 {
987 TArray<int32> FoundIDs;
989
990 if (FoundIDs.Num() == 0)
991 {
992 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Couldn't Get Tracked Devices!!"));
994 return nullptr;
995 }
996
997 DeviceID = FoundIDs[0];
998 }
999
1000 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
1001
1002 uint32_t buffersize = vr::k_unMaxPropertyStringSize;
1003 uint32_t ret = VRSystem->GetStringTrackedDeviceProperty(DeviceID, vr::ETrackedDeviceProperty::Prop_RenderModelName_String, RenderModelName, buffersize, &pError);
1004
1005 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
1006 {
1007 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Couldn't Get Render Model Name String!!"));
1009 return nullptr;
1010
1011 }
1012
1013 RenderModelNameOut = FString(ANSI_TO_TCHAR(RenderModelName));
1014 }
1015
1016 //uint32_t numComponents = VRRenderModels->GetComponentCount("vr_controller_vive_1_5");
1017 //UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("NumComponents: %i"), (int32)numComponents);
1018 // if numComponents > 0 load each, otherwise load the main one only
1019
1020 vr::RenderModel_t *RenderModel = NULL;
1021
1022 //VRRenderModels->LoadRenderModel()
1023 vr::EVRRenderModelError ModelErrorCode = VRRenderModels->LoadRenderModel_Async(RenderModelName, &RenderModel);
1024
1025 if (ModelErrorCode != vr::EVRRenderModelError::VRRenderModelError_None)
1026 {
1027 if (ModelErrorCode != vr::EVRRenderModelError::VRRenderModelError_Loading)
1028 {
1029 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Couldn't Load Model!!"));
1031 }
1032 else
1034
1035 return nullptr;
1036 }
1037
1038 if (!RenderModel)
1039 {
1040 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Couldn't Load Model!!"));
1042 return nullptr;
1043 }
1044
1045 vr::TextureID_t texID = RenderModel->diffuseTextureId;
1046 vr::RenderModel_TextureMap_t * texture = NULL;
1047 UTexture2D* OutTexture = nullptr;
1048
1049 if (texID != vr::INVALID_TEXTURE_ID)
1050 {
1051 //UTexture2DDynamic * OutTexture = nullptr;
1052 vr::EVRRenderModelError TextureErrorCode = VRRenderModels->LoadTexture_Async(texID, &texture);
1053
1054 if (TextureErrorCode != vr::EVRRenderModelError::VRRenderModelError_None)
1055 {
1056 if (TextureErrorCode != vr::EVRRenderModelError::VRRenderModelError_Loading)
1057 {
1058 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Couldn't Load Texture!!"));
1060 }
1061 else
1063
1064 return nullptr;
1065 }
1066
1067 if (!texture)
1068 {
1069 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Couldn't Load Texture!!"));
1071 return nullptr;
1072 }
1073 }
1074
1075 if (ProceduralMeshComponentsToFill.Num() > 0)
1076 {
1077 TArray<FVector> vertices;
1078 TArray<int32> triangles;
1079 TArray<FVector> normals;
1080 TArray<FVector2D> UV0;
1081 TArray<FColor> vertexColors;
1082 TArray<FProcMeshTangent> tangents;
1083
1084 vr::HmdVector3_t vPosition;
1085 vr::HmdVector3_t vNormal;
1086
1087 vertices.Reserve(RenderModel->unVertexCount);
1088 normals.Reserve(RenderModel->unVertexCount);
1089 UV0.Reserve(RenderModel->unVertexCount);
1090
1091 for (uint32_t i = 0; i < RenderModel->unVertexCount; ++i)
1092 {
1093 vPosition = RenderModel->rVertexData[i].vPosition;
1094 // OpenVR y+ Up, +x Right, -z Going away
1095 // UE4 z+ up, +y right, +x forward
1096
1097 vertices.Add(FVector(-vPosition.v[2], vPosition.v[0], vPosition.v[1]));
1098
1099 vNormal = RenderModel->rVertexData[i].vNormal;
1100
1101 normals.Add(FVector(-vNormal.v[2], vNormal.v[0], vNormal.v[1]));
1102
1103 UV0.Add(FVector2D(RenderModel->rVertexData[i].rfTextureCoord[0], RenderModel->rVertexData[i].rfTextureCoord[1]));
1104 }
1105
1106 triangles.Reserve(RenderModel->unTriangleCount);
1107 for (uint32_t i = 0; i < RenderModel->unTriangleCount * 3; i += 3)
1108 {
1109 triangles.Add(RenderModel->rIndexData[i]);
1110 triangles.Add(RenderModel->rIndexData[i + 1]);
1111 triangles.Add(RenderModel->rIndexData[i + 2]);
1112 }
1113
1114 float scale = UHeadMountedDisplayFunctionLibrary::GetWorldToMetersScale(WorldContextObject);
1115 for (int i = 0; i < ProceduralMeshComponentsToFill.Num(); ++i)
1116 {
1117 ProceduralMeshComponentsToFill[i]->ClearAllMeshSections();
1118 ProceduralMeshComponentsToFill[i]->CreateMeshSection(0, vertices, triangles, normals, UV0, vertexColors, tangents, bCreateCollision);
1119 ProceduralMeshComponentsToFill[i]->SetMeshSectionVisible(0, true);
1120 ProceduralMeshComponentsToFill[i]->SetWorldScale3D(FVector(scale, scale, scale));
1121 }
1122 }
1123
1124 if (texture != nullptr)
1125 {
1126 uint32 Width = texture->unWidth;
1127 uint32 Height = texture->unHeight;
1128
1129
1130 //OutTexture = UTexture2DDynamic::Create(Width, Height, PF_R8G8B8A8);
1131 OutTexture = UTexture2D::CreateTransient(Width, Height, PF_R8G8B8A8);
1132
1133
1134 //FTexture2DDynamicResource * TexResource = static_cast<FTexture2DDynamicResource*>(OutTexture->Resource);
1135 //FTexture2DRHIParamRef TextureRHI = TexResource->GetTexture2DRHI();
1136
1137 //uint32 DestStride = 0;
1138 //uint8* MipData = reinterpret_cast<uint8*>(RHILockTexture2D(TextureRHI, 0, RLM_WriteOnly, DestStride, false, false));
1139
1140 uint8* MipData = (uint8*)OutTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
1141 FMemory::Memcpy(MipData, (void*)texture->rubTextureMapData, Height * Width * 4);
1142 OutTexture->PlatformData->Mips[0].BulkData.Unlock();
1143 //RHIUnlockTexture2D(TextureRHI, 0, false, false);
1144
1145
1146 //Setting some Parameters for the Texture and finally returning it
1147 OutTexture->PlatformData->SetNumSlices(1);
1148 OutTexture->NeverStream = true;
1149 OutTexture->UpdateResource();
1150
1151 /*if (bReturnRawTexture)
1152 {
1153 OutRawTexture.AddUninitialized(Height * Width * 4);
1154 FMemory::Memcpy(OutRawTexture.GetData(), (void*)texture->rubTextureMapData, Height * Width * 4);
1155 }*/
1156
1158 VRRenderModels->FreeTexture(texture);
1159 }
1160
1161 VRRenderModels->FreeRenderModel(RenderModel);
1162 return OutTexture;
1163#endif
1164}
1165
1166
1167bool UOpenVRExpansionFunctionLibrary::SetSkyboxOverride_LatLongStereoPair(UTexture2D * LatLongSkyboxL, UTexture2D * LatLongSkyboxR)
1168{
1169#if !STEAMVR_SUPPORTED_PLATFORM
1170 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1171 return false;
1172#else
1173
1174 if (!LatLongSkyboxL || !LatLongSkyboxR)
1175 {
1176 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Bad texture passed in to SetSkyBoxOverride"));
1177 return false;
1178 }
1179
1180 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1181
1182 if (!VRCompositor)
1183 {
1184 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1185 return false;
1186 }
1187
1188 vr::Texture_t TextureArray[2];
1189
1190 TextureArray[0] = CreateOpenVRTexture_t(LatLongSkyboxL);
1191 TextureArray[1] = CreateOpenVRTexture_t(LatLongSkyboxR);
1192
1193 vr::EVRCompositorError CompositorError;
1194 CompositorError = VRCompositor->SetSkyboxOverride(TextureArray, 2);
1195
1196 if (CompositorError != vr::VRCompositorError_None)
1197 {
1198 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor Error %i"), (int32)CompositorError);
1199 return false;
1200 }
1201
1202 return true;
1203
1204#endif
1205}
1206
1208{
1209#if !STEAMVR_SUPPORTED_PLATFORM
1210 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1211 return false;
1212#else
1213 if (!LatLongSkybox)
1214 {
1215 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Bad texture passed in to SetSkyBoxOverride"));
1216 return false;
1217 }
1218
1219 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1220
1221 if (!VRCompositor)
1222 {
1223 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1224 return false;
1225 }
1226
1227 vr::Texture_t Texture;
1228
1229 Texture = CreateOpenVRTexture_t(LatLongSkybox);
1230
1231 vr::EVRCompositorError CompositorError;
1232 CompositorError = VRCompositor->SetSkyboxOverride(&Texture, 1);
1233
1234 if (CompositorError != vr::VRCompositorError_None)
1235 {
1236 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor Error %i"), (int32)CompositorError);
1237 return false;
1238 }
1239
1240 return true;
1241#endif
1242}
1243
1244
1245bool UOpenVRExpansionFunctionLibrary::SetSkyboxOverride(UTexture * tFront, UTexture2D * tBack, UTexture * tLeft, UTexture * tRight, UTexture * tTop, UTexture * tBottom)
1246{
1247#if !STEAMVR_SUPPORTED_PLATFORM
1248 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1249 return false;
1250#else
1251 if (!tFront || !tBack || !tLeft || !tRight || !tTop || !tBottom)
1252 {
1253 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Bad texture passed in to SetSkyBoxOverride"));
1254 return false;
1255 }
1256
1257 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1258
1259 if (!VRCompositor)
1260 {
1261 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1262 return false;
1263 }
1264
1265 vr::Texture_t TextureArray[6];
1266
1267 TextureArray[0] = CreateOpenVRTexture_t(tFront);
1268 TextureArray[1] = CreateOpenVRTexture_t(tBack);
1269 TextureArray[2] = CreateOpenVRTexture_t(tLeft);
1270 TextureArray[3] = CreateOpenVRTexture_t(tRight);
1271 TextureArray[4] = CreateOpenVRTexture_t(tTop);
1272 TextureArray[5] = CreateOpenVRTexture_t(tBottom);
1273
1274 vr::EVRCompositorError CompositorError;
1275 CompositorError = VRCompositor->SetSkyboxOverride(TextureArray, 6);
1276
1277 if (CompositorError != vr::VRCompositorError_None)
1278 {
1279 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor Error %i"), (int32)CompositorError);
1280 return false;
1281 }
1282
1283 return true;
1284#endif
1285}
1286
1288{
1289#if !STEAMVR_SUPPORTED_PLATFORM
1290 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1291 return false;
1292#else
1293 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1294
1295 if (!VRCompositor)
1296 {
1297 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1298 return false;
1299 }
1300
1301 VRCompositor->ClearSkyboxOverride();
1302
1303 return true;
1304
1305#endif
1306}
1307
1308bool UOpenVRExpansionFunctionLibrary::FadeHMDToColor(float fSeconds, FColor Color, bool bBackground)
1309{
1310#if !STEAMVR_SUPPORTED_PLATFORM
1311 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1312 return false;
1313#else
1314 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1315
1316 if (!VRCompositor)
1317 {
1318 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1319 return false;
1320 }
1321
1322 VRCompositor->FadeToColor(fSeconds, Color.R, Color.G, Color.B, Color.A, bBackground);
1323
1324 return true;
1325
1326#endif
1327}
1328
1329bool UOpenVRExpansionFunctionLibrary::GetCurrentHMDFadeColor(FColor & ColorOut, bool bBackground)
1330{
1331#if !STEAMVR_SUPPORTED_PLATFORM
1332 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1333 return false;
1334#else
1335 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1336
1337 if (!VRCompositor)
1338 {
1339 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1340 return false;
1341 }
1342
1343 vr::HmdColor_t HMDColor = VRCompositor->GetCurrentFadeColor(bBackground);
1344
1345 ColorOut = FColor(HMDColor.r, HMDColor.g, HMDColor.b, HMDColor.a);
1346 return true;
1347
1348#endif
1349}
1350
1351bool UOpenVRExpansionFunctionLibrary::FadeVRGrid(float fSeconds, bool bFadeIn)
1352{
1353#if !STEAMVR_SUPPORTED_PLATFORM
1354 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1355 return false;
1356#else
1357 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1358
1359 if (!VRCompositor)
1360 {
1361 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1362 return false;
1363 }
1364
1365 VRCompositor->FadeGrid(fSeconds, bFadeIn);
1366 return true;
1367
1368#endif
1369}
1370
1372{
1373#if !STEAMVR_SUPPORTED_PLATFORM
1374 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1375 return false;
1376#else
1377 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1378
1379 if (!VRCompositor)
1380 {
1381 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1382 return false;
1383 }
1384
1385 VRGridAlpha = VRCompositor->GetCurrentGridAlpha();
1386 return true;
1387
1388#endif
1389}
1390
1392{
1393#if !STEAMVR_SUPPORTED_PLATFORM
1394 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("Not SteamVR Supported Platform!!"));
1395 return false;
1396#else
1397 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1398
1399 if (!VRCompositor)
1400 {
1401 UE_LOG(OpenVRExpansionFunctionLibraryLog, Warning, TEXT("VR Compositor InterfaceErrored"));
1402 return false;
1403 }
1404
1405 VRCompositor->SuspendRendering(bSuspendRendering);
1406 return true;
1407
1408#endif
1409}
DEFINE_LOG_CATEGORY(OpenVRExpansionFunctionLibraryLog)
EAsyncBlueprintResultSwitch
UENUM()
EVRDeviceProperty_UInt64
UENUM(BlueprintType)
EBPOpenVRTrackedDeviceClass
UENUM()
static FName SteamVRSystemName(TEXT("SteamVR"))
EVRDeviceProperty_Bool
UENUM(BlueprintType)
EBPOpenVRControllerDeviceType
UENUM(Blueprintable)
EBPOVRResultSwitch
UENUM()
EVRDeviceProperty_String
UENUM(BlueprintType)
EVRDeviceProperty_Int32
UENUM(BlueprintType)
EOpenVRCameraFrameType
UENUM(BlueprintType)
EVRDeviceProperty_Float
UENUM(BlueprintType)
EVRDeviceProperty_Matrix34
UENUM(BlueprintType)
EBPOpenVRHMDDeviceType
UENUM(Blueprintable)
static void ReleaseVRCamera(UPARAM(ref) FBPOpenVRCameraHandle &CameraHandle, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|VRCamera", meta = (bIgnoreSelf ...
static UTexture2D * CreateCameraTexture2D(UPARAM(ref) FBPOpenVRCameraHandle &CameraHandle, EOpenVRCameraFrameType FrameType, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|VRCamera", meta = (bIgnoreSelf ...
static bool SetSkyboxOverride_LatLong(UTexture2D *LatLongSkybox)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static void GetVRDevicePropertyString(EVRDeviceProperty_String PropertyToRetrieve, int32 DeviceID, FString &StringValue, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static EBPOpenVRControllerDeviceType GetOpenVRControllerType()
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static bool IsValid(UPARAM(ref) FBPOpenVRCameraHandle &CameraHandle)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|VRCamera", meta = (bIgnoreSelf ...
static void GetOpenVRDevices(TArray< EBPOpenVRTrackedDeviceClass > &FoundDevices)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true")...
static bool ClearSkyboxOverride()
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static bool SetSkyboxOverride(UTexture *tFront, UTexture2D *tBack, UTexture *tLeft, UTexture *tRight, UTexture *tTop, UTexture *tBottom)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
UOpenVRExpansionFunctionLibrary(const FObjectInitializer &ObjectInitializer)
static void GetVRDevicePropertyInt32(EVRDeviceProperty_Int32 PropertyToRetrieve, int32 DeviceID, int32 &IntValue, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static bool SetSuspendRendering(bool bSuspendRendering)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static void GetOpenVRDevicesByType(EBPOpenVRTrackedDeviceClass TypeToRetreive, TArray< int32 > &FoundIndexs)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true")...
static void AcquireVRCamera(FBPOpenVRCameraHandle &CameraHandle, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|VRCamera", meta = (bIgnoreSelf ...
static void GetVRDevicePropertyBool(EVRDeviceProperty_Bool PropertyToRetrieve, int32 DeviceID, bool &BoolValue, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static bool HasVRCamera(EOpenVRCameraFrameType FrameType, int32 &Width, int32 &Height)
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions|SteamVR|VRCamera", meta = (bIgnoreSelf = "t...
static bool FadeHMDToColor(float fSeconds, FColor Color, bool bBackground=false)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static bool GetCurrentHMDFadeColor(FColor &ColorOut, bool bBackground=false)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static bool IsOpenVRDeviceConnected(int32 DeviceIndex)
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true"))
static UTexture2D * GetVRDeviceModelAndTexture(UObject *WorldContextObject, FString RenderModelNameOverride, FString &RenderModelNameOut, EBPOpenVRTrackedDeviceClass DeviceType, TArray< UProceduralMeshComponent * > ProceduralMeshComponentsToFill, bool bCreateCollision, EAsyncBlueprintResultSwitch &Result, int32 OverrideDeviceID=-1)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static bool GetCurrentVRGridAlpha(float &VRGridAlpha)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static void GetVRDevicePropertyUInt64(EVRDeviceProperty_UInt64 PropertyToRetrieve, int32 DeviceID, FString &UInt64Value, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static EBPOpenVRHMDDeviceType GetOpenVRHMDType()
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static void GetVRDevicePropertyFloat(EVRDeviceProperty_Float PropertyToRetrieve, int32 DeviceID, float &FloatValue, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
static bool SetSkyboxOverride_LatLongStereoPair(UTexture2D *LatLongSkyboxL, UTexture2D *LatLongSkyboxR)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static void GetVRCameraFrame(UPARAM(ref) FBPOpenVRCameraHandle &CameraHandle, EOpenVRCameraFrameType FrameType, EBPOVRResultSwitch &Result, UTexture2D *TargetRenderTarget=nullptr)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|VRCamera", meta = (bIgnoreSelf ...
static EBPOpenVRTrackedDeviceClass GetOpenVRDeviceType(int32 DeviceIndex)
UFUNCTION(BlueprintPure, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true"))
static bool FadeVRGrid(float fSeconds, bool bFadeIn)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR|Compositor",...
static void GetVRDevicePropertyMatrix34AsTransform(EVRDeviceProperty_Matrix34 PropertyToRetrieve, int32 DeviceID, FTransform &TransformValue, EBPOVRResultSwitch &Result)
UFUNCTION(BlueprintCallable, Category = "VRExpansionFunctions|SteamVR", meta = (bIgnoreSelf = "true",...
USTRUCT(BlueprintType, Category = "VRExpansionFunctions|SteamVR|VRCamera")