OVRMixedRealityCaptureSettings.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using UnityEngine;
  2. using System;
  3. using System.IO;
  4. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
  5. public class OVRMixedRealityCaptureSettings : ScriptableObject
  6. {
  7. public bool enableMixedReality = false;
  8. public LayerMask extraHiddenLayers;
  9. public OVRManager.CompositionMethod compositionMethod = OVRManager.CompositionMethod.External;
  10. public OVRManager.CameraDevice capturingCameraDevice = OVRManager.CameraDevice.WebCamera0;
  11. public bool flipCameraFrameHorizontally = false;
  12. public bool flipCameraFrameVertically = false;
  13. public float handPoseStateLatency = 0.0f;
  14. public float sandwichCompositionRenderLatency = 0.0f;
  15. public int sandwichCompositionBufferedFrames = 8;
  16. public Color chromaKeyColor = Color.green;
  17. public float chromaKeySimilarity = 0.6f;
  18. public float chromaKeySmoothRange = 0.03f;
  19. public float chromaKeySpillRange = 0.04f;
  20. public bool useDynamicLighting = false;
  21. public OVRManager.DepthQuality depthQuality = OVRManager.DepthQuality.Medium;
  22. public float dynamicLightingSmoothFactor = 8.0f;
  23. public float dynamicLightingDepthVariationClampingValue = 0.001f;
  24. public OVRManager.VirtualGreenScreenType virtualGreenScreenType = OVRManager.VirtualGreenScreenType.Off;
  25. public float virtualGreenScreenTopY;
  26. public float virtualGreenScreenBottomY;
  27. public bool virtualGreenScreenApplyDepthCulling = false;
  28. public float virtualGreenScreenDepthTolerance = 0.2f;
  29. public void ReadFrom(OVRManager manager)
  30. {
  31. enableMixedReality = manager.enableMixedReality;
  32. compositionMethod = manager.compositionMethod;
  33. extraHiddenLayers = manager.extraHiddenLayers;
  34. capturingCameraDevice = manager.capturingCameraDevice;
  35. flipCameraFrameHorizontally = manager.flipCameraFrameHorizontally;
  36. flipCameraFrameVertically = manager.flipCameraFrameVertically;
  37. handPoseStateLatency = manager.handPoseStateLatency;
  38. sandwichCompositionRenderLatency = manager.sandwichCompositionRenderLatency;
  39. sandwichCompositionBufferedFrames = manager.sandwichCompositionBufferedFrames;
  40. chromaKeyColor = manager.chromaKeyColor;
  41. chromaKeySimilarity = manager.chromaKeySimilarity;
  42. chromaKeySmoothRange = manager.chromaKeySmoothRange;
  43. chromaKeySpillRange = manager.chromaKeySpillRange;
  44. useDynamicLighting = manager.useDynamicLighting;
  45. depthQuality = manager.depthQuality;
  46. dynamicLightingSmoothFactor = manager.dynamicLightingSmoothFactor;
  47. dynamicLightingDepthVariationClampingValue = manager.dynamicLightingDepthVariationClampingValue;
  48. virtualGreenScreenType = manager.virtualGreenScreenType;
  49. virtualGreenScreenTopY = manager.virtualGreenScreenTopY;
  50. virtualGreenScreenBottomY = manager.virtualGreenScreenBottomY;
  51. virtualGreenScreenApplyDepthCulling = manager.virtualGreenScreenApplyDepthCulling;
  52. virtualGreenScreenDepthTolerance = manager.virtualGreenScreenDepthTolerance;
  53. }
  54. public void ApplyTo(OVRManager manager)
  55. {
  56. manager.enableMixedReality = enableMixedReality;
  57. manager.compositionMethod = compositionMethod;
  58. manager.extraHiddenLayers = extraHiddenLayers;
  59. manager.capturingCameraDevice = capturingCameraDevice;
  60. manager.flipCameraFrameHorizontally = flipCameraFrameHorizontally;
  61. manager.flipCameraFrameVertically = flipCameraFrameVertically;
  62. manager.handPoseStateLatency = handPoseStateLatency;
  63. manager.sandwichCompositionRenderLatency = sandwichCompositionRenderLatency;
  64. manager.sandwichCompositionBufferedFrames = sandwichCompositionBufferedFrames;
  65. manager.chromaKeyColor = chromaKeyColor;
  66. manager.chromaKeySimilarity = chromaKeySimilarity;
  67. manager.chromaKeySmoothRange = chromaKeySmoothRange;
  68. manager.chromaKeySpillRange = chromaKeySpillRange;
  69. manager.useDynamicLighting = useDynamicLighting;
  70. manager.depthQuality = depthQuality;
  71. manager.dynamicLightingSmoothFactor = dynamicLightingSmoothFactor;
  72. manager.dynamicLightingDepthVariationClampingValue = dynamicLightingDepthVariationClampingValue;
  73. manager.virtualGreenScreenType = virtualGreenScreenType;
  74. manager.virtualGreenScreenTopY = virtualGreenScreenTopY;
  75. manager.virtualGreenScreenBottomY = virtualGreenScreenBottomY;
  76. manager.virtualGreenScreenApplyDepthCulling = virtualGreenScreenApplyDepthCulling;
  77. manager.virtualGreenScreenDepthTolerance = virtualGreenScreenDepthTolerance;
  78. }
  79. const string configFileName = "mrc.config";
  80. public void WriteToConfigurationFile()
  81. {
  82. string text = JsonUtility.ToJson(this, true);
  83. try
  84. {
  85. string configPath = Path.Combine(Application.dataPath, configFileName);
  86. Debug.Log("Write OVRMixedRealityCaptureSettings to " + configPath);
  87. File.WriteAllText(configPath, text);
  88. }
  89. catch(Exception e)
  90. {
  91. Debug.LogWarning("Exception caught " + e.Message);
  92. }
  93. }
  94. public void CombineWithConfigurationFile()
  95. {
  96. try
  97. {
  98. string configPath = Path.Combine(Application.dataPath, configFileName);
  99. if (File.Exists(configPath))
  100. {
  101. Debug.Log("MixedRealityCapture configuration file found at " + configPath);
  102. string text = File.ReadAllText(configPath);
  103. Debug.Log("Apply MixedRealityCapture configuration");
  104. JsonUtility.FromJsonOverwrite(text, this);
  105. }
  106. else
  107. {
  108. Debug.Log("MixedRealityCapture configuration file doesn't exist at " + configPath);
  109. }
  110. }
  111. catch(Exception e)
  112. {
  113. Debug.LogWarning("Exception caught " + e.Message);
  114. }
  115. }
  116. }
  117. #endif