Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a better way to draw SplineCurve that this
#1
So I am learning the API for curvy. And I just wanted to draw the spline genered by CurvySpline. So I wrote this class:

Code:
using UnityEngine;
using System.Collections;
using FluffyUnderware.Curvy;
using FluffyUnderware.Curvy.Utils;

public class SplineRenderer : MonoBehaviour {
LineRenderer linerender;
CurvySpline spline;

// Use this for initialization
void Start () {
linerender = gameObject.AddComponent<LineRenderer> ();
spline = GetComponent<CurvySpline> ();
// while (!spline.IsInitialized)
// yield return null;
}

public void RedrawSpline()
{
SplinePolyLine line = new SplinePolyLine (spline);
Vector3[] vtx = line.getVertices ();

linerender.SetVertexCount(vtx.Length);
for( int i=0; i<vtx.Length; ++i )
{
linerender.SetPosition(i, vtx[i]);
}
linerender.SetWidth(.25f, .25f);
}
}

I attach this component to a CurvySpline GameObject. And in the CurvySpline component put in the OnRefresh event a callback to the RedrawSpline() function. When I run the scene, my line draws. I can manipulate the spline and the line redraws. Just wonder If I'm missing something more efficient you have already written.

I just found that Curvy has a component called CurvyLineRenderer which does what I was trying to do. I love reinventing wheels!
Reply
#2
Hehe, glad you've found it Wink Have a look at CurvySplineBase.GetPolygon(), too.

SplinePolyLine is a helper class for the Export Wizard...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Draw a spline as a string in 2D game theKing 1 3,494 03-29-2016, 06:38 PM
Last Post: Jake

Forum Jump: