From c0a1b4f32def9306ff5a2ffb9327dd36024c8990 Mon Sep 17 00:00:00 2001 From: kleonc <9283098+kleonc@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:52:37 +0100 Subject: [PATCH] Fix CanvasItem/Node3D editor plugin drag drop transform calculation --- editor/plugins/canvas_item_editor_plugin.cpp | 2 +- editor/plugins/node_3d_editor_plugin.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 3ea42a48aea3..987a28adc9c1 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5783,7 +5783,7 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & target_position = canvas_item_editor->snap_point(target_position); CanvasItem *parent_ci = Object::cast_to(parent); - Point2 local_target_pos = parent_ci ? parent_ci->get_global_transform().xform_inv(target_position) : target_position; + Point2 local_target_pos = parent_ci ? parent_ci->get_global_transform().affine_inverse().xform(target_position) : target_position; undo_redo->add_do_method(child, "set_position", local_target_pos); } diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 83b5a136fdab..31166075a7d2 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -3298,7 +3298,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { } Node3D *parent = sp->get_parent_node_3d(); - Transform3D local_xform = parent ? parent->get_global_transform().inverse_xform(xform) : xform; + Transform3D local_xform = parent ? parent->get_global_transform().affine_inverse() * xform : xform; undo_redo->add_do_method(sp, "set_transform", local_xform); undo_redo->add_undo_method(sp, "set_transform", sp->get_local_gizmo_transform()); } @@ -4371,7 +4371,7 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po } Transform3D new_tf = node3d->get_transform(); - new_tf.origin = parent_tf.xform_inv(preview_node_pos); + new_tf.origin = parent_tf.affine_inverse().xform(preview_node_pos); undo_redo->add_do_method(instantiated_scene, "set_transform", new_tf); } @@ -6166,7 +6166,7 @@ void Node3DEditor::_xform_dialog_action() { } Node3D *parent = sp->get_parent_node_3d(); - Transform3D local_tr = parent ? parent->get_global_transform().inverse_xform(tr) : tr; + Transform3D local_tr = parent ? parent->get_global_transform().affine_inverse() * tr : tr; undo_redo->add_do_method(sp, "set_transform", local_tr); undo_redo->add_undo_method(sp, "set_transform", sp->get_transform()); } @@ -7517,7 +7517,7 @@ void Node3DEditor::_snap_selected_nodes_to_floor() { new_transform.origin = new_transform.origin - position_offset; Node3D *parent = sp->get_parent_node_3d(); - Transform3D new_local_xform = parent ? parent->get_global_transform().inverse_xform(new_transform) : new_transform; + Transform3D new_local_xform = parent ? parent->get_global_transform().affine_inverse() * new_transform : new_transform; undo_redo->add_do_method(sp, "set_transform", new_local_xform); undo_redo->add_undo_method(sp, "set_transform", sp->get_transform()); }