public static void ExportRoomToWavefront()
        {
            string selectedFile = EditorUtility.OpenFilePanelWithFilters("Select Room File", MeshSaver.MeshFolderName, new string[] { "Room", "room" });

            if (string.IsNullOrEmpty(selectedFile))
            {
                return;
            }

            string             fileName = Path.GetFileNameWithoutExtension(selectedFile);
            IEnumerable <Mesh> meshes   = null;

            try
            {
                meshes = MeshSaver.Load(fileName);
            }
            catch
            {
                // Handling exceptions, and null returned by MeshSaver.Load, by checking if meshes
                // is still null below.
            }

            if (meshes == null)
            {
                EditorUtility.DisplayDialog(ExportDialogErrorTitle, "Unable to parse selected file.", "Ok");
                return;
            }

            SaveMeshesToWavefront(fileName, meshes);

            // Open the location on where the mesh was saved.
            System.Diagnostics.Process.Start(ExportDirectory);
        }
示例#2
0
        /// <summary>
        /// Loads the SpatialMapping mesh from the specified file.
        /// </summary>
        /// <param Name="fileName">The Name, without path or extension, of the file to load.</param>
        public void Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                Debug.Log("No mesh file specified.");
                return;
            }

            Cleanup();

            try
            {
                IList <Mesh> storedMeshes = MeshSaver.Load(fileName);

                for (int iMesh = 0; iMesh < storedMeshes.Count; iMesh++)
                {
                    AddSurfaceObject(CreateSurfaceObject(
                                         mesh: storedMeshes[iMesh],
                                         objectName: "storedmesh-" + iMesh,
                                         parentObject: transform,
                                         meshID: iMesh
                                         ));
                }
            }
            catch
            {
                Debug.Log("Failed to load " + fileName);
            }
        }
        /// <summary>
        /// Loads the SpatialMapping mesh from the specified file.
        /// </summary>
        /// <param name="fileName">The name, without path or extension, of the file to load.</param>
        public void Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                Debug.Log("No mesh file specified.");
                return;
            }

            Cleanup();

            List <Mesh> storedMeshes = new List <Mesh>();

            try
            {
                storedMeshes.AddRange(MeshSaver.Load(fileName));

                foreach (Mesh mesh in storedMeshes)
                {
                    GameObject surface      = AddSurfaceObject(mesh, "storedmesh-" + SurfaceObjects.Count, transform);
                    Renderer   meshRenderer = surface.GetComponent <MeshRenderer>();

                    if (SpatialMappingManager.Instance.DrawVisualMeshes == false)
                    {
                        meshRenderer.enabled = false;
                    }

                    if (SpatialMappingManager.Instance.CastShadows == false)
                    {
                        meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                    }

                    // Reset the surface mesh collider to fit the updated mesh.
                    // Unity tribal knowledge indicates that to change the mesh assigned to a
                    // mesh collider, the mesh must first be set to null.  Presumably there
                    // is a side effect in the setter when setting the shared mesh to null.
                    MeshCollider meshCollider = surface.GetComponent <MeshCollider>();
                    meshCollider.sharedMesh = null;
                    meshCollider.sharedMesh = surface.GetComponent <MeshFilter>().mesh;
                }
            }
            catch
            {
                Debug.Log("Failed to load " + fileName);
            }
        }
        // Called every frame.
        private void Update()
        {
            // Keyboard commands for saving and loading a remotely generated mesh file.
#if UNITY_EDITOR || UNITY_STANDALONE
            // S - saves the active mesh
            if (Input.GetKeyUp(KeyCode.S))
            {
                MeshSaver.Save(MeshFileName, SpatialMappingManager.Instance.GetMeshes());
            }

            // L - loads the previously saved mesh into editor and sets it to be the spatial mapping source.
            if (Input.GetKeyUp(KeyCode.L))
            {
                SpatialMappingManager.Instance.SetSpatialMappingSource(this);
                Load(MeshFileName);
            }
#endif
        }
示例#5
0
        private void AnchorStoreReady(WorldAnchorStore store)
        {
            // save instance
            anchorStore = store;

            // load room meshes
            roomMeshes = MeshSaver.Load(fileName) as List <Mesh>;

            foreach (Mesh surface in roomMeshes)
            {
                GameObject obj = Instantiate(surfaceObject) as GameObject;
                obj.GetComponent <MeshFilter>().mesh         = surface;
                obj.GetComponent <MeshCollider>().sharedMesh = surface;

                if (!anchorStore.Load(surface.name, obj))
                {
                    Debug.Log("WorldAnchor load failed...");
                }
            }

            GameObject.Find("GameManager").GetComponent <GameManager>().RoomLoaded();
        }
