Merge pull request #51164 from TokageItLab/fix-gizmo-transform-scaling

Fixed gizmo forced implicit normalization and inconsistent rotation
This commit is contained in:
Rémi Verschelde 2021-08-05 16:42:33 +02:00 committed by GitHub
commit dcf2a62b05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1113,9 +1113,9 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const
local_motion.snap(Vector3(p_extra, p_extra, p_extra)); 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;
Transform3D local_t = p_original_local; local_t.basis = p_original_local.basis.scaled_local(local_motion + Vector3(1, 1, 1));
local_t.basis.set_euler_scale(p_original_local.basis.get_rotation_euler(), local_scale); local_t.origin = p_original_local.origin;
return local_t; return local_t;
} else { } else {
Transform3D base = Transform3D(Basis(), _edit.center); Transform3D base = Transform3D(Basis(), _edit.center);
@ -1123,9 +1123,9 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const
p_motion.snap(Vector3(p_extra, p_extra, p_extra)); p_motion.snap(Vector3(p_extra, p_extra, p_extra));
} }
Transform3D r; Transform3D global_t;
r.basis.scale(p_motion + Vector3(1, 1, 1)); global_t.basis.scale(p_motion + Vector3(1, 1, 1));
return base * (r * (base.inverse() * p_original)); return base * (global_t * (base.inverse() * p_original));
} }
} }
case TRANSFORM_TRANSLATE: { case TRANSFORM_TRANSLATE: {
@ -1151,19 +1151,18 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const
} }
case TRANSFORM_ROTATE: { case TRANSFORM_ROTATE: {
if (p_local) { if (p_local) {
Basis rot = Basis(p_motion, p_extra); Transform3D r;
Vector3 axis = p_original_local.basis.xform(p_motion);
Vector3 scale = p_original_local.basis.get_scale(); r.basis = Basis(axis.normalized(), p_extra) * p_original_local.basis;
Vector3 euler = (p_original_local.get_basis().orthonormalized() * rot).get_euler(); r.origin = p_original_local.origin;
Transform3D t; return r;
t.basis.set_euler_scale(euler, scale);
t.origin = p_original_local.origin;
return t;
} else { } else {
Transform3D r; Transform3D r;
r.basis.rotate(p_motion, p_extra); Basis local = p_original.basis * p_original_local.basis.inverse();
Transform3D base = Transform3D(Basis(), _edit.center); Vector3 axis = local.xform_inv(p_motion);
return base * r * base.inverse() * p_original; 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: { default: {