Exemplo n.º 1
0
 void WriteFrames(BinaryWriter bw, Vmd vmd)
 {
     foreach (var frame in vmd.Frames)
     {
         foreach (var bone in frame.Bones)
         {
             WriteString(bw, bone.Key, 15);
             bw.Write(frame.Index);
             if (IsPositionOutputTarget(bone.Key))
             {
                 bw.Write(bone.Value.Position.X);
                 bw.Write(bone.Value.Position.Y);
                 bw.Write(bone.Value.Position.Z);
             }
             else
             {
                 bw.Write(0f);
                 bw.Write(0f);
                 bw.Write(0f);
             }
             bw.Write(bone.Value.Quaternion.X);
             bw.Write(bone.Value.Quaternion.Y);
             bw.Write(bone.Value.Quaternion.Z);
             bw.Write(bone.Value.Quaternion.W);
             bw.Write(bone.Value.InterpolationParameters.ToArray());
         }
     }
 }
Exemplo n.º 2
0
        public void Execute()
        {
            // KMR モジュールで全ファイル分のList<Keypoint>(平滑化済み)を取ってくる(今はまだ1フレーム分)
            var opr = new OpenPoseReader(@"C:\tmp\");

            _keypointsCollection.Add(1, opr.ReadOneFile("Sample_000000000213_keypoints.json"));

            // foreachで1つずつSZKモジュールで処理
            var dolls = new Dictionary <int, Doll>();

            foreach (var keypoints in _keypointsCollection)
            {
                var estimator = new PoseEstimator();
                dolls.Add(keypoints.Key, estimator.EstimateSingleFrame(1920, 1080, keypoints.Value));
            }

            var vmd = new Vmd("Sample", dolls);
            var vw  = new VmdWriter(@"C:\tmp\Sample_000000000213_keypoints.vmd");

            vw.Write(vmd);

            // ※必要な入力引数
            // OpenPoseディレクトリ(平面座標取得から一貫して行うなら)
            // OpenPose出力先ディレクトリ
            // Vmd出力ファイルパス
        }
Exemplo n.º 3
0
        void ReadFrames(BinaryReader br, ref Vmd vmd)
        {
            Frame currentFrame = new Frame {
                Index = 0
            };
            var baseStream = br.BaseStream;

            try
            {
                while (baseStream.Position != baseStream.Length)
                {
                    var    bone     = new Bone();
                    string boneName = ReadString(br, 15);
                    // EOF checking workaround: For some reason baseStream checking doesn't work
                    if (string.IsNullOrEmpty(boneName))
                    {
                        break;
                    }
                    int frameIdx = br.ReadInt32();

                    // Finalize and register the current frame and create a new instance when the frame index increases
                    if (currentFrame.Index != frameIdx)
                    {
                        if (currentFrame.Index > frameIdx)
                        {
                            throw new Exception("Frame indices are not sorted in ascending order.");
                        }

                        vmd.Frames.Add(currentFrame);
                        currentFrame = new Frame {
                            Index = frameIdx
                        };
                    }

                    // Read bone data and set to the current frame
                    bone.Name = boneName;
                    float x = br.ReadSingle();
                    float y = br.ReadSingle();
                    float z = br.ReadSingle();
                    bone.Position = new Vector3(x, y, z);
                    float qx = br.ReadSingle();
                    float qy = br.ReadSingle();
                    float qz = br.ReadSingle();
                    float qw = br.ReadSingle();
                    bone.Quaternion = new Quaternion(qx, qy, qz, qw);
                    bone.InterpolationParameters = br.ReadBytes(64).ToList();
                    currentFrame.Bones.Add(boneName, bone);
                }

                // Register the last frame
                vmd.Frames.Add(currentFrame);
            }
            catch (Exception ex)
            {
                string msg = $"Following error occured while reading {_path}:\n  {ex.Message}";
                ErrorHandler.AskTermination(msg);
            }
        }
Exemplo n.º 4
0
        public Vmd Read()
        {
            var vmd = new Vmd();

            using (var br = new BinaryReader(File.OpenRead(_path)))
            {
                ReadHeader(br, ref vmd);
                ReadFrames(br, ref vmd);
            }
            return(vmd);
        }
Exemplo n.º 5
0
        public void Write(Vmd vmd)
        {
            using (var bw = new BinaryWriter(File.OpenWrite(_path), System.Text.Encoding.GetEncoding("Shift_JIS")))
            {
                WriteHeader(bw, vmd);
                WriteFrames(bw, vmd);

                // Void data for expressions, camera, light, self-shadow
                for (int i = 0; i < 4; i++)
                {
                    bw.Write(0);
                }
            }
        }
Exemplo n.º 6
0
 // --- private ---
 void WriteHeader(BinaryWriter bw, Vmd vmd)
 {
     WriteString(bw, vmd.Header, 30);
     WriteString(bw, vmd.ModelName, 20);
     bw.Write(vmd.ItemsTotal);
 }
Exemplo n.º 7
0
 // --- private ---
 void ReadHeader(BinaryReader br, ref Vmd vmd)
 {
     vmd.Header     = ReadString(br, 30);
     vmd.ModelName  = ReadString(br, 20);
     vmd.ItemsTotal = br.ReadInt32();
 }