Exemplo n.º 1
0
        public Skeleton(GraphicsDevice Device, byte[] Filedata, Matrix WorldMatrix)
        {
            MemoryStream MemStream = new MemoryStream(Filedata);
            BinaryReader Reader    = new BinaryReader(MemStream);

            m_WorldMatrix = WorldMatrix;

            m_Version = Endian.SwapUInt32(Reader.ReadUInt32());
            m_Name    = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte()));

            m_BoneCount = Endian.SwapUInt16(Reader.ReadUInt16());
            m_Bones     = new Bone[m_BoneCount];

            for (int i = 0; i < m_BoneCount; i++)
            {
                Endian.SwapUInt32(Reader.ReadUInt32()); //1 in hexadecimal... typical useless Maxis value...

                Bone Bne = new Bone(this);

                Bne.ID = i;

                Bne.BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte()));
                Log.LogThis("BoneName: " + Bne.BoneName, eloglevel.info);
                Bne.ParentName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte()));

                Bne.HasPropertyList = Reader.ReadByte();

                if (Bne.HasPropertyList == 1)
                {
                    Bne.PList = ReadPropList(Reader);
                }

                //Little Endian
                Bne.Translations    = new float[3];
                Bne.Translations[0] = Reader.ReadSingle();
                Bne.Translations[1] = Reader.ReadSingle();
                Bne.Translations[2] = Reader.ReadSingle();

                Bne.Versor = new float[4];
                //These values are given in degrees...
                Bne.Versor[0] = MathHelper.ToRadians(Reader.ReadSingle());
                Bne.Versor[1] = MathHelper.ToRadians(Reader.ReadSingle());
                Bne.Versor[2] = MathHelper.ToRadians(Reader.ReadSingle());
                Bne.Versor[3] = MathHelper.ToRadians(Reader.ReadSingle());

                Bne.CanTranslate   = Endian.SwapInt32(Reader.ReadInt32());
                Bne.CanRotate      = Endian.SwapInt32(Reader.ReadInt32());
                Bne.CanUseBlending = Endian.SwapInt32(Reader.ReadInt32());
                //Little endian.
                Bne.CanWiggle    = Reader.ReadSingle();
                Bne.WiggleAmount = Reader.ReadSingle();

                Bne.BoneEffect = new BasicEffect(Device, null);

                Bne.Children = new int[m_BoneCount - i - 1];

                int Parent = FindBone(Bne.ParentName, i);
                if (Parent != -1)
                {
                    m_Bones[Parent].Children[m_Bones[Parent].NumChildren] = Bne.ID;
                    m_Bones[Parent].NumChildren += 1;
                    Bne.Parent = m_Bones[Parent];
                    Bne.ComputeAbsoluteTransform(m_WorldMatrix);
                }

                m_Bones[i] = Bne;

                /*Log.LogThis("Bone: " + Bne.BoneName, eloglevel.info);
                 * if (Parent != -1)
                 * {
                 *  Log.LogThis("Parent: " + Bne.Parent.BoneName, eloglevel.info);
                 *
                 *  for (int j = 0; j < Bne.Parent.NumChildren; j++)
                 *      Log.LogThis("Child: " + Bne.Parent.Children[j].BoneName, eloglevel.info);
                 * }
                 * else
                 *  Log.LogThis("Parent: NULL", eloglevel.info);*/
            }

            Reader.Close();
        }
Exemplo n.º 2
0
        public Skeleton(GraphicsDevice Device, string Filepath, ref Matrix WorldMatrix)
        {
            BinaryReader Reader = new BinaryReader(File.Open(Filepath, FileMode.Open));

            m_WorldMatrix = WorldMatrix;

            m_Version = Endian.SwapUInt32(Reader.ReadUInt32());
            m_Name    = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte()));

            m_BoneCount = Endian.SwapUInt16(Reader.ReadUInt16());
            m_Bones     = new Bone[m_BoneCount];

            for (int i = 0; i < m_BoneCount; i++)
            {
                Endian.SwapUInt32(Reader.ReadUInt32()); //1 in hexadecimal... typical useless Maxis value...

                Bone Bne = new Bone(this);

                Bne.ID = i;

                Bne.BoneName   = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte()));
                Bne.ParentName = Encoding.ASCII.GetString(Reader.ReadBytes(Reader.ReadByte()));

                Bne.HasPropertyList = Reader.ReadByte();

                if (Bne.HasPropertyList == 1)
                {
                    Bne.PList = ReadPropList(Reader);
                }

                //Little Endian
                Bne.Translations    = new float[3];
                Bne.Translations[0] = Reader.ReadSingle();
                Bne.Translations[1] = Reader.ReadSingle();
                Bne.Translations[2] = Reader.ReadSingle();

                Bne.Versor = new float[4];
                //These values are given in degrees...
                Bne.Versor[0] = MathHelper.ToRadians(Reader.ReadSingle());
                Bne.Versor[1] = MathHelper.ToRadians(Reader.ReadSingle());
                Bne.Versor[2] = MathHelper.ToRadians(Reader.ReadSingle());
                Bne.Versor[3] = MathHelper.ToRadians(Reader.ReadSingle());

                Bne.CanTranslate   = Endian.SwapInt32(Reader.ReadInt32());
                Bne.CanRotate      = Endian.SwapInt32(Reader.ReadInt32());
                Bne.CanUseBlending = Endian.SwapInt32(Reader.ReadInt32());
                //Little endian.
                Bne.CanWiggle    = Reader.ReadSingle();
                Bne.WiggleAmount = Reader.ReadSingle();

                Bne.BoneEffect = new BasicEffect(Device, null);

                Bne.Children = new int[m_BoneCount - i - 1];

                int Parent = FindBone(Bne.ParentName, i);
                if (Parent != -1)
                {
                    m_Bones[Parent].Children[m_Bones[Parent].NumChildren] = Bne.ID;
                    m_Bones[Parent].NumChildren += 1;
                    Bne.Parent = m_Bones[Parent];
                    Bne.ComputeAbsoluteTransform(m_WorldMatrix);
                }

                m_Bones[i] = Bne;
            }

            Reader.Close();
        }