Exemplo n.º 1
0
 public byte[] Serialize(Tag tag, CompressionInfo boundingBox)
 {
     RawOffset = tag.AddRaw(mesh.Serialize(this, boundingBox, out Resources));
     MemoryStream stream = new MemoryStream(Size);
     BinaryWriter bw = new BinaryWriter(stream);
     bw.Write(buffer);
     stream.Seek(0, SeekOrigin.Begin);
     VertexCount = (short)mesh.Vertices.Length;
     TriangleCount = (short)(mesh.Indices.Length - 2);
     VertexType = VertexType.Rigid;
     CompressionFlags = Compression.Position | Compression.Texcoord;
     bw.Write((int)VertexType);
     bw.Write(VertexCount);
     bw.Write(TriangleCount);
     stream.Position = 26;
     bw.Write((int)CompressionFlags);
     stream.Position = 56;
     bw.Write(RawOffset);//*
     bw.Write(0);//*
     bw.Write(RawHeaderSize);
     bw.Write(RawDataSize);
     if (!tag.TagReferences.Contains(tag.Filename))
     {
         tag.TagReferences.Add(tag.Filename);
     }
     bw.Write(tag.TagReferences.IndexOf(tag.Filename));
     bw.Close();
     return stream.GetBuffer();
 }
Exemplo n.º 2
0
        public Model(Tag tag)
        {
            BinaryReader br = new BinaryReader(tag.TagStream);
            tag.TagStream.Position = 0;
            buffer = br.ReadBytes(Size);
            tag.TagStream.Position = 0;
            Name = tag.Strings[br.ReadInt32()];

            #region Bounding Boxes

            tag.TagStream.Position = 20;
            int Count = br.ReadInt32();
            if (Count == 1)
            {
                int Offset = br.ReadInt32();
                tag.TagStream.Position = Offset;
                Space = new CompressionInfo(tag.TagStream);
            }
            else throw new Exception();

            #endregion

            #region Mesh Regions

            tag.TagStream.Position = 28;
            Count = br.ReadInt32();
            if (Count > 0)
            {
                int Offset = br.ReadInt32();
                Regions = new Region[Count];
                for (int i = 0; i < Count; i++)
                {
                    tag.TagStream.Position = Offset + (i * Region.Size);
                    Regions[i] = new Region(tag);
                }
            }

            #endregion

            #region Mesh Sections

            tag.TagStream.Position = 36;
            Count = br.ReadInt32();
            if (Count > 0)
            {
                int Offset = br.ReadInt32();
                Sections = new Section[Count];
                for (int i = 0; i < Count; i++)
                {
                    tag.TagStream.Position = Offset + (i * Section.Size);
                    Sections[i] = new Section(tag, Space);
                }
            }

            #endregion

            #region Section Groups

            tag.TagStream.Position = 52;
            Count = br.ReadInt32();
            if (Count > 0)
            {
                int Offset = br.ReadInt32();
                SectionGroups = new SectionGroup[Count];
                for (int i = 0; i < Count; i++)
                {
                    tag.TagStream.Position = Offset + (i * MarkerGroup.Size);
                    SectionGroups[i] = new SectionGroup(tag.TagStream);
                }
            }

            #endregion

            #region Nodes

            tag.TagStream.Position = 72;
            Count = br.ReadInt32();
            if (Count > 0)
            {
                int Offset = br.ReadInt32();
                Nodes = new Node[Count];
                for (int i = 0; i < Count; i++)
                {
                    tag.TagStream.Position = Offset + (i * Node.Size);
                    Nodes[i] = new Node(tag);
                }
            }

            #endregion            

            #region Marker Groups

            tag.TagStream.Position = 88;
            Count = br.ReadInt32();
            if (Count > 0)
            {
                int Offset = br.ReadInt32();
                MarkerGroups = new MarkerGroup[Count];
                for (int i = 0; i < Count; i++)
                {
                    tag.TagStream.Position = Offset + (i * MarkerGroup.Size);
                    MarkerGroups[i] = new MarkerGroup(tag);
                }
            }

            #endregion

            #region Shaders

            tag.TagStream.Position = 96;
            Count = br.ReadInt32();
            if (Count > 0)
            {
                int Offset = br.ReadInt32();
                Shaders = new Shader[Count];
                for (int i = 0; i < Count; i++)
                {
                    tag.TagStream.Position = Offset + (i * Shader.Size);
                    Shaders[i] = new Shader(tag);
                }
            }

            #endregion
        }
Exemplo n.º 3
0
        public Section(Tag tag, CompressionInfo boundingBox)
        {
            BinaryReader br = new BinaryReader(tag.TagStream);
            int StartOffset = (int)tag.TagStream.Position;

            buffer = br.ReadBytes(Size);
            tag.TagStream.Position = StartOffset;

            VertexType = (VertexType)br.ReadInt32();
            VertexCount = br.ReadInt16();
            TriangleCount = br.ReadInt16();

            tag.TagStream.Position = StartOffset + 26;
            CompressionFlags = (Compression)br.ReadInt32();

            tag.TagStream.Position = StartOffset + 56;
            RawOffset = br.ReadInt32();
            RawSize = br.ReadInt32();
            br.ReadInt32();
            RawDataSize = br.ReadInt32();

            tag.TagStream.Position = StartOffset + 72;
            int Count = br.ReadInt32();
            if (Count > 0)
            {
                int Offset = br.ReadInt32();
                Resources = new Resource[Count];
                for (int i = 0; i < Count; i++)
                {
                    tag.TagStream.Position = Offset + (i * Resource.Size);
                    Resources[i] = new Resource(tag.TagStream);
                }
            }
            if (Globals.IsExternalResource(RawOffset)) { return; }
            tag.ResourceStream.Position = tag.ResourceInformation[RawOffset].Address;
            mesh = new Mesh(tag.ResourceStream, Resources, this, boundingBox);

            Microsoft.Xna.Framework.Vector3[] points = new Microsoft.Xna.Framework.Vector3[mesh.Vertices.Length];
            for (int i = 0; i < points.Length; i++)
                points[i] = mesh.Vertices[i].Position;
            BoundingBox = Microsoft.Xna.Framework.BoundingBox.CreateFromPoints(points);
        }