diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-07-26 08:31:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-26 08:31:20 +0200 |
commit | 4c5f0844e1cba7d964dda5292f22ecb324d12706 (patch) | |
tree | 68a8e0b92a15214f025c335189d102fc0a19cb7c | |
parent | 832e2bfcd38965a01a9149d509169dd197e42f58 (diff) | |
parent | 46ec1deba579c7b3c073201324d241b498eacb15 (diff) |
Merge pull request #19758 from kyledayton/feature/spatial-viewport-lock-rotation
Add lock rotation feature to spatial editor viewport
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 29 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.h | 4 |
2 files changed, 32 insertions, 1 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 4ac6636bc8..4b410b5ece 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1928,6 +1928,11 @@ void SpatialEditorViewport::_nav_zoom(Ref<InputEventWithModifiers> p_event, cons void SpatialEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { + if (lock_rotation) { + _nav_pan(p_event, p_relative); + return; + } + real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); bool invert_y_axis = EditorSettings::get_singleton()->get("editors/3d/navigation/invert_y-axis"); @@ -2563,6 +2568,19 @@ void SpatialEditorViewport::_menu_option(int p_option) { _update_name(); } break; + case VIEW_LOCK_ROTATION: { + + int idx = view_menu->get_popup()->get_item_index(VIEW_LOCK_ROTATION); + bool current = view_menu->get_popup()->is_item_checked(idx); + lock_rotation = !current; + view_menu->get_popup()->set_item_checked(idx, !current); + if (lock_rotation) { + view_menu->set_icon(get_icon("Lock", "EditorIcons")); + } else { + view_menu->set_icon(Ref<Texture>()); + } + + } break; case VIEW_AUDIO_LISTENER: { int idx = view_menu->get_popup()->get_item_index(VIEW_AUDIO_LISTENER); @@ -2836,6 +2854,12 @@ void SpatialEditorViewport::set_state(const Dictionary &p_state) { if (!view_menu->get_popup()->is_item_checked(idx)) _menu_option(display); } + if (p_state.has("lock_rotation")) { + lock_rotation = p_state["lock_rotation"]; + + int idx = view_menu->get_popup()->get_item_index(VIEW_LOCK_ROTATION); + view_menu->get_popup()->set_item_checked(idx, lock_rotation); + } if (p_state.has("use_environment")) { bool env = p_state["use_environment"]; @@ -2923,6 +2947,8 @@ Dictionary SpatialEditorViewport::get_state() const { d["half_res"] = viewport_container->get_stretch_shrink() > 1; if (previewing) d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing); + if (lock_rotation) + d["lock_rotation"] = lock_rotation; return d; } @@ -2951,6 +2977,7 @@ void SpatialEditorViewport::_bind_methods() { void SpatialEditorViewport::reset() { orthogonal = false; + lock_rotation = false; message_time = 0; message = ""; last_message = ""; @@ -3377,6 +3404,8 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_radio_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); view_menu->get_popup()->add_separator(); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_lock_rotation", TTR("Lock View Rotation")), VIEW_LOCK_ROTATION); + view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_normal", TTR("Display Normal")), VIEW_DISPLAY_NORMAL); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index af882f6e05..c89db1867b 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -94,7 +94,8 @@ class SpatialEditorViewport : public Control { VIEW_DISPLAY_NORMAL, VIEW_DISPLAY_WIREFRAME, VIEW_DISPLAY_OVERDRAW, - VIEW_DISPLAY_SHADELESS + VIEW_DISPLAY_SHADELESS, + VIEW_LOCK_ROTATION }; public: @@ -132,6 +133,7 @@ private: Camera *camera; bool transforming; bool orthogonal; + bool lock_rotation; float gizmo_scale; bool freelook_active; |