/// <summary>
        /// Sends the spatial mapping surfaces from the HoloLens to a remote system running the Unity editor.
        /// </summary>
        private void SendMeshes()
        {
#if !UNITY_EDITOR && UNITY_METRO
            List <MeshFilter> MeshFilters = SpatialMappingManager.Instance.GetMeshFilters();
            for (int index = 0; index < MeshFilters.Count; index++)
            {
                List <Mesh>    meshesToSend = new List <Mesh>();
                MeshFilter     filter       = MeshFilters[index];
                Mesh           source       = filter.sharedMesh;
                Mesh           clone        = new Mesh();
                List <Vector3> verts        = new List <Vector3>();
                verts.AddRange(source.vertices);

                for (int vertIndex = 0; vertIndex < verts.Count; vertIndex++)
                {
                    verts[vertIndex] = filter.transform.TransformPoint(verts[vertIndex]);
                }

                clone.SetVertices(verts);
                clone.SetTriangles(source.triangles, 0);
                meshesToSend.Add(clone);
                byte[] serialized = SimpleMeshSerializer.Serialize(meshesToSend);
                RemoteMeshSource.Instance.SendData(serialized);
            }
#endif
        }
Пример #2
0
        /// <summary>
        /// Saves the provided meshes to the specified file.
        /// </summary>
        /// <param name="fileName">Name to give the saved mesh file. Exclude path and extension.</param>
        /// <param name="meshes">The collection of Mesh objects to save.</param>
        /// <returns>Fully qualified name of the saved mesh file.</returns>
        /// <remarks>Determines the save path to use and automatically applies the file extension.</remarks>
        public static string Save(string fileName, IEnumerable <Mesh> meshes)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Must specify a valid fileName.");
            }

            if (meshes == null)
            {
                throw new ArgumentNullException("Value of meshes cannot be null.");
            }

            // Create the mesh file.
            String folderName = MeshFolderName;

            Debug.Log(String.Format("Saving mesh file: {0}", Path.Combine(folderName, fileName + fileExtension)));

            using (Stream stream = OpenFileForWrite(folderName, fileName + fileExtension))
            {
                // Serialize and write the meshes to the file.
                byte[] data = SimpleMeshSerializer.Serialize(meshes);
                stream.Write(data, 0, data.Length);
                stream.Flush();
            }

            Debug.Log("Mesh file saved.");

            return(Path.Combine(folderName, fileName + fileExtension));
        }
Пример #3
0
        /// <summary>
        /// Sends the spatial mapping surfaces from the HoloLens to a remote system running the Unity editor.
        /// </summary>
        private void SendMeshes(object source, System.EventArgs args)
        {
                        #if !UNITY_EDITOR && UNITY_WSA
            Debug.Log("Entered sendmeshes");
            List <GameObject> vertical = new List <GameObject> ();
            vertical = SurfaceMeshesToPlanes.Instance.GetActivePlanes(PlaneTypes.Wall);
            List <Mesh> meshesToSend = new List <Mesh>();

            foreach (GameObject plane in vertical)
            {
                Mesh       viewedModel;
                MeshFilter viewedModelFilter = (MeshFilter)plane.GetComponent("MeshFilter");
                viewedModel = viewedModelFilter.sharedMesh;

                Mesh           clone = new Mesh();
                List <Vector3> verts = new List <Vector3>();
                verts.AddRange(viewedModel.vertices);

                for (int vertIndex = 0; vertIndex < verts.Count; vertIndex++)
                {
                    verts[vertIndex] = viewedModelFilter.transform.TransformPoint(verts[vertIndex]);
                }
                clone.SetVertices(verts);
                clone.SetTriangles(viewedModel.triangles, 0);
                meshesToSend.Add(clone);
            }
            byte[] serialized = SimpleMeshSerializer.Serialize(meshesToSend);
            RemoteMeshSource.Instance.SendData(serialized);

            /*List<MeshFilter> MeshFilters = SpatialMappingManager.Instance.GetMeshFilters();
             * for (int index = 0; index < MeshFilters.Count; index++)
             * {
             * List<Mesh> meshesToSend = new List<Mesh>();
             * MeshFilter filter = MeshFilters[index];
             * Mesh source = filter.sharedMesh;
             * Mesh clone = new Mesh();
             * List<Vector3> verts = new List<Vector3>();
             * verts.AddRange(source.vertices);
             *
             * for(int vertIndex=0; vertIndex < verts.Count; vertIndex++)
             * {
             * verts[vertIndex] = filter.transform.TransformPoint(verts[vertIndex]);
             * }
             *
             *
             *
             * clone.SetVertices(verts);
             * clone.SetTriangles(source.triangles, 0);
             * meshesToSend.Add(clone);
             * byte[] serialized = SimpleMeshSerializer.Serialize(meshesToSend);
             * RemoteMeshSource.Instance.SendData(serialized);
             * }*/
                #endif
        }