/// <summary> Return up vector at set distance along the <see cref="Bezier3DSpline"/>. </summary> public void GetPoint(float dist, out Vector3 result) { Bezier3DCurve curve = GetCurveDistance(dist, out dist); curve.GetPoint(curve.Dist2Time(dist), out result); result = transform.TransformPoint(result); }
/// <summary> Return point at lerped position where 0 = start, 1 = end </summary> public Vector3 GetPointLocal(float dist) { Bezier3DCurve curve = GetCurveDistance(dist, out dist); Vector3 result = Vector3.zero; curve.GetPoint(curve.Dist2Time(dist), out result); return(result); }
/// <summary> Return point at lerped position where 0 = start, 1 = end </summary> public Vector3 GetPointLocal(float dist) { Bezier3DCurve curve = GetCurveDistance(dist, out dist); return(curve.GetPoint(curve.Dist2Time(dist))); }
/// <summary> Return up vector at set distance along the <see cref="Bezier3DSpline"/>. </summary> public Vector3 GetPoint(float dist) { Bezier3DCurve curve = GetCurveDistance(dist, out dist); return(transform.TransformPoint(curve.GetPoint(curve.Dist2Time(dist)))); }
/// <summary> Return forward vector at set distance along the <see cref="Bezier3DSpline"/> in local coordinates. Uses approximation. </summary> public Vector3 GetForwardLocalFast(float dist) { Bezier3DCurve curve = GetCurveDistance(dist, out dist); return(curve.GetForwardFast(curve.Dist2Time(dist))); }
void DrawSelectedSplitters() { Handles.color = Color.white; //Start add if (!spline.closed && activeKnot == 0) { Bezier3DCurve curve = spline.GetCurve(0); Vector3 a = spline.transform.TransformPoint(curve.a), b = spline.transform.TransformDirection(curve.b.normalized) * 2f; float handleScale = HandleUtility.GetHandleSize(a); b *= handleScale; Handles.DrawDottedLine(a, a - b, 3f); if (Handles.Button(a - b, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); spline.InsertKnot(0, new Bezier3DSpline.Knot(curve.a - (curve.b.normalized * handleScale * 2), Vector3.zero, curve.b.normalized * 0.5f, knot.auto, knot.orientation)); if (onUpdateSpline != null) { onUpdateSpline(spline); } } } //End add if (!spline.closed && activeKnot == spline.CurveCount) { Bezier3DCurve curve = spline.GetCurve(spline.CurveCount - 1); Vector3 c = spline.transform.TransformDirection(curve.c.normalized) * 2f, d = spline.transform.TransformPoint(curve.d); float handleScale = HandleUtility.GetHandleSize(d); c *= handleScale; Handles.DrawDottedLine(d, d - c, 3f); if (Handles.Button(d - c, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); spline.AddKnot(new Bezier3DSpline.Knot(curve.d - (curve.c.normalized * handleScale * 2), curve.c.normalized * 0.5f, Vector3.zero, knot.auto, knot.orientation)); SelectKnot(spline.CurveCount, false); if (onUpdateSpline != null) { onUpdateSpline(spline); } } } // Prev split if (spline.closed || activeKnot != 0) { Bezier3DCurve curve = spline.GetCurve(activeKnot == 0 ? spline.CurveCount - 1 : activeKnot - 1); Vector3 centerLocal = curve.GetPoint(curve.Dist2Time(curve.length * 0.5f)); Vector3 center = spline.transform.TransformPoint(centerLocal); Vector3 a = curve.a + curve.b; Vector3 b = curve.c + curve.d; Vector3 ab = (b - a) * 0.3f; float handleScale = HandleUtility.GetHandleSize(center); if (Handles.Button(center, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); spline.InsertKnot(activeKnot == 0 ? spline.CurveCount : activeKnot, new Bezier3DSpline.Knot(centerLocal, -ab, ab, knot.auto, knot.orientation)); if (activeKnot == 0) { SelectKnot(spline.CurveCount - 1, false); } if (onUpdateSpline != null) { onUpdateSpline(spline); } } } // Next split if (activeKnot != spline.CurveCount) { Bezier3DCurve curve = spline.GetCurve(activeKnot); Vector3 centerLocal = curve.GetPoint(curve.Dist2Time(curve.length * 0.5f)); Vector3 center = spline.transform.TransformPoint(centerLocal); Vector3 a = curve.a + curve.b; Vector3 b = curve.c + curve.d; Vector3 ab = (b - a) * 0.3f; float handleScale = HandleUtility.GetHandleSize(center); if (Handles.Button(center, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); spline.InsertKnot(activeKnot + 1, new Bezier3DSpline.Knot(centerLocal, -ab, ab)); SelectKnot(activeKnot + 1, false); if (onUpdateSpline != null) { onUpdateSpline(spline); } } } }
/// <summary> Return point at lerped position where 0 = start, 1 = end </summary> public void GetPointLocal(float dist, out Vector3 result) { Bezier3DCurve curve = GetCurveDistance(dist, out dist); curve.GetPoint(curve.Dist2Time(dist), out result); }