コード例 #1
0
ファイル: MeshSaver.cs プロジェクト: Darrus/ClicketyClack
        /// <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 IList <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;
            string filePath   = Path.Combine(folderName, fileName + fileExtension);

            Debug.Log(String.Format("Loading mesh file: {0}", filePath));

#if UNITY_WINRT
            byte[] bytes = UnityEngine.Windows.File.ReadAllBytes(filePath);
#else
            byte[] bytes = System.IO.File.ReadAllBytes(fileName);
#endif

            meshes.AddRange(SimpleMeshSerializer.Deserialize(bytes));
            Debug.Log("Mesh file loaded.");
            return(meshes);
        }
コード例 #2
0
        // 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);
                    }

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

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