Deserialize() public static method

Deserializes a list of Mesh objects from the provided byte array.
public static Deserialize ( byte data ) : IEnumerable
data byte Binary data to be deserialized into a list of Mesh objects.
return IEnumerable
示例#1
0
        /// <summary>
        /// Loads the specified mesh file.
        /// </summary>
        /// <param name="fileName">Name of the saved mesh file. Exclude path and extension.</param>
        /// <returns>Collection of Mesh objects read from the file.</returns>
        /// <remarks>Determines the path from which to load and automatically applies the file extension.</remarks>
        public static IEnumerable <Mesh> Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Must specify a valid fileName.");
            }

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

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

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

            using (Stream stream = OpenFileForRead(folderName, fileName + fileExtension))
            {
                // Read the file and deserialize the meshes.
                byte[] data = new byte[stream.Length];
                stream.Read(data, 0, data.Length);

                meshes.AddRange(SimpleMeshSerializer.Deserialize(data));
            }

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

            return(meshes);
        }
示例#2
0
        // Update is called once per frame.
        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++)
                    {
                        GameObject surface = AddSurfaceObject(meshes[index], string.Format("Beamed-{0}", surfaceObjects.Count), transform);
                        surface.transform.parent = SpatialMappingManager.Instance.transform;

                        if (SpatialMappingManager.Instance.DrawVisualMeshes == false)
                        {
                            surface.GetComponent <MeshRenderer>().enabled = false;
                        }

                        if (SpatialMappingManager.Instance.CastShadows == false)
                        {
                            surface.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                        }
                    }

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

                    // And wait for the next connection.
                    AsyncCallback callback = new AsyncCallback(OnClientConnect);
                    networkListener.BeginAcceptTcpClient(callback, this);
                }
            }
        }