protected OVRCameraComposition(GameObject parentObject, Camera mainCamera, OVRManager.CameraDevice inCameraDevice, bool inUseDynamicLighting, OVRManager.DepthQuality depthQuality)
        : base(parentObject, mainCamera)
    {
        cameraDevice = OVRCompositionUtil.ConvertCameraDevice(inCameraDevice);

        Debug.Assert(!hasCameraDeviceOpened);
        Debug.Assert(!OVRPlugin.IsCameraDeviceAvailable(cameraDevice) || !OVRPlugin.HasCameraDeviceOpened(cameraDevice));
        hasCameraDeviceOpened = false;
        useDynamicLighting    = inUseDynamicLighting;

        bool cameraSupportsDepth = OVRPlugin.DoesCameraDeviceSupportDepth(cameraDevice);

        if (useDynamicLighting && !cameraSupportsDepth)
        {
            Debug.LogWarning("The camera device doesn't support depth. The result of dynamic lighting might not be correct");
        }

        if (OVRPlugin.IsCameraDeviceAvailable(cameraDevice))
        {
            OVRPlugin.CameraExtrinsics extrinsics;
            OVRPlugin.CameraIntrinsics intrinsics;
            OVRPlugin.Posef            calibrationRawPose;
            if (OVRPlugin.GetExternalCameraCount() > 0 && OVRPlugin.GetMixedRealityCameraInfo(0, out extrinsics, out intrinsics, out calibrationRawPose))
            {
                OVRPlugin.SetCameraDevicePreferredColorFrameSize(cameraDevice, intrinsics.ImageSensorPixelResolution.w, intrinsics.ImageSensorPixelResolution.h);
            }

            if (useDynamicLighting)
            {
                OVRPlugin.SetCameraDeviceDepthSensingMode(cameraDevice, OVRPlugin.CameraDeviceDepthSensingMode.Fill);
                OVRPlugin.CameraDeviceDepthQuality quality = OVRPlugin.CameraDeviceDepthQuality.Medium;
                if (depthQuality == OVRManager.DepthQuality.Low)
                {
                    quality = OVRPlugin.CameraDeviceDepthQuality.Low;
                }
                else if (depthQuality == OVRManager.DepthQuality.Medium)
                {
                    quality = OVRPlugin.CameraDeviceDepthQuality.Medium;
                }
                else if (depthQuality == OVRManager.DepthQuality.High)
                {
                    quality = OVRPlugin.CameraDeviceDepthQuality.High;
                }
                else
                {
                    Debug.LogWarning("Unknown depth quality");
                }
                OVRPlugin.SetCameraDevicePreferredDepthQuality(cameraDevice, quality);
            }

            Debug.LogFormat("Opening camera device {0}", cameraDevice);
            OVRPlugin.OpenCameraDevice(cameraDevice);
            if (OVRPlugin.HasCameraDeviceOpened(cameraDevice))
            {
                Debug.LogFormat("Opened camera device {0}", cameraDevice);
                hasCameraDeviceOpened = true;
            }
        }
    }
Ejemplo n.º 2
0
	protected OVRCameraComposition(OVRManager.CameraDevice inCameraDevice, bool inUseDynamicLighting, OVRManager.DepthQuality depthQuality)
	{
		cameraDevice = OVRCompositionUtil.ConvertCameraDevice(inCameraDevice):

		Debug.Assert(!hasCameraDeviceOpened):
		Debug.Assert(!OVRPlugin.IsCameraDeviceAvailable(cameraDevice) || !OVRPlugin.HasCameraDeviceOpened(cameraDevice)):
		hasCameraDeviceOpened = false:
		useDynamicLighting = inUseDynamicLighting:

		bool cameraSupportsDepth = OVRPlugin.DoesCameraDeviceSupportDepth(cameraDevice):
		if (useDynamicLighting && !cameraSupportsDepth)
		{
			Debug.LogWarning("The camera device doesn't support depth. The result of dynamic lighting might not be correct"):
		}

		if (OVRPlugin.IsCameraDeviceAvailable(cameraDevice))
		{
			OVRPlugin.CameraExtrinsics extrinsics:
			OVRPlugin.CameraIntrinsics intrinsics:
			if (OVRPlugin.GetExternalCameraCount() > 0 && OVRPlugin.GetMixedRealityCameraInfo(0, out extrinsics, out intrinsics))
			{
				OVRPlugin.SetCameraDevicePreferredColorFrameSize(cameraDevice, intrinsics.ImageSensorPixelResolution.w, intrinsics.ImageSensorPixelResolution.h):
			}

			if (useDynamicLighting)
			{
				OVRPlugin.SetCameraDeviceDepthSensingMode(cameraDevice, OVRPlugin.CameraDeviceDepthSensingMode.Fill):
				OVRPlugin.CameraDeviceDepthQuality quality = OVRPlugin.CameraDeviceDepthQuality.Medium:
				if (depthQuality == OVRManager.DepthQuality.Low)
				{
					quality = OVRPlugin.CameraDeviceDepthQuality.Low:
				}
				else if (depthQuality == OVRManager.DepthQuality.Medium)
				{
					quality = OVRPlugin.CameraDeviceDepthQuality.Medium:
				}
				else if (depthQuality == OVRManager.DepthQuality.High)
				{
					quality = OVRPlugin.CameraDeviceDepthQuality.High:
				}
				else
				{
					Debug.LogWarning("Unknown depth quality"):
				}
				OVRPlugin.SetCameraDevicePreferredDepthQuality(cameraDevice, quality):
			}

			OVRPlugin.OpenCameraDevice(cameraDevice):
			if (OVRPlugin.HasCameraDeviceOpened(cameraDevice))
			{
				hasCameraDeviceOpened = true:
			}
		}
	}
