/// <summary> /// Updates the preview camera with the camera model, and displays the rendered view in the preview window. /// </summary> /// <param name="useFullResolution"></param> Whether to use the full resolution (capture) or one limited for preview (preview window). public void UpdatePreviewCameraModel(bool useFullResolution) { // The preview camera manager, and its camera, need to have been initialized in a previous step. if (_previewCameraManager != null && _previewCameraManager.previewCamera != null) { // Update the preview camera's camera model, and render the preview image. CameraModel cameraParams = cameraSetup.cameraModels[cameraSetup.previewIndex]; _previewCameraManager.UpdateCameraModel(cameraParams, useFullResolution); _previewCameraManager.RenderPreviewToTarget(ref _previewCameraManager.targetTexture, false); int previewMaxIndex = cameraSetup.cameraModels.Length - 1; PreviewWindow.DisplayImage(_colorCallerName, _previewCameraManager.targetTexture, previewMaxIndex); // If depth data, or mesh data, is to be acquired, display a depth preview. if (_acquireDepthData || _copyGlobalMesh) { // Render actual depth into a precise depth texture. GeneralToolkit.CreateRenderTexture(ref _targetDepthTexture, cameraParams.pixelResolution, 24, RenderTextureFormat.RFloat, true, FilterMode.Point, TextureWrapMode.Clamp); _previewCameraManager.RenderPreviewToTarget(ref _targetDepthTexture, true); // Encode the depth texture into a color texture, using a colormap suited for visualization. if (_distanceToColorMat == null) { _distanceToColorMat = new Material(GeneralToolkit.shaderAcquisitionConvert01ToColor); } _distanceToColorMat.SetInt(shaderNameIsPrecise, 0); GeneralToolkit.CreateRenderTexture(ref _distanceAsColorTexture, cameraParams.pixelResolution, 0, RenderTextureFormat.ARGB32, true, FilterMode.Point, TextureWrapMode.Clamp); Graphics.Blit(_targetDepthTexture, _distanceAsColorTexture, _distanceToColorMat); // Display the texture in the preview window. PreviewWindow.DisplayImage(_depthCallerName, _distanceAsColorTexture, previewMaxIndex); // Reset the active render texture. RenderTexture.active = null; } } }
/// <summary> /// Updates the preview camera's pose and parameters. /// </summary> public void UpdateCameraModel() { // Render the image and display it in the preview window. if (_previewCameraManager != null && _previewCameraManager.previewCamera != null) { // Set the preview camera to the current model parameters. _previewCameraManager.UpdateCameraModel(cameraModel); // Render the preview and display it. _previewCameraManager.RenderPreviewToTarget(ref _previewCameraManager.targetTexture, false); PreviewWindow.DisplayImage(_previewCallerName, _previewCameraManager.targetTexture, 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); }
/// <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); } }