OVRMixedReality.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /************************************************************************************
  2. Copyright : Copyright 2017 Oculus VR, LLC. All Rights reserved.
  3. Licensed under the Oculus VR Rift SDK License Version 3.4.1 (the "License");
  4. you may not use the Oculus VR Rift SDK except in compliance with the License,
  5. which is provided at the time of installation or download, or which
  6. otherwise accompanies this software in either electronic or hard copy form.
  7. You may obtain a copy of the License at
  8. https://developer.oculus.com/licenses/sdk-3.4.1
  9. Unless required by applicable law or agreed to in writing, the Oculus VR SDK
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ************************************************************************************/
  15. using System;
  16. using System.Runtime.InteropServices;
  17. using System.Text.RegularExpressions;
  18. using System.Collections.Generic;
  19. using UnityEngine;
  20. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
  21. /// <summary>
  22. /// Manages mix-reality elements
  23. /// </summary>
  24. internal static class OVRMixedReality
  25. {
  26. /// <summary>
  27. /// Configurable parameters
  28. /// </summary>
  29. public static Color chromaKeyColor = Color.green;
  30. /// <summary>
  31. /// For Debugging purpose, we can use preset parameters to fake a camera when external camera is not available
  32. /// </summary>
  33. public static bool useFakeExternalCamera = false;
  34. public static Vector3 fakeCameraPositon = new Vector3(3.0f, 0.0f, 3.0f);
  35. public static Quaternion fakeCameraRotation = Quaternion.LookRotation((new Vector3(0.0f, 1.0f, 0.0f) - fakeCameraPositon).normalized, Vector3.up);
  36. public static float fakeCameraFov = 60.0f;
  37. public static float fakeCameraAspect = 16.0f / 9.0f;
  38. /// <summary>
  39. /// Composition object
  40. /// </summary>
  41. public static OVRComposition currentComposition = null;
  42. /// <summary>
  43. /// Updates the internal state of the Mixed Reality Camera. Called by OVRManager.
  44. /// </summary>
  45. public static void Update(GameObject parentObject, Camera mainCamera, OVRManager.CompositionMethod compositionMethod, bool useDynamicLighting, OVRManager.CameraDevice cameraDevice, OVRManager.DepthQuality depthQuality)
  46. {
  47. if (!OVRPlugin.initialized)
  48. {
  49. Debug.LogError("OVRPlugin not initialized");
  50. return;
  51. }
  52. if (!OVRPlugin.IsMixedRealityInitialized())
  53. OVRPlugin.InitializeMixedReality();
  54. if (!OVRPlugin.IsMixedRealityInitialized())
  55. {
  56. Debug.LogError("Unable to initialize MixedReality");
  57. return;
  58. }
  59. OVRPlugin.UpdateExternalCamera();
  60. OVRPlugin.UpdateCameraDevices();
  61. if (currentComposition != null && currentComposition.CompositionMethod() != compositionMethod)
  62. {
  63. currentComposition.Cleanup();
  64. currentComposition = null;
  65. }
  66. if (compositionMethod == OVRManager.CompositionMethod.External)
  67. {
  68. if (currentComposition == null)
  69. {
  70. currentComposition = new OVRExternalComposition(parentObject, mainCamera);
  71. }
  72. }
  73. else if (compositionMethod == OVRManager.CompositionMethod.Direct)
  74. {
  75. if (currentComposition == null)
  76. {
  77. currentComposition = new OVRDirectComposition(parentObject, mainCamera, cameraDevice, useDynamicLighting, depthQuality);
  78. }
  79. }
  80. else if (compositionMethod == OVRManager.CompositionMethod.Sandwich)
  81. {
  82. if (currentComposition == null)
  83. {
  84. currentComposition = new OVRSandwichComposition(parentObject, mainCamera, cameraDevice, useDynamicLighting, depthQuality);
  85. }
  86. }
  87. else
  88. {
  89. Debug.LogError("Unknown CompositionMethod : " + compositionMethod);
  90. return;
  91. }
  92. currentComposition.Update(mainCamera);
  93. }
  94. public static void Cleanup()
  95. {
  96. if (currentComposition != null)
  97. {
  98. currentComposition.Cleanup();
  99. currentComposition = null;
  100. }
  101. if (OVRPlugin.IsMixedRealityInitialized())
  102. {
  103. OVRPlugin.ShutdownMixedReality();
  104. }
  105. }
  106. public static void RecenterPose()
  107. {
  108. if (currentComposition != null)
  109. {
  110. currentComposition.RecenterPose();
  111. }
  112. }
  113. }
  114. #endif