/// <summary> /// Same as Spline.Evaluate but the result is transformed by the computer's transform /// </summary> /// <param name="percent">Evaluation percent</param> /// <param name="address">Optional address if junctions should be used</param> /// <returns></returns> public SplineResult Evaluate(double percent) { SplineResult result = spline.Evaluate(percent); if (_space == SplineComputer.Space.Local) { TransformResult(result); } return(result); }
public static void DrawSpline(Spline spline, Color color, double from = 0.0, double to = 1.0, bool drawThickness = false, bool thicknessAutoRotate = false) { double add = spline.moveStep; if (add < 0.0025) { add = 0.0025; } double percent = from; Color prevColor = Handles.color; Handles.color = color; if (drawThickness) { Camera editorCamera = SceneView.currentDrawingSceneView.camera; SplineResult fromResult = spline.Evaluate(percent); SplineResult toResult = new SplineResult(); Vector3 fromNormal = fromResult.normal; if (thicknessAutoRotate) { fromNormal = (editorCamera.transform.position - fromResult.position).normalized; } Vector3 fromRight = Vector3.Cross(fromResult.direction, fromNormal).normalized *fromResult.size * 0.5f; while (true) { percent = DMath.Move(percent, to, add); spline.Evaluate(toResult, percent); Vector3 toNormal = toResult.normal; if (thicknessAutoRotate) { toNormal = (editorCamera.transform.position - toResult.position).normalized; } Vector3 toRight = Vector3.Cross(toResult.direction, toNormal).normalized *toResult.size * 0.5f; Handles.DrawLine(fromResult.position + fromRight, toResult.position + toRight); Handles.DrawLine(fromResult.position - fromRight, toResult.position - toRight); Handles.DrawLine(fromResult.position + fromRight, fromResult.position - fromRight); if (percent == to) { break; } fromResult.CopyFrom(toResult); fromNormal = toNormal; fromRight = toRight; } } else { Vector3 fromPoint = spline.EvaluatePosition(percent); Vector3 toPoint = new Vector3(); while (true) { percent = DMath.Move(percent, to, add); toPoint = spline.EvaluatePosition(percent); Handles.DrawLine(fromPoint, toPoint); if (percent == to) { break; } fromPoint = toPoint; } } Handles.color = prevColor; }
public static void DrawSpline(Spline spline, Color color, double from = 0.0, double to = 1.0, bool drawThickness = false, bool thicknessAutoRotate = false) { double add = spline.moveStep; if (add < 0.0025) { add = 0.0025; } Color prevColor = Handles.color; Handles.color = color; int iterations = spline.iterations; if (drawThickness) { Transform editorCamera = SceneView.currentDrawingSceneView.camera.transform; if (positions.Length != iterations * 6) { positions = new Vector3[iterations * 6]; } SplineResult prevResult = spline.Evaluate(from); Vector3 prevNormal = prevResult.normal; if (thicknessAutoRotate) { prevNormal = (editorCamera.position - prevResult.position).normalized; } Vector3 prevRight = Vector3.Cross(prevResult.direction, prevNormal).normalized *prevResult.size * 0.5f; int pointIndex = 0; for (int i = 1; i < iterations; i++) { double p = DMath.Lerp(from, to, (double)i / (iterations - 1)); SplineResult newResult = spline.Evaluate(p); Vector3 newNormal = newResult.normal; if (thicknessAutoRotate) { newNormal = (editorCamera.position - newResult.position).normalized; } Vector3 newRight = Vector3.Cross(newResult.direction, newNormal).normalized *newResult.size * 0.5f; positions[pointIndex] = prevResult.position + prevRight; positions[pointIndex + iterations * 2] = prevResult.position - prevRight; positions[pointIndex + iterations * 4] = newResult.position - newRight; pointIndex++; positions[pointIndex] = newResult.position + newRight; positions[pointIndex + iterations * 2] = newResult.position - newRight; positions[pointIndex + iterations * 4] = newResult.position + newRight; pointIndex++; prevResult = newResult; prevRight = newRight; prevNormal = newNormal; } Handles.DrawLines(positions); } else { if (positions.Length != iterations * 2) { positions = new Vector3[iterations * 2]; } Vector3 prevPoint = spline.EvaluatePosition(from); int pointIndex = 0; for (int i = 1; i < iterations; i++) { double p = DMath.Lerp(from, to, (double)i / (iterations - 1)); positions[pointIndex] = prevPoint; pointIndex++; positions[pointIndex] = spline.EvaluatePosition(p); pointIndex++; prevPoint = positions[pointIndex - 1]; } Handles.DrawLines(positions); } Handles.color = prevColor; }