Vixen
02b45cc4
csharp
public sealed class SplineEdit

Editing a spline in the viewport: pick a handle, drag it through the gizmo, insert on the curve, delete, join and split.

Read the guide page for this →

Remarks

[docs/plan/31 § T8]'s viewport editing, on the gizmo and SnapContext that already exist. A control point is a position and nothing else, so dragging one is what IGizmoTarget already does — which is why this is a target and a command rather than a mode.

⚠ Tangent handles are selectable in their own right, and they have to be. A tangent is where the curve leaves a point, and the only way to author a corner is to move one of them without the other — so a handle set that held only positions could express a smooth road and nothing else.

⚠ The undo record is the whole point list. A stroke on a heightfield records a rect because a terrain is megabytes; a spline is a hundred points and about three kilobytes, so the machinery that makes a rect worth having buys nothing here and costs a class of bug — an edit that inserts or removes a point changes every index after it, which a per-point delta would have to reason about and a whole-list snapshot does not.

Fields and properties (6)

  • public SplineAsset? Asset

    Which spline is being edited.

  • public SnapContext? Snapping

    What snapping applies to a drag, or none.

  • public float PickRadius

    How close a pick has to be to a handle, in metres.

  • public float HandleScale

    How far a tangent handle sits from its point, as a fraction of the tangent.

  • public IReadOnlyCollection<SplineHandle> Selection

    Which handles are selected.

  • public bool HasSelection

    Whether anything is selected.

Methods (10)

  • public Vector3? PositionOf(SplineHandle handle)

    Where a handle is, in world space.

  • public SplineHandle? Pick(Vector3 at, bool add = false)

    Selects the handle nearest a point, if one is close enough.

  • public void Deselect()

    Deselects everything.

  • public void Begin()

    Takes a snapshot, so the drag that follows becomes one undo entry.

  • public void Move(Vector3 delta, bool mirror = true)

    Moves every selected handle by a world-space delta.

  • public int Append(Vector3 at)

    Appends a control point at the end of the path and selects it.

  • public int InsertOn(Vector3 near)

    Inserts a control point on the curve nearest a place, without changing its shape.

  • public int Delete()

    Removes every selected control point.

  • public SplineCommand? Commit()

    Ends the drag, as one entry for the undo stack.

  • public void Cancel()

    Abandons the drag, putting the points back.

Used by (2)

  • SplineCommandVixen.Editor.SceneView
  • SplineEditTestsVixen.Editor.SceneView.Tests