コード例 #1
0
        public void TestParsingMotion(FileInfo modelFile)
        {
            Vmd.Vmd motion;
            using (var stream = Open(modelFile))
            {
                motion = VmdParser.Parse(stream);
                TestContext.Out.WriteLine("Model Name: {0}", motion.ModelName);
                TestContext.Out.WriteLine("Bone Key Frames: {0}", motion.BoneKeyFrames.Length);
                TestContext.Out.WriteLine("Morph Key Frames: {0}", motion.MorphKeyFrames.Length);
                TestContext.Out.WriteLine("Camera Key Frames: {0}", motion.CameraKeyFrames.Length);
                TestContext.Out.WriteLine("Light Key Frames: {0}", motion.LightKeyFrames?.Length ?? 0);
                TestContext.Out.WriteLine("Shadow Key Frames: {0}", motion.ShadowKeyFrames?.Length ?? 0);

                Warn.If(stream.Position != stream.Length, "File not read to end. Read {0} out of {1} bytes, {2} bytes remaining", stream.Position, stream.Length, stream.Length - stream.Position);
            }

            Assert.That(motion, Is.Not.Null);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: superowner/mio
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            var options = new Options();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                Environment.Exit(0);
            }

            if (options.Language != "english" && options.Language != "japanese")
            {
                Console.WriteLine("Language must be 'english' or 'japanese' (without the quote)");
                Environment.Exit(0);
            }

            if (options.Scale < 0f)
            {
                Console.WriteLine("The scaling factor must be a positive real number.");
                Environment.Exit(0);
            }

            if (options.Files.Count < 2)
            {
                Console.WriteLine(options.GetUsage());
                Environment.Exit(0);
            }

            Console.WriteLine("Loading PMD file {0}...", options.Files[0]);
            var pmdModel = PmdParser.Parse(options.Files[0]);

            Console.WriteLine("Loading VMD file...");
            var vmdAnimation = VmdParser.Parse(options.Files[1]);

            int firstFrame = vmdAnimation.GetFirstFrame();
            int lastFrame  = vmdAnimation.GetLastFrame();

            var poseAnimation = vmdAnimation.GetIkLessPoseAnimation(pmdModel, (frame) =>
            {
                Console.WriteLine("Frame #{0} out of {1}", frame, lastFrame - firstFrame + 1);
                return(true);
            });

            var exportedContent = BvhExporter.Export(pmdModel.GetRestArmature(),
                                                     poseAnimation,
                                                     options.Language,
                                                     30,
                                                     options.Scale);

            string bvhFileName;

            if (options.Files.Count < 3)
            {
                var modelName     = Path.GetFileNameWithoutExtension(options.Files[0]);
                var animationPath = Path.GetFullPath(options.Files[1]);
                var animationName = Path.GetFileNameWithoutExtension(animationPath);
                var animationDir  = Path.GetDirectoryName(animationPath);
                bvhFileName = Path.Combine(animationDir, modelName + "-" + animationName + ".bvh");
            }
            else
            {
                bvhFileName = Path.GetFullPath(options.Files[2]);
            }

            Console.WriteLine("Saving BVH data to {0}", bvhFileName);

            using (StreamWriter writer = new StreamWriter(bvhFileName))
            {
                writer.Write(exportedContent);
            }
        }