Fix 2D instance drop position

(cherry picked from commit 3a9fb3aff0)
This commit is contained in:
kobewi 2022-02-20 22:36:14 +01:00 committed by Rémi Verschelde
parent 156d9d1643
commit fdded6b44d
1 changed files with 9 additions and 7 deletions

View File

@ -6475,16 +6475,18 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons
editor_data->get_undo_redo().add_do_method(sed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name); editor_data->get_undo_redo().add_do_method(sed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name);
editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
CanvasItem *parent_ci = Object::cast_to<CanvasItem>(parent);
if (parent_ci) {
Vector2 target_pos = canvas_item_editor->get_canvas_transform().affine_inverse().xform(p_point);
target_pos = canvas_item_editor->snap_point(target_pos);
target_pos = parent_ci->get_global_transform_with_canvas().affine_inverse().xform(target_pos);
// Preserve instance position of the original scene.
CanvasItem *instance_ci = Object::cast_to<CanvasItem>(instanced_scene); CanvasItem *instance_ci = Object::cast_to<CanvasItem>(instanced_scene);
if (instance_ci) { if (instance_ci) {
target_pos += instance_ci->_edit_get_position(); Vector2 target_pos = canvas_item_editor->get_canvas_transform().affine_inverse().xform(p_point);
target_pos = canvas_item_editor->snap_point(target_pos);
CanvasItem *parent_ci = Object::cast_to<CanvasItem>(parent);
if (parent_ci) {
target_pos = parent_ci->get_global_transform_with_canvas().affine_inverse().xform(target_pos);
} }
// Preserve instance position of the original scene.
target_pos += instance_ci->_edit_get_position();
editor_data->get_undo_redo().add_do_method(instanced_scene, "set_position", target_pos); editor_data->get_undo_redo().add_do_method(instanced_scene, "set_position", target_pos);
} }