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