/// <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_WSA 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 }
/// <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)); }