OVRMixedReality.cs
3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
https://developer.oculus.com/licenses/oculussdk/
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
ANY KIND, either express or implied. See the License for the specific language governing
permissions and limitations under the License.
************************************************************************************/
#if UNITY_ANDROID && !UNITY_EDITOR
#define OVR_ANDROID_MRC
#endif
using System;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_ANDROID
/// <summary>
/// Manages mix-reality elements
/// </summary>
internal static class OVRMixedReality
{
/// <summary>
/// For Debugging purpose, we can use preset parameters to fake a camera when external camera is not available
/// </summary>
public static bool useFakeExternalCamera = false;
public static Vector3 fakeCameraFloorLevelPosition = new Vector3(0.0f, 2.0f, -0.5f);
public static Vector3 fakeCameraEyeLevelPosition = fakeCameraFloorLevelPosition - new Vector3(0.0f, 1.8f, 0.0f);
public static Quaternion fakeCameraRotation = Quaternion.LookRotation((new Vector3(0.0f, fakeCameraFloorLevelPosition.y, 0.0f) - fakeCameraFloorLevelPosition).normalized, Vector3.up);
public static float fakeCameraFov = 60.0f;
public static float fakeCameraAspect = 16.0f / 9.0f;
/// <summary>
/// Composition object
/// </summary>
public static OVRComposition currentComposition = null;
/// <summary>
/// Updates the internal state of the Mixed Reality Camera. Called by OVRManager.
/// </summary>
public static void Update(GameObject parentObject, Camera mainCamera, OVRMixedRealityCaptureConfiguration configuration, OVRManager.TrackingOrigin trackingOrigin)
{
if (!OVRPlugin.initialized)
{
Debug.LogError("OVRPlugin not initialized");
return;
}
if (!OVRPlugin.IsMixedRealityInitialized())
{
OVRPlugin.InitializeMixedReality();
if (OVRPlugin.IsMixedRealityInitialized())
{
Debug.Log("OVRPlugin_MixedReality initialized");
}
else
{
Debug.LogError("Unable to initialize OVRPlugin_MixedReality");
return;
}
}
if (!OVRPlugin.IsMixedRealityInitialized())
{
return;
}
OVRPlugin.UpdateExternalCamera();
#if !OVR_ANDROID_MRC
OVRPlugin.UpdateCameraDevices();
#endif
#if OVR_ANDROID_MRC
useFakeExternalCamera = OVRPlugin.Media.UseMrcDebugCamera();
#endif
if (currentComposition != null && (currentComposition.CompositionMethod() != configuration.compositionMethod))
{
currentComposition.Cleanup();
currentComposition = null;
}
if (configuration.compositionMethod == OVRManager.CompositionMethod.External)
{
if (currentComposition == null)
{
currentComposition = new OVRExternalComposition(parentObject, mainCamera, configuration);
}
}
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
else if (configuration.compositionMethod == OVRManager.CompositionMethod.Direct)
{
if (currentComposition == null)
{
currentComposition = new OVRDirectComposition(parentObject, mainCamera, configuration);
}
}
#endif
else
{
Debug.LogError("Unknown CompositionMethod : " + configuration.compositionMethod);
return;
}
currentComposition.Update(parentObject, mainCamera, configuration, trackingOrigin);
}
public static void Cleanup()
{
if (currentComposition != null)
{
currentComposition.Cleanup();
currentComposition = null;
}
if (OVRPlugin.IsMixedRealityInitialized())
{
OVRPlugin.ShutdownMixedReality();
}
}
public static void RecenterPose()
{
if (currentComposition != null)
{
currentComposition.RecenterPose();
}
}
}
#endif