Ejemplo n.º 3
0
    protected OVRCameraComposition(OVRManager.CameraDevice inCameraDevice, bool inUseDynamicLighting, OVRManager.DepthQuality depthQuality)
    {
        this.cameraDevice          = OVRCompositionUtil.ConvertCameraDevice(inCameraDevice);
        this.hasCameraDeviceOpened = false;
        this.useDynamicLighting    = inUseDynamicLighting;
        bool flag = OVRPlugin.DoesCameraDeviceSupportDepth(this.cameraDevice);

        if (this.useDynamicLighting && !flag)
        {
            Debug.LogWarning("The camera device doesn't support depth. The result of dynamic lighting might not be correct");
        }
        if (OVRPlugin.IsCameraDeviceAvailable(this.cameraDevice))
        {
            OVRPlugin.CameraExtrinsics cameraExtrinsics;
            OVRPlugin.CameraIntrinsics cameraIntrinsics;
            if (OVRPlugin.GetExternalCameraCount() > 0 && OVRPlugin.GetMixedRealityCameraInfo(0, out cameraExtrinsics, out cameraIntrinsics))
            {
                OVRPlugin.SetCameraDevicePreferredColorFrameSize(this.cameraDevice, cameraIntrinsics.ImageSensorPixelResolution.w, cameraIntrinsics.ImageSensorPixelResolution.h);
            }
            if (this.useDynamicLighting)
            {
                OVRPlugin.SetCameraDeviceDepthSensingMode(this.cameraDevice, OVRPlugin.CameraDeviceDepthSensingMode.Fill);
                OVRPlugin.CameraDeviceDepthQuality depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.Medium;
                if (depthQuality == OVRManager.DepthQuality.Low)
                {
                    depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.Low;
                }
                else if (depthQuality == OVRManager.DepthQuality.Medium)
                {
                    depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.Medium;
                }
                else if (depthQuality == OVRManager.DepthQuality.High)
                {
                    depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.High;
                }
                else
                {
                    Debug.LogWarning("Unknown depth quality");
                }
                OVRPlugin.SetCameraDevicePreferredDepthQuality(this.cameraDevice, depthQuality2);
            }
            OVRPlugin.OpenCameraDevice(this.cameraDevice);
            if (OVRPlugin.HasCameraDeviceOpened(this.cameraDevice))
            {
                this.hasCameraDeviceOpened = true;
            }
        }
    }
