我需要一个!有效!平滑线渲染器的算法(基本上,给定的Vector3保存渲染器的点)
这样的事情 这是我的代码,但带有它的fps非常低:public static List<Vector3> MakeSmoothCurve(Vector3[] arrayToCurve, float smoothness)
{
List<Vector3> points;
List<Vector3> curvedPoints;
int pointsLength = 0;
int curvedLength = 0;
if (smoothness < 1.0f) smoothness = 1.0f;
pointsLength = arrayToCurve.Length;
curvedLength = (pointsLength * Mathf.RoundToInt(smoothness)) - 1;
curvedPoints = new List<Vector3>(curvedLength);
float t = 0.0f;
for (int pointInTimeOnCurve = 0; pointInTimeOnCurve < curvedLength + 1; pointInTimeOnCurve++)
{
t = Mathf.InverseLerp(0, curvedLength, pointInTimeOnCurve);
points = new List<Vector3>(arrayToCurve);
for (int j = pointsLength - 1; j > 0; j--)
{
for (int i = 0; i < j; i++)
{
points[i] = (1 - t) * points[i] + t * points[i + 1];
}
}
curvedPoints.Add(points[0]);
}
return (curvedPoints);
}
答案 0 :(得分:0)
您可以使用CurveField
https://docs.unity3d.com/ScriptReference/EditorGUILayout.CurveField.html
通过它,您可以轻松编辑/测试曲线并在给定时间检索点。
https://docs.unity3d.com/ScriptReference/AnimationCurve.Evaluate.html