public static void Generate(MmdModel model, MmdMotion motion, string savePath,
                             float frameStepLength   = DefaultStepLength, float timeAfterMotionFinish = 0.0f,
                             float physicsStepLength = DefaultStepLength)
 {
     new BonePoseFileGenerator().DoGenerate(model, motion, savePath, frameStepLength, timeAfterMotionFinish,
                                            physicsStepLength);
 }
Exemplo n.º 2
0
        private void DoGenerate(MmdModel model, MmdMotion motion, string savePath, float frameStepLength, float timeAfterMotionFinish, float physicsStepLength)
        {
            try
            {
                _status = GenerateStatus.Preparing;
                if (physicsStepLength > frameStepLength)
                {
                    physicsStepLength = frameStepLength;
                }
                var poser          = new Poser(model);
                var motionPlayer   = new MotionPlayer(motion, poser);
                var physicsReactor = new BulletPyhsicsReactor();

                var totalTimeLength = motion.Length / 30.0 + timeAfterMotionFinish;
                var totalStepCount  = (int)(totalTimeLength / frameStepLength) + 1;
                var playPos         = 0.0;
                var maxSubSteps     = (int)(frameStepLength / physicsStepLength) + 1;

                using (var fileStream = new FileStream(savePath, FileMode.Create))
                {
                    using (var bufferedStream = new BufferedStream(fileStream))
                    {
                        using (var binaryWriter = new BinaryWriter(bufferedStream))
                        {
                            WriteHeader(binaryWriter, model, totalStepCount + 1, frameStepLength);
                            _status           = GenerateStatus.CalculatingFrames;
                            _totalFrames      = totalStepCount + 1;
                            _calculatedFrames = 0;
                            physicsReactor.AddPoser(poser);
                            motionPlayer.SeekFrame(0);
                            poser.PrePhysicsPosing();
                            physicsReactor.Reset();
                            poser.PostPhysicsPosing();
                            WritePose(binaryWriter, poser);
                            _calculatedFrames = 1;
                            for (var i = 0; i < totalStepCount; ++i)
                            {
                                playPos += frameStepLength;
                                motionPlayer.SeekTime(playPos);
                                poser.PrePhysicsPosing();
                                physicsReactor.React(frameStepLength, maxSubSteps, physicsStepLength);
                                poser.PostPhysicsPosing();
                                WritePose(binaryWriter, poser);
                                _calculatedFrames = i + 2;
                            }
                        }
                    }
                }
                _status = GenerateStatus.Finished;
            }
            catch (Exception e)
            {
                _status = GenerateStatus.Failed;
                Debug.LogException(e);
            }
        }
Exemplo n.º 3
0
        public static BonePoseFileGenerator GenerateAsync(MmdModel model, MmdMotion motion, string savePath,
                                                          float frameStepLength = DefaultStepLength, float timeAfterMotionFinish = 0.0f, float physicsStepLength = DefaultStepLength)
        {
            var ret = new BonePoseFileGenerator();

            new Thread(() =>
            {
                ret.DoGenerate(model, motion, savePath, frameStepLength, timeAfterMotionFinish, physicsStepLength);
            }).Start();
            return(ret);
        }
Exemplo n.º 4
0
 private bool LoadMotionKernal(string filePath)
 {
     _motion = new VmdReader().Read(filePath);
     if (_motion.Length == 0)
     {
         StopBonePoseCalculation();
         _poser.ResetPosing();
         ResetMotionPlayer();
         return(false);
     }
     ResetMotionPlayer();
     //_poser.Deform();
     return(true);
 }
Exemplo n.º 5
0
            public MmdMotion BuildMmdMotion()
            {
                var ret = new MmdMotion();

                ret.BoneMotions = new Dictionary <string, List <KeyValuePair <int, BoneKeyframe> > >();
                foreach (var entry in BoneMotions)
                {
                    var value = entry.Value.ToList();
                    value = value.OrderBy(kv => kv.Key).ToList();
                    ret.BoneMotions.Add(entry.Key, value);
                }
                ret.MorphMotions = new Dictionary <string, List <KeyValuePair <int, MorphKeyframe> > >();
                foreach (var entry in MorphMotions)
                {
                    var value = entry.Value.ToList();
                    value = value.OrderBy(kv => kv.Key).ToList();
                    ret.MorphMotions.Add(entry.Key, value);
                }
                ret.Length = Length;
                ret.Name   = Name;
                return(ret);
            }
Exemplo n.º 6
0
 private void LoadMotionKernal(string filePath)
 {
     _motion = new VmdReader().Read(filePath);
     ResetMotionPlayer();
     //_poser.Deform();
 }