// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; using FlaxEngine; namespace FlaxEditor.Gizmo { public partial class TransformGizmoBase { /// /// Scale of the gizmo itself /// private const float GizmoScaleFactor = 24; /// /// The length of each axis (outwards) /// private const float AxisLength = 3.5f; /// /// Offset to move axis away from center /// private const float AxisOffset = 0.8f; /// /// How thick the axis should be /// private const float AxisThickness = 0.3f; /// /// Center box scale /// private const float CenterBoxScale = 0.8f; /// /// The inner minimum of the multiscale /// private const float InnerExtend = AxisOffset + 0.5f; /// /// The outer maximum of the multiscale /// private const float OuterExtend = AxisOffset * 3.5f; // Cube with the size AxisThickness, then moves it along the axis (AxisThickness) and finally makes it really long (AxisLength) private BoundingBox XAxisBox = new BoundingBox(new Vector3(-AxisThickness), new Vector3(AxisThickness)).MakeOffsetted(AxisOffset * Vector3.UnitX).Merge(AxisLength * Vector3.UnitX); private BoundingBox YAxisBox = new BoundingBox(new Vector3(-AxisThickness), new Vector3(AxisThickness)).MakeOffsetted(AxisOffset * Vector3.UnitY).Merge(AxisLength * Vector3.UnitY); private BoundingBox ZAxisBox = new BoundingBox(new Vector3(-AxisThickness), new Vector3(AxisThickness)).MakeOffsetted(AxisOffset * Vector3.UnitZ).Merge(AxisLength * Vector3.UnitZ); private BoundingBox XZBox = new BoundingBox(new Vector3(InnerExtend, 0, InnerExtend), new Vector3(OuterExtend, 0, OuterExtend)); private BoundingBox XYBox = new BoundingBox(new Vector3(InnerExtend, InnerExtend, 0), new Vector3(OuterExtend, OuterExtend, 0)); private BoundingBox YZBox = new BoundingBox(new Vector3(0, InnerExtend, InnerExtend), new Vector3(0, OuterExtend, OuterExtend)); private BoundingBox CenterBoxRaw = new BoundingBox(new Vector3(-0.5f * CenterBoxScale), new Vector3(0.5f * CenterBoxScale)); private OrientedBoundingBox CenterBox => new OrientedBoundingBox(CenterBoxRaw) * _gizmoWorld; private const float RotateRadiusRaw = 4.0f; private Mode _activeMode = Mode.Translate; private Axis _activeAxis = Axis.None; private TransformSpace _activeTransformSpace = TransformSpace.World; private PivotType _activePivotType = PivotType.SelectionCenter; /// /// True if enable grid snapping when moving objects /// public bool TranslationSnapEnable = false; /// /// True if enable grid snapping when rotating objects /// public bool RotationSnapEnabled = false; /// /// True if enable grid snapping when scaling objects /// public bool ScaleSnapEnabled = false; /// /// Translation snap value /// public float TranslationSnapValue = 10; /// /// Rotation snap value /// public float RotationSnapValue = 15; /// /// Scale snap value /// public float ScaleSnapValue = 1.0f; /// /// Gets the current pivot type. /// public PivotType ActivePivot => _activePivotType; /// /// Gets the current axis type. /// public Axis ActiveAxis => _activeAxis; /// /// Gets or sets the current gizmo mode. /// public Mode ActiveMode { get => _activeMode; set { if (_activeMode != value) { _activeMode = value; ModeChanged?.Invoke(); } } } /// /// Event fired when active gizmo mode gets changed. /// public Action ModeChanged; /// /// Gets or sets the current gizmo transform space. /// public TransformSpace ActiveTransformSpace { get => _activeTransformSpace; set { if (_activeTransformSpace != value) { _activeTransformSpace = value; TransformSpaceChanged?.Invoke(); } } } /// /// Event fired when active transform space gets changed. /// public Action TransformSpaceChanged; /// /// Toggles gizmo transform space /// public void ToggleTransformSpace() { ActiveTransformSpace = _activeTransformSpace == TransformSpace.World ? TransformSpace.Local : TransformSpace.World; } } }