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"
14#include "Editor/UnrealEd/Classes/Editor/EditorEngine.h"
20#if STEAMVR_SUPPORTED_PLATFORM
27 : Super(ObjectInitializer)
34#if STEAMVR_SUPPORTED_PLATFORM
45 if (GEngine && GEngine->XRSystem.IsValid())
49 static const FName OculusSystemName(TEXT(
"OculusHMD"));
52 FName DeviceName(NAME_None);
53 DeviceName = GEngine->XRSystem->GetSystemName();
58 else if (DeviceName == OculusSystemName)
64#if !STEAMVR_SUPPORTED_PLATFORM
65 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Get OpenVRHMDType returning default value as this is not a steamvr supported platform!!!"));
72 FString DeviceModelNumber;
98 if (DeviceModelNumber.Find(
"index", ESearchCase::IgnoreCase) != INDEX_NONE)
102 else if (DeviceModelNumber.Find(
"vive_cosmos", ESearchCase::IgnoreCase) != INDEX_NONE)
106 else if (DeviceModelNumber.Find(
"vive", ESearchCase::IgnoreCase) != INDEX_NONE)
108 if (DeviceModelNumber.Find(
"focus3", ESearchCase::IgnoreCase) != INDEX_NONE)
112 else if (DeviceModelNumber.Find(
"focus", ESearchCase::IgnoreCase) != INDEX_NONE)
116 else if (DeviceModelNumber.Find(
"Pico Neo3", ESearchCase::IgnoreCase) != INDEX_NONE)
125 else if ((DeviceModelNumber.Find(
"oculus quest", ESearchCase::IgnoreCase) != INDEX_NONE) ||
126 (DeviceModelNumber.Find(
"miramar", ESearchCase::IgnoreCase) != INDEX_NONE))
130 else if (DeviceModelNumber.Find(
"oculus", ESearchCase::IgnoreCase) != INDEX_NONE)
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
148 if (DeviceModelNumber.Find(
"WindowsMR", ESearchCase::IgnoreCase) != INDEX_NONE)
157 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Tell VRE about unhandled HMD model type: %s !!!"), *DeviceModelNumber);
164 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Get OpenVRHMDType failed to get the OpenVR property string!!!"));
177#if !STEAMVR_SUPPORTED_PLATFORM
181 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
186 vr::IVRSystem* VRSystem = vr::VRSystem();
193 int32 DeviceIndexOut = INDEX_NONE;
194 int32 FallbackIndex = INDEX_NONE;
196 for (uint32 DeviceIndex = 0; DeviceIndex < vr::k_unMaxTrackedDeviceCount; ++DeviceIndex)
198 const vr::ETrackedDeviceClass DeviceClass = VRSystem->GetTrackedDeviceClass(DeviceIndex);
199 if (DeviceClass == vr::ETrackedDeviceClass::TrackedDeviceClass_Controller)
202 const vr::ETrackedControllerRole ControllerRole = VRSystem->GetControllerRoleForTrackedDeviceIndex(DeviceIndex);
203 if (ControllerRole != vr::TrackedControllerRole_LeftHand && ControllerRole != vr::TrackedControllerRole_RightHand)
208 DeviceIndexOut = DeviceIndex;
213 if (DeviceIndexOut == INDEX_NONE)
220 FString DeviceModelNumber;
224 if (DeviceModelNumber.Find(
"knuckles", ESearchCase::IgnoreCase) != INDEX_NONE || DeviceModelNumber.Find(
"index", ESearchCase::IgnoreCase) != INDEX_NONE)
228 else if (DeviceModelNumber.Find(
"cosmos", ESearchCase::IgnoreCase) != INDEX_NONE)
232 else if (DeviceModelNumber.Find(
"VIVE", ESearchCase::IgnoreCase) != INDEX_NONE)
236 else if ((DeviceModelNumber.Find(
"oculus quest", ESearchCase::IgnoreCase) != INDEX_NONE) ||
237 (DeviceModelNumber.Find(
"miramar", ESearchCase::IgnoreCase) != INDEX_NONE))
241 else if (DeviceModelNumber.Find(
"oculus rift cv1", ESearchCase::IgnoreCase) != INDEX_NONE)
245 else if (DeviceModelNumber.Find(
"oculus rift s", ESearchCase::IgnoreCase) != INDEX_NONE)
249 else if (DeviceModelNumber.Find(
"windowsmr", ESearchCase::IgnoreCase) != INDEX_NONE)
253 else if (DeviceModelNumber.Find(
"Pico Neo3 Controller", ESearchCase::IgnoreCase) != INDEX_NONE)
260 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Tell VRE about unhandled controller model type: %s !!!"), *DeviceModelNumber);
272#if !STEAMVR_SUPPORTED_PLATFORM
282 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
285 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
292 vr::EVRTrackedCameraError CamError = VRCamera->HasCamera(vr::k_unTrackedDeviceIndex_Hmd, &pHasCamera);
294 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None)
299 uint32 FrameBufferSize;
300 CamError = VRCamera->GetCameraFrameSize(vr::k_unTrackedDeviceIndex_Hmd, (vr::EVRTrackedCameraFrameType)FrameType, &WidthOut, &HeightOut, &FrameBufferSize);
312#if !STEAMVR_SUPPORTED_PLATFORM
318 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
325 if (OpenCamera.IsValid())
327 CameraHandle = OpenCamera;
332 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
340 vr::EVRTrackedCameraError CamError = VRCamera->AcquireVideoStreamingService(vr::k_unTrackedDeviceIndex_Hmd, &CameraHandle.
pCameraHandle);
342 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None)
345 if (CameraHandle.
pCameraHandle == INVALID_TRACKED_CAMERA_HANDLE)
351 OpenCamera = CameraHandle;
359#if !STEAMVR_SUPPORTED_PLATFORM
365 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
371 if (!CameraHandle.IsValid())
378 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
386 vr::EVRTrackedCameraError CamError = VRCamera->ReleaseVideoStreamingService(CameraHandle.pCameraHandle);
387 CameraHandle.pCameraHandle = INVALID_TRACKED_CAMERA_HANDLE;
389 OpenCamera = CameraHandle;
398 return (CameraHandle.IsValid());
404#if !STEAMVR_SUPPORTED_PLATFORM
410 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
416 if (!CameraHandle.IsValid() || !FApp::CanEverRender())
422 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
432 uint32 FrameBufferSize;
433 vr::EVRTrackedCameraError CamError = VRCamera->GetCameraFrameSize(vr::k_unTrackedDeviceIndex_Hmd, (vr::EVRTrackedCameraFrameType)FrameType, &Width, &Height, &FrameBufferSize);
435 if (Width > 0 && Height > 0)
438 UTexture2D * NewRenderTarget2D = UTexture2D::CreateTransient(Width, Height, EPixelFormat::PF_R8G8B8A8);
439 check(NewRenderTarget2D);
442 NewRenderTarget2D->PlatformData->SetNumSlices(1);
443 NewRenderTarget2D->NeverStream =
true;
444 NewRenderTarget2D->UpdateResource();
447 return NewRenderTarget2D;
457#if !STEAMVR_SUPPORTED_PLATFORM
463 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
469 if (!TargetRenderTarget || !CameraHandle.IsValid())
475 vr::IVRTrackedCamera* VRCamera = vr::VRTrackedCamera();
485 uint32 FrameBufferSize;
486 vr::EVRTrackedCameraError CamError = VRCamera->GetCameraFrameSize(vr::k_unTrackedDeviceIndex_Hmd, (vr::EVRTrackedCameraFrameType)FrameType, &Width, &Height, &FrameBufferSize);
488 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None || Width <= 0 || Height <= 0)
495 check(FrameBufferSize == (Width * Height * GPixelFormats[EPixelFormat::PF_R8G8B8A8].BlockBytes));
501 if (TargetRenderTarget->GetSizeX() != Width || TargetRenderTarget->GetSizeY() != Height || TargetRenderTarget->GetPixelFormat() != EPixelFormat::PF_R8G8B8A8)
503 TargetRenderTarget->PlatformData->SizeX = Width;
504 TargetRenderTarget->PlatformData->SizeY = Height;
505 TargetRenderTarget->PlatformData->PixelFormat = EPixelFormat::PF_R8G8B8A8;
508 int32 NumBlocksX = Width / GPixelFormats[EPixelFormat::PF_R8G8B8A8].BlockSizeX;
509 int32 NumBlocksY = Height / GPixelFormats[EPixelFormat::PF_R8G8B8A8].BlockSizeY;
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();
518 vr::CameraVideoStreamFrameHeader_t CamHeader;
519 uint8* pData =
new uint8[FrameBufferSize];
521 CamError = VRCamera->GetVideoStreamFrameBuffer(CameraHandle.pCameraHandle, (vr::EVRTrackedCameraFrameType)FrameType, pData, FrameBufferSize, &CamHeader,
sizeof(vr::CameraVideoStreamFrameHeader_t));
524 if (CamError != vr::EVRTrackedCameraError::VRTrackedCameraError_None || CamError == vr::EVRTrackedCameraError::VRTrackedCameraError_NoFrameAvailable)
549 UTexture2D* TexturePtr = TargetRenderTarget;
550 const uint8* TextureData = pData;
551 ENQUEUE_RENDER_COMMAND(OpenVRExpansionPlugin_GetVRCameraFrame)(
552 [TexturePtr, TextureData](FRHICommandList& RHICmdList)
554 FUpdateTextureRegion2D region;
559 region.Width = TexturePtr->GetSizeX();
560 region.Height = TexturePtr->GetSizeY();
562 FTexture2DResource* resource = (FTexture2DResource*)TexturePtr->Resource;
563 RHIUpdateTexture2D(resource->GetTexture2DRHI(), 0, region, region.Width * GPixelFormats[TexturePtr->GetPixelFormat()].BlockBytes, TextureData);
564 delete[] TextureData;
576#if !STEAMVR_SUPPORTED_PLATFORM
581 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
587 vr::IVRSystem* VRSystem = vr::VRSystem();
595 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
597 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT(
"EVRDeviceProperty_String"),
static_cast<uint8
>(PropertyToRetrieve));
598 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
604 char charvalue[vr::k_unMaxPropertyStringSize];
605 uint32_t buffersize = vr::k_unMaxPropertyStringSize;
606 uint32_t ret = VRSystem->GetStringTrackedDeviceProperty(DeviceID, EnumPropertyValue, charvalue, buffersize, &pError);
608 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
614 StringValue = FString(ANSI_TO_TCHAR(charvalue));
623#if !STEAMVR_SUPPORTED_PLATFORM
628 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
634 vr::IVRSystem* VRSystem = vr::VRSystem();
642 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
644 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT(
"EVRDeviceProperty_Bool"),
static_cast<uint8
>(PropertyToRetrieve));
645 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
651 bool ret = VRSystem->GetBoolTrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
653 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
668#if !STEAMVR_SUPPORTED_PLATFORM
673 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
679 vr::IVRSystem* VRSystem = vr::VRSystem();
687 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
689 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT(
"EVRDeviceProperty_Float"),
static_cast<uint8
>(PropertyToRetrieve));
690 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
696 float ret = VRSystem->GetFloatTrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
698 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
713#if !STEAMVR_SUPPORTED_PLATFORM
718 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
724 vr::IVRSystem* VRSystem = vr::VRSystem();
732 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
734 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT(
"EVRDeviceProperty_Int32"),
static_cast<uint8
>(PropertyToRetrieve));
735 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
741 int32 ret = VRSystem->GetInt32TrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
743 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
758#if !STEAMVR_SUPPORTED_PLATFORM
763 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
769 vr::IVRSystem* VRSystem = vr::VRSystem();
777 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
779 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT(
"EVRDeviceProperty_UInt64"),
static_cast<uint8
>(PropertyToRetrieve));
780 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
786 uint64 ret = VRSystem->GetUint64TrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
788 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
794 UInt64Value = FString::Printf(TEXT(
"%llu"), ret);
803#if !STEAMVR_SUPPORTED_PLATFORM
808 if (!GEngine->XRSystem.IsValid() || (GEngine->XRSystem->GetSystemName() !=
SteamVRSystemName))
814 vr::IVRSystem* VRSystem = vr::VRSystem();
822 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
824 vr::ETrackedDeviceProperty EnumPropertyValue = VREnumToString(TEXT(
"EVRDeviceProperty_Matrix34"),
static_cast<uint8
>(PropertyToRetrieve));
825 if (EnumPropertyValue == vr::ETrackedDeviceProperty::Prop_Invalid)
831 vr::HmdMatrix34_t ret = VRSystem->GetMatrix34TrackedDeviceProperty(DeviceID, EnumPropertyValue, &pError);
833 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
839 TransformValue = FTransform(ToFMatrix(ret));
849#if !STEAMVR_SUPPORTED_PLATFORM
853 if (OpenVRDeviceIndex < 0 || OpenVRDeviceIndex > (vr::k_unMaxTrackedDeviceCount - 1))
856 vr::IVRSystem* VRSystem = vr::VRSystem();
860 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VRSystem InterfaceErrored in GetOpenVRDevices"));
870#if !STEAMVR_SUPPORTED_PLATFORM
873 vr::IVRSystem* VRSystem = vr::VRSystem();
877 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VRSystem InterfaceErrored in GetOpenVRDevices"));
881 vr::ETrackedDeviceClass DeviceClass = vr::ETrackedDeviceClass::TrackedDeviceClass_Invalid;
882 for (vr::TrackedDeviceIndex_t deviceIndex = vr::k_unTrackedDeviceIndex_Hmd; deviceIndex < vr::k_unMaxTrackedDeviceCount; ++deviceIndex)
884 DeviceClass = VRSystem->GetTrackedDeviceClass(deviceIndex);
886 if (VRSystem->GetTrackedDeviceClass(deviceIndex) != vr::ETrackedDeviceClass::TrackedDeviceClass_Invalid)
894#if !STEAMVR_SUPPORTED_PLATFORM
897 vr::IVRSystem* VRSystem = vr::VRSystem();
901 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VRSystem InterfaceErrored in GetOpenVRDevices"));
905 for (vr::TrackedDeviceIndex_t deviceIndex = vr::k_unTrackedDeviceIndex_Hmd; deviceIndex < vr::k_unMaxTrackedDeviceCount; ++deviceIndex)
907 if (VRSystem->GetTrackedDeviceClass(deviceIndex) == (vr::ETrackedDeviceClass)TypeToRetreive)
908 FoundIndexs.Add(deviceIndex);
915#if !STEAMVR_SUPPORTED_PLATFORM
919 vr::IVRSystem* VRSystem = vr::VRSystem();
923 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VRSystem InterfaceErrored in IsOpenVRDeviceConnected"));
927 return VRSystem->IsTrackedDeviceConnected(OpenVRDeviceIndex);
935#if !STEAMVR_SUPPORTED_PLATFORM
936 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
941 vr::IVRSystem* VRSystem = vr::VRSystem();
945 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VRSystem InterfaceErrored"));
948 vr::IVRRenderModels* VRRenderModels = vr::VRRenderModels();
952 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Render Models Errored"));
956 if (!VRSystem || !VRRenderModels)
958 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Couldn't Get Interfaces!!"));
963 char RenderModelName[vr::k_unMaxPropertyStringSize];
964 FMemory::Memzero(&RenderModelName, vr::k_unMaxPropertyStringSize);
966 if (!RenderModelNameOverride.IsEmpty())
968 int len = RenderModelNameOverride.Len();
969 FMemory::Memcpy(&RenderModelName, TCHAR_TO_ANSI(*RenderModelNameOverride), len > vr::k_unMaxPropertyStringSize ? vr::k_unMaxPropertyStringSize : len);
970 RenderModelNameOut = RenderModelNameOverride;
975 if (OverrideDeviceID != -1)
977 DeviceID = (uint32)OverrideDeviceID;
978 if (OverrideDeviceID > (vr::k_unMaxTrackedDeviceCount - 1) || VRSystem->GetTrackedDeviceClass(DeviceID) == vr::k_unTrackedDeviceIndexInvalid)
980 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Override Tracked Device Was Missing!!"));
987 TArray<int32> FoundIDs;
990 if (FoundIDs.Num() == 0)
992 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Couldn't Get Tracked Devices!!"));
997 DeviceID = FoundIDs[0];
1000 vr::TrackedPropertyError pError = vr::TrackedPropertyError::TrackedProp_Success;
1002 uint32_t buffersize = vr::k_unMaxPropertyStringSize;
1003 uint32_t ret = VRSystem->GetStringTrackedDeviceProperty(DeviceID, vr::ETrackedDeviceProperty::Prop_RenderModelName_String, RenderModelName, buffersize, &pError);
1005 if (pError != vr::TrackedPropertyError::TrackedProp_Success)
1007 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Couldn't Get Render Model Name String!!"));
1013 RenderModelNameOut = FString(ANSI_TO_TCHAR(RenderModelName));
1020 vr::RenderModel_t *RenderModel = NULL;
1023 vr::EVRRenderModelError ModelErrorCode = VRRenderModels->LoadRenderModel_Async(RenderModelName, &RenderModel);
1025 if (ModelErrorCode != vr::EVRRenderModelError::VRRenderModelError_None)
1027 if (ModelErrorCode != vr::EVRRenderModelError::VRRenderModelError_Loading)
1029 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Couldn't Load Model!!"));
1040 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Couldn't Load Model!!"));
1045 vr::TextureID_t texID = RenderModel->diffuseTextureId;
1046 vr::RenderModel_TextureMap_t * texture = NULL;
1047 UTexture2D* OutTexture =
nullptr;
1049 if (texID != vr::INVALID_TEXTURE_ID)
1052 vr::EVRRenderModelError TextureErrorCode = VRRenderModels->LoadTexture_Async(texID, &texture);
1054 if (TextureErrorCode != vr::EVRRenderModelError::VRRenderModelError_None)
1056 if (TextureErrorCode != vr::EVRRenderModelError::VRRenderModelError_Loading)
1058 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Couldn't Load Texture!!"));
1069 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Couldn't Load Texture!!"));
1075 if (ProceduralMeshComponentsToFill.Num() > 0)
1077 TArray<FVector> vertices;
1078 TArray<int32> triangles;
1079 TArray<FVector> normals;
1080 TArray<FVector2D> UV0;
1081 TArray<FColor> vertexColors;
1082 TArray<FProcMeshTangent> tangents;
1084 vr::HmdVector3_t vPosition;
1085 vr::HmdVector3_t vNormal;
1087 vertices.Reserve(RenderModel->unVertexCount);
1088 normals.Reserve(RenderModel->unVertexCount);
1089 UV0.Reserve(RenderModel->unVertexCount);
1091 for (uint32_t i = 0; i < RenderModel->unVertexCount; ++i)
1093 vPosition = RenderModel->rVertexData[i].vPosition;
1097 vertices.Add(FVector(-vPosition.v[2], vPosition.v[0], vPosition.v[1]));
1099 vNormal = RenderModel->rVertexData[i].vNormal;
1101 normals.Add(FVector(-vNormal.v[2], vNormal.v[0], vNormal.v[1]));
1103 UV0.Add(FVector2D(RenderModel->rVertexData[i].rfTextureCoord[0], RenderModel->rVertexData[i].rfTextureCoord[1]));
1106 triangles.Reserve(RenderModel->unTriangleCount);
1107 for (uint32_t i = 0; i < RenderModel->unTriangleCount * 3; i += 3)
1109 triangles.Add(RenderModel->rIndexData[i]);
1110 triangles.Add(RenderModel->rIndexData[i + 1]);
1111 triangles.Add(RenderModel->rIndexData[i + 2]);
1114 float scale = UHeadMountedDisplayFunctionLibrary::GetWorldToMetersScale(WorldContextObject);
1115 for (
int i = 0; i < ProceduralMeshComponentsToFill.Num(); ++i)
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));
1124 if (texture !=
nullptr)
1126 uint32 Width = texture->unWidth;
1127 uint32 Height = texture->unHeight;
1131 OutTexture = UTexture2D::CreateTransient(Width, Height, PF_R8G8B8A8);
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();
1147 OutTexture->PlatformData->SetNumSlices(1);
1148 OutTexture->NeverStream =
true;
1149 OutTexture->UpdateResource();
1158 VRRenderModels->FreeTexture(texture);
1161 VRRenderModels->FreeRenderModel(RenderModel);
1169#if !STEAMVR_SUPPORTED_PLATFORM
1170 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1174 if (!LatLongSkyboxL || !LatLongSkyboxR)
1176 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Bad texture passed in to SetSkyBoxOverride"));
1180 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1184 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1188 vr::Texture_t TextureArray[2];
1190 TextureArray[0] = CreateOpenVRTexture_t(LatLongSkyboxL);
1191 TextureArray[1] = CreateOpenVRTexture_t(LatLongSkyboxR);
1193 vr::EVRCompositorError CompositorError;
1194 CompositorError = VRCompositor->SetSkyboxOverride(TextureArray, 2);
1196 if (CompositorError != vr::VRCompositorError_None)
1198 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor Error %i"), (int32)CompositorError);
1209#if !STEAMVR_SUPPORTED_PLATFORM
1210 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1215 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Bad texture passed in to SetSkyBoxOverride"));
1219 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1223 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1227 vr::Texture_t Texture;
1229 Texture = CreateOpenVRTexture_t(LatLongSkybox);
1231 vr::EVRCompositorError CompositorError;
1232 CompositorError = VRCompositor->SetSkyboxOverride(&Texture, 1);
1234 if (CompositorError != vr::VRCompositorError_None)
1236 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor Error %i"), (int32)CompositorError);
1247#if !STEAMVR_SUPPORTED_PLATFORM
1248 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1251 if (!tFront || !tBack || !tLeft || !tRight || !tTop || !tBottom)
1253 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Bad texture passed in to SetSkyBoxOverride"));
1257 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1261 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1265 vr::Texture_t TextureArray[6];
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);
1274 vr::EVRCompositorError CompositorError;
1275 CompositorError = VRCompositor->SetSkyboxOverride(TextureArray, 6);
1277 if (CompositorError != vr::VRCompositorError_None)
1279 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor Error %i"), (int32)CompositorError);
1289#if !STEAMVR_SUPPORTED_PLATFORM
1290 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1293 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1297 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1301 VRCompositor->ClearSkyboxOverride();
1310#if !STEAMVR_SUPPORTED_PLATFORM
1311 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1314 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1318 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1322 VRCompositor->FadeToColor(fSeconds, Color.R, Color.G, Color.B, Color.A, bBackground);
1331#if !STEAMVR_SUPPORTED_PLATFORM
1332 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1335 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1339 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1343 vr::HmdColor_t HMDColor = VRCompositor->GetCurrentFadeColor(bBackground);
1345 ColorOut = FColor(HMDColor.r, HMDColor.g, HMDColor.b, HMDColor.a);
1353#if !STEAMVR_SUPPORTED_PLATFORM
1354 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1357 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1361 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1365 VRCompositor->FadeGrid(fSeconds, bFadeIn);
1373#if !STEAMVR_SUPPORTED_PLATFORM
1374 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1377 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1381 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1385 VRGridAlpha = VRCompositor->GetCurrentGridAlpha();
1393#if !STEAMVR_SUPPORTED_PLATFORM
1394 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"Not SteamVR Supported Platform!!"));
1397 vr::IVRCompositor* VRCompositor = vr::VRCompositor();
1401 UE_LOG(OpenVRExpansionFunctionLibraryLog,
Warning, TEXT(
"VR Compositor InterfaceErrored"));
1405 VRCompositor->SuspendRendering(bSuspendRendering);
DEFINE_LOG_CATEGORY(OpenVRExpansionFunctionLibraryLog)
EAsyncBlueprintResultSwitch
UENUM()
EVRDeviceProperty_UInt64
UENUM(BlueprintType)
EBPOpenVRTrackedDeviceClass
UENUM()
@ TrackedDeviceClass_Invalid
static FName SteamVRSystemName(TEXT("SteamVR"))
EVRDeviceProperty_Bool
UENUM(BlueprintType)
EBPOpenVRControllerDeviceType
UENUM(Blueprintable)
EBPOVRResultSwitch
UENUM()
EVRDeviceProperty_String
UENUM(BlueprintType)
@ Prop_ManufacturerName_String_1005
@ Prop_ModelNumber_String_1001
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",...
~UOpenVRExpansionFunctionLibrary()
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")