Example #1
0
        public void OnDrawGizmos()
        {
            if (SplineSolver == null)
            {
                return;
            }

            SplineSolver.OnInternalDrawGizmos(SplineColor, DisplayResolution);
        }
Example #2
0
        public void Close()
        {
            if (IsClosed)
            {
                throw new System.Exception("Closing a Spline that is already closed");
            }

            IsClosed = true;
            SplineSolver.Close();
        }
Example #3
0
        public void BuildFromKeyframes(List <SplineKeyframe> keyframes)
        {
            var keyframeDifference = SplineSolver == null;

            if (SplineSolver != null)
            {
                keyframeDifference = keyframes.Count() != Nodes.Count();
                if (!(SplineSolver is LinearSplineSolver) && SplineSolver.Nodes.Count == 2)
                {
                    keyframeDifference = true;
                }
                else if (!(SplineSolver is QuadraticSplineSolver) && SplineSolver.Nodes.Count == 3)
                {
                    keyframeDifference = true;
                }
                else if (!(SplineSolver is QuadraticSplineSolver) && SplineSolver.Nodes.Count == 4)
                {
                    keyframeDifference = true;
                }
                else if (!(SplineSolver is CatmullRomSplineSolver))
                {
                    keyframeDifference = true;
                }
            }

            if (keyframeDifference)
            {
                if (SplineSolver != null)
                {
                    Object.DestroyImmediate(SplineSolver);
                }

                if (keyframes.Count == 2)
                {
                    SplineSolver = ScriptableObject.CreateInstance <LinearSplineSolver>();
                }
                else if (keyframes.Count == 3)
                {
                    SplineSolver = ScriptableObject.CreateInstance <QuadraticSplineSolver>();
                }
                else if (keyframes.Count == 4)
                {
                    SplineSolver = ScriptableObject.CreateInstance <CubicBezierSplineSolver>();
                }
                else
                {
                    SplineSolver = ScriptableObject.CreateInstance <CatmullRomSplineSolver>();
                }
            }

            SplineSolver.Nodes = keyframes;
            SplineSolver.Build();
        }
Example #4
0
 public void Reverse()
 {
     if (!IsReversed)
     {
         SplineSolver.Reverse();
         IsReversed = true;
     }
     else
     {
         SplineSolver.Reverse();
         IsReversed = false;
     }
 }
Example #5
0
        public Vector3 GetPositionOnPath(float time)
        {
            if (time < 0.0f || time > 1.0f)
            {
                if (IsClosed)
                {
                    if (time < 0.0f)
                    {
                        time += 1.0f;
                    }
                    else
                    {
                        time -= 1.0f;
                    }
                }
                else
                {
                    time = Mathf.Clamp01(time);
                }
            }

            return(SplineSolver.GetPositionOnPath(time));
        }
Example #6
0
 private Vector3 GetPosition(float time)
 {
     return(SplineSolver.GetPosition(time));
 }
Example #7
0
        public void BuildFromKeyframes(List <JSplineKeyframe> keyframes)
        {
            bool keyframeDifference = SplineSolver == null;

            if (SplineSolver != null)
            {
                keyframeDifference = keyframes.Count() != Nodes.Count();

                if (SplineType != SplineSolver.SplineType())
                {
                    keyframeDifference = true;
                }
            }

            if (keyframeDifference)
            {
                if (SplineSolver != null)
                {
                    ScriptableObject.DestroyImmediate(SplineSolver);
                }
                if (SplineType == JSplineType.Liner)
                {
                    if (keyframes.Count >= 2)
                    {
                        SplineSolver = ScriptableObject.CreateInstance <JLinearSplineSolver>();
                    }
                    else
                    {
                        throw new SystemException("Need At Least 2 Points");
                    }
                }
                else if (SplineType == JSplineType.Hermite)
                {
                    if (keyframes.Count >= 2)
                    {
                        SplineSolver = ScriptableObject.CreateInstance <JHermiteSplineSolver>();
                    }
                    else
                    {
                        throw new SystemException("Need At Least 2 Points");
                    }
                }
                else if (SplineType == JSplineType.Bezier)
                {
                    if (keyframes.Count >= 2)
                    {
                        SplineSolver = ScriptableObject.CreateInstance <JNTimesBezierSplineSolver>();
                    }
                    else
                    {
                        throw new SystemException("Need At Least 2 Points");
                    }
                }
                else if (SplineType == JSplineType.CatmullRom)
                {
                    if (keyframes.Count >= 4)
                    {
                        SplineSolver = ScriptableObject.CreateInstance <JCatmullRomSplineSolver>();
                    }
                    else
                    {
                        throw new SystemException("Need At Least 4 Points");
                    }
                }
                else if (SplineType == JSplineType.CubicSpline)
                {
                    if (keyframes.Count >= 2)
                    {
                        SplineSolver = ScriptableObject.CreateInstance <JNaturalCubicSplineSolver>();
                    }
                    else
                    {
                        throw new SystemException("Need At Least 2 Points");
                    }
                }
            }
            if (SplineSolver != null)
            {
                SplineSolver.Nodes       = keyframes;
                SplineSolver.closedCurve = IsClosed;
                SplineSolver.Build();
            }
        }
Example #8
0
 public Quaternion GetRotation(float time)
 {
     return(SplineSolver.GetRotation(time));
 }