Ejemplo n.º 4
0
    protected void UpdateCameraFramePlaneObject(Camera mainCamera, Camera mixedRealityCamera, OVRMixedRealityCaptureConfiguration configuration, RenderTexture boundaryMeshMaskTexture)
    {
        cameraFrameCompositionManager.configuration = configuration;
        bool      hasError            = false;
        Material  cameraFrameMaterial = cameraFramePlaneObject.GetComponent <MeshRenderer>().material;
        Texture2D colorTexture        = Texture2D.blackTexture;
        Texture2D depthTexture        = Texture2D.whiteTexture;

        if (OVRPlugin.IsCameraDeviceColorFrameAvailable(cameraDevice))
        {
            colorTexture = OVRPlugin.GetCameraDeviceColorFrameTexture(cameraDevice);
        }
        else
        {
            Debug.LogWarning("Camera: color frame not ready");
            hasError = true;
        }
        bool cameraSupportsDepth = OVRPlugin.DoesCameraDeviceSupportDepth(cameraDevice);

        if (configuration.useDynamicLighting && cameraSupportsDepth)
        {
            if (OVRPlugin.IsCameraDeviceDepthFrameAvailable(cameraDevice))
            {
                depthTexture = OVRPlugin.GetCameraDeviceDepthFrameTexture(cameraDevice);
            }
            else
            {
                Debug.LogWarning("Camera: depth frame not ready");
                hasError = true;
            }
        }
        if (!hasError)
        {
            Vector3 offset   = mainCamera.transform.position - mixedRealityCamera.transform.position;
            float   distance = Vector3.Dot(mixedRealityCamera.transform.forward, offset);
            cameraFramePlaneDistance = distance;

            cameraFramePlaneObject.transform.position = mixedRealityCamera.transform.position + mixedRealityCamera.transform.forward * distance;
            cameraFramePlaneObject.transform.rotation = mixedRealityCamera.transform.rotation;

            float tanFov = Mathf.Tan(mixedRealityCamera.fieldOfView * Mathf.Deg2Rad * 0.5f);
            cameraFramePlaneObject.transform.localScale = new Vector3(distance * mixedRealityCamera.aspect * tanFov * 2.0f, distance * tanFov * 2.0f, 1.0f);

            float worldHeight = distance * tanFov * 2.0f;
            float worldWidth  = worldHeight * mixedRealityCamera.aspect;

            float cullingDistance = float.MaxValue;

            if (OVRManager.instance.virtualGreenScreenType != OVRManager.VirtualGreenScreenType.Off)
            {
                RefreshBoundaryMesh(mixedRealityCamera, configuration, out cullingDistance);
            }

            cameraFrameMaterial.mainTexture = colorTexture;
            cameraFrameMaterial.SetTexture("_DepthTex", depthTexture);
            cameraFrameMaterial.SetVector("_FlipParams", new Vector4((configuration.flipCameraFrameHorizontally ? 1.0f : 0.0f), (configuration.flipCameraFrameVertically ? 1.0f : 0.0f), 0.0f, 0.0f));
            cameraFrameMaterial.SetColor("_ChromaKeyColor", configuration.chromaKeyColor);
            cameraFrameMaterial.SetFloat("_ChromaKeySimilarity", configuration.chromaKeySimilarity);
            cameraFrameMaterial.SetFloat("_ChromaKeySmoothRange", configuration.chromaKeySmoothRange);
            cameraFrameMaterial.SetFloat("_ChromaKeySpillRange", configuration.chromaKeySpillRange);
            cameraFrameMaterial.SetVector("_TextureDimension", new Vector4(colorTexture.width, colorTexture.height, 1.0f / colorTexture.width, 1.0f / colorTexture.height));
            cameraFrameMaterial.SetVector("_TextureWorldSize", new Vector4(worldWidth, worldHeight, 0, 0));
            cameraFrameMaterial.SetFloat("_SmoothFactor", configuration.dynamicLightingSmoothFactor);
            cameraFrameMaterial.SetFloat("_DepthVariationClamp", configuration.dynamicLightingDepthVariationClampingValue);
            cameraFrameMaterial.SetFloat("_CullingDistance", cullingDistance);
            if (configuration.virtualGreenScreenType == OVRManager.VirtualGreenScreenType.Off || boundaryMesh == null || boundaryMeshMaskTexture == null)
            {
                cameraFrameMaterial.SetTexture("_MaskTex", Texture2D.whiteTexture);
            }
            else
            {
                if (cameraRig == null)
                {
                    if (!nullcameraRigWarningDisplayed)
                    {
                        Debug.LogWarning("Could not find the OVRCameraRig/CenterEyeAnchor object. Please check if the OVRCameraRig has been setup properly. The virtual green screen has been temporarily disabled");
                        nullcameraRigWarningDisplayed = true;
                    }

                    cameraFrameMaterial.SetTexture("_MaskTex", Texture2D.whiteTexture);
                }
                else
                {
                    if (nullcameraRigWarningDisplayed)
                    {
                        Debug.Log("OVRCameraRig/CenterEyeAnchor object found. Virtual green screen is activated");
                        nullcameraRigWarningDisplayed = false;
                    }

                    cameraFrameMaterial.SetTexture("_MaskTex", boundaryMeshMaskTexture);
                }
            }
        }
    }
