Ejemplo n.º 1
0
    void OnGUI()
    {
        EditorGUILayout.BeginVertical("Box");
        {
            RenderTitle("Recording");

            if (!IsRecording())
            {
                EditorGUILayout.BeginVertical("Box");
                {
                    if (GUILayout.Button("Start Recording"))
                    {
                        StartRecording();
                    }
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.BeginVertical("Box");
                {
                    if (GUILayout.Button("Stop Recording"))
                    {
                        StopRecording();
                    }
                }
                EditorGUILayout.EndVertical();
            }
        }

        if (GUILayout.Button("Take Picture"))
        {
            TakePicture();
        }

        if (CaptureHiResHolograms() && GUILayout.Button("Take Canon Picture"))
        {
            TakeCanonPicture();
        }

        EditorGUILayout.Space();

        // Open Folder
        if (GUILayout.Button("Open Folder"))
        {
            Process.Start(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "HologramCapture"));
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical("Box");
        {
            RenderTitle("Hologram Settings");

            float oldAlpha = GetAlpha();
            float newAlpha = EditorGUILayout.Slider("Alpha", oldAlpha, 0, 1);
            if (newAlpha != oldAlpha)
            {
                SetAlpha(newAlpha);
            }

            if (SpectatorView.HolographicCameraManager.Instance != null &&
                SpectatorView.ShaderManager.Instance != null &&
                SpectatorView.ShaderManager.Instance.colorTexture != null &&
                SpectatorView.ShaderManager.Instance.renderTexture != null &&
                SpectatorView.ShaderManager.Instance.holoTexture != null &&
                SpectatorView.ShaderManager.Instance.alphaBlendVideoMat != null &&
                SpectatorView.ShaderManager.Instance.alphaBlendOutputMat != null &&
                SpectatorView.ShaderManager.Instance.alphaBlendPreviewMat != null)
            {
                SpectatorView.HolographicCameraManager.Instance.DefaultAlpha = newAlpha;

                SpectatorView.ShaderManager.Instance.alphaBlendVideoMat.SetFloat("_Alpha", newAlpha);
                SpectatorView.ShaderManager.Instance.alphaBlendOutputMat.SetFloat("_Alpha", newAlpha);
                SpectatorView.ShaderManager.Instance.alphaBlendPreviewMat.SetFloat("_Alpha", newAlpha);
            }

            EditorGUILayout.Space();

            float previousFrameOffset = GetFrameOffset();
            float newFrameOffset      = EditorGUILayout.Slider("Frame Offset", previousFrameOffset, 0, maxFrameOffset);

            if (SpectatorView.HolographicCameraManager.Instance)
            {
                SpectatorView.HolographicCameraManager.Instance.DefaultFrameOffset = newFrameOffset;
            }

            if (newFrameOffset != previousFrameOffset)
            {
                SetFrameOffset(newFrameOffset);
            }
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical("Box");
        {
            RenderTitle("Composite");

            if (GUILayout.Button("Toggle View"))
            {
                showAllTextures = !showAllTextures;
            }

            EditorGUILayout.BeginHorizontal("Box");
            {
                if (GUILayout.Button("Toggle Full Screen"))
                {
                    PreviewWindow.ShowWindow();
                }

                GUILayout.Label("Width: ");
                string w = GUILayout.TextField(fullScreenWidth.ToString());
                fullScreenWidth = Convert.ToInt32(w);

                GUILayout.Label("Height: ");
                string h = GUILayout.TextField(fullScreenHeight.ToString());
                fullScreenHeight = Convert.ToInt32(h);

                PreviewWindow.SetDimensions(Convert.ToInt32(w), Convert.ToInt32(h));
            }
            EditorGUILayout.EndHorizontal();

            if (HoloToolkit.Unity.SpatialMapping.SpatialMappingManager.Instance != null)
            {
                // Request Spatial Mapping
                if (GUILayout.Button("Spatial Mapping"))
                {
                    // Clear any old spatial mapping meshes.
                    if (HoloToolkit.Unity.SpatialMapping.SpatialMappingManager.Instance)
                    {
                        SpectatorView.RemoteSpatialMappingSource rsms =
                            HoloToolkit.Unity.SpatialMapping.SpatialMappingManager.Instance.GetComponent <SpectatorView.RemoteSpatialMappingSource>();
                        if (rsms != null)
                        {
                            rsms.ClearMeshes();
                        }
                        else
                        {
                            rsms = HoloToolkit.Unity.SpatialMapping.SpatialMappingManager.Instance.gameObject.AddComponent <SpectatorView.RemoteSpatialMappingSource>();
                            if (rsms != null)
                            {
                                rsms.ClearMeshes();
                            }
                        }
                    }

                    // Set a flag on the tppc device to send a new mesh.
                    SpectatorView.SV_CustomMessages.Instance.SendSpatialMappingRequest();
                }
            }

            // Rendering
            if (showVideo)
            {
                Rect  spacing = GUILayoutUtility.GetRect(1, 2);
                float left    = 0;
                UpdateFrameDimensions(spacing.y, ref left);

                Rect framesRect = GUILayoutUtility.GetRect(frameWidth * 2 + padding, frameHeight * 2 + padding);
                framesRect.x += left;

                if (Event.current != null && Event.current.type == EventType.Repaint)
                {
                    if (SpectatorView.HolographicCameraManager.Instance != null &&
                        SpectatorView.ShaderManager.Instance != null)
                    {
                        if (
                            SpectatorView.ShaderManager.Instance.colorTexture != null &&
                            SpectatorView.ShaderManager.Instance.renderTexture != null &&
                            SpectatorView.ShaderManager.Instance.holoTexture != null &&
                            SpectatorView.ShaderManager.Instance.alphaBlendVideoMat != null &&
                            SpectatorView.ShaderManager.Instance.alphaBlendOutputMat != null &&
                            SpectatorView.ShaderManager.Instance.alphaBlendPreviewMat != null
                            )
                        {
                            if (!SpectatorView.ShaderManager.Instance.setAlphaBlendPreviewHoloTex)
                            {
                                SpectatorView.ShaderManager.Instance.setAlphaBlendPreviewHoloTex = true;
                                if (QueueingHoloFrames())
                                {
                                    SpectatorView.ShaderManager.Instance.alphaBlendPreviewMat.SetTexture("_FrontTex", SpectatorView.ShaderManager.Instance.holoTexture);
                                    SpectatorView.ShaderManager.Instance.alphaBlendVideoMat.SetTexture("_FrontTex", SpectatorView.ShaderManager.Instance.holoTexture);
                                    SpectatorView.ShaderManager.Instance.alphaBlendOutputMat.SetTexture("_FrontTex", SpectatorView.ShaderManager.Instance.holoTexture);
                                }
                                else
                                {
                                    SpectatorView.ShaderManager.Instance.alphaBlendPreviewMat.SetTexture("_FrontTex", SpectatorView.ShaderManager.Instance.renderTexture);
                                    SpectatorView.ShaderManager.Instance.alphaBlendVideoMat.SetTexture("_FrontTex", SpectatorView.ShaderManager.Instance.renderTexture);
                                    SpectatorView.ShaderManager.Instance.alphaBlendOutputMat.SetTexture("_FrontTex", SpectatorView.ShaderManager.Instance.renderTexture);
                                }
                            }

                            Graphics.DrawTexture(
                                new Rect(framesRect.x, framesRect.y, frameWidth, frameHeight),
                                SpectatorView.ShaderManager.Instance.colorTexture,
                                SpectatorView.ShaderManager.Instance.alphaBlendPreviewMat);
                        }

                        if (showAllTextures)
                        {
                            if (QueueingHoloFrames())
                            {
                                if (SpectatorView.ShaderManager.Instance.holoTexture != null)
                                {
                                    Graphics.DrawTexture
                                    (
                                        new Rect(framesRect.x, framesRect.y + frameHeight + padding, frameWidth, frameHeight),
                                        SpectatorView.ShaderManager.Instance.holoTexture
                                    );
                                }
                            }
                            else
                            {
                                if (SpectatorView.ShaderManager.Instance.renderTexture != null)
                                {
                                    Graphics.DrawTexture
                                    (
                                        new Rect(framesRect.x, framesRect.y + frameHeight + padding, frameWidth, frameHeight),
                                        SpectatorView.ShaderManager.Instance.renderTexture
                                    );
                                }
                            }

                            if (SpectatorView.ShaderManager.Instance.flipHorizontallyMat != null &&
                                SpectatorView.ShaderManager.Instance.colorTexture != null)
                            {
                                Graphics.DrawTexture
                                (
                                    new Rect(framesRect.x + frameWidth + padding, framesRect.y + 0, frameWidth, frameHeight),
                                    SpectatorView.ShaderManager.Instance.colorTexture,
                                    SpectatorView.ShaderManager.Instance.flipHorizontallyMat
                                );
                            }

                            if (QueueingHoloFrames())
                            {
                                if (SpectatorView.ShaderManager.Instance.holoTexture != null && SpectatorView.ShaderManager.Instance.alphaMat != null)
                                {
                                    Graphics.DrawTexture
                                    (
                                        new Rect(framesRect.x + frameWidth + padding, framesRect.y + frameHeight + padding, frameWidth, frameHeight),
                                        SpectatorView.ShaderManager.Instance.holoTexture,
                                        SpectatorView.ShaderManager.Instance.alphaMat
                                    );
                                }
                            }
                            else
                            {
                                if (SpectatorView.ShaderManager.Instance.renderTexture != null && SpectatorView.ShaderManager.Instance.alphaMat != null)
                                {
                                    Graphics.DrawTexture
                                    (
                                        new Rect(framesRect.x + frameWidth + padding, framesRect.y + frameHeight + padding, frameWidth, frameHeight),
                                        SpectatorView.ShaderManager.Instance.renderTexture,
                                        SpectatorView.ShaderManager.Instance.alphaMat
                                    );
                                }
                            }
                        }
                    }
                }
            }
        }
        EditorGUILayout.EndVertical();
    }