diff --git a/NomaiVR/Assets/AssetLoader.cs b/NomaiVR/Assets/AssetLoader.cs index a327863..cf9ae3f 100644 --- a/NomaiVR/Assets/AssetLoader.cs +++ b/NomaiVR/Assets/AssetLoader.cs @@ -29,6 +29,7 @@ namespace NomaiVR.Assets public static GameObject ProbeLauncherHandheldScreenPrefab; public static GameObject SignalscopeHandheldButtonsPrefab; public static AssetBundle VRBindingTextures; + public static AssetBundle XRManager; public static Sprite SplashSprite; public static Texture2D EmptyTexture; @@ -41,6 +42,8 @@ namespace NomaiVR.Assets VRBindingTextures = LoadBundle("vrbindings-textures"); ShaderLoader.LoadBundle(LoadBundle("steamvr-shaders")); + XRManager = LoadBundle("xrmanager"); + var postCreditsBundle = LoadBundle("cinema-camera"); PostCreditsPrefab = LoadAsset(postCreditsBundle, "postcreditscamera.prefab"); PostCreditsRenderTexture = LoadAsset(postCreditsBundle, "screen.renderTexture"); diff --git a/NomaiVR/Hands/HandsController.cs b/NomaiVR/Hands/HandsController.cs index 110c70c..97fbf1d 100644 --- a/NomaiVR/Hands/HandsController.cs +++ b/NomaiVR/Hands/HandsController.cs @@ -2,6 +2,7 @@ using NomaiVR.Helpers; using NomaiVR.ModConfig; using UnityEngine; +using UnityEngine.SpatialTracking; using UnityEngine.XR; using Valve.VR; @@ -60,6 +61,7 @@ namespace NomaiVR.Hands camera.cullingMask = activeCamera.cullingMask; camera.depth = activeCamera.mainCamera.depth; camera.tag = activeCamera.tag; + ActivateCameraTracking(camera); var owCamera = cameraObject.AddComponent(); owCamera.renderSkybox = true; @@ -72,12 +74,21 @@ namespace NomaiVR.Hands private void SetUpWrapperInGame() { + ActivateCameraTracking(Camera.main); wrapper = new GameObject().transform; wrapper.parent = Camera.main.transform.parent; wrapper.localRotation = Quaternion.identity; wrapper.localPosition = Camera.main.transform.localPosition; } + private void ActivateCameraTracking(Camera camera) + { + var hmdTracking = camera.gameObject.AddComponent(); + hmdTracking.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.Head); + hmdTracking.updateType = TrackedPoseDriver.UpdateType.BeforeRender; + hmdTracking.UseRelativeTransform = false; + } + private void SetUpHands() { var right = new GameObject().AddComponent(); diff --git a/NomaiVR/Helpers/GraphicsHelper.cs b/NomaiVR/Helpers/GraphicsHelper.cs index f4f8500..00af675 100644 --- a/NomaiVR/Helpers/GraphicsHelper.cs +++ b/NomaiVR/Helpers/GraphicsHelper.cs @@ -6,6 +6,7 @@ namespace NomaiVR.Helpers public static class GraphicsHelper { private static readonly Matrix4x4 scaleBiasDXToGL = Matrix4x4.TRS(Vector3.back, Quaternion.identity, new Vector3(1, 1, 2)); + private static readonly Matrix4x4 scaleBiasGLToDX = Matrix4x4.TRS(Vector3.forward, Quaternion.identity, new Vector3(1, 1, 0.5f)); public static void ForceCameraToEye(Camera targetCamera, Transform headTransform, EVREye eye) { targetCamera.transform.position = headTransform.TransformPoint(SteamVR.instance.eyes[(int)eye].pos); @@ -14,12 +15,17 @@ namespace NomaiVR.Helpers public static void SetCameraEyeProjectionMatrix(Camera targetCamera, EVREye eye) { - targetCamera.projectionMatrix = scaleBiasDXToGL * GetSteamVREyeProjection(targetCamera, eye); + targetCamera.projectionMatrix = GetSteamVREyeProjection(targetCamera, eye); + } + + public static Matrix4x4 ToDX(Matrix4x4 matrix) + { + return scaleBiasGLToDX * matrix; } public static Matrix4x4 GetSteamVREyeProjection(Camera cam, EVREye eye) { - return HmdMatrix44ToMatrix4X4(SteamVR.instance.hmd.GetProjectionMatrix(eye, cam.nearClipPlane, cam.farClipPlane)); + return scaleBiasDXToGL * HmdMatrix44ToMatrix4X4(SteamVR.instance.hmd.GetProjectionMatrix(eye, cam.nearClipPlane, cam.farClipPlane)); } public static Matrix4x4 HmdMatrix44ToMatrix4X4(HmdMatrix44_t mat) diff --git a/NomaiVR/NomaiVR.cs b/NomaiVR/NomaiVR.cs index 2f6800e..37932f4 100644 --- a/NomaiVR/NomaiVR.cs +++ b/NomaiVR/NomaiVR.cs @@ -10,6 +10,11 @@ using NomaiVR.Loaders.Harmony; using NomaiVR.Player; using NomaiVR.Saves; using NomaiVR.Ship; +using UnityEngine.XR.Management; +using Unity.XR.OpenVR; +using UnityEngine.XR; +using System.Collections.Generic; +using UnityEngine; namespace NomaiVR { @@ -76,6 +81,7 @@ namespace NomaiVR private static void InitSteamVR() { SteamVR_Actions.PreInitialize(); + LoadXRModule(); SteamVR.Initialize(); SteamVR_Settings.instance.pauseGameWhenDashboardVisible = true; @@ -88,6 +94,45 @@ namespace NomaiVR steamAppId: 753640); OpenVR.Input.SetActionManifestPath(ModFolderPath + @"\bindings\actions.json"); + + if (XRGeneralSettings.Instance != null && XRGeneralSettings.Instance.Manager != null + && XRGeneralSettings.Instance.Manager.activeLoader != null) + { + XRGeneralSettings.Instance.Manager.StartSubsystems(); + } + else + throw new System.Exception("Cannot initialize VRSubsystem"); + + //Change tracking origin to headset + List subsystems = new List(); + SubsystemManager.GetInstances(subsystems); + for (int i = 0; i < subsystems.Count; i++) + { + subsystems[i].TrySetTrackingOriginMode(TrackingOriginModeFlags.Device); + subsystems[i].TryRecenter(); + } + } + + private static void LoadXRModule() + { + foreach (var xrManager in AssetLoader.XRManager.LoadAllAssets()) + Logs.WriteInfo($"Loaded xrManager: {xrManager.name}"); + + XRGeneralSettings instance = XRGeneralSettings.Instance; + if (instance == null) throw new System.Exception("XRGeneralSettings instance is null"); + + var xrManagerSettings = instance.Manager; + if (xrManagerSettings == null) throw new System.Exception("XRManagerSettings instance is null"); + + xrManagerSettings.InitializeLoaderSync(); + if (xrManagerSettings.activeLoader == null) throw new System.Exception("Cannot initialize OpenVR Loader"); + + OpenVRSettings openVrSettings = OpenVRSettings.GetSettings(false); + openVrSettings.EditorAppKey = "steam.app.753640"; + openVrSettings.InitializationType = OpenVRSettings.InitializationTypes.Scene; + if (openVrSettings == null) throw new System.Exception("OpenVRSettings instance is null"); + + openVrSettings.SetMirrorViewMode(OpenVRSettings.MirrorViewModes.Right); } } } diff --git a/NomaiVR/NomaiVR.csproj b/NomaiVR/NomaiVR.csproj index f1f7324..eb23d5d 100644 --- a/NomaiVR/NomaiVR.csproj +++ b/NomaiVR/NomaiVR.csproj @@ -68,6 +68,14 @@ False $(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\SteamVR.dll + + False + $(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\Unity.XR.OpenVR.dll + + + False + $(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\Unity.XR.Management.dll + False $(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\SteamVR_Actions.dll @@ -145,6 +153,8 @@ + + diff --git a/NomaiVRPatcher/NomaiVREnabler.cs b/NomaiVRPatcher/NomaiVREnabler.cs index a42af26..a09d9d1 100644 --- a/NomaiVRPatcher/NomaiVREnabler.cs +++ b/NomaiVRPatcher/NomaiVREnabler.cs @@ -25,7 +25,7 @@ namespace NomaiVRPatcher CopyGameFiles(AppDomain.CurrentDomain.BaseDirectory, Path.Combine(basePath, "files")); - PatchGlobalGameManagers(gameManagersPath, backupPath, basePath); + //PatchGlobalGameManagers(gameManagersPath, backupPath, basePath); } // List of assemblies to patch @@ -46,7 +46,7 @@ namespace NomaiVRPatcher CopyGameFiles(executablePath, Path.Combine(patchersPath, "files")); - PatchGlobalGameManagers(gameManagersPath, backupPath, patchersPath); + //PatchGlobalGameManagers(gameManagersPath, backupPath, patchersPath); } // Clean up files left from previous versions of the mod diff --git a/NomaiVRPatcher/NomaiVRPatcher.csproj b/NomaiVRPatcher/NomaiVRPatcher.csproj index 1b157c8..025a88f 100644 --- a/NomaiVRPatcher/NomaiVRPatcher.csproj +++ b/NomaiVRPatcher/NomaiVRPatcher.csproj @@ -21,6 +21,7 @@ + diff --git a/Unity/ProjectSettings/ProjectSettings.asset b/Unity/ProjectSettings/ProjectSettings.asset index b1b54ec..5fd06b8 100644 --- a/Unity/ProjectSettings/ProjectSettings.asset +++ b/Unity/ProjectSettings/ProjectSettings.asset @@ -126,7 +126,8 @@ PlayerSettings: Others: 1 bundleVersion: 0.1 preloadedAssets: - - {fileID: 5477527979194124351, guid: bd54447987d8bd845bbb7e7341ebdf98, type: 2} + - {fileID: 0} + - {fileID: 3723299434278802999, guid: 13906739c9868ee489584241300fc5bc, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1 @@ -329,10 +330,8 @@ PlayerSettings: m_Automatic: 1 m_BuildTargetVRSettings: - m_BuildTarget: Standalone - m_Enabled: 1 - m_Devices: - - OpenVR - - Oculus + m_Enabled: 0 + m_Devices: [] openGLRequireES31: 0 openGLRequireES31AEP: 0 openGLRequireES32: 0 diff --git a/Unity/ProjectSettings/XRPackageSettings.asset b/Unity/ProjectSettings/XRPackageSettings.asset index 7e791e1..e6eb497 100644 --- a/Unity/ProjectSettings/XRPackageSettings.asset +++ b/Unity/ProjectSettings/XRPackageSettings.asset @@ -1,5 +1,6 @@ { "m_Settings": [ - "RemoveLegacyInputHelpersForReload" + "RemoveLegacyInputHelpersForReload", + "ShouldQueryLegacyPackageRemoval" ] } \ No newline at end of file