From 41af859c68d03486a9efbdd4bb4399133b3c6974 Mon Sep 17 00:00:00 2001 From: Marcus Brummer Date: Sun, 7 Jun 2020 22:09:41 +0200 Subject: [PATCH] Re-apply basis of newly added node (via drag-n-drop) in editor viewport --- editor/plugins/node_3d_editor_plugin.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index f59b4171b45..2dd29f70464 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -3658,16 +3658,20 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po editor_data->get_undo_redo().add_do_method(ed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name); editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); - Transform global_transform; - Node3D *parent_spatial = Object::cast_to(parent); - if (parent_spatial) { - global_transform = parent_spatial->get_global_gizmo_transform(); + Node3D *node3d = Object::cast_to(instanced_scene); + if (node3d) { + Transform global_transform; + Node3D *parent_node3d = Object::cast_to(parent); + if (parent_node3d) { + global_transform = parent_node3d->get_global_gizmo_transform(); + } + + global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); + global_transform.basis *= node3d->get_transform().basis; + + editor_data->get_undo_redo().add_do_method(instanced_scene, "set_global_transform", global_transform); } - global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); - - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_global_transform", global_transform); - return true; }