Exemple #1
0
        public byte[] Serialize()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(Centre.Serialize());
                    writer.Write(CollRadius);
                    writer.Write(NumVetices);

                    foreach (TRVertex vert in Vertices)
                    {
                        writer.Write(vert.Serialize());
                    }

                    writer.Write(NumNormals);

                    if (NumNormals > 0)
                    {
                        foreach (TRVertex normal in Normals)
                        {
                            writer.Write(normal.Serialize());
                        }
                    }
                    else
                    {
                        foreach (ushort light in Lights)
                        {
                            writer.Write(light);
                        }
                    }

                    writer.Write(NumTexturedRectangles);
                    foreach (TRFace4 face in TexturedRectangles)
                    {
                        writer.Write(face.Serialize());
                    }

                    writer.Write(NumTexturedTriangles);
                    foreach (TRFace3 face in TexturedTriangles)
                    {
                        writer.Write(face.Serialize());
                    }

                    writer.Write(NumColouredRectangles);
                    foreach (TRFace4 face in ColouredRectangles)
                    {
                        writer.Write(face.Serialize());
                    }

                    writer.Write(NumColouredTriangles);
                    foreach (TRFace3 face in ColouredTriangles)
                    {
                        writer.Write(face.Serialize());
                    }
                }

                return(stream.ToArray());
            }
        }
Exemple #2
0
        public byte[] Serialize()
        {
            using (MemoryStream stream = new MemoryStream())
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(Centre.Serialize());
                    writer.Write(CollRadius);
                    writer.Write(NumVertices);

                    foreach (TRVertex vert in Vertices)
                    {
                        writer.Write(vert.Serialize());
                    }

                    writer.Write(NumNormals);

                    if (NumNormals > 0)
                    {
                        foreach (TRVertex normal in Normals)
                        {
                            writer.Write(normal.Serialize());
                        }
                    }
                    else
                    {
                        foreach (ushort light in Lights)
                        {
                            writer.Write(light);
                        }
                    }

                    writer.Write(NumTexturedRectangles);
                    foreach (TRFace4 face in TexturedRectangles)
                    {
                        writer.Write(face.Serialize());
                    }

                    writer.Write(NumTexturedTriangles);
                    foreach (TRFace3 face in TexturedTriangles)
                    {
                        writer.Write(face.Serialize());
                    }

                    writer.Write(NumColouredRectangles);
                    foreach (TRFace4 face in ColouredRectangles)
                    {
                        writer.Write(face.Serialize());
                    }

                    writer.Write(NumColouredTriangles);
                    foreach (TRFace3 face in ColouredTriangles)
                    {
                        writer.Write(face.Serialize());
                    }

                    // 4-byte alignment for mesh data
                    long padding = writer.BaseStream.Position % 4;
                    for (int i = 0; i < padding; i++)
                    {
                        writer.Write((byte)0);
                    }

                    return(stream.ToArray());
                }
        }