/// <summary>
 /// Determines how to display the spline depending on the number of control points that are present.
 /// </summary>
 protected virtual void ChooseDisplayMethod()
 {
     sphereObject.SetActive(false);
     if (SplineMesh.GetNumberOfControlPoints() == 0)
     {
         //display nothing
         meshFilter.mesh = new Mesh();
         //update collider
         meshCollider.sharedMesh = meshFilter.sharedMesh;
     }
     else if (SplineMesh.GetNumberOfControlPoints() == 1)
     {
         //display sphere if there is only one control point
         sphereObject.SetActive(true);
         sphereObject.transform.localPosition = SplineMesh.GetControlPoints()[0];
         //update collider
         meshCollider.sharedMesh = null;
     }
     else if (SplineMesh.GetNumberOfControlPoints() == 2)
     {
         //display linearly interpolated segment if there are two control points
         List <Vector3> controlPoints = SplineMesh.GetControlPoints();
         //set the two control points
         meshFilter.mesh = LinearSplineMesh.SetControlPoints(controlPoints.ToArray());
         //update collider
         meshCollider.sharedMesh = meshFilter.sharedMesh;
     }
     else
     {
         //display smoothly interpolated segments by not overwriting the previously generated mesh
         //update collider
         meshCollider.sharedMesh = meshFilter.sharedMesh;
     }
 }
 /// <summary>
 /// Determines how to display the spline depending on the number of control points that are present.
 /// </summary>
 protected virtual void ChooseDisplayMethod(Mesh newMesh)
 {
     sphereObject.SetActive(false);
     if (SplineMesh.GetNumberOfControlPoints() == 0)
     {
         UpdateSceneMesh(null);
     }
     else if (SplineMesh.GetNumberOfControlPoints() == 1)
     {
         //display sphere if there is only one control point
         sphereObject.SetActive(true);
         sphereObject.transform.localPosition = SplineMesh.GetControlPoints()[0];
         //update collider
         UpdateSceneMesh(null);
     }
     else if (SplineMesh.GetNumberOfControlPoints() == 2)
     {
         //display linearly interpolated segment if there are two control points
         List <Vector3> controlPoints = SplineMesh.GetControlPoints();
         //set the two control points
         UpdateSceneMesh(LinearSplineMesh.SetControlPoints(controlPoints.ToArray()));
     }
     else
     {
         UpdateSceneMesh(newMesh);
     }
 }
        public void SplineMesh_AddControlPoint_Performance([NUnit.Framework.Range(9, 99, 10)] int length)
        {
            SplineMesh splineMesh = null;

            Measure.Method(() =>
            {
                splineMesh.AddControlPoint(new Vector3(length + 1, 0, 0));
            })
            .SetUp(() => {
                splineMesh = new SplineMesh(new KochanekBartelsSpline());
                splineMesh.SetControlPoints(GenerateControlPoints(length).ToArray());
            })
            .Run();
        }
Esempio n. 4
0
    // Start is called before the first frame update
    void Start()
    {
        ControlPoints = new Vector3[ControlPointObjects.Length];
        for (int i = 0; i < ControlPointObjects.Length; i++)
        {
            ControlPoints[i] = ControlPointObjects[i].transform.position;
        }

        SplineMesh = new SplineMesh(new KochanekBartelsSpline());
        GetComponent <MeshFilter>().mesh = SplineMesh.SetControlPoints(ControlPoints);
        //SplineMesh.deleteControlPoint(9);
        //SplineMesh.addControlPoint(extraControlPoint.transform.position);
        //SplineMesh.insertControlPoint(1, extraControlPoint.transform.position);
    }