diff --git a/Source/Editor/Options/InputOptions.cs b/Source/Editor/Options/InputOptions.cs
index 0a1a78cab..f02d91da4 100644
--- a/Source/Editor/Options/InputOptions.cs
+++ b/Source/Editor/Options/InputOptions.cs
@@ -68,6 +68,10 @@ namespace FlaxEditor.Options
[EditorDisplay("Common"), EditorOrder(220)]
public InputBinding ContentFinder = new InputBinding(KeyboardKeys.O, KeyboardKeys.Control);
+ [DefaultValue(typeof(InputBinding), "R")]
+ [EditorDisplay("Common"), EditorOrder(230)]
+ public InputBinding RotateSelection = new InputBinding(KeyboardKeys.R);
+
#endregion
#region Scene
diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs
index eb82a42bf..bf72bc1c0 100644
--- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs
+++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs
@@ -362,6 +362,7 @@ namespace FlaxEditor.Viewport
InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate);
InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale);
InputActions.Add(options => options.FocusSelection, FocusSelection);
+ InputActions.Add(options => options.RotateSelection, RotateSelection);
InputActions.Add(options => options.Delete, _editor.SceneEditing.Delete);
}
@@ -666,6 +667,49 @@ namespace FlaxEditor.Viewport
Gizmos.ForEach(x => x.OnSelectionChanged(selection));
}
+ ///
+ /// Press "R" to rotate the selected gizmo objects 45 degrees.
+ ///
+ public void RotateSelection()
+ {
+ var win = (WindowRootControl)Root;
+ var selection = _editor.SceneEditing.Selection;
+ var IsShiftDown = win.GetKey(KeyboardKeys.Shift);
+
+ Quaternion rotationDelta;
+ if(IsShiftDown)
+ rotationDelta = Quaternion.Euler(0.0f, -45.0f, 0.0f);
+ else
+ rotationDelta = Quaternion.Euler(0.0f, 45.0f, 0.0f);
+
+ bool useObjCenter = TransformGizmo.ActivePivot == TransformGizmoBase.PivotType.ObjectCenter;
+ Vector3 gizmoPosition = TransformGizmo.Position;
+
+ //PE: Rotate selected objects.
+ bool isPlayMode = Editor.Instance.StateMachine.IsPlayMode;
+ for (int i = 0; i < selection.Count; i++)
+ {
+ var obj = selection[i];
+ if (isPlayMode && obj.CanTransform == false)
+ continue;
+ var trans = obj.Transform;
+ Vector3 pivotOffset = trans.Translation - gizmoPosition;
+ if (useObjCenter || pivotOffset.IsZero)
+ {
+ trans.Orientation *= Quaternion.Invert(trans.Orientation) * rotationDelta * trans.Orientation;
+ }
+ else
+ {
+ Matrix.RotationQuaternion(ref trans.Orientation, out var transWorld);
+ Matrix.RotationQuaternion(ref rotationDelta, out var deltaWorld);
+ Matrix world = transWorld * Matrix.Translation(pivotOffset) * deltaWorld * Matrix.Translation(-pivotOffset);
+ trans.SetRotation(ref world);
+ trans.Translation += world.TranslationVector;
+ }
+ obj.Transform = trans;
+ }
+ }
+
///
/// Focuses the viewport on the current selection of the gizmo.
///