Пример #1
0
 private void ResetMotionPlayer()
 {
     _motionPlayer = new MotionPlayer(_motion, _poser);
     _motionPlayer.SeekFrame(0);
     _poser.PrePhysicsPosing();
     _physicsReactor.Reset();
     _poser.PostPhysicsPosing();
 }
Пример #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);
            }
        }
Пример #3
0
        public BonePosePreCalculator(MmdPose pose, Poser poser, BulletPyhsicsReactor physicsReactor, double stepLength, double startTimePos, int frameCacheSize, bool autoStepLength)
        {
            _poseMode            = true;
            _poser               = poser;
            _physicsReactor      = physicsReactor;
            _stepLength          = stepLength;
            _bonePoseImagesStore = new BlockingQueue <BonePoseFrame>(frameCacheSize);
            _timePos             = startTimePos;
            _autoStepLength      = autoStepLength;

            poser.ResetPosing();
            SetPoseToPoser(pose, _poser);
            _poser.PrePhysicsPosing();
            _physicsReactor.Reset();
            _poser.PostPhysicsPosing();
            var image = GetBonePoseImage(_poser);

            _bonePoseImagesStore.Enqueue(new BonePoseFrame(startTimePos, image));
        }
Пример #4
0
        public BonePosePreCalculator(Poser poser, BulletPyhsicsReactor physicsReactor, MotionPlayer motionPlayer, double stepLength, double startTimePos, int frameCacheSize, bool autoStepLength)
        {
            _poseMode            = false;
            _poser               = poser;
            _physicsReactor      = physicsReactor;
            _motionPlayer        = motionPlayer;
            _stepLength          = stepLength;
            _bonePoseImagesStore = new BlockingQueue <BonePoseFrame>(frameCacheSize);
            _timePos             = startTimePos;
            _autoStepLength      = autoStepLength;

            _motionPlayer.SeekTime(startTimePos);
            _poser.PrePhysicsPosing();
            _physicsReactor.Reset();
            _poser.PostPhysicsPosing();
            var image = GetBonePoseImage(_poser);

            _bonePoseImagesStore.Enqueue(new BonePoseFrame(startTimePos, image));
        }
Пример #5
0
        public BonePosePreCalculator(BonePoseCalculatorWorker worker, MmdPose pose, Poser poser, BulletPyhsicsReactor physicsReactor, float stepLength, float startTimePos, int frameCacheSize, bool autoStepLength)
        {
            _poseMode            = true;
            _poser               = poser;
            _physicsReactor      = physicsReactor;
            _stepLength          = stepLength;
            _bonePoseImagesStore = new SynchronizedQueue <BonePoseFrame>();
            _timePos             = startTimePos;
            _autoStepLength      = autoStepLength;
            _frameCacheSize      = frameCacheSize;
            poser.ResetPosing();
            SetPoseToPoser(pose, _poser);
            _poser.PrePhysicsPosing();
            _physicsReactor.Reset();
            _poser.PostPhysicsPosing();
            var image = GetBonePoseImage(_poser);

            _bonePoseImagesStore.Enqueue(new BonePoseFrame(startTimePos, image));
            _worker = worker;
        }