示例#1
0
        //Sample the computer
        private void SampleComputer()
        {
            if (computer == null)
            {
                return;
            }
            if (computer.pointCount < 1)
            {
                return;
            }
            double moveStep       = _address.moveStep / _resolution;
            int    fullIterations = DMath.CeilInt(1.0 / moveStep) + 1;
            double _span          = span;

            if (_span != span)
            {
                fullIterations = DMath.CeilInt(_span / moveStep) + 1;
            }
            if (_samples.Length != fullIterations)
            {
                _samples = new SplineResult[fullIterations];
            }
            for (int i = 0; i < fullIterations; i++)
            {
                double eval = (double)i / (fullIterations - 1);
                if (computer.isClosed && i == fullIterations - 1)
                {
                    eval = 0.0;
                }
                SplineResult result = _address.Evaluate(eval);
                result.percent = eval;
                _samples[i]    = result;
            }
            if (_samples.Length == 0)
            {
                _clippedSamples = new SplineResult[0];
                return;
            }
            if (_samples.Length > 1)
            {
                if (_averageResultVectors)
                {
                    //Average directions
                    Vector3 lastDir = _samples[1].position - _samples[0].position;
                    for (int i = 0; i < _samples.Length - 1; i++)
                    {
                        Vector3 dir = (_samples[i + 1].position - _samples[i].position).normalized;
                        _samples[i].direction = (lastDir + dir).normalized;
                        _samples[i].normal    = (_samples[i].normal + _samples[i + 1].normal).normalized;
                        lastDir = dir;
                    }

                    if (computer.isClosed)
                    {
                        _samples[_samples.Length - 1].direction = _samples[0].direction = Vector3.Slerp(_samples[0].direction, lastDir, 0.5f);
                    }
                    else
                    {
                        _samples[_samples.Length - 1].direction = lastDir;
                    }
                }
            }
            if (computer.isClosed && _span == 1f)
            {
                //Handle closed splines
                _samples[_samples.Length - 1]         = new SplineResult(_samples[0]);
                _samples[_samples.Length - 1].percent = clipTo;
            }
            GetClippedSamples();
        }
示例#2
0
        //Sample the computer
        private void SampleComputer()
        {
            if (computer == null)
            {
                return;
            }
            if (computer.pointCount == 0)
            {
                return;
            }
            if (computer.pointCount == 1)
            {
                _samples    = new SplineResult[1];
                _samples[0] = _address.Evaluate(0.0);
                return;
            }
            if (_resolution == 0f)
            {
                _samples        = new SplineResult[0];
                _clippedSamples = new SplineResult[0];
                return;
            }
            double moveStep       = _address.moveStep / _resolution;
            int    fullIterations = DMath.CeilInt(1.0 / moveStep) + 1;

            // double _span = span;
            // if (_span != span) fullIterations = DMath.CeilInt(_span / moveStep) + 1;
            if (_samples.Length != fullIterations)
            {
                _samples = new SplineResult[fullIterations];
            }
            if (uniformSample)
            {
                float lengthStep = computer.CalculateLength() / (fullIterations - 1);
                _samples[0]         = _address.Evaluate(0.0);
                _samples[0].percent = 0.0;
                for (int i = 1; i < fullIterations - 1; i++)
                {
                    _samples[i] = _address.Evaluate(_address.Travel(_samples[i - 1].percent, lengthStep, Spline.Direction.Forward, fullIterations));
                }
                if (computer.isClosed)
                {
                    _samples[samples.Length - 1] = new SplineResult(_samples[0]);
                }
                else
                {
                    _samples[_samples.Length - 1] = _address.Evaluate(1.0);
                }
                _samples[_samples.Length - 1].percent = 1.0;
            }
            else
            {
                for (int i = 0; i < fullIterations; i++)
                {
                    double eval = (double)i / (fullIterations - 1);
                    if (computer.isClosed && i == fullIterations - 1)
                    {
                        eval = 0.0;
                    }
                    _samples[i]         = _address.Evaluate(eval);
                    _samples[i].percent = eval;
                }
            }
            if (_samples.Length == 0)
            {
                _clippedSamples = new SplineResult[0];
                GetClippedSamples();
                return;
            }
            if (_samples.Length > 1)
            {
                if (_averageResultVectors)
                {
                    //Average directions
                    Vector3 lastDir = _samples[1].position - _samples[0].position;
                    for (int i = 0; i < _samples.Length - 1; i++)
                    {
                        Vector3 dir = (_samples[i + 1].position - _samples[i].position).normalized;
                        _samples[i].direction = (lastDir + dir).normalized;
                        _samples[i].normal    = (_samples[i].normal + _samples[i + 1].normal).normalized;
                        lastDir = dir;
                    }

                    if (computer.isClosed)
                    {
                        _samples[_samples.Length - 1].direction = _samples[0].direction = Vector3.Slerp(_samples[0].direction, lastDir, 0.5f);
                    }
                    else
                    {
                        _samples[_samples.Length - 1].direction = lastDir;
                    }
                }
            }
            if (computer.isClosed && clipTo == 1.0)
            {
                _samples[_samples.Length - 1] = new SplineResult(_samples[0]);                                     //Handle closed splines
            }
            _samples[_samples.Length - 1].percent = 1.0;
            GetClippedSamples();
        }
