// 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
        }
 /// <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);
                }
            }
        }
Ejemplo n.º 4
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);
        }