コード例 #1
0
        public override void LateUpdate()
        {
            if (_framesPassed <= 4)
            {
                if (_framesPassed == 4)
                {
                    Init();
                }
                ++_framesPassed;
            }
            else
            {
                BladeMovementDataElement lastAddedData = _movementData.lastAddedData;
                BladeMovementDataElement prevAddedData = _movementData.prevAddedData;
                --_framesToScaleCheck;
                if (_framesToScaleCheck <= 0)
                {
                    _framesToScaleCheck = 10;
                    if (!Mathf.Approximately(transform.lossyScale.z, _lastZScale))
                    {
                        _lastZScale = transform.lossyScale.z;
                        _trailRenderer.SetTrailWidth(GetTrailWidth(lastAddedData));
                    }
                }
                int numSamples = (int)Mathf.Floor((lastAddedData.time - _lastTrailElementTime) / _sampleStep);
                for (int index = 0; index < numSamples; ++index)
                {
                    _lastTrailElementTime += _sampleStep;
                    float t = (lastAddedData.time - _lastTrailElementTime) / (lastAddedData.time - prevAddedData.time);

                    Vector3 bottom = Vector3.LerpUnclamped(lastAddedData.bottomPos, prevAddedData.bottomPos, t);
                    Vector3 top    = Vector3.LerpUnclamped(lastAddedData.topPos, prevAddedData.topPos, t);

                    _trailElementCollection.head.SetData(bottom, calcNewTopPos(bottom, top), _lastTrailElementTime);
                    _trailElementCollection.MoveTailToHead();
                }
                _trailElementCollection.head.SetData(lastAddedData.bottomPos, lastAddedData.topPos, lastAddedData.time);
                _trailElementCollection.UpdateDistances();

                _trailRenderer.transform.position    = this.transform.rotation * new Vector3(0, TRAIL_Y_OFFSET);
                leftClawRenderer.transform.position  = this.transform.rotation * new Vector3(-TRAIL_X_OFFSET, TRAIL_Y_OFFSET);
                rightClawRenderer.transform.position = this.transform.rotation * new Vector3(TRAIL_X_OFFSET, TRAIL_Y_OFFSET);

                _trailRenderer.UpdateMesh(_trailElementCollection, _color);
                leftClawRenderer.UpdateMesh(_trailElementCollection, _color);
                rightClawRenderer.UpdateMesh(_trailElementCollection, _color);
            }
        }
コード例 #2
0
        public void LateUpdate()
        {
            if (_pointStart == null || _pointEnd == null)
            {
                return;
            }

            // wait until the fps is stable
            const int passThroughFrames = 4;

            if (_framesPassed <= passThroughFrames)
            {
                if (_framesPassed == passThroughFrames)
                {
                    _samplingFrequency = Mathf.RoundToInt(VRDeviceInfo.Instance.refreshRate);

                    /* no need after recent steamvr update for pimax?
                     * if (VRDeviceInfo.Instance.isPimax)
                     * {
                     *  _samplingFrequency = _samplingFrequency / 2;
                     * }
                     * else
                     */
                    {
                        _samplingFrequency = Mathf.RoundToInt((float)_samplingFrequency * Settings.Utilities.PluginConfig.Instance.samplingMultiplier);
                    }
                    if (_samplingFrequency == 0)
                    {
                        _samplingFrequency = 60;
                    }

                    _sampleStep = 1f / (float)_samplingFrequency;
                    int capacity = Mathf.CeilToInt((float)_samplingFrequency * _trailDuration);
                    Logger.log.Debug($"trail samplingFrequency={_samplingFrequency}, duration={_trailDuration}, capacity={capacity}");
                    _lastTrailElementTime   = TimeHelper.time;
                    _trailElementCollection = new TrailElementCollection(capacity, _pointStart.position, _pointEnd.position, _lastTrailElementTime);
                    float trailWidth = (_pointEnd.position - _pointStart.position).magnitude;
                    _whiteSectionMaxDuration = Mathf.Min(_whiteSectionMaxDuration, _trailDuration);
                    _lastZScale = transform.lossyScale.z;
                    _trailRenderer.Init(trailWidth, _trailDuration, (int)_granularity, _whiteSectionMaxDuration);

                    _lastPointStart = _pointStart.position;
                    _lastPointEnd   = _pointEnd.position;

                    _inited = true;
                }
                _framesPassed++;

                return;
            }

            if (TimeHelper.time <= _lastTrailElementTime)
            {
                return;
            }

            int   num      = Mathf.FloorToInt((TimeHelper.time - _lastTrailElementTime) / _sampleStep);
            float time     = TimeHelper.time;
            float lastTime = _lastTrailElementTime;

            for (int i = 1; i <= num; i++)
            {
                _lastTrailElementTime += _sampleStep;
                float t = (_lastTrailElementTime - lastTime) / (time - lastTime);
                _lastPointStart = Vector3.LerpUnclamped(_lastPointStart, _pointStart.position, t);
                _lastPointEnd   = Vector3.LerpUnclamped(_lastPointEnd, _pointEnd.position, t);

                _trailElementCollection.MoveTailToHead();
                _trailElementCollection.head.SetData(_lastPointStart, _lastPointEnd, _lastTrailElementTime);
            }

            if (num > 0)
            {
                _trailElementCollection.UpdateDistances();
                _trailRenderer.UpdateMesh(_trailElementCollection, color);
            }
        }