示例#3
0
        private void SampleComputer()
        {
            if (computer == null || computer.pointCount == 0)
            {
                return;
            }
            if (computer.pointCount == 1)
            {
                _samples    = new SplineResult[1];
                _samples[0] = _address.Evaluate(0.0);
                return;
            }
            if (_resolution == 0.0)
            {
                _samples        = new SplineResult[0];
                _clippedSamples = new SplineResult[0];
                return;
            }
            double num  = _address.moveStep / _resolution;
            int    num2 = DMath.CeilInt(1.0 / num) + 1;

            if (_samples.Length != num2)
            {
                _samples = new SplineResult[num2];
            }
            if (uniformSample)
            {
                float distance = computer.CalculateLength() / (float)(num2 - 1);
                _samples[0]         = _address.Evaluate(0.0);
                _samples[0].percent = 0.0;
                for (int i = 1; i < num2 - 1; i++)
                {
                    _samples[i] = _address.Evaluate(_address.Travel(_samples[i - 1].percent, distance, Spline.Direction.Forward, num2));
                }
                if (computer.isClosed)
                {
                    _samples[samples.Length - 1] = new SplineResult(_samples[0]);
                }
                else
                {
                    _samples[_samples.Length - 1] = _address.Evaluate(1.0);
                }
                _samples[_samples.Length - 1].percent = 1.0;
            }
            else
            {
                for (int j = 0; j < num2; j++)
                {
                    double percent = (double)j / (double)(num2 - 1);
                    if (computer.isClosed && j == num2 - 1)
                    {
                        percent = 0.0;
                    }
                    _samples[j]         = _address.Evaluate(percent);
                    _samples[j].percent = percent;
                }
            }
            if (_samples.Length == 0)
            {
                _clippedSamples = new SplineResult[0];
                GetClippedSamples();
                return;
            }
            if (_samples.Length > 1 && _averageResultVectors)
            {
                Vector3 vector = _samples[1].position - _samples[0].position;
                for (int k = 0; k < _samples.Length - 1; k++)
                {
                    Vector3 normalized = (_samples[k + 1].position - _samples[k].position).normalized;
                    _samples[k].direction = (vector + normalized).normalized;
                    _samples[k].normal    = (_samples[k].normal + _samples[k + 1].normal).normalized;
                    vector = normalized;
                }
                if (computer.isClosed)
                {
                    _samples[_samples.Length - 1].direction = (_samples[0].direction = Vector3.Slerp(_samples[0].direction, vector, 0.5f));
                }
                else
                {
                    _samples[_samples.Length - 1].direction = vector;
                }
            }
            if (computer.isClosed && clipTo == 1.0)
            {
                _samples[_samples.Length - 1] = new SplineResult(_samples[0]);
            }
            _samples[_samples.Length - 1].percent = 1.0;
            GetClippedSamples();
        }