Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch back to XR Plugin #484

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NomaiVR/Assets/AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AssetLoader
public static GameObject ProbeLauncherHandheldScreenPrefab;
public static GameObject SignalscopeHandheldButtonsPrefab;
public static AssetBundle VRBindingTextures;
public static AssetBundle XRManager;
public static Sprite SplashSprite;
public static Texture2D EmptyTexture;

Expand All @@ -41,6 +42,8 @@ public AssetLoader()
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");
Expand Down
1 change: 1 addition & 0 deletions NomaiVR/EffectFixes/LoopTransitionFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private static void PatchTriggerFlashback(Flashback __instance, Transform ____ma
{
Transform parent;
CameraHelper.SetFieldOfViewFactor(1, true);
CameraHelper.ActivateCameraTracking(__instance._flashbackCamera.mainCamera, true);

if (____screenTransform.parent == __instance.transform)
{
Expand Down
3 changes: 3 additions & 0 deletions NomaiVR/EffectFixes/MapFix.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using NomaiVR.Helpers;
using UnityEngine;

namespace NomaiVR.EffectFixes
Expand Down Expand Up @@ -53,6 +54,8 @@ internal void Start()
newCamera.gameObject.SetActive(true);
mapController._mapCamera = owCamera;

CameraHelper.ActivateCameraTracking(owCamera.mainCamera);

var markerManager = mapCameraTransform.Find("MarkerManager").GetComponent<Canvas>();
var lockOnCanvas = mapCameraTransform.Find("MapLockOnCanvas").GetComponent<Canvas>();

Expand Down
4 changes: 3 additions & 1 deletion NomaiVR/EffectFixes/PeepholeCameraFix.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using NomaiVR.Helpers;
using UnityEngine;

namespace NomaiVR.EffectFixes
{
Expand Down Expand Up @@ -26,6 +27,7 @@ private static void SwitchToPeepholeCamera(Peephole __instance)
parent.localPosition = __instance._peepholeCamera.transform.localPosition - Vector3.up*playerHeight.y + Vector3.forward*0.3f;
parent.localRotation = Quaternion.identity;
__instance._peepholeCamera.transform.parent = parent;
CameraHelper.ActivateCameraTracking(__instance._peepholeCamera.mainCamera);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion NomaiVR/EffectFixes/ProjectionStoneCameraFix.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using NomaiVR.Helpers;
using UnityEngine;

namespace NomaiVR.EffectFixes
{
Expand All @@ -25,6 +26,7 @@ private static void SwitchToRemoteCamera(NomaiRemoteCameraPlatform ____slavePlat
parent.localRotation = Quaternion.identity;
____slavePlatform.GetOwnedCamera().transform.parent = parent;
____playerHologram.Find("Traveller_HEA_Player_v2").gameObject.SetActive(false);
CameraHelper.ActivateCameraTracking(____slavePlatform.GetOwnedCamera()._camera.mainCamera);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions NomaiVR/Hands/HandsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NomaiVR.Helpers;
using NomaiVR.ModConfig;
using UnityEngine;
using UnityEngine.SpatialTracking;
using UnityEngine.XR;
using Valve.VR;

Expand Down Expand Up @@ -60,6 +61,7 @@ private void SetUpWrapperTitle()
camera.cullingMask = activeCamera.cullingMask;
camera.depth = activeCamera.mainCamera.depth;
camera.tag = activeCamera.tag;
CameraHelper.ActivateCameraTracking(camera);

var owCamera = cameraObject.AddComponent<OWCamera>();
owCamera.renderSkybox = true;
Expand All @@ -72,6 +74,7 @@ private void SetUpWrapperTitle()

private void SetUpWrapperInGame()
{
CameraHelper.ActivateCameraTracking(Camera.main);
wrapper = new GameObject("VrGameStage").transform;
wrapper.parent = Camera.main.transform.parent;
wrapper.localRotation = Quaternion.identity;
Expand Down
10 changes: 10 additions & 0 deletions NomaiVR/Helpers/CameraHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.SpatialTracking;
using UnityEngine.XR;

namespace NomaiVR.Helpers
Expand Down Expand Up @@ -30,5 +31,14 @@ public static float GetScaledFieldOfView(Camera camera)
{
return camera.fieldOfView / fovFactor;
}


public static void ActivateCameraTracking(Camera camera, bool relativeTransform = false)
{
var hmdTracking = camera.gameObject.GetAddComponent<TrackedPoseDriver>();
hmdTracking.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.Head);
hmdTracking.updateType = TrackedPoseDriver.UpdateType.BeforeRender;
hmdTracking.UseRelativeTransform = relativeTransform;
}
}
}
10 changes: 8 additions & 2 deletions NomaiVR/Helpers/GraphicsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -14,12 +15,17 @@ public static void ForceCameraToEye(Camera targetCamera, Transform headTransform

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)
Expand Down
45 changes: 45 additions & 0 deletions NomaiVR/NomaiVR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
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
{
Expand Down Expand Up @@ -71,6 +76,7 @@ internal static void ApplyMod()
private static void InitSteamVR()
{
SteamVR_Actions.PreInitialize();
LoadXRModule();
SteamVR.Initialize();
SteamVR_Settings.instance.pauseGameWhenDashboardVisible = true;

Expand All @@ -83,6 +89,45 @@ private static void InitSteamVR()
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);
}
}
}
10 changes: 10 additions & 0 deletions NomaiVR/NomaiVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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>
Expand Down Expand Up @@ -142,6 +150,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;" />
Expand Down
2 changes: 1 addition & 1 deletion NomaiVRPatcher/NomaiVREnabler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Main(string[] args)

CopyGameFiles(gamePath, Path.Combine(basePath, "files"));

PatchGlobalGameManagers(gameManagersPath, backupPath, basePath);
//PatchGlobalGameManagers(gameManagersPath, backupPath, basePath);
}

private static string GetExecutableName(string gamePath)
Expand Down
1 change: 1 addition & 0 deletions NomaiVRPatcher/NomaiVRPatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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>
Expand Down
8 changes: 8 additions & 0 deletions Unity/Assets/OpenVRAutoUpdater.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Unity/Assets/OpenVRAutoUpdater/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Unity/Assets/OpenVRAutoUpdater/Editor/OpenVRAutoUpdater.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "OpenVRAutoUpdater",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.ugui",
"expression": "",
"define": "VALVE_UPDATE_FORCE"
},
{
"name": "com.valvesoftware.openvr.installer.skipdelete",
"expression": "",
"define": "VALVE_SKIP_DELETE"
}
],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading