diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 2e3632f18f6..1bf425f3f3c 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -1166,7 +1166,6 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { Transform r; r.basis.scale(Vector3(scale,scale,scale)); - List &selection = editor_selection->get_selected_node_list(); for(List::Element *E=selection.front();E;E=E->next()) { @@ -1519,7 +1518,13 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { } break; case KEY_F: { - _menu_option(VIEW_CENTER_TO_SELECTION); + + if (k.pressed && k.mod.shift && k.mod.control) { + _menu_option(VIEW_ALIGN_SELECTION_WITH_VIEW); + } else if (k.pressed) { + _menu_option(VIEW_CENTER_TO_SELECTION); + } + } break; case KEY_SPACE: { @@ -1818,6 +1823,34 @@ void SpatialEditorViewport::_menu_option(int p_option) { cursor.pos=center; } break; + case VIEW_ALIGN_SELECTION_WITH_VIEW: { + + if (!get_selected_count()) + break; + + Transform camera_transform = camera->get_global_transform(); + + List &selection = editor_selection->get_selected_node_list(); + + undo_redo->create_action("Align with view"); + for(List::Element *E=selection.front();E;E=E->next()) { + + Spatial *sp = E->get()->cast_to(); + if (!sp) + continue; + + SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data(sp); + if (!se) + continue; + + Vector3 original_scale = sp->get_scale(); + sp->set_global_transform(camera_transform); + sp->set_scale(original_scale); + undo_redo->add_do_method(sp,"set_global_transform",sp->get_global_transform()); + undo_redo->add_undo_method(sp,"set_global_transform",se->original); + } + undo_redo->commit_action(); + } break; case VIEW_ENVIRONMENT: { int idx = view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT); @@ -2060,7 +2093,8 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_check_item("Environment",VIEW_ENVIRONMENT); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT),true); view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_item("Selection",VIEW_CENTER_TO_SELECTION); + view_menu->get_popup()->add_item("Selection (F)",VIEW_CENTER_TO_SELECTION); + view_menu->get_popup()->add_item("Align with view (Ctrl+Shift+F)",VIEW_ALIGN_SELECTION_WITH_VIEW); view_menu->get_popup()->connect("item_pressed",this,"_menu_option"); preview_camera = memnew( Button ); diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h index 4bc3b553efc..29719cb80ca 100644 --- a/tools/editor/plugins/spatial_editor_plugin.h +++ b/tools/editor/plugins/spatial_editor_plugin.h @@ -75,6 +75,7 @@ class SpatialEditorViewport : public Control { VIEW_FRONT, VIEW_REAR, VIEW_CENTER_TO_SELECTION, + VIEW_ALIGN_SELECTION_WITH_VIEW, VIEW_PERSPECTIVE, VIEW_ENVIRONMENT, VIEW_ORTHOGONAL