Exemple #1
0
 public void Read(BinaryReader reader, float CoordZ, float scale)
 {
     RigidBodyName   = MMDUtils.GetString(reader.ReadBytes(20));
     RelateBoneIndex = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     GroupIndex      = reader.ReadByte();
     GroupTarget     = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     ShapeType       = reader.ReadByte();
     ShapeWidth      = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     ShapeHeight     = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     ShapeDepth      = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     Position        = new float[3];
     for (int i = 0; i < Position.Length; i++)
     {
         Position[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     }
     Rotation = new float[3];
     for (int i = 0; i < Rotation.Length; i++)
     {
         Rotation[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     Weight         = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     LinerDamping   = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     AngularDamping = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     Restitution    = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     Friction       = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     Type           = reader.ReadByte();
     Position[2]   *= CoordZ;
     // 必要らしい
     Rotation[0] *= CoordZ;
     Rotation[1] *= CoordZ;
 }
Exemple #2
0
 public void Read(BinaryReader reader, float CoordZ, float scale)
 {
     Name       = MMDUtils.GetString(reader.ReadBytes(20));
     RigidBodyA = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     RigidBodyB = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     Position   = new float[3];
     for (int i = 0; i < Position.Length; i++)
     {
         Position[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     }
     Rotation = new float[3];
     for (int i = 0; i < Rotation.Length; i++)
     {
         Rotation[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     ConstrainPosition1 = new float[3];
     for (int i = 0; i < ConstrainPosition1.Length; i++)
     {
         ConstrainPosition1[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     }
     ConstrainPosition2 = new float[3];
     for (int i = 0; i < ConstrainPosition2.Length; i++)
     {
         ConstrainPosition2[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     }
     ConstrainRotation1 = new float[3];
     for (int i = 0; i < ConstrainRotation1.Length; i++)
     {
         ConstrainRotation1[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     ConstrainRotation2 = new float[3];
     for (int i = 0; i < ConstrainRotation2.Length; i++)
     {
         ConstrainRotation2[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     SpringPosition = new float[3];
     for (int i = 0; i < SpringPosition.Length; i++)
     {
         SpringPosition[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     SpringRotation = new float[3];
     for (int i = 0; i < SpringRotation.Length; i++)
     {
         SpringRotation[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     // 必要?
     ConstrainRotation1[0] *= CoordZ;
     ConstrainRotation1[1] *= CoordZ;
     ConstrainRotation2[0] *= CoordZ;
     ConstrainRotation2[1] *= CoordZ;
     // これは必要
     ConstrainPosition1[2] *= CoordZ;
     ConstrainPosition2[2] *= CoordZ;
 }
Exemple #3
0
        public void Read(BinaryReader reader, float CoordZ, float scale)
        {
            SkinName = MMDUtils.GetString(reader.ReadBytes(20));
            DWORD skinVertCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            SkinType      = reader.ReadByte();
            SkinVertDatas = new ModelSkinVertexData[skinVertCount];
            for (int i = 0; i < SkinVertDatas.Length; i++)
            {
                SkinVertDatas[i] = new ModelSkinVertexData(reader, CoordZ, scale);
            }
            SkinNameEnglish = null;
        }
 public void Read(BinaryReader reader, float CoordZ, float scale)
 {
     BoneHeadPos       = new float[3];
     BoneName          = MMDUtils.GetString(reader.ReadBytes(20));
     ParentBoneIndex   = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     TailPosBoneIndex  = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     BoneType          = reader.ReadByte();
     IKParentBoneIndex = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     for (int i = 0; i < BoneHeadPos.Length; i++)
     {
         BoneHeadPos[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     }
     BoneNameEnglish = null; // MMDModel.EnglishExpantionがtrueなら後で設定される
     // 座標系の調整
     BoneHeadPos[2] *= CoordZ;
 }
        public void Read(BinaryReader reader)
        {
            DiffuseColor = new float[3];
            for (int i = 0; i < DiffuseColor.Length; i++)
            {
                DiffuseColor[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
            }
            Alpha         = BitConverter.ToSingle(reader.ReadBytes(4), 0);
            Specularity   = BitConverter.ToSingle(reader.ReadBytes(4), 0);
            SpecularColor = new float[3];
            for (int i = 0; i < SpecularColor.Length; i++)
            {
                SpecularColor[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
            }
            AmbientColor = new float[3];
            for (int i = 0; i < AmbientColor.Length; i++)
            {
                AmbientColor[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
            }
            ToonIndex     = reader.ReadByte();
            EdgeFlag      = reader.ReadByte();
            FaceVertCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
            string FileName = MMDUtils.GetString(reader.ReadBytes(20));

            string[] FileNames = FileName.Split('*');
            TextureFileName = SphereTextureFileName = "";
            foreach (var s in FileNames)
            {
                string ext = Path.GetExtension(s).ToLower();
                if (ext == ".sph" || ext == ".spa")
                {
                    SphereTextureFileName = s.Trim();
                }
                else
                {
                    TextureFileName = s.Trim();
                }
            }
        }
Exemple #6
0
        public MMDModel(string inputPath, string outputPath, float scale)
        {
            Vertexes         = null;
            EnglishExpantion = ToonExpantion = PhysicsExpantion = false;
            ToonFileNames    = new List <string>();
            Coordinate       = CoordinateType.LeftHandedCoordinate;

            using (var fs = new FileStream(inputPath, FileMode.Open))
            {
                var reader = new BinaryReader(fs);
                Magic = MMDUtils.GetString(reader.ReadBytes(3));
                if (Magic != "Pmd")
                {
                    throw new FileLoadException("MMDモデルファイルではありません");
                }
                Version = BitConverter.ToSingle(reader.ReadBytes(4), 0);
                if (Version != 1.0)
                {
                    throw new FileLoadException("version=" + Version + "モデルは対応していません");
                }
                Read(reader, Coordinate, scale);
                if (fs.Length != fs.Position)
                {
                    Console.WriteLine("警告:ファイル末尾以降に不明データ?");
                }
                fs.Close();
            }

            using (var fs = new FileStream(outputPath, FileMode.Create))
            {
                var writer = new StreamWriter(fs);
                writer.WriteLine(Magic + "," + Version);
                Write(writer);
                writer.Close();
            }
        }
Exemple #7
0
 public void ReadEnglishExpantion(BinaryReader reader)
 {
     ModelNameEnglish = MMDUtils.GetString(reader.ReadBytes(20));
     CommentEnglish   = MMDUtils.GetString(reader.ReadBytes(256));
 }
Exemple #8
0
 public void Read(BinaryReader reader)
 {
     ModelName        = MMDUtils.GetString(reader.ReadBytes(20));
     Comment          = MMDUtils.GetString(reader.ReadBytes(256));
     ModelNameEnglish = CommentEnglish = null;
 }
Exemple #9
0
 public void ReadEnglishExpantion(BinaryReader reader)
 {
     SkinNameEnglish = MMDUtils.GetString(reader.ReadBytes(20));
 }
Exemple #10
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);
                }
            }
        }
 public void ReadEnglishExpantion(BinaryReader reader)
 {
     BoneDispNameEnglish = MMDUtils.GetString(reader.ReadBytes(50));
 }
 public void Read(BinaryReader reader)
 {
     BoneDispName        = MMDUtils.GetString(reader.ReadBytes(50));
     BoneDispNameEnglish = null;
 }