public static Vector3[] ToPoints(this CatmullRomSpline bezierPath, float stepAngle = 2, float step = 0.01f, float maxSegmentLength = Single.PositiveInfinity) { var previous = bezierPath.Evaluate(0); var points = new List <Vector3>(); points.Add(previous); var previousDirection = bezierPath.Evaluate(0.01f) - previous; Vector3 previousPoint = previous; for (float t = step; t < 1.0f; t += step) { var point = bezierPath.Evaluate(t); var currentDirection = point - previousPoint; if (Vector3.Angle(currentDirection, previousDirection) > stepAngle || Vector3.Distance(point, previous) > maxSegmentLength) { points.Add(point); previous = point; previousDirection = currentDirection; } previousPoint = point; } points.Add(bezierPath.Evaluate(1)); return(points.ToArray()); }
public static Vector3[] ToPoints(this CatmullRomSpline bezierPath, int pointCount) { if (pointCount < 2) { pointCount = 2; } var step = 1.0f / (pointCount - 1); var previous = bezierPath.Evaluate(0); var points = new List <Vector3>(); points.Add(previous); for (float t = step; t < 1.0f; t += step) { var point = bezierPath.Evaluate(t); points.Add(point); } points.Add(bezierPath.Evaluate(1)); return(points.ToArray()); }