Skip to content

Commit cea8ae8

Browse files
committed
Use R/F keys for local up/down and Space/Ctrl for global up/down
1 parent 9cd297b commit cea8ae8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

editor/scene/3d/node_3d_editor_plugin.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void ViewportNavigationControl::_update_navigation() {
240240

241241
Vector3 forward;
242242
if (navigation_scheme == Node3DEditorViewport::FreelookNavigationScheme::FREELOOK_FULLY_AXIS_LOCKED) {
243-
// Forward/backward keys will always go straight forward/backward, never moving on the Y axis.
243+
// Forward/backward keys will always go horizontally forward/backward, never moving on the Y axis.
244244
forward = Vector3(0, 0, delta_normalized.y).rotated(Vector3(0, 1, 0), viewport->camera->get_rotation().y);
245245
} else {
246246
// Forward/backward keys will be relative to the camera pitch.
@@ -2999,18 +2999,19 @@ void Node3DEditorViewport::_update_freelook(real_t delta) {
29992999
forward = Vector3(0, 0, -1).rotated(Vector3(0, 1, 0), camera->get_rotation().y);
30003000
} else {
30013001
// Forward/backward keys will be relative to the camera pitch.
3002-
forward = camera->get_transform().basis.xform(Vector3(0, 0, -1));
3002+
forward = -camera->get_transform().basis.get_column(2);
30033003
}
30043004

3005-
const Vector3 right = camera->get_transform().basis.xform(Vector3(1, 0, 0));
3005+
const Vector3 right = camera->get_transform().basis.get_column(0);
30063006

3007+
Vector3 local_up = camera->get_transform().basis.get_column(1);
30073008
Vector3 up;
30083009
if (navigation_scheme == FREELOOK_PARTIALLY_AXIS_LOCKED || navigation_scheme == FREELOOK_FULLY_AXIS_LOCKED) {
30093010
// Up/down keys will always go up/down regardless of camera pitch.
30103011
up = Vector3(0, 1, 0);
30113012
} else {
30123013
// Up/down keys will be relative to the camera pitch.
3013-
up = camera->get_transform().basis.xform(Vector3(0, 1, 0));
3014+
up = local_up;
30143015
}
30153016

30163017
Vector3 direction;
@@ -3036,6 +3037,18 @@ void Node3DEditorViewport::_update_freelook(real_t delta) {
30363037
if (inp->is_action_pressed("spatial_editor/freelook_down")) {
30373038
direction -= up;
30383039
}
3040+
if (inp->is_action_pressed("spatial_editor/freelook_global_up")) {
3041+
direction += Vector3(0, 1, 0);
3042+
}
3043+
if (inp->is_action_pressed("spatial_editor/freelook_global_down")) {
3044+
direction -= Vector3(0, 1, 0);
3045+
}
3046+
if (inp->is_action_pressed("spatial_editor/freelook_local_up")) {
3047+
direction += local_up;
3048+
}
3049+
if (inp->is_action_pressed("spatial_editor/freelook_local_down")) {
3050+
direction -= local_up;
3051+
}
30393052

30403053
real_t speed = freelook_speed;
30413054

@@ -5937,6 +5950,12 @@ void Node3DEditorViewport::register_shortcut_action(const String &p_path, const
59375950
sc->connect_changed(callable_mp(this, &Node3DEditorViewport::shortcut_changed_callback).bind(sc, p_path));
59385951
}
59395952

5953+
void Node3DEditorViewport::register_shortcuts_action(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical) {
5954+
Ref<Shortcut> sc = ED_SHORTCUT_ARRAY(p_path, p_name, p_keycodes, p_physical);
5955+
shortcut_changed_callback(sc, p_path);
5956+
sc->connect_changed(callable_mp(this, &Node3DEditorViewport::shortcut_changed_callback).bind(sc, p_path));
5957+
}
5958+
59405959
// Update the action in the InputMap to the provided shortcut events.
59415960
void Node3DEditorViewport::shortcut_changed_callback(const Ref<Shortcut> p_shortcut, const String &p_shortcut_path) {
59425961
InputMap *im = InputMap::get_singleton();
@@ -6156,6 +6175,10 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
61566175
register_shortcut_action("spatial_editor/freelook_backwards", TTRC("Freelook Backwards"), Key::S, true);
61576176
register_shortcut_action("spatial_editor/freelook_up", TTRC("Freelook Up"), Key::E, true);
61586177
register_shortcut_action("spatial_editor/freelook_down", TTRC("Freelook Down"), Key::Q, true);
6178+
register_shortcut_action("spatial_editor/freelook_global_up", TTRC("Freelook Global Up"), Key::SPACE, true);
6179+
register_shortcuts_action("spatial_editor/freelook_global_down", TTRC("Freelook Global Down"), { int32_t(Key::CTRL), int32_t(Key::META) }, true);
6180+
register_shortcut_action("spatial_editor/freelook_local_up", TTRC("Freelook Local Up"), Key::R, true);
6181+
register_shortcut_action("spatial_editor/freelook_local_down", TTRC("Freelook Local Down"), Key::F, true);
61596182
register_shortcut_action("spatial_editor/freelook_speed_modifier", TTRC("Freelook Speed Modifier"), Key::SHIFT);
61606183
register_shortcut_action("spatial_editor/freelook_slow_modifier", TTRC("Freelook Slow Modifier"), Key::ALT);
61616184

editor/scene/3d/node_3d_editor_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ class Node3DEditorViewport : public Control {
542542
void finish_transform();
543543

544544
void register_shortcut_action(const String &p_path, const String &p_name, Key p_keycode, bool p_physical = false);
545+
void register_shortcuts_action(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical = false);
545546
void shortcut_changed_callback(const Ref<Shortcut> p_shortcut, const String &p_shortcut_path);
546547

547548
// Supported rendering methods for advanced debug draw mode items.

0 commit comments

Comments
 (0)