Skip to content

Commit

Permalink
Make 3D transforms done inside editor viewport, but w/o grabbing a gi…
Browse files Browse the repository at this point in the history
…zmo handle require pressing alt
  • Loading branch information
ryevdokimov committed Oct 26, 2024
1 parent 61accf0 commit 403edef
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
4 changes: 4 additions & 0 deletions doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@
<member name="editors/2d/zoom_speed_factor" type="float" setter="" getter="">
The factor to use when zooming in or out in the 2D editor. For example, [code]1.1[/code] will zoom in by 10% with every step. If set to [code]2.0[/code], zooming will only cycle through powers of two.
</member>
<member name="editors/3d/alt_gizmo_transform" type="bool" setter="" getter="">
If [code]true[/code], enables selection of nodes with any gizmo mode, even if a node is already selected.
To enable manipulations of nodes outside the gizmo handles [kbd]Alt[/kbd] can be used.
</member>
<member name="editors/3d/default_fov" type="float" setter="" getter="">
The default camera vertical field of view to use in the 3D editor (in degrees). The camera field of view can be adjusted on a per-scene basis using the [b]View[/b] menu at the top of the 3D editor. If a scene had its camera field of view adjusted using the [b]View[/b] menu, this setting is ignored in the scene in question. This setting is also ignored while a [Camera3D] node is being previewed in the editor.
[b]Note:[/b] The editor camera always uses the [b]Keep Height[/b] aspect mode.
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/manipulator_gizmo_size", 80, "16,160,1");
EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/manipulator_gizmo_opacity", 0.9, "0,1,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)

// 3D: Selection
_initial_set("editors/3d/alt_gizmo_transform", false);

// 2D
_initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07), true);
_initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8), true);
Expand Down
49 changes: 26 additions & 23 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,24 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {

bool node_selected = get_selected_count() > 0;

if (after != EditorPlugin::AFTER_GUI_INPUT_CUSTOM && (!b->is_alt_pressed() && (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || !node_selected || EDITOR_GET("editors/3d/alt_gizmo_transform")))) {
// Single item selection.
clicked = _select_ray(b->get_position());

if (clicked.is_valid() && !editor_selection->is_selected(Object::cast_to<Node>(ObjectDB::get_instance(clicked)))) {
selection_in_progress = true;
break;
}

if (clicked.is_null()) {
// Default to region select.
cursor.region_select = true;
cursor.region_begin = b->get_position();
cursor.region_end = b->get_position();
break;
}
}

if (node_selected && ((spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT && b->is_command_or_control_pressed()) || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE)) {
begin_transform(TRANSFORM_ROTATE, false);
break;
Expand All @@ -1935,20 +1953,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
break;
}

if (after != EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
// Single item selection.
clicked = _select_ray(b->get_position());

selection_in_progress = true;

if (clicked.is_null()) {
// Default to region select.
cursor.region_select = true;
cursor.region_begin = b->get_position();
cursor.region_end = b->get_position();
}
}

surface->queue_redraw();
} else {
if (_edit.gizmo.is_valid()) {
Expand Down Expand Up @@ -1995,7 +1999,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
set_message("");
spatial_editor->update_transform_gizmo();
}
surface->queue_redraw();
}

} break;
Expand Down Expand Up @@ -2081,12 +2084,10 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
} else {
const bool movement_threshold_passed = _edit.original_mouse_pos.distance_to(_edit.mouse_pos) > 8 * EDSCALE;

if (selection_in_progress && movement_threshold_passed && clicked.is_valid()) {
if (clicked_wants_append || !editor_selection->is_selected(Object::cast_to<Node>(ObjectDB::get_instance(clicked)))) {
cursor.region_select = true;
cursor.region_begin = _edit.original_mouse_pos;
clicked = ObjectID();
}
if ((selection_in_progress || clicked_wants_append) && movement_threshold_passed && clicked.is_valid()) {
cursor.region_select = true;
cursor.region_begin = _edit.original_mouse_pos;
clicked = ObjectID();
}

if (cursor.region_select) {
Expand All @@ -2095,7 +2096,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
return;
}

if (clicked.is_valid() && movement_threshold_passed) {
if (clicked.is_valid() && movement_threshold_passed && (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE)) {
_compute_edit(_edit.original_mouse_pos);
clicked = ObjectID();
_edit.mode = TRANSFORM_TRANSLATE;
Expand All @@ -2105,7 +2106,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
return;
}

update_transform(_get_key_modifier(m) == Key::SHIFT);
if (!selection_in_progress) {
update_transform(_get_key_modifier(m) == Key::SHIFT);
}
}
} else if (m->get_button_mask().has_flag(MouseButtonMask::RIGHT) || freelook_active) {
NavigationMode change_nav_from_shortcut = _get_nav_mode_from_shortcut_check(NAVIGATION_RIGHT_MOUSE, shortcut_check_sets, false);
Expand Down

0 comments on commit 403edef

Please sign in to comment.