Exemple #1
0
        public static LamellaPerformance Deserialize(byte[] data)
        {
            Mesh mesh  = new Mesh();
            int  index = 0;

            int id     = BitConverter.ToInt32(data, index); index += sizeof(int);
            int nVerts = BitConverter.ToInt32(data, index); index += sizeof(int);

            var vertArray = new float[nVerts * 3];

            Buffer.BlockCopy(data, index, vertArray, 0, nVerts * 3 * sizeof(float));
            index += nVerts * 3 * sizeof(float);

            for (int i = 0; i < nVerts; ++i)
            {
                mesh.Vertices.Add(vertArray[i * 3], vertArray[i * 3 + 1], vertArray[i * 3 + 2]);
            }

            int nFaces = BitConverter.ToInt32(data, index); index += sizeof(int);

            var faceArray = new int[nFaces * 4];

            Buffer.BlockCopy(data, index, faceArray, 0, nFaces * 4 * sizeof(int));
            index += nFaces * 4 * sizeof(int);

            for (int i = 0; i < nFaces; ++i)
            {
                mesh.Faces.AddFace(
                    faceArray[i * 4],
                    faceArray[i * 4 + 1],
                    faceArray[i * 4 + 2],
                    faceArray[i * 4 + 3]);
            }

            var lp = new LamellaPerformance(mesh, id);

            int nLayers = BitConverter.ToInt32(data, index); index += sizeof(int);

            for (int i = 0; i < nLayers; ++i)
            {
                int nameLength = BitConverter.ToInt32(data, index); index += sizeof(int);
                var nameBytes  = new byte[nameLength];
                Buffer.BlockCopy(data, index, nameBytes, 0, nameLength); index += nameLength;
                string layer_name = System.Text.Encoding.UTF8.GetString(nameBytes);

                int layerLength = BitConverter.ToInt32(data, index); index += sizeof(int);
                var layerData   = new double[layerLength];
                Buffer.BlockCopy(data, index, layerData, 0, layerLength * sizeof(double));
                index += layerLength * sizeof(double);

                lp.Layers.Add(layer_name, layerData);
            }

            return(lp);
        }
Exemple #2
0
        public static List <LamellaPerformance> DeserializeMany(byte[] data)
        {
            var lps = new List <LamellaPerformance>();

            int index = 0;
            var N     = BitConverter.ToInt32(data, index);

            for (int i = 0; i < N; ++i)
            {
                var lpLength = BitConverter.ToInt32(data, index);
                index += sizeof(int);

                var lpdata = new byte[lpLength];
                Buffer.BlockCopy(data, index, lpdata, 0, lpLength);

                var lp = LamellaPerformance.Deserialize(lpdata);

                lps.Add(lp);
            }

            return(lps);
        }