Exemplo n.º 1
0
        /// <summary>
        /// Loads the selected source image as preview.
        /// </summary>
        public void LoadSourceImageAsPreview()
        {
            if (!Application.isPlaying || _previewSourceImagesLoader == null || _previewSourceImagesLoader.colorData == null ||
                cameraSetup.previewIndex == _lastLoadedPreviewIndex || cameraSetup.cameraModels == null || cameraSetup.cameraModels.Length < 1)
            {
                return;
            }
            _lastLoadedPreviewIndex = cameraSetup.previewIndex;
            if (previewSourceTexture != null)
            {
                DestroyImmediate(previewSourceTexture);
            }
            Vector2Int previewResolution = PreviewWindow.GetPreviewResolution(cameraSetup.cameraModels[_lastLoadedPreviewIndex].pixelResolution);

            GeneralToolkit.CreateRenderTexture(ref previewSourceTexture, previewResolution, 0, RenderTextureFormat.ARGB32, false, FilterMode.Point);
            Graphics.Blit(_previewSourceImagesLoader.colorData, previewSourceTexture, _lastLoadedPreviewIndex, 0);
            int previewMaxIndex = cameraSetup.cameraModels.Length - 1;

            PreviewWindow.DisplayImage(_sourceCallerName, previewSourceTexture, previewMaxIndex);
        }
Exemplo n.º 2
0
        /// <summary>
        /// In play mode, loads the rendered view and the evaluation metric for preview.
        /// </summary>
        public void LoadRenderedViewAsPreview()
        {
            RenderTexture.active = null;
            if (_previewEvalTexture != null)
            {
                DestroyImmediate(_previewEvalTexture);
            }
            if (_previewRenderTexture != null)
            {
                DestroyImmediate(_previewRenderTexture);
            }
            // Check that there are camera models, that the application is playing, and that the object is active.
            if (processing.cameraSetup.cameraModels == null || !Application.isPlaying || !gameObject.activeInHierarchy || !_launched)
            {
                return;
            }
            int previewMaxIndex = processing.cameraSetup.cameraModels.Length - 1;
            // Get the camera model for this index.
            CameraModel tempCameraModel = CameraModel.CreateCameraModel();

            tempCameraModel.ParametersFromCameraModel(processing.cameraSetup.cameraModels[processing.cameraSetup.previewIndex]);
            tempCameraModel.pixelResolution = PreviewWindow.GetPreviewResolution(tempCameraModel.pixelResolution);
            // Display a preview of the rendered view.
            if (selectedBlendingMethod != null && selectedEvaluationMethod != null)
            {
                // Inform the blending method to exclude the source view if desired.
                if (selectedEvaluationMethod.excludeSourceView)
                {
                    selectedBlendingMethod.ExcludeSourceView(processing.cameraSetup.previewIndex);
                }
                // Create a preview camera manager and initialize it with the camera model's pose and parameters.
                PreviewCameraManager previewCameraManager   = new GameObject("Preview Camera Manager").AddComponent <PreviewCameraManager>();
                Transform            previewCameraTransform = new GameObject("Preview Camera").transform;
                GeneralToolkit.CreateRenderTexture(ref previewCameraManager.targetTexture, Vector2Int.one, 0, RenderTextureFormat.ARGB32, false, FilterMode.Point, TextureWrapMode.Clamp);
                previewCameraManager.CreatePreviewCamera(previewCameraManager.gameObject, previewCameraTransform, tempCameraModel);
                previewCameraManager.previewCamera.clearFlags      = CameraClearFlags.Color;
                previewCameraManager.previewCamera.backgroundColor = Color.black;
                // Render the preview camera to a target texture, and display it in the preview window.
                previewCameraManager.RenderPreviewToTarget(ref previewCameraManager.targetTexture, false);
                GeneralToolkit.CreateRenderTexture(ref _previewRenderTexture, tempCameraModel.pixelResolution, 0, RenderTextureFormat.ARGB32, false, FilterMode.Point, TextureWrapMode.Clamp);
                Graphics.Blit(previewCameraManager.targetTexture, _previewRenderTexture);
                PreviewWindow.DisplayImage(_renderCallerName, _previewRenderTexture, previewMaxIndex);
                // Destroy the preview camera manager.
                previewCameraManager.DestroyPreviewCamera();
                DestroyImmediate(previewCameraManager.gameObject);
                // Inform the blending method that it should no longer exclude the source view.
                selectedBlendingMethod.ExcludeSourceView(-1);
            }
            DestroyImmediate(tempCameraModel.gameObject);
            // Display the evaluation metric as an RGB color texture.
            if (selectedEvaluationMethod != null && selectedEvaluationMethod.evaluationMaterial != null)
            {
                // Use a shader to compute the evaluation metric for each pixel and display it as a color value.
                GeneralToolkit.CreateRenderTexture(ref _previewEvalTexture, tempCameraModel.pixelResolution, 0, RenderTextureFormat.ARGB32, true, FilterMode.Point, TextureWrapMode.Clamp);
                selectedEvaluationMethod.evaluationMaterial.SetTexture(EvaluationMethod.shaderNameTextureOne, processing.previewSourceTexture);
                selectedEvaluationMethod.evaluationMaterial.SetTexture(EvaluationMethod.shaderNameTextureTwo, _previewRenderTexture);
                Graphics.Blit(null, _previewEvalTexture, selectedEvaluationMethod.evaluationMaterial);
                // Display the created texture in the preview window.
                PreviewWindow.DisplayImage(_evalCallerName, _previewEvalTexture, previewMaxIndex);
            }
        }