protected void OnPreviewFrameChanged(Wrapper.CaptureState state)
        {
            var sizeChanged = false;

            if (videoTexture == null)
            {
                if (state.width != Width || state.height != Height)
                {
                    Debug.Log("Video texture does not match the size requested, using " + state.width + " x " + state.height);
                }

                videoTexture = Texture2D.CreateExternalTexture(state.width, state.height, TextureFormat.BGRA32, false, false, state.imgTexture);

                sizeChanged = true;

                if (VideoRenderer != null)
                {
                    VideoRenderer.enabled = true;
                    VideoRenderer.sharedMaterial.SetTexture("_MainTex", videoTexture);
                    VideoRenderer.sharedMaterial.SetTextureScale("_MainTex", new Vector2(1, -1)); // flip texture
                }
            }
            else if (videoTexture.width != state.width || videoTexture.height != state.height)
            {
                Debug.Log("Video texture size changed, using " + state.width + " x " + state.height);

                videoTexture.UpdateExternalTexture(state.imgTexture);

                sizeChanged = true;
            }

            if (sizeChanged)
            {
                Debug.Log($"Size Changed = {state.width} x {state.height}");

                Width  = state.width;
                Height = state.height;
            }

            if (CameraTracker != null)
            {
                CameraTracker.UpdateCameraMatrices(state.cameraWorld, state.cameraProjection);
            }
        }
Exemple #2
0
        private void OnVideoFrame(Wrapper.CaptureState state)
        {
            if (videoTexture == null)
            {
                videoTexture = Texture2D.CreateExternalTexture(state.width, state.height, TextureFormat.BGRA32, false, false, state.imgTexture);

                if (videoRenderer != null)
                {
                    videoRenderer.enabled = true;
                    videoRenderer.material.SetTexture("_MainTex", videoTexture);
                    videoRenderer.material.SetTextureScale("_MainTex", new Vector2(1, -1));
                }
            }
            else if (videoTexture.width != state.width || videoTexture.height != state.height)
            {
                videoTexture.UpdateExternalTexture(state.imgTexture);
            }

            // upate object using this information
            if (cameraTracker != null)
            {
                cameraTracker.UpdateCameraMatrices(state.cameraWorld, state.cameraProjection);
            }
        }