Cleanup editor viewports code
This commit is contained in:
@@ -41,6 +41,7 @@ namespace FlaxEditor.Viewport
|
||||
Gizmos[i].Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EditorViewport Viewport => this;
|
||||
|
||||
@@ -121,5 +122,41 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
internal static readonly float[] TranslateSnapValues =
|
||||
{
|
||||
0.1f,
|
||||
0.5f,
|
||||
1.0f,
|
||||
5.0f,
|
||||
10.0f,
|
||||
100.0f,
|
||||
1000.0f,
|
||||
};
|
||||
|
||||
internal static readonly float[] RotateSnapValues =
|
||||
{
|
||||
1.0f,
|
||||
5.0f,
|
||||
10.0f,
|
||||
15.0f,
|
||||
30.0f,
|
||||
45.0f,
|
||||
60.0f,
|
||||
90.0f,
|
||||
};
|
||||
|
||||
internal static readonly float[] ScaleSnapValues =
|
||||
{
|
||||
0.05f,
|
||||
0.1f,
|
||||
0.25f,
|
||||
0.5f,
|
||||
1.0f,
|
||||
2.0f,
|
||||
4.0f,
|
||||
6.0f,
|
||||
8.0f,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,16 +268,14 @@ namespace FlaxEditor.Viewport
|
||||
Parent = scaleSnappingWidget
|
||||
};
|
||||
enableScaleSnapping.Toggled += OnScaleSnappingToggle;
|
||||
|
||||
var scaleSnappingCM = new ContextMenu();
|
||||
_scaleSnapping = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM)
|
||||
{
|
||||
TooltipText = "Scale snapping values"
|
||||
};
|
||||
|
||||
for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++)
|
||||
for (int i = 0; i < ScaleSnapValues.Length; i++)
|
||||
{
|
||||
var v = EditorViewportScaleSnapValues[i];
|
||||
var v = ScaleSnapValues[i];
|
||||
var button = scaleSnappingCM.AddButton(v.ToString());
|
||||
button.Tag = v;
|
||||
}
|
||||
@@ -295,16 +293,14 @@ namespace FlaxEditor.Viewport
|
||||
Parent = rotateSnappingWidget
|
||||
};
|
||||
enableRotateSnapping.Toggled += OnRotateSnappingToggle;
|
||||
|
||||
var rotateSnappingCM = new ContextMenu();
|
||||
_rotateSnapping = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM)
|
||||
{
|
||||
TooltipText = "Rotation snapping values"
|
||||
};
|
||||
|
||||
for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++)
|
||||
for (int i = 0; i < RotateSnapValues.Length; i++)
|
||||
{
|
||||
var v = EditorViewportRotateSnapValues[i];
|
||||
var v = RotateSnapValues[i];
|
||||
var button = rotateSnappingCM.AddButton(v.ToString());
|
||||
button.Tag = v;
|
||||
}
|
||||
@@ -322,7 +318,6 @@ namespace FlaxEditor.Viewport
|
||||
Parent = translateSnappingWidget
|
||||
};
|
||||
enableTranslateSnapping.Toggled += OnTranslateSnappingToggle;
|
||||
|
||||
var translateSnappingCM = new ContextMenu();
|
||||
_translateSnapping = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM)
|
||||
{
|
||||
@@ -330,16 +325,14 @@ namespace FlaxEditor.Viewport
|
||||
};
|
||||
if (TransformGizmo.TranslationSnapValue < 0.0f)
|
||||
_translateSnapping.Text = "Bounding Box";
|
||||
|
||||
for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++)
|
||||
for (int i = 0; i < TranslateSnapValues.Length; i++)
|
||||
{
|
||||
var v = EditorViewportTranslateSnapValues[i];
|
||||
var v = TranslateSnapValues[i];
|
||||
var button = translateSnappingCM.AddButton(v.ToString());
|
||||
button.Tag = v;
|
||||
}
|
||||
var buttonBB = translateSnappingCM.AddButton("Bounding Box").LinkTooltip("Snaps the selection based on it's bounding volume");
|
||||
buttonBB.Tag = -1.0f;
|
||||
|
||||
translateSnappingCM.ButtonClicked += OnWidgetTranslateSnapClick;
|
||||
translateSnappingCM.VisibleChanged += OnWidgetTranslateSnapShowHide;
|
||||
_translateSnapping.Parent = translateSnappingWidget;
|
||||
@@ -552,7 +545,7 @@ namespace FlaxEditor.Viewport
|
||||
var task = renderContext.Task;
|
||||
|
||||
// Render editor primitives, gizmo and debug shapes in debug view modes
|
||||
// Note: can use Output buffer as both input and output because EditorPrimitives is using a intermediate buffers
|
||||
// Note: can use Output buffer as both input and output because EditorPrimitives is using an intermediate buffer
|
||||
if (EditorPrimitives && EditorPrimitives.CanRender())
|
||||
{
|
||||
EditorPrimitives.Render(context, ref renderContext, task.Output, task.Output);
|
||||
@@ -619,19 +612,6 @@ namespace FlaxEditor.Viewport
|
||||
_gizmoModeScale.Checked = mode == TransformGizmoBase.Mode.Scale;
|
||||
}
|
||||
|
||||
private static readonly float[] EditorViewportScaleSnapValues =
|
||||
{
|
||||
0.05f,
|
||||
0.1f,
|
||||
0.25f,
|
||||
0.5f,
|
||||
1.0f,
|
||||
2.0f,
|
||||
4.0f,
|
||||
6.0f,
|
||||
8.0f,
|
||||
};
|
||||
|
||||
private void OnWidgetScaleSnapClick(ContextMenuButton button)
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
@@ -651,25 +631,11 @@ namespace FlaxEditor.Viewport
|
||||
if (e is ContextMenuButton b)
|
||||
{
|
||||
var v = (float)b.Tag;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f
|
||||
? Style.Current.CheckBoxTick
|
||||
: SpriteHandle.Invalid;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly float[] EditorViewportRotateSnapValues =
|
||||
{
|
||||
1.0f,
|
||||
5.0f,
|
||||
10.0f,
|
||||
15.0f,
|
||||
30.0f,
|
||||
45.0f,
|
||||
60.0f,
|
||||
90.0f,
|
||||
};
|
||||
|
||||
private void OnWidgetRotateSnapClick(ContextMenuButton button)
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
@@ -689,24 +655,11 @@ namespace FlaxEditor.Viewport
|
||||
if (e is ContextMenuButton b)
|
||||
{
|
||||
var v = (float)b.Tag;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f
|
||||
? Style.Current.CheckBoxTick
|
||||
: SpriteHandle.Invalid;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly float[] EditorViewportTranslateSnapValues =
|
||||
{
|
||||
0.1f,
|
||||
0.5f,
|
||||
1.0f,
|
||||
5.0f,
|
||||
10.0f,
|
||||
100.0f,
|
||||
1000.0f,
|
||||
};
|
||||
|
||||
private void OnWidgetTranslateSnapClick(ContextMenuButton button)
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
@@ -729,9 +682,7 @@ namespace FlaxEditor.Viewport
|
||||
if (e is ContextMenuButton b)
|
||||
{
|
||||
var v = (float)b.Tag;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f
|
||||
? Style.Current.CheckBoxTick
|
||||
: SpriteHandle.Invalid;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,16 +131,14 @@ namespace FlaxEditor.Viewport
|
||||
Parent = scaleSnappingWidget
|
||||
};
|
||||
enableScaleSnapping.Toggled += OnScaleSnappingToggle;
|
||||
|
||||
var scaleSnappingCM = new ContextMenu();
|
||||
_scaleSnapping = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM)
|
||||
{
|
||||
TooltipText = "Scale snapping values"
|
||||
};
|
||||
|
||||
for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++)
|
||||
for (int i = 0; i < EditorGizmoViewport.ScaleSnapValues.Length; i++)
|
||||
{
|
||||
var v = EditorViewportScaleSnapValues[i];
|
||||
var v = EditorGizmoViewport.ScaleSnapValues[i];
|
||||
var button = scaleSnappingCM.AddButton(v.ToString());
|
||||
button.Tag = v;
|
||||
}
|
||||
@@ -158,16 +156,14 @@ namespace FlaxEditor.Viewport
|
||||
Parent = rotateSnappingWidget
|
||||
};
|
||||
enableRotateSnapping.Toggled += OnRotateSnappingToggle;
|
||||
|
||||
var rotateSnappingCM = new ContextMenu();
|
||||
_rotateSnapping = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM)
|
||||
{
|
||||
TooltipText = "Rotation snapping values"
|
||||
};
|
||||
|
||||
for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++)
|
||||
for (int i = 0; i < EditorGizmoViewport.RotateSnapValues.Length; i++)
|
||||
{
|
||||
var v = EditorViewportRotateSnapValues[i];
|
||||
var v = EditorGizmoViewport.RotateSnapValues[i];
|
||||
var button = rotateSnappingCM.AddButton(v.ToString());
|
||||
button.Tag = v;
|
||||
}
|
||||
@@ -185,16 +181,14 @@ namespace FlaxEditor.Viewport
|
||||
Parent = translateSnappingWidget
|
||||
};
|
||||
enableTranslateSnapping.Toggled += OnTranslateSnappingToggle;
|
||||
|
||||
var translateSnappingCM = new ContextMenu();
|
||||
_translateSnappng = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM)
|
||||
{
|
||||
TooltipText = "Position snapping values"
|
||||
};
|
||||
|
||||
for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++)
|
||||
for (int i = 0; i < EditorGizmoViewport.TranslateSnapValues.Length; i++)
|
||||
{
|
||||
var v = EditorViewportTranslateSnapValues[i];
|
||||
var v = EditorGizmoViewport.TranslateSnapValues[i];
|
||||
var button = translateSnappingCM.AddButton(v.ToString());
|
||||
button.Tag = v;
|
||||
}
|
||||
@@ -428,19 +422,6 @@ namespace FlaxEditor.Viewport
|
||||
_gizmoModeScale.Checked = mode == TransformGizmoBase.Mode.Scale;
|
||||
}
|
||||
|
||||
private static readonly float[] EditorViewportScaleSnapValues =
|
||||
{
|
||||
0.05f,
|
||||
0.1f,
|
||||
0.25f,
|
||||
0.5f,
|
||||
1.0f,
|
||||
2.0f,
|
||||
4.0f,
|
||||
6.0f,
|
||||
8.0f,
|
||||
};
|
||||
|
||||
private void OnWidgetScaleSnapClick(ContextMenuButton button)
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
@@ -459,25 +440,11 @@ namespace FlaxEditor.Viewport
|
||||
if (e is ContextMenuButton b)
|
||||
{
|
||||
var v = (float)b.Tag;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f
|
||||
? Style.Current.CheckBoxTick
|
||||
: SpriteHandle.Invalid;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.ScaleSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly float[] EditorViewportRotateSnapValues =
|
||||
{
|
||||
1.0f,
|
||||
5.0f,
|
||||
10.0f,
|
||||
15.0f,
|
||||
30.0f,
|
||||
45.0f,
|
||||
60.0f,
|
||||
90.0f,
|
||||
};
|
||||
|
||||
private void OnWidgetRotateSnapClick(ContextMenuButton button)
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
@@ -496,24 +463,11 @@ namespace FlaxEditor.Viewport
|
||||
if (e is ContextMenuButton b)
|
||||
{
|
||||
var v = (float)b.Tag;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f
|
||||
? Style.Current.CheckBoxTick
|
||||
: SpriteHandle.Invalid;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.RotationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly float[] EditorViewportTranslateSnapValues =
|
||||
{
|
||||
0.1f,
|
||||
0.5f,
|
||||
1.0f,
|
||||
5.0f,
|
||||
10.0f,
|
||||
100.0f,
|
||||
1000.0f,
|
||||
};
|
||||
|
||||
private void OnWidgetTranslateSnapClick(ContextMenuButton button)
|
||||
{
|
||||
var v = (float)button.Tag;
|
||||
@@ -532,9 +486,7 @@ namespace FlaxEditor.Viewport
|
||||
if (e is ContextMenuButton b)
|
||||
{
|
||||
var v = (float)b.Tag;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f
|
||||
? Style.Current.CheckBoxTick
|
||||
: SpriteHandle.Invalid;
|
||||
b.Icon = Mathf.Abs(TransformGizmo.TranslationSnapValue - v) < 0.001f ? Style.Current.CheckBoxTick : SpriteHandle.Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace FlaxEditor.Viewport
|
||||
var gridPlane = new Plane(Vector3.Zero, Vector3.Up);
|
||||
var flags = SceneGraphNode.RayCastData.FlagTypes.SkipColliders | SceneGraphNode.RayCastData.FlagTypes.SkipEditorPrimitives;
|
||||
hit = _owner.SceneGraphRoot.RayCast(ref ray, ref view, out var closest, out var normal, flags);
|
||||
var girdGizmo = (GridGizmo)_owner.Gizmos.FirstOrDefault(x => x is GridGizmo);
|
||||
var girdGizmo = _owner.Gizmos.Get<GridGizmo>();
|
||||
if (hit != null)
|
||||
{
|
||||
// Use hit location
|
||||
@@ -180,7 +180,7 @@ namespace FlaxEditor.Viewport
|
||||
var location = hitLocation + new Vector3(0, bottomToCenter, 0);
|
||||
|
||||
// Apply grid snapping if enabled
|
||||
var transformGizmo = (TransformGizmo)_owner.Gizmos.FirstOrDefault(x => x is TransformGizmo);
|
||||
var transformGizmo = _owner.Gizmos.Get<TransformGizmo>();
|
||||
if (transformGizmo != null && (_owner.UseSnapping || transformGizmo.TranslationSnapEnable))
|
||||
{
|
||||
float snapValue = transformGizmo.TranslationSnapValue;
|
||||
|
||||
Reference in New Issue
Block a user