From af63858d800ae836f64ea716000bba86933671b2 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 17 Feb 2024 19:42:38 -0600 Subject: [PATCH 1/4] Fix Scale gizmo for multiple directions. --- Source/Editor/Gizmo/TransformGizmoBase.cs | 66 +++++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Gizmo/TransformGizmoBase.cs b/Source/Editor/Gizmo/TransformGizmoBase.cs index 6123d348a..5a46b6fbf 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.cs @@ -253,7 +253,21 @@ namespace FlaxEditor.Gizmo _intersectPosition = ray.Position + ray.Direction * intersection; if (_lastIntersectionPosition != Vector3.Zero) _tDelta = _intersectPosition - _lastIntersectionPosition; - delta = new Vector3(0, _tDelta.Y, _tDelta.Z); + if (isScaling) + { + var tDeltaAbs = Vector3.Abs(_tDelta); + var maxDelta = Mathf.Max(tDeltaAbs.Y, tDeltaAbs.Z); + float sign = 0; + if (tDeltaAbs.Y > tDeltaAbs.Z) + sign = Mathf.Sign(_tDelta.Y); + else if (tDeltaAbs.Z > tDeltaAbs.Y) + sign = Mathf.Sign(_tDelta.Z); + delta = new Vector3(0, maxDelta * sign, maxDelta * sign); + } + else + { + delta = new Vector3(0, _tDelta.Y, _tDelta.Z); + } } break; } @@ -264,7 +278,21 @@ namespace FlaxEditor.Gizmo _intersectPosition = ray.Position + ray.Direction * intersection; if (_lastIntersectionPosition != Vector3.Zero) _tDelta = _intersectPosition - _lastIntersectionPosition; - delta = new Vector3(_tDelta.X, _tDelta.Y, 0); + if (isScaling) + { + var tDeltaAbs = Vector3.Abs(_tDelta); + var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Y); + float sign = 0; + if (tDeltaAbs.X > tDeltaAbs.Y) + sign = Mathf.Sign(_tDelta.X); + else if (tDeltaAbs.Y > tDeltaAbs.X) + sign = Mathf.Sign(_tDelta.Y); + delta = new Vector3(maxDelta * sign, maxDelta * sign, 0); + } + else + { + delta = new Vector3(_tDelta.X, _tDelta.Y, 0); + } } break; } @@ -275,7 +303,21 @@ namespace FlaxEditor.Gizmo _intersectPosition = ray.Position + ray.Direction * intersection; if (_lastIntersectionPosition != Vector3.Zero) _tDelta = _intersectPosition - _lastIntersectionPosition; - delta = new Vector3(_tDelta.X, 0, _tDelta.Z); + if (isScaling) + { + var tDeltaAbs = Vector3.Abs(_tDelta); + var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Z); + float sign = 0; + if (tDeltaAbs.X > tDeltaAbs.Z) + sign = Mathf.Sign(_tDelta.X); + else if (tDeltaAbs.Z > tDeltaAbs.X) + sign = Mathf.Sign(_tDelta.Z); + delta = new Vector3(maxDelta * sign, 0, maxDelta * sign); + } + else + { + delta = new Vector3(_tDelta.X, 0, _tDelta.Z); + } } break; } @@ -289,7 +331,23 @@ namespace FlaxEditor.Gizmo if (_lastIntersectionPosition != Vector3.Zero) _tDelta = _intersectPosition - _lastIntersectionPosition; } - delta = _tDelta; + if (isScaling) + { + var tDeltaAbs = Vector3.Abs(_tDelta); + var maxDelta = Mathf.Max(new[] { tDeltaAbs.X, tDeltaAbs.Y, tDeltaAbs.Z }); + float sign = 0; + if (Mathf.NearEqual(maxDelta, tDeltaAbs.X)) + sign = Mathf.Sign(_tDelta.X); + else if (Mathf.NearEqual(maxDelta, tDeltaAbs.Y)) + sign = Mathf.Sign(_tDelta.Y); + else if (Mathf.NearEqual(maxDelta, tDeltaAbs.Z)) + sign = Mathf.Sign(_tDelta.Z); + delta = new Vector3(maxDelta * sign); + } + else + { + delta = _tDelta; + } break; } } From eed44c14df98178cb18cce5e2b15d62f90b62572 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 17 Feb 2024 19:47:18 -0600 Subject: [PATCH 2/4] Simplify code --- Source/Editor/Gizmo/TransformGizmoBase.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/Source/Editor/Gizmo/TransformGizmoBase.cs b/Source/Editor/Gizmo/TransformGizmoBase.cs index 5a46b6fbf..2ce1c8e5e 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.cs @@ -257,11 +257,7 @@ namespace FlaxEditor.Gizmo { var tDeltaAbs = Vector3.Abs(_tDelta); var maxDelta = Mathf.Max(tDeltaAbs.Y, tDeltaAbs.Z); - float sign = 0; - if (tDeltaAbs.Y > tDeltaAbs.Z) - sign = Mathf.Sign(_tDelta.Y); - else if (tDeltaAbs.Z > tDeltaAbs.Y) - sign = Mathf.Sign(_tDelta.Z); + float sign = Mathf.Sign(tDeltaAbs.Y > tDeltaAbs.Z ? _tDelta.Y : _tDelta.Z); delta = new Vector3(0, maxDelta * sign, maxDelta * sign); } else @@ -282,11 +278,7 @@ namespace FlaxEditor.Gizmo { var tDeltaAbs = Vector3.Abs(_tDelta); var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Y); - float sign = 0; - if (tDeltaAbs.X > tDeltaAbs.Y) - sign = Mathf.Sign(_tDelta.X); - else if (tDeltaAbs.Y > tDeltaAbs.X) - sign = Mathf.Sign(_tDelta.Y); + float sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Y ? _tDelta.X : _tDelta.Y); delta = new Vector3(maxDelta * sign, maxDelta * sign, 0); } else @@ -307,11 +299,7 @@ namespace FlaxEditor.Gizmo { var tDeltaAbs = Vector3.Abs(_tDelta); var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Z); - float sign = 0; - if (tDeltaAbs.X > tDeltaAbs.Z) - sign = Mathf.Sign(_tDelta.X); - else if (tDeltaAbs.Z > tDeltaAbs.X) - sign = Mathf.Sign(_tDelta.Z); + float sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Z ? _tDelta.X : _tDelta.Z); delta = new Vector3(maxDelta * sign, 0, maxDelta * sign); } else From 6d77d455298178206a76590ca2c755b6d102794c Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 6 Mar 2024 06:42:20 -0600 Subject: [PATCH 3/4] use var and real for sign --- Source/Editor/Gizmo/TransformGizmoBase.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Gizmo/TransformGizmoBase.cs b/Source/Editor/Gizmo/TransformGizmoBase.cs index 2ce1c8e5e..3e1527e1d 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.cs @@ -257,7 +257,7 @@ namespace FlaxEditor.Gizmo { var tDeltaAbs = Vector3.Abs(_tDelta); var maxDelta = Mathf.Max(tDeltaAbs.Y, tDeltaAbs.Z); - float sign = Mathf.Sign(tDeltaAbs.Y > tDeltaAbs.Z ? _tDelta.Y : _tDelta.Z); + var sign = Mathf.Sign(tDeltaAbs.Y > tDeltaAbs.Z ? _tDelta.Y : _tDelta.Z); delta = new Vector3(0, maxDelta * sign, maxDelta * sign); } else @@ -278,7 +278,7 @@ namespace FlaxEditor.Gizmo { var tDeltaAbs = Vector3.Abs(_tDelta); var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Y); - float sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Y ? _tDelta.X : _tDelta.Y); + var sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Y ? _tDelta.X : _tDelta.Y); delta = new Vector3(maxDelta * sign, maxDelta * sign, 0); } else @@ -299,7 +299,7 @@ namespace FlaxEditor.Gizmo { var tDeltaAbs = Vector3.Abs(_tDelta); var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Z); - float sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Z ? _tDelta.X : _tDelta.Z); + var sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Z ? _tDelta.X : _tDelta.Z); delta = new Vector3(maxDelta * sign, 0, maxDelta * sign); } else @@ -323,7 +323,7 @@ namespace FlaxEditor.Gizmo { var tDeltaAbs = Vector3.Abs(_tDelta); var maxDelta = Mathf.Max(new[] { tDeltaAbs.X, tDeltaAbs.Y, tDeltaAbs.Z }); - float sign = 0; + Real sign = 0; if (Mathf.NearEqual(maxDelta, tDeltaAbs.X)) sign = Mathf.Sign(_tDelta.X); else if (Mathf.NearEqual(maxDelta, tDeltaAbs.Y)) From c858b67f2e8f7bd67f48c2ca91442af51bca83c4 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 13 May 2024 16:48:45 -0500 Subject: [PATCH 4/4] Try and fix large world issue. --- Source/Editor/Gizmo/TransformGizmoBase.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/Editor/Gizmo/TransformGizmoBase.cs b/Source/Editor/Gizmo/TransformGizmoBase.cs index 3e1527e1d..0d209889f 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.cs @@ -256,8 +256,8 @@ namespace FlaxEditor.Gizmo if (isScaling) { var tDeltaAbs = Vector3.Abs(_tDelta); - var maxDelta = Mathf.Max(tDeltaAbs.Y, tDeltaAbs.Z); - var sign = Mathf.Sign(tDeltaAbs.Y > tDeltaAbs.Z ? _tDelta.Y : _tDelta.Z); + var maxDelta = Math.Max(tDeltaAbs.Y, tDeltaAbs.Z); + var sign = Math.Sign(tDeltaAbs.Y > tDeltaAbs.Z ? _tDelta.Y : _tDelta.Z); delta = new Vector3(0, maxDelta * sign, maxDelta * sign); } else @@ -277,8 +277,8 @@ namespace FlaxEditor.Gizmo if (isScaling) { var tDeltaAbs = Vector3.Abs(_tDelta); - var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Y); - var sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Y ? _tDelta.X : _tDelta.Y); + var maxDelta = Math.Max(tDeltaAbs.X, tDeltaAbs.Y); + var sign = Math.Sign(tDeltaAbs.X > tDeltaAbs.Y ? _tDelta.X : _tDelta.Y); delta = new Vector3(maxDelta * sign, maxDelta * sign, 0); } else @@ -298,8 +298,8 @@ namespace FlaxEditor.Gizmo if (isScaling) { var tDeltaAbs = Vector3.Abs(_tDelta); - var maxDelta = Mathf.Max(tDeltaAbs.X, tDeltaAbs.Z); - var sign = Mathf.Sign(tDeltaAbs.X > tDeltaAbs.Z ? _tDelta.X : _tDelta.Z); + var maxDelta = Math.Max(tDeltaAbs.X, tDeltaAbs.Z); + var sign = Math.Sign(tDeltaAbs.X > tDeltaAbs.Z ? _tDelta.X : _tDelta.Z); delta = new Vector3(maxDelta * sign, 0, maxDelta * sign); } else @@ -322,14 +322,15 @@ namespace FlaxEditor.Gizmo if (isScaling) { var tDeltaAbs = Vector3.Abs(_tDelta); - var maxDelta = Mathf.Max(new[] { tDeltaAbs.X, tDeltaAbs.Y, tDeltaAbs.Z }); + var maxDelta = Math.Max(tDeltaAbs.X, tDeltaAbs.Y); + maxDelta = Math.Max(maxDelta, tDeltaAbs.Z); Real sign = 0; if (Mathf.NearEqual(maxDelta, tDeltaAbs.X)) - sign = Mathf.Sign(_tDelta.X); + sign = Math.Sign(_tDelta.X); else if (Mathf.NearEqual(maxDelta, tDeltaAbs.Y)) - sign = Mathf.Sign(_tDelta.Y); + sign = Math.Sign(_tDelta.Y); else if (Mathf.NearEqual(maxDelta, tDeltaAbs.Z)) - sign = Mathf.Sign(_tDelta.Z); + sign = Math.Sign(_tDelta.Z); delta = new Vector3(maxDelta * sign); } else