summaryrefslogtreecommitdiff
path: root/tools/editor/plugins
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2014-06-17 11:55:52 -0300
committerreduz <reduzio@gmail.com>2014-06-17 11:55:52 -0300
commita285708a0c77e9d306297ae8fb227aeb7207ad86 (patch)
treec240a1328c426eb22062c2fe5253c5fc3652ac7d /tools/editor/plugins
parent59fd2c51f69aeb56805a18bd15b42928e165ba60 (diff)
parent2f79e59c000f54e9af48a0368a27d35e304eff09 (diff)
Merge pull request #510 from marynate/PR-align-with-view
Align selected node with current view (3d editor)
Diffstat (limited to 'tools/editor/plugins')
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.cpp40
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.h1
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