コード例 #1
0
        public bool Step()
        {
            if (_bonePoseImagesStore.Count() >= _frameCacheSize)
            {
                return(false);
            }
            var actualStepLength = _stepLength;

            _timePos += _stepLength;
            if (_autoStepLength && _timePos < _lastMissedPos)
            {
                //Debug.LogWarningFormat("auto step length triggered, _timePos={0}, _lastMissedPos={1}", _timePos, _lastMissedPos);
                actualStepLength = _lastMissedPos - _timePos + _stepLength;
                _timePos         = _lastMissedPos;
            }
            if (!_poseMode)
            {
                _motionPlayer.SeekTime(_timePos);
            }
            _poser.PrePhysicsPosing(false);
            //var tickCount = Environment.TickCount;
            _physicsReactor.React(actualStepLength, 2, actualStepLength);
            //Debug.LogFormat("{0} ms for physics", Environment.TickCount - tickCount);
            _poser.PostPhysicsPosing();
            var image = GetBonePoseImage(_poser);

            _bonePoseImagesStore.Enqueue(new BonePoseFrame(_timePos, image));
            //Debug.LogFormat("{0} frames in pose cache", cachedCount);
            return(true);
        }
コード例 #2
0
        private void Step(double time, float fixStepTime = 1.0f / 60.0f, int maxStep = 10)
        {
            if (time <= 0.0f)
            {
                return;
            }

            time += _restStepTime;
            var nStep = Math.Floor(time / fixStepTime);

            if (nStep > maxStep)
            {
                Debug.Log("too many play steps, time= " + time + ", fixStepTime= " + fixStepTime);
                nStep         = maxStep;
                fixStepTime   = (float)(time / nStep);
                _restStepTime = 0.0f;
            }
            else
            {
                _restStepTime = time - nStep * fixStepTime;
            }
            for (var i = 0; i < nStep; i++)
            {
                _playTime += fixStepTime;
                _motionPlayer.SeekTime(_playTime);
                _poser.PrePhysicsPosing();
                _physicsReactor.React(fixStepTime, 2, fixStepTime);
                _poser.PostPhysicsPosing();
            }
            //_poser.Deform();
        }
コード例 #3
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);
            }
        }