Vixen
02b45cc4
csharp
public sealed class SnapContext

What every transform in the editor rounds to, as one thing they all consult.

Read the guide page for this →

Remarks

Doc 24's D4, and it is a context rather than a settings bag for one reason. Snapping attached to the gizmo is a vertex snap that works when you drag an object and not when you extrude a face, which reads as the feature being broken rather than as two features. TransformGizmo, ScenePlacement and every blockout tool take the same instance, so there is one answer to "am I snapping" and one place it is written.

Three orthogonal parts, which is Blender's arrangement and the reason its snapping is the one people miss: Elements is what you land on, Base is what of yours lands on it, and Modifiers is everything that is true of a snap without being either.

⚠ The four booleans and three steps that were here before are still here, and still mean what they meant. They are views over Elements rather than separate state — two writers for one fact is how a toolbar toggle and a settings panel end up disagreeing — so everything that reads SnapPosition or SnapToVertex is unchanged, and everything that writes them moves the set.

Snapping rounds the total of a drag, not each step of it. Rounding each frame's delta accumulates the rounding error, so a slow drag across ten grid squares lands somewhere between two of them and a fast one lands on a line. Every implementation gets this wrong once.

The steps are separate numbers because they are separate decisions: a level built on a quarter-metre grid still wants fifteen-degree rotations.

Fields and properties (15)

  • public SnapElements Elements

    What a position may land on.

  • public SnapBase Base

    Which part of what is being dragged is put on it.

  • public SnapModifiers Modifiers

    The orthogonal switches.

  • public bool SnapPosition

    Whether a translate moves by whole steps of GridStep.

  • public bool AbsoluteGrid

    Whether a translate lands on the world grid rather than moving by whole steps of it.

  • public bool SnapToVertex

    Whether a drag lands on the nearest vertex of what is under the pointer.

  • public bool SnapToSurface

    Whether a drop or a drag lands on the surface under the pointer.

  • public bool SnapRotation

    Whether a rotate rounds to AngleStep.

  • public bool SnapScale

    Whether a scale rounds to ScaleStep.

  • public WorkPlane? Plane

    The plane whose step this follows, or for a step of its own.

  • public float GridStep

    How far apart the grid lines are, in world units.

  • public float AngleStep

    How far one rotation step is, in degrees.

  • public float ScaleStep

    How far one scale step is, as a factor.

  • public float VertexRadius

    How near an element has to be to be snapped to, in render pixels.

  • public bool SnapsToGeometry

    Whether any element needing geometry under the pointer is on.

Methods (8)

  • public bool Has(SnapElements element)

    Whether an element is on.

  • public bool Is(SnapModifiers modifier)

    Whether a modifier is on.

  • public void Toggle(SnapElements element, bool on)

    Turns an element on or off.

  • public void Toggle(SnapModifiers modifier, bool on)

    Turns a modifier on or off.

  • public float Position(float value)

    Rounds a distance to the grid, if position snapping is on.

  • public Vector3 Position(Vector3 value)

    Rounds an offset to the grid, component by component.

  • public float Rotation(float radians)

    Rounds an angle in radians to the angle step, if rotation snapping is on.

  • public float Scale(float factor)

    Rounds a scale factor, if scale snapping is on.

Used by (16)

  • EditorApplicationVixen.Editor.App
  • GizmoTestsVixen.Editor.SceneView.Tests
  • ISceneProbeVixen.Editor.SceneView
  • PrecisionTestsVixen.Editor.SceneView.Tests
  • ScenePlacementVixen.Editor.SceneView
  • SceneProbeVixen.Editor.SceneView
  • SceneTestsVixen.Editor.SceneView.Tests
  • SceneViewportVixen.Editor.SceneView
  • SnapCommandTestsVixen.Editor.App.Tests
  • SnapContextTestsVixen.Editor.SceneView.Tests
  • SnapTestsVixen.Editor.SceneView.Tests
  • SplineEditVixen.Editor.SceneView
  • SplineEditTestsVixen.Editor.SceneView.Tests
  • TransformGizmoVixen.Editor.SceneView
  • WorkPlaneCommandTestsVixen.Editor.App.Tests
  • WorkPlaneTestsVixen.Editor.SceneView.Tests