summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilc Renew <tokage.it.lab@gmail.com>2023-02-04 00:45:12 +0900
committerSilc Renew <tokage.it.lab@gmail.com>2023-02-04 00:46:04 +0900
commit1459b9c24c9bf7c4781fde3ea55c0dbd9b020e2f (patch)
treed38c5be867ee987248e4016b6282eea9e9798a23
parent604493eb6ee3def65aca089c1d4bc71ea03ca19a (diff)
Fix scaled_orthogonal() & subgizmo global scaling
-rw-r--r--core/math/basis.cpp7
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp5
-rw-r--r--editor/plugins/skeleton_3d_editor_plugin.cpp2
3 files changed, 8 insertions, 6 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index 234a4ddb79..95a4187062 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -239,13 +239,18 @@ void Basis::scale_orthogonal(const Vector3 &p_scale) {
Basis Basis::scaled_orthogonal(const Vector3 &p_scale) const {
Basis m = *this;
Vector3 s = Vector3(-1, -1, -1) + p_scale;
+ bool sign = signbit(s.x + s.y + s.z);
+ Basis b = m.orthonormalized();
+ s = b.xform_inv(s);
Vector3 dots;
- Basis b;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
dots[j] += s[i] * abs(m.get_column(i).normalized().dot(b.get_column(j)));
}
}
+ if (sign != signbit(dots.x + dots.y + dots.z)) {
+ dots = -dots;
+ }
m.scale_local(Vector3(1, 1, 1) + dots);
return m;
}
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 36d1e54246..b001b4f766 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -1415,9 +1415,6 @@ Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const
// Recalculate orthogonalized scale without moving origin.
if (p_orthogonal) {
s.basis = p_original.basis.scaled_orthogonal(p_motion + Vector3(1, 1, 1));
- // The scaled_orthogonal() does not require orthogonal Basis,
- // but it may make a bit skew by precision problems.
- s.basis.orthogonalize();
}
}
@@ -4634,7 +4631,7 @@ void Node3DEditorViewport::update_transform(Point2 p_mousepos, bool p_shift) {
if (se->gizmo.is_valid()) {
for (KeyValue<int, Transform3D> &GE : se->subgizmos) {
Transform3D xform = GE.value;
- Transform3D new_xform = _compute_transform(TRANSFORM_SCALE, se->original * xform, xform, motion, snap, local_coords, true); // Force orthogonal with subgizmo.
+ Transform3D new_xform = _compute_transform(TRANSFORM_SCALE, se->original * xform, xform, motion, snap, local_coords, _edit.plane != TRANSFORM_VIEW); // Force orthogonal with subgizmo.
if (!local_coords) {
new_xform = se->original.affine_inverse() * new_xform;
}
diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp
index 782e365138..7f43de3240 100644
--- a/editor/plugins/skeleton_3d_editor_plugin.cpp
+++ b/editor/plugins/skeleton_3d_editor_plugin.cpp
@@ -1301,7 +1301,7 @@ void Skeleton3DGizmoPlugin::set_subgizmo_transform(const EditorNode3DGizmo *p_gi
Transform3D original_to_local;
int parent_idx = skeleton->get_bone_parent(p_id);
if (parent_idx >= 0) {
- original_to_local = original_to_local * skeleton->get_bone_global_pose(parent_idx);
+ original_to_local = skeleton->get_bone_global_pose(parent_idx);
}
Basis to_local = original_to_local.get_basis().inverse();