public static Texture2D CaptureCameraFrame(Camera camera, int frameWidth, int frameHeight, CameraTransformInfo captureLocation, LayerMask layerToRender)
        {
            var originalTransform = new CameraTransformInfo()
            {
                position = camera.transform.position, rotation = camera.transform.rotation.eulerAngles
            };
            var originalRenderTarget  = camera.targetTexture;
            var originalRenderTexture = RenderTexture.active;
            var originalLayerMask     = camera.cullingMask;
            var rt = RenderTexture.GetTemporary(frameWidth, frameHeight, 0, RenderTextureFormat.ARGB32);

            camera.transform.position = captureLocation.position;
            camera.transform.rotation = Quaternion.Euler(captureLocation.rotation);
            camera.targetTexture      = rt;
            camera.cullingMask        = layerToRender;
            RenderTexture.active      = rt;

            camera.Render();
            var tex = new Texture2D(frameWidth, frameHeight, TextureFormat.RGB24, false);

            TextureUtils.RenderTextureToTexture2D(rt, tex);

            camera.transform.position = originalTransform.position;
            camera.transform.rotation = Quaternion.Euler(originalTransform.rotation);
            camera.targetTexture      = originalRenderTarget;
            camera.cullingMask        = originalLayerMask;
            RenderTexture.active      = originalRenderTexture;

            RenderTexture.ReleaseTemporary(rt);
            return(tex);
        }
Beispiel #2
0
        void OnCameraTransformInfoChanged(CameraTransformInfo newData)
        {
            if (m_XrRig == null)
            {
                return;
            }

            m_XrRig.MoveCameraToWorldLocation(newData.position);
            var rotation = newData.rotation.y - m_XrRig.transform.eulerAngles.y;

            m_XrRig.RotateAroundCameraUsingRigUp(rotation);
        }
Beispiel #3
0
        void OnProjectStateDataChanged(UIProjectStateData data)
        {
            if (m_XrRig == null || m_CameraTransformInfo == data.cameraTransformInfo)
            {
                return;
            }

            m_XrRig.MoveCameraToWorldLocation(data.cameraTransformInfo.position);
            var rotation = data.cameraTransformInfo.rotation.y - m_XrRig.transform.eulerAngles.y;

            m_XrRig.RotateAroundCameraUsingRigUp(rotation);

            m_CameraTransformInfo = data.cameraTransformInfo;
        }
        public static Texture2D CaptureCameraFrame(Camera camera, int frameWidth, int frameHeight, CameraTransformInfo captureLocation, LayerMask layerToRender, ScriptableRendererFeature[] featuresToDisable = null)
        {
            var originalTransform = new CameraTransformInfo()
            {
                position = camera.transform.position, rotation = camera.transform.rotation.eulerAngles
            };
            var originalRenderTarget  = camera.targetTexture;
            var originalRenderTexture = RenderTexture.active;
            var originalLayerMask     = camera.cullingMask;
            var rt = RenderTexture.GetTemporary(frameWidth, frameHeight, 0, RenderTextureFormat.ARGB32);

            camera.transform.position = captureLocation.position;
            camera.transform.rotation = Quaternion.Euler(captureLocation.rotation);
            camera.targetTexture      = rt;
            camera.cullingMask        = layerToRender;
            RenderTexture.active      = rt;
            var originalFeaturesActive = new bool[featuresToDisable.Length];

            if (featuresToDisable != null)
            {
                for (int i = 0; i < featuresToDisable.Length; i++)
                {
                    originalFeaturesActive[i] = featuresToDisable[i].isActive;
                    featuresToDisable[i].SetActive(false);
                }
            }

            camera.Render();
            var tex = new Texture2D(frameWidth, frameHeight, TextureFormat.RGB24, false);

            TextureUtils.RenderTextureToTexture2D(rt, tex);

            camera.transform.position = originalTransform.position;
            camera.transform.rotation = Quaternion.Euler(originalTransform.rotation);
            camera.targetTexture      = originalRenderTarget;
            camera.cullingMask        = originalLayerMask;
            RenderTexture.active      = originalRenderTexture;

            if (featuresToDisable != null)
            {
                for (int i = 0; i < featuresToDisable.Length; i++)
                {
                    featuresToDisable[i].SetActive(originalFeaturesActive[i]);
                }
            }

            RenderTexture.ReleaseTemporary(rt);
            return(tex);
        }