From 4822499d701065203666e661b9445042d90928de Mon Sep 17 00:00:00 2001 From: Silc 'Tokage' Renew <61938263+TokageItLab@users.noreply.github.com> Date: Sun, 1 Aug 2021 09:28:37 +0900 Subject: [PATCH] Fixed gizmo forced uniform scale and inconsistent rotation --- editor/plugins/node_3d_editor_plugin.cpp | 33 ++++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index c342d30012c..8dba494bf32 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -1111,9 +1111,9 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const local_motion.snap(Vector3(p_extra, p_extra, p_extra)); } - Vector3 local_scale = p_original_local.basis.get_scale() * (local_motion + Vector3(1, 1, 1)); - Transform3D local_t = p_original_local; - local_t.basis.set_euler_scale(p_original_local.basis.get_rotation_euler(), local_scale); + Transform3D local_t; + local_t.basis = p_original_local.basis.scaled_local(local_motion + Vector3(1, 1, 1)); + local_t.origin = p_original_local.origin; return local_t; } else { Transform3D base = Transform3D(Basis(), _edit.center); @@ -1121,9 +1121,9 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const p_motion.snap(Vector3(p_extra, p_extra, p_extra)); } - Transform3D r; - r.basis.scale(p_motion + Vector3(1, 1, 1)); - return base * (r * (base.inverse() * p_original)); + Transform3D global_t; + global_t.basis.scale(p_motion + Vector3(1, 1, 1)); + return base * (global_t * (base.inverse() * p_original)); } } case TRANSFORM_TRANSLATE: { @@ -1149,19 +1149,18 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const } case TRANSFORM_ROTATE: { if (p_local) { - Basis rot = Basis(p_motion, p_extra); - - Vector3 scale = p_original_local.basis.get_scale(); - Vector3 euler = (p_original_local.get_basis().orthonormalized() * rot).get_euler(); - Transform3D t; - t.basis.set_euler_scale(euler, scale); - t.origin = p_original_local.origin; - return t; + Transform3D r; + Vector3 axis = p_original_local.basis.xform(p_motion); + r.basis = Basis(axis.normalized(), p_extra) * p_original_local.basis; + r.origin = p_original_local.origin; + return r; } else { Transform3D r; - r.basis.rotate(p_motion, p_extra); - Transform3D base = Transform3D(Basis(), _edit.center); - return base * r * base.inverse() * p_original; + Basis local = p_original.basis * p_original_local.basis.inverse(); + Vector3 axis = local.xform_inv(p_motion); + r.basis = local * Basis(axis.normalized(), p_extra) * p_original_local.basis; + r.origin = Basis(p_motion, p_extra).xform(p_original.origin - _edit.center) + _edit.center; + return r; } } default: {