示例#6
0
        public static void ExportRoomToWavefront()
        {
            string             fileName = Path.GetFileNameWithoutExtension("MeshModel");
            IEnumerable <Mesh> meshes   = null;

            try {
                meshes = MeshSaver.Load(fileName);
            }
            catch {
                // Handling exceptions, and null returned by MeshSaver.Load, by checking if meshes
                // is still null below.
            }

            if (meshes == null)
            {
                return;
            }

            SaveMeshesToWavefront(fileName, meshes);

            // Open the location on where the mesh was saved.
            //System.Diagnostics.Process.Start(MeshFolderName);
        }
 /// <summary>
 /// Saves all the currently created spatial source meshes in world space.
 /// </summary>
 /// <param name="fileName">Name to give the mesh file. Exclude path and extension.</param>
 public void SaveSpatialMeshes(string fileName)
 {
     MeshSaver.Save(fileName, GetMeshFilters());
 }
        // Update is called once per frame.
        private void Update()
        {
            // If we have a connected client, presumably the client wants to send some meshes.
            if (clientConnected)
            {
                // Get the clients stream.
                NetworkStream stream = networkClient.GetStream();

                // Make sure there is data in the stream.
                if (stream.DataAvailable)
                {
                    // The first 4 bytes will be the size of the data containing the mesh(es).
                    int datasize = ReadInt(stream);

                    // Allocate a buffer to hold the data.
                    byte[] dataBuffer = new byte[datasize];

                    // Read the data.
                    // The data can come in chunks.
                    int readsize = 0;

                    while (readsize != datasize)
                    {
                        readsize += stream.Read(dataBuffer, readsize, datasize - readsize);
                    }

                    if (readsize != datasize)
                    {
                        Debug.Log("reading mesh failed: " + readsize + " != " + datasize);
                    }

                    // Pass the data to the mesh serializer.
                    List <Mesh> meshes = new List <Mesh>(SimpleMeshSerializer.Deserialize(dataBuffer));

                    // For each mesh, create a GameObject to render it.
                    for (int index = 0; index < meshes.Count; index++)
                    {
                        int meshID = SurfaceObjects.Count;

                        SurfaceObject surface = CreateSurfaceObject(
                            mesh: meshes[index],
                            objectName: "Beamed-" + meshID,
                            parentObject: transform,
                            meshID: meshID
                            );

                        surface.Object.transform.parent = SpatialMappingManager.Instance.transform;

                        AddSurfaceObject(surface);
                    }

                    // SEYOUNG CUSTOM
                    // SAVE AS FILE
                    String MeshFileName = DateTime.Now.ToString("h:mm:ss tt");
                    MeshSaver.Save(MeshFileName, meshes);

                    // Finally disconnect.
                    clientConnected = false;
                    networkClient.Close();

                    // And wait for the next connection.
                    AsyncCallback callback = OnClientConnect;
                    networkListener.BeginAcceptTcpClient(callback, this);
                }
            }
        }
示例#9
0
 /// <summary>
 /// Loads the SpatialMapping mesh from the specified file.
 /// </summary>
 /// <param name="fileName">The name, without path or extension, of the file to load.</param>
 ///
 public void save(string MeshFileName)
 {
     MeshSaver.Save(MeshFileName, SpatialUnderstanding.Instance.GetMeshFilters());
 }
        public bool SaveRoom()
        {
            // if the anchor store is not ready then we cannot save the room mesh
            if (anchorStore == null)
            {
                return(false);
            }

            // delete old relevant anchors
            string[] anchorIds = anchorStore.GetAllIds();
            for (int i = 0; i < anchorIds.Length; i++)
            {
                if (anchorIds[i].Contains(anchorStoreName))
                {
                    anchorStore.Delete(anchorIds[i]);
                }
            }

            // Old anchors deleted...

            // get all mesh filters used for spatial mapping meshes
            roomMeshFilters = SpatialUnderstanding.Instance.UnderstandingCustomMesh.GetMeshFilters() as List <MeshFilter>;

            // Mesh filters fetched...

            // create new list of room meshes for serialization
            List <Mesh> roomMeshes = new List <Mesh>();

            // cycle through all room mesh filters
            foreach (MeshFilter filter in roomMeshFilters)
            {
                // increase count of meshes in room
                meshCount++;

                // make mesh name = anchor name + mesh count
                string meshName = anchorStoreName + meshCount.ToString();
                filter.mesh.name = meshName;

                // add mesh to room meshes for serialization
                roomMeshes.Add(filter.mesh);

                // save world anchor
                WorldAnchor attachingAnchor = filter.gameObject.GetComponent <WorldAnchor>();
                if (attachingAnchor == null)
                {
                    attachingAnchor = filter.gameObject.AddComponent <WorldAnchor>();
                }
                else
                {
                    // Deleting existing anchor...
                    Destroy(attachingAnchor);
                    // Creating new anchor...
                    attachingAnchor = filter.gameObject.AddComponent <WorldAnchor>();
                }
                if (attachingAnchor.isLocated)
                {
                    if (!anchorStore.Save(meshName, attachingAnchor))
                    {
                        Debug.Log("" + meshName + ": Anchor save failed...");
                    }
                }
                else
                {
                    attachingAnchor.OnTrackingChanged += AttachingAnchor_OnTrackingChanged;
                }
            }

            // serialize and save meshes
            MeshSaver.Save(fileName, roomMeshes);
            return(true);
        }