示例#1
0
    public void SmoothPaths()
    {
        foreach (PathData data in pathData)
        {
            List <Vector3> points = data.nodes.Select(x => x.position).ToList();
            data.curves = BezierInterpolator.Interpolate(points);

            int n = data.curves.Count - 1;
            data.curves[0].SetControl1(data.curves[0].anchor1);
            data.curves[n].SetControl2(data.curves[n].anchor2);
        }
        EditorApplication.QueuePlayerLoopUpdate();
    }
 public void Update()
 {
     curves = BezierInterpolator.Interpolate(Vertices);
 }
 public void Clear()
 {
     points = null;
     curves = BezierInterpolator.Interpolate(Vertices);
     EditorApplication.QueuePlayerLoopUpdate();
 }
示例#4
0
    /// <summary>
    /// This function updates the spline. It is called automatically once in a while, if updateMode isn't set to DontUpdate.
    /// </summary>
    public void UpdateSpline( )
    {
        switch (interpolationMode)
        {
        case InterpolationMode.Linear:
            if (!(splineInterpolator is LinearInterpolator))
            {
                splineInterpolator = new LinearInterpolator( );
            }
            break;

        case InterpolationMode.Bezier:
            if (!(splineInterpolator is BezierInterpolator))
            {
                splineInterpolator = new BezierInterpolator( );
            }
            break;

        case InterpolationMode.Hermite:
            if (!(splineInterpolator is HermiteInterpolator))
            {
                splineInterpolator = new HermiteInterpolator( );
            }
            break;

        case InterpolationMode.BSpline:
            if (!(splineInterpolator is BSplineInterpolator))
            {
                splineInterpolator = new BSplineInterpolator( );
            }
            break;
        }

        //Count valid spline nodes
        int validNodes = 0;

        foreach (SplineNode sNode in splineNodesArray)
        {
            if (sNode != null)
            {
                ++validNodes;
            }
        }

        //Get relevant count
        int relevantNodeCount = GetRelevantNodeCount(validNodes);

        //Initialize the internal node array
        if (splineNodesInternal == null)
        {
            splineNodesInternal = new List <SplineNode>( );
        }

        splineNodesInternal.Clear( );

        if (!EnoughNodes(relevantNodeCount))
        {
            return;
        }

        splineNodesInternal.AddRange(splineNodesArray.GetRange(0, relevantNodeCount));
        splineNodesInternal.Remove(null);

        ReparameterizeCurve( );

        updateFrame = Time.frameCount;
    }