Changes to re-enable xr plugin

This commit is contained in:
Jacopo Libè 2021-11-18 23:08:46 +01:00
parent 2c4160e6d9
commit ac537cb4cc
9 changed files with 86 additions and 10 deletions

View File

@ -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<GameObject>(postCreditsBundle, "postcreditscamera.prefab");
PostCreditsRenderTexture = LoadAsset<RenderTexture>(postCreditsBundle, "screen.renderTexture");

View File

@ -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>();
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<TrackedPoseDriver>();
hmdTracking.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.Head);
hmdTracking.updateType = TrackedPoseDriver.UpdateType.BeforeRender;
hmdTracking.UseRelativeTransform = false;
}
private void SetUpHands()
{
var right = new GameObject().AddComponent<Hand>();

View File

@ -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)

View File

@ -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<XRInputSubsystem> subsystems = new List<XRInputSubsystem>();
SubsystemManager.GetInstances<XRInputSubsystem>(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);
}
}
}

View File

@ -68,6 +68,14 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\SteamVR.dll</HintPath>
</Reference>
<Reference Include="Unity.XR.OpenVR">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\Unity.XR.OpenVR.dll</HintPath>
</Reference>
<Reference Include="Unity.XR.Management">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\Unity.XR.Management.dll</HintPath>
</Reference>
<Reference Include="SteamVR_Actions">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\SteamVR_Actions.dll</HintPath>
@ -145,6 +153,8 @@
<Exec Command="copy /y &quot;$(TargetPath)&quot; &quot;$(OwmlDir)\$(ModDir)&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\SteamVR.dll&quot; &quot;$(OwmlDir)\$(ModDir)\SteamVR.dll&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\SteamVR_Actions.dll&quot; &quot;$(OwmlDir)\$(ModDir)\SteamVR_Actions.dll&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\Unity.XR.OpenVR.dll&quot; &quot;$(OwmlDir)\$(ModDir)\Unity.XR.OpenVR.dll&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\Unity.XR.Management.dll&quot; &quot;$(OwmlDir)\$(ModDir)\Unity.XR.Management.dll&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Managed\Valve.Newtonsoft.Json.dll&quot; &quot;$(OwmlDir)\$(ModDir)\Valve.Newtonsoft.Json.dll&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\StreamingAssets\SteamVR\*&quot; &quot;$(OwmlDir)\$(ModDir)\bindings&quot;" />

View File

@ -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

View File

@ -21,6 +21,7 @@
<Exec Command="copy /y &quot;$(TargetDir)\Mono*.dll&quot; &quot;$(TargetDir)\..\..\dist&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\ClassDatabase\*&quot; &quot;$(TargetDir)\..\..\dist&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\StreamingAssets\SteamVR\*&quot; &quot;$(TargetDir)\..\..\dist\files\OuterWilds_Data\StreamingAssets\SteamVR&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\..\Unity\Build\OuterWildsVR_Data\Plugins\x86_64\XRSDKOpenVR.dll&quot; &quot;$(TargetDir)\..\..\dist\files\OuterWilds_Data\Plugins\x86_64\XRSDKOpenVR.dll&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\OpenVrFsr\openvr_api.dll&quot; &quot;$(TargetDir)\..\..\dist\files\OuterWilds_Data\Plugins\x86_64\openvr_api.dll&quot;" />
<Exec Command="copy /y &quot;$(ProjectDir)\OpenVrFsr\openvr_mod.cfg&quot; &quot;$(TargetDir)\..\..\dist\files\OuterWilds_Data\Plugins\x86_64\openvr_mod.cfg&quot;" />
</Target>

View File

@ -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

View File

@ -1,5 +1,6 @@
{
"m_Settings": [
"RemoveLegacyInputHelpersForReload"
"RemoveLegacyInputHelpersForReload",
"ShouldQueryLegacyPackageRemoval"
]
}