Ejemplo n.º 1
0
 public short ReadInt16()
 {
     return(Endian.SwapInt16(Reader.ReadInt16()));
 }
Ejemplo n.º 2
0
 public int ReadInt32()
 {
     return(Endian.SwapInt32(Reader.ReadInt32()));
 }
Ejemplo n.º 3
0
        public Mesh(byte[] Filedata, bool BodyMesh)
        {
            MemoryStream MemStream = new MemoryStream(Filedata);
            BinaryReader Reader    = new BinaryReader(MemStream);

            IsBodyMesh = BodyMesh;

            m_Version = Endian.SwapInt32(Reader.ReadInt32());

            m_BoneCount = Endian.SwapInt32(Reader.ReadInt32());

            for (int i = 0; i < m_BoneCount; i++)
            {
                byte   StrLen   = Reader.ReadByte();
                string BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(StrLen));
                m_BoneNames.Add(BoneName);
            }

            m_FaceCount = Endian.SwapInt32(Reader.ReadInt32());
            m_Faces     = new Face[m_FaceCount];

            for (int i = 0; i < m_FaceCount; i++)
            {
                m_Faces[i].AVertexIndex = Endian.SwapInt32(Reader.ReadInt32());
                m_Faces[i].BVertexIndex = Endian.SwapInt32(Reader.ReadInt32());
                m_Faces[i].CVertexIndex = Endian.SwapInt32(Reader.ReadInt32());
            }

            m_BndCount = Endian.SwapInt32(Reader.ReadInt32());

            for (int i = 0; i < m_BndCount; i++)
            {
                BoneBinding Binding = new BoneBinding();
                Binding.BoneIndex          = Endian.SwapInt32(Reader.ReadInt32());
                Binding.FirstVertex        = Endian.SwapInt32(Reader.ReadInt32());
                Binding.VertexCount        = Endian.SwapInt32(Reader.ReadInt32());
                Binding.FirstBlendedVert   = Endian.SwapInt32(Reader.ReadInt32());
                Binding.BlendedVertexCount = Endian.SwapInt32(Reader.ReadInt32());

                m_BoneBindings.Add(Binding);
            }

            m_RealVertexCount = Endian.SwapInt32(Reader.ReadInt32());
            m_TexVerticies    = new Single[m_RealVertexCount, 3];

            for (int i = 0; i < m_RealVertexCount; i++)
            {
                m_TexVerticies[i, 0] = i;
                m_TexVerticies[i, 1] = Reader.ReadSingle();
                m_TexVerticies[i, 2] = Reader.ReadSingle();
            }

            m_BlendCount = Endian.SwapInt32(Reader.ReadInt32());

            for (int i = 0; i < m_BlendCount; i++)
            {
                BlendData Blend = new BlendData();
                Blend.WeightFixed      = (float)(Endian.SwapInt32(Reader.ReadInt32())) / 0x8000;
                Blend.OtherVertexIndex = Endian.SwapInt32(Reader.ReadInt32());
                m_BlendData.Add(Blend);
            }

            m_TotalVertexCount = Endian.SwapInt32(Reader.ReadInt32());

            m_VertexData          = new Single[m_TotalVertexCount, 6];
            m_TransformedVertices = new Vertex[m_TotalVertexCount];

            for (int i = 0; i < m_TotalVertexCount; i++)
            {
                m_VertexData[i, 0] = Reader.ReadSingle();
                m_VertexData[i, 1] = Reader.ReadSingle();
                m_VertexData[i, 2] = Reader.ReadSingle();
                //Normals
                m_VertexData[i, 3] = Reader.ReadSingle();
                m_VertexData[i, 4] = Reader.ReadSingle();
                m_VertexData[i, 5] = Reader.ReadSingle();

                if (i < m_RealVertexCount)
                {
                    if (m_TransformedVertices[i] == null)
                    {
                        m_TransformedVertices[i] = new Vertex();
                    }

                    //Fixed vertex
                    m_TransformedVertices[i].TextureCoord.X = m_TexVerticies[i, 1];
                    m_TransformedVertices[i].TextureCoord.Y = m_TexVerticies[i, 2];
                }
                else
                {
                    if (m_TransformedVertices[i] == null)
                    {
                        m_TransformedVertices[i] = new Vertex();
                    }

                    //Blended vertex
                    m_TransformedVertices[i].Blend.WeightFixed      = m_BlendData[i - m_RealVertexCount].WeightFixed;
                    m_TransformedVertices[i].Blend.OtherVertexIndex = m_BlendData[i - m_RealVertexCount].OtherVertexIndex;
                }
            }
        }