示例#1
0
        void OnSpatialMapping(NetworkInMessage msg)
        {
#if UNITY_EDITOR
            if (SpatialMappingManager.Instance == null)
            {
                return;
            }

            RemoteSpatialMappingSource rsms = SpatialMappingManager.Instance.GetComponent <RemoteSpatialMappingSource>();

            if (rsms == null)
            {
                return;
            }

            msg.ReadInt64();

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector3> normals   = new List <Vector3>();
            List <int>     triangles = new List <int>();

            int vertexCount   = msg.ReadInt32();
            int normalCount   = msg.ReadInt32();
            int triangleCount = msg.ReadInt32();

            for (int i = 0; i < vertexCount; i++)
            {
                Vector3 vertex = SV_CustomMessages.Instance.ReadVector3(msg);
                vertices.Add(vertex);
            }

            for (int i = 0; i < normalCount; i++)
            {
                Vector3 normal = SV_CustomMessages.Instance.ReadVector3(msg);
                normals.Add(normal);
            }

            for (int i = 0; i < triangleCount; i++)
            {
                int index = msg.ReadInt32();
                triangles.Add(index);
            }

            SpatialMappingManager.Instance.transform.parent        = transform;
            SpatialMappingManager.Instance.transform.localPosition = Vector3.zero;
            SpatialMappingManager.Instance.transform.localRotation = Quaternion.identity;

            rsms.AddSurface(vertices, normals, triangles);
#endif
        }
        void Update()
        {
#if UNITY_EDITOR
            if (_createSpatialMapInEditor && smBytes.Count >= spatialMappingNumChunks)
            {
                _createSpatialMapInEditor = false;

                int    meshIndex = -1;
                byte[] bytes     = new byte[0];

                for (int i = 0; i < smBytes.Count; i++)
                {
                    if (smBytes[i].meshIndex != meshIndex)
                    {
                        meshIndex = smBytes[i].meshIndex;
                        if (bytes.Length != 0)
                        {
                            // Deserialize the old bytes.
                            IEnumerable <Mesh> meshes = SpectatorView.SV_SimpleMeshSerializer.Deserialize(bytes);
                            foreach (Mesh mesh in meshes)
                            {
                                GameObject sm = HoloToolkit.Unity.SpatialMapping.SpatialMappingManager.Instance.gameObject;
                                RemoteSpatialMappingSource src = sm.GetComponent <RemoteSpatialMappingSource>();
                                List <Vector3>             v   = new List <Vector3>(mesh.vertices);
                                List <Vector3>             n   = new List <Vector3>(mesh.normals);
                                List <int> t = new List <int>(mesh.triangles);

                                src.AddSurface(v, n, t, UNetAnchorManager.Instance.gameObject.transform);
                            }
                        }

                        // Update byte array with new mesh's size.
                        bytes = new byte[smBytes[i].totalMeshBytes];
                    }

                    // Copy network chunk to appropriate spot in the destination buffer.
                    System.Array.Copy(smBytes[i].bytes, 0, bytes, NetworkedChunkSize * smBytes[i].chunkIndex, smBytes[i].chunkLength);
                }
            }
#endif
        }
示例#3
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();
    }