Exemplo n.º 1
0
        public void Read(BinaryReader reader, CoordinateType coordinate, float scale)
        {
            Coordinate = coordinate;
            ModelName  = MMDUtils.GetString(reader.ReadBytes(20));
            DWORD motionCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            Motions = new MotionData[motionCount];
            for (long i = 0; i < Motions.Length; i++)
            {
                Motions[i] = new MotionData(reader, CoordZ, scale);
            }
            DWORD faceCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            FaceMotions = new FaceMotionData[faceCount];
            for (long i = 0; i < FaceMotions.Length; i++)
            {
                FaceMotions[i] = new FaceMotionData(reader, CoordZ, scale);
            }
            DWORD cameraCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            CameraMotions = new CameraMotionData[cameraCount];
            for (long i = 0; i < CameraMotions.Length; i++)
            {
                CameraMotions[i] = new CameraMotionData(reader, CoordZ, scale);
            }
            DWORD lightCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0);

            LightMotions = new LightMotionData[lightCount];
            for (long i = 0; i < LightMotions.Length; i++)
            {
                LightMotions[i] = new LightMotionData(reader, CoordZ, scale);
            }
        }
Exemplo n.º 2
0
 public void Read(BinaryReader reader, float CoordZ, float scale)
 {
     BoneName = MMDUtils.GetString(reader.ReadBytes(15));
     FrameNo  = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     Location = new float[3];
     for (int i = 0; i < Location.Length; i++)
     {
         Location[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     }
     Quatanion = new float[4];
     for (int i = 0; i < Quatanion.Length; i++)
     {
         Quatanion[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     Interpolation = new byte[4][][];
     for (int i = 0; i < Interpolation.Length; i++)
     {
         Interpolation[i] = new byte[4][];
         for (int j = 0; j < Interpolation[i].Length; j++)
         {
             Interpolation[i][j] = new byte[4];
             for (int k = 0; k < Interpolation[i][j].Length; k++)
             {
                 Interpolation[i][j][k] = reader.ReadByte();
             }
         }
     }
     Location[2]  *= CoordZ;
     Quatanion[0] *= CoordZ;
     Quatanion[1] *= CoordZ;
 }
Exemplo n.º 3
0
        public MMDMotion(string inputPath, string outputPath, float scale)
        {
            Coordinate = CoordinateType.LeftHandedCoordinate;

            //ファイルチェック
            if (!File.Exists(inputPath))
            {
                throw new FileNotFoundException("MMDモーションファイル:" + inputPath + "が見つかりません");
            }
            //ファイルリーダー
            using (FileStream fs = new FileStream(inputPath, FileMode.Open))
            {
                BinaryReader reader = new BinaryReader(fs);
                //マジック文字列
                Magic = MMDUtils.GetString(reader.ReadBytes(30));
                if (Magic.Substring(0, 20) != "Vocaloid Motion Data")
                {
                    throw new FileLoadException("MMDモーションファイルではありません");
                }
                //バージョン
                Version = Convert.ToInt32(Magic.Substring(21));
                if (Version != 2)
                {
                    throw new FileLoadException("version=" + Version.ToString() + "モデルは対応していません");
                }
                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);
                writer.WriteLine("バージョン," + Version);
                Write(writer);
                fs.Close();
            }
        }
 public void Read(BinaryReader reader, float CoordZ, float scale)
 {
     FaceName = MMDUtils.GetString(reader.ReadBytes(15));
     FrameNo  = BitConverter.ToUInt32(reader.ReadBytes(4), 0);
     Rate     = BitConverter.ToSingle(reader.ReadBytes(4), 0);
 }