Ejemplo n.º 5
0
    protected void UpdateCameraFramePlaneObject(Camera mainCamera, Camera mixedRealityCamera, RenderTexture boundaryMeshMaskTexture)
    {
        bool      flag      = false;
        Material  material  = this.cameraFramePlaneObject.GetComponent <MeshRenderer>().material;
        Texture2D texture2D = Texture2D.blackTexture;
        Texture2D value     = Texture2D.whiteTexture;

        if (OVRPlugin.IsCameraDeviceColorFrameAvailable(this.cameraDevice))
        {
            texture2D = OVRPlugin.GetCameraDeviceColorFrameTexture(this.cameraDevice);
        }
        else
        {
            Debug.LogWarning("Camera: color frame not ready");
            flag = true;
        }
        bool flag2 = OVRPlugin.DoesCameraDeviceSupportDepth(this.cameraDevice);

        if (this.useDynamicLighting && flag2)
        {
            if (OVRPlugin.IsCameraDeviceDepthFrameAvailable(this.cameraDevice))
            {
                value = OVRPlugin.GetCameraDeviceDepthFrameTexture(this.cameraDevice);
            }
            else
            {
                Debug.LogWarning("Camera: depth frame not ready");
                flag = true;
            }
        }
        if (!flag)
        {
            Vector3 rhs = mainCamera.transform.position - mixedRealityCamera.transform.position;
            float   num = Vector3.Dot(mixedRealityCamera.transform.forward, rhs);
            this.cameraFramePlaneDistance = num;
            this.cameraFramePlaneObject.transform.position = mixedRealityCamera.transform.position + mixedRealityCamera.transform.forward * num;
            this.cameraFramePlaneObject.transform.rotation = mixedRealityCamera.transform.rotation;
            float num2 = Mathf.Tan(mixedRealityCamera.fieldOfView * 0.0174532924f * 0.5f);
            this.cameraFramePlaneObject.transform.localScale = new Vector3(num * mixedRealityCamera.aspect * num2 * 2f, num * num2 * 2f, 1f);
            float num3     = num * num2 * 2f;
            float x        = num3 * mixedRealityCamera.aspect;
            float maxValue = float.MaxValue;
            this.cameraRig = null;
            if (OVRManager.instance.virtualGreenScreenType != OVRManager.VirtualGreenScreenType.Off)
            {
                this.cameraRig = mainCamera.GetComponentInParent <OVRCameraRig>();
                if (this.cameraRig != null && this.cameraRig.centerEyeAnchor == null)
                {
                    this.cameraRig = null;
                }
                this.RefreshBoundaryMesh(mixedRealityCamera, out maxValue);
            }
            material.mainTexture = texture2D;
            material.SetTexture("_DepthTex", value);
            material.SetVector("_FlipParams", new Vector4((!OVRManager.instance.flipCameraFrameHorizontally) ? 0f : 1f, (!OVRManager.instance.flipCameraFrameVertically) ? 0f : 1f, 0f, 0f));
            material.SetColor("_ChromaKeyColor", OVRManager.instance.chromaKeyColor);
            material.SetFloat("_ChromaKeySimilarity", OVRManager.instance.chromaKeySimilarity);
            material.SetFloat("_ChromaKeySmoothRange", OVRManager.instance.chromaKeySmoothRange);
            material.SetFloat("_ChromaKeySpillRange", OVRManager.instance.chromaKeySpillRange);
            material.SetVector("_TextureDimension", new Vector4((float)texture2D.width, (float)texture2D.height, 1f / (float)texture2D.width, 1f / (float)texture2D.height));
            material.SetVector("_TextureWorldSize", new Vector4(x, num3, 0f, 0f));
            material.SetFloat("_SmoothFactor", OVRManager.instance.dynamicLightingSmoothFactor);
            material.SetFloat("_DepthVariationClamp", OVRManager.instance.dynamicLightingDepthVariationClampingValue);
            material.SetFloat("_CullingDistance", maxValue);
            if (OVRManager.instance.virtualGreenScreenType == OVRManager.VirtualGreenScreenType.Off || this.boundaryMesh == null || boundaryMeshMaskTexture == null)
            {
                material.SetTexture("_MaskTex", Texture2D.whiteTexture);
            }
            else if (this.cameraRig == null)
            {
                if (!this.nullcameraRigWarningDisplayed)
                {
                    Debug.LogWarning("Could not find the OVRCameraRig/CenterEyeAnchor object. Please check if the OVRCameraRig has been setup properly. The virtual green screen has been temporarily disabled");
                    this.nullcameraRigWarningDisplayed = true;
                }
                material.SetTexture("_MaskTex", Texture2D.whiteTexture);
            }
            else
            {
                if (this.nullcameraRigWarningDisplayed)
                {
                    Debug.Log("OVRCameraRig/CenterEyeAnchor object found. Virtual green screen is activated");
                    this.nullcameraRigWarningDisplayed = false;
                }
                material.SetTexture("_MaskTex", boundaryMeshMaskTexture);
            }
        }
    }