Skip to content

Commit

Permalink
Merge pull request #88279 from kleonc/editor-plugins-2d3d-drag-drop-t…
Browse files Browse the repository at this point in the history
…ransform-calculation-fix

Fix `CanvasItem`/`Node3D` editor plugin drag drop transform calculation
  • Loading branch information
akien-mga committed Feb 13, 2024
2 parents ace0aea + c0a1b4f commit e0b1e79
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CanvasItem>(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);
}
Expand Down
8 changes: 4 additions & 4 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit e0b1e79

Please sign in to comment.