OVRMixedRealityCaptureSettings.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /************************************************************************************
  2. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use
  4. the Utilities SDK except in compliance with the License, which is provided at the time of installation
  5. or download, or which otherwise accompanies this software in either electronic or hard copy form.
  6. You may obtain a copy of the License at
  7. https://developer.oculus.com/licenses/utilities-1.31
  8. Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
  9. under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  10. ANY KIND, either express or implied. See the License for the specific language governing
  11. permissions and limitations under the License.
  12. ************************************************************************************/
  13. #if UNITY_ANDROID && !UNITY_EDITOR
  14. #define OVR_ANDROID_MRC
  15. #endif
  16. using UnityEngine;
  17. using System;
  18. using System.IO;
  19. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || OVR_ANDROID_MRC
  20. public class OVRMixedRealityCaptureSettings : ScriptableObject
  21. {
  22. public bool enableMixedReality = false;
  23. public LayerMask extraHiddenLayers;
  24. public OVRManager.CompositionMethod compositionMethod = OVRManager.CompositionMethod.External;
  25. public Color externalCompositionBackdropColorRift = Color.green;
  26. public Color externalCompositionBackdropColorQuest = Color.clear;
  27. public OVRManager.CameraDevice capturingCameraDevice = OVRManager.CameraDevice.WebCamera0;
  28. public bool flipCameraFrameHorizontally = false;
  29. public bool flipCameraFrameVertically = false;
  30. public float handPoseStateLatency = 0.0f;
  31. public float sandwichCompositionRenderLatency = 0.0f;
  32. public int sandwichCompositionBufferedFrames = 8;
  33. public Color chromaKeyColor = Color.green;
  34. public float chromaKeySimilarity = 0.6f;
  35. public float chromaKeySmoothRange = 0.03f;
  36. public float chromaKeySpillRange = 0.04f;
  37. public bool useDynamicLighting = false;
  38. public OVRManager.DepthQuality depthQuality = OVRManager.DepthQuality.Medium;
  39. public float dynamicLightingSmoothFactor = 8.0f;
  40. public float dynamicLightingDepthVariationClampingValue = 0.001f;
  41. public OVRManager.VirtualGreenScreenType virtualGreenScreenType = OVRManager.VirtualGreenScreenType.Off;
  42. public float virtualGreenScreenTopY;
  43. public float virtualGreenScreenBottomY;
  44. public bool virtualGreenScreenApplyDepthCulling = false;
  45. public float virtualGreenScreenDepthTolerance = 0.2f;
  46. public void ReadFrom(OVRManager manager)
  47. {
  48. enableMixedReality = manager.enableMixedReality;
  49. compositionMethod = manager.compositionMethod;
  50. extraHiddenLayers = manager.extraHiddenLayers;
  51. externalCompositionBackdropColorRift = manager.externalCompositionBackdropColorRift;
  52. externalCompositionBackdropColorQuest = manager.externalCompositionBackdropColorQuest;
  53. capturingCameraDevice = manager.capturingCameraDevice;
  54. flipCameraFrameHorizontally = manager.flipCameraFrameHorizontally;
  55. flipCameraFrameVertically = manager.flipCameraFrameVertically;
  56. handPoseStateLatency = manager.handPoseStateLatency;
  57. sandwichCompositionRenderLatency = manager.sandwichCompositionRenderLatency;
  58. sandwichCompositionBufferedFrames = manager.sandwichCompositionBufferedFrames;
  59. chromaKeyColor = manager.chromaKeyColor;
  60. chromaKeySimilarity = manager.chromaKeySimilarity;
  61. chromaKeySmoothRange = manager.chromaKeySmoothRange;
  62. chromaKeySpillRange = manager.chromaKeySpillRange;
  63. useDynamicLighting = manager.useDynamicLighting;
  64. depthQuality = manager.depthQuality;
  65. dynamicLightingSmoothFactor = manager.dynamicLightingSmoothFactor;
  66. dynamicLightingDepthVariationClampingValue = manager.dynamicLightingDepthVariationClampingValue;
  67. virtualGreenScreenType = manager.virtualGreenScreenType;
  68. virtualGreenScreenTopY = manager.virtualGreenScreenTopY;
  69. virtualGreenScreenBottomY = manager.virtualGreenScreenBottomY;
  70. virtualGreenScreenApplyDepthCulling = manager.virtualGreenScreenApplyDepthCulling;
  71. virtualGreenScreenDepthTolerance = manager.virtualGreenScreenDepthTolerance;
  72. }
  73. public void ApplyTo(OVRManager manager)
  74. {
  75. manager.enableMixedReality = enableMixedReality;
  76. manager.compositionMethod = compositionMethod;
  77. manager.extraHiddenLayers = extraHiddenLayers;
  78. manager.externalCompositionBackdropColorRift = externalCompositionBackdropColorRift;
  79. manager.externalCompositionBackdropColorQuest = externalCompositionBackdropColorQuest;
  80. manager.capturingCameraDevice = capturingCameraDevice;
  81. manager.flipCameraFrameHorizontally = flipCameraFrameHorizontally;
  82. manager.flipCameraFrameVertically = flipCameraFrameVertically;
  83. manager.handPoseStateLatency = handPoseStateLatency;
  84. manager.sandwichCompositionRenderLatency = sandwichCompositionRenderLatency;
  85. manager.sandwichCompositionBufferedFrames = sandwichCompositionBufferedFrames;
  86. manager.chromaKeyColor = chromaKeyColor;
  87. manager.chromaKeySimilarity = chromaKeySimilarity;
  88. manager.chromaKeySmoothRange = chromaKeySmoothRange;
  89. manager.chromaKeySpillRange = chromaKeySpillRange;
  90. manager.useDynamicLighting = useDynamicLighting;
  91. manager.depthQuality = depthQuality;
  92. manager.dynamicLightingSmoothFactor = dynamicLightingSmoothFactor;
  93. manager.dynamicLightingDepthVariationClampingValue = dynamicLightingDepthVariationClampingValue;
  94. manager.virtualGreenScreenType = virtualGreenScreenType;
  95. manager.virtualGreenScreenTopY = virtualGreenScreenTopY;
  96. manager.virtualGreenScreenBottomY = virtualGreenScreenBottomY;
  97. manager.virtualGreenScreenApplyDepthCulling = virtualGreenScreenApplyDepthCulling;
  98. manager.virtualGreenScreenDepthTolerance = virtualGreenScreenDepthTolerance;
  99. }
  100. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN // Rift MRC only
  101. const string configFileName = "mrc.config";
  102. public void WriteToConfigurationFile()
  103. {
  104. string text = JsonUtility.ToJson(this, true);
  105. try
  106. {
  107. string configPath = Path.Combine(Application.dataPath, configFileName);
  108. Debug.Log("Write OVRMixedRealityCaptureSettings to " + configPath);
  109. File.WriteAllText(configPath, text);
  110. }
  111. catch(Exception e)
  112. {
  113. Debug.LogWarning("Exception caught " + e.Message);
  114. }
  115. }
  116. public void CombineWithConfigurationFile()
  117. {
  118. try
  119. {
  120. string configPath = Path.Combine(Application.dataPath, configFileName);
  121. if (File.Exists(configPath))
  122. {
  123. Debug.Log("MixedRealityCapture configuration file found at " + configPath);
  124. string text = File.ReadAllText(configPath);
  125. Debug.Log("Apply MixedRealityCapture configuration");
  126. JsonUtility.FromJsonOverwrite(text, this);
  127. }
  128. else
  129. {
  130. Debug.Log("MixedRealityCapture configuration file doesn't exist at " + configPath);
  131. }
  132. }
  133. catch(Exception e)
  134. {
  135. Debug.LogWarning("Exception caught " + e.Message);
  136. }
  137. }
  138. #endif
  139. }
  140. #endif