Пример #1
0
        public void Read(BinaryReader reader, CoordinateType coordinate, float scale)
        {
            Coordinate = coordinate;
            // ヘッダ
            Header = new ModelHeader(reader);
            // 頂点リスト
            DWORD numVertex = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            Vertexes = new ModelVertex[numVertex];
            for (DWORD i = 0; i < Vertexes.Length; i++)
            {
                Vertexes[i] = new ModelVertex(reader, CoordZ, scale);
            }
            DWORD faceVertCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            FaceVertexes = new WORD[faceVertCount];
            for (DWORD i = 0; i < faceVertCount; i++)
            {
                FaceVertexes[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
            }
            DWORD materialCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            Materials = new ModelMaterial[materialCount];
            for (DWORD i = 0; i < materialCount; i++)
            {
                Materials[i] = new ModelMaterial(reader);
            }
            WORD boneCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0);

            Bones = new ModelBone[boneCount];
            for (WORD i = 0; i < boneCount; i++)
            {
                Bones[i] = new ModelBone(reader, CoordZ, scale);
            }
            WORD IKCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0);

            IKs = new ModelIK[IKCount];
            for (WORD i = 0; i < IKs.Length; i++)
            {
                IKs[i] = new ModelIK(reader);
            }
            WORD skinCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0);

            Skins = new ModelSkin[skinCount];
            for (WORD i = 0; i < skinCount; i++)
            {
                Skins[i] = new ModelSkin(reader, CoordZ, scale);
            }
            byte skinDispCount = reader.ReadByte();

            SkinIndex = new WORD[skinDispCount];
            for (byte i = 0; i < skinDispCount; i++)
            {
                SkinIndex[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
            }
            byte boneDispNameCount = reader.ReadByte();

            BoneDispName = new ModelBoneDispName[boneDispNameCount];
            for (byte i = 0; i < boneDispNameCount; i++)
            {
                BoneDispName[i] = new ModelBoneDispName(reader);
            }
            DWORD boneDispCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            BoneDisp = new ModelBoneDisp[boneDispCount];
            for (DWORD i = 0; i < boneDispCount; i++)
            {
                BoneDisp[i] = new ModelBoneDisp(reader);
            }
            EnglishExpantion = (reader.ReadByte() != 0);
            if (EnglishExpantion)
            {
                Header.ReadEnglishExpantion(reader);
                for (int i = 0; i < Bones.Length; i++)
                {
                    Bones[i].ReadEnglishExpantion(reader);
                }
                for (int i = 0; i < Skins.Length; i++)
                {
                    // base のスキンには英名はない
                    if (Skins[i].SkinType != 0)
                    {
                        Skins[i].ReadEnglishExpantion(reader);
                    }
                }
                for (int i = 0; i < BoneDispName.Length; i++)
                {
                    BoneDispName[i].ReadEnglishExpantion(reader);
                }
            }
            if (reader.BaseStream.Position >= reader.BaseStream.Length)
            {
                ToonExpantion = false;
            }
            else
            {
                ToonExpantion = true;
                ToonFileNames.Clear();
                for (int i = 0; i < NumToonFileName; i++)
                {
                    ToonFileNames.Add(MMDUtils.GetString(reader.ReadBytes(100)));
                }
            }
            if (reader.BaseStream.Position >= reader.BaseStream.Length)
            {
                PhysicsExpantion = false;
            }
            else
            {
                PhysicsExpantion = true;
                // 剛体リスト
                DWORD rigidbodyCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
                RigidBodies = new ModelRigidBody[rigidbodyCount];
                for (int i = 0; i < RigidBodies.Length; i++)
                {
                    RigidBodies[i] = new ModelRigidBody(reader, CoordZ, scale);
                }
                DWORD jointCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
                Joints = new ModelJoint[jointCount];
                for (int i = 0; i < Joints.Length; i++)
                {
                    Joints[i] = new ModelJoint(reader, CoordZ, scale);
                }
            }
        }
Пример #2
0
 public void Read(BinaryReader reader, CoordinateType coordinate, float scale)
 {
     Coordinate = coordinate;
     // ヘッダ
     Header = new ModelHeader(reader);
     // 頂点リスト
     DWORD numVertex = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     Vertexes = new ModelVertex[numVertex];
     for (DWORD i = 0; i < Vertexes.Length; i++)
     {
         Vertexes[i] = new ModelVertex(reader, CoordZ, scale);
     }
     DWORD faceVertCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     FaceVertexes = new WORD[faceVertCount];
     for (DWORD i = 0; i < faceVertCount; i++)
     {
         FaceVertexes[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     }
     DWORD materialCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     Materials = new ModelMaterial[materialCount];
     for (DWORD i = 0; i < materialCount; i++)
     {
         Materials[i] = new ModelMaterial(reader);
     }
     WORD boneCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     Bones = new ModelBone[boneCount];
     for (WORD i = 0; i < boneCount; i++)
     {
         Bones[i] = new ModelBone(reader, CoordZ, scale);
     }
     WORD IKCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     IKs = new ModelIK[IKCount];
     for (WORD i = 0; i < IKs.Length; i++)
     {
         IKs[i] = new ModelIK(reader);
     }
     WORD skinCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     Skins = new ModelSkin[skinCount];
     for (WORD i = 0; i < skinCount; i++)
     {
         Skins[i] = new ModelSkin(reader, CoordZ, scale);
     }
     byte skinDispCount = reader.ReadByte();
     SkinIndex = new WORD[skinDispCount];
     for (byte i = 0; i < skinDispCount; i++)
     {
         SkinIndex[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     }
     byte boneDispNameCount = reader.ReadByte();
     BoneDispName = new ModelBoneDispName[boneDispNameCount];
     for (byte i = 0; i < boneDispNameCount; i++)
     {
         BoneDispName[i] = new ModelBoneDispName(reader);
     }
     DWORD boneDispCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     BoneDisp = new ModelBoneDisp[boneDispCount];
     for (DWORD i = 0; i < boneDispCount; i++)
     {
         BoneDisp[i] = new ModelBoneDisp(reader);
     }
     EnglishExpantion = (reader.ReadByte() != 0);
     if (EnglishExpantion)
     {
         Header.ReadEnglishExpantion(reader);
         for (int i = 0; i < Bones.Length; i++)
         {
             Bones[i].ReadEnglishExpantion(reader);
         }
         for (int i = 0; i < Skins.Length; i++)
         {
             // base のスキンには英名はない
             if (Skins[i].SkinType != 0)
             {
                 Skins[i].ReadEnglishExpantion(reader);
             }
         }
         for (int i = 0; i < BoneDispName.Length; i++)
         {
             BoneDispName[i].ReadEnglishExpantion(reader);
         }
     }
     if (reader.BaseStream.Position >= reader.BaseStream.Length)
     {
         ToonExpantion = false;
     }
     else
     {
         ToonExpantion = true;
         ToonFileNames.Clear();
         for (int i = 0; i < NumToonFileName; i++)
         {
             ToonFileNames.Add(MMDUtils.GetString(reader.ReadBytes(100)));
         }
     }
     if (reader.BaseStream.Position >= reader.BaseStream.Length)
     {
         PhysicsExpantion = false;
     }
     else
     {
         PhysicsExpantion = true;
         // 剛体リスト
         DWORD rigidbodyCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
         RigidBodies = new ModelRigidBody[rigidbodyCount];
         for (int i = 0; i < RigidBodies.Length; i++)
         {
             RigidBodies[i] = new ModelRigidBody(reader, CoordZ, scale);
         }
         DWORD jointCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
         Joints = new ModelJoint[jointCount];
         for (int i = 0; i < Joints.Length; i++)
         {
             Joints[i] = new ModelJoint(reader, CoordZ, scale);
         }
     }
 }