diff options
author | marynate <mary.w.nate@gmail.com> | 2014-03-31 23:06:36 +0800 |
---|---|---|
committer | marynate <mary.w.nate@gmail.com> | 2014-06-13 15:59:02 +0800 |
commit | 2f79e59c000f54e9af48a0368a27d35e304eff09 (patch) | |
tree | fe70b09dfc24d2775810140c650c41405fb130e8 /tools | |
parent | 64e83bfd1404ea593f0c79b478d196a3fcde42a8 (diff) |
Add align with view in 3d editor viewport (useful for aligning camera with
current view)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/editor/plugins/spatial_editor_plugin.cpp | 40 | ||||
-rw-r--r-- | tools/editor/plugins/spatial_editor_plugin.h | 1 |
2 files changed, 38 insertions, 3 deletions
diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 2e3632f18f..1bf425f3f3 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<Node*> &selection = editor_selection->get_selected_node_list(); for(List<Node*>::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<Node*> &selection = editor_selection->get_selected_node_list(); + + undo_redo->create_action("Align with view"); + for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + + Spatial *sp = E->get()->cast_to<Spatial>(); + if (!sp) + continue; + + SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(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 4bc3b553ef..29719cb80c 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 |