Make 3D snapping finer when holding Shift

This also changes the default rotation and scale snapping increments
to better make use of fine snapping possibilities.
This commit is contained in:
Hugo Locurcio 2019-04-09 17:55:44 +02:00
parent 5772f60f96
commit 156faf535c
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
2 changed files with 38 additions and 5 deletions

View File

@ -5598,11 +5598,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
snap_dialog_vbc->add_margin_child(TTR("Translate Snap:"), snap_translate); snap_dialog_vbc->add_margin_child(TTR("Translate Snap:"), snap_translate);
snap_rotate = memnew(LineEdit); snap_rotate = memnew(LineEdit);
snap_rotate->set_text("5"); snap_rotate->set_text("15");
snap_dialog_vbc->add_margin_child(TTR("Rotate Snap (deg.):"), snap_rotate); snap_dialog_vbc->add_margin_child(TTR("Rotate Snap (deg.):"), snap_rotate);
snap_scale = memnew(LineEdit); snap_scale = memnew(LineEdit);
snap_scale->set_text("5"); snap_scale->set_text("10");
snap_dialog_vbc->add_margin_child(TTR("Scale Snap (%):"), snap_scale); snap_dialog_vbc->add_margin_child(TTR("Scale Snap (%):"), snap_scale);
/* SETTINGS DIALOG */ /* SETTINGS DIALOG */
@ -5760,6 +5760,39 @@ Vector3 SpatialEditor::snap_point(Vector3 p_target, Vector3 p_start) const {
return p_target; return p_target;
} }
float SpatialEditor::get_translate_snap() const {
float snap_value;
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
snap_value = snap_translate->get_text().to_double() / 10.0;
} else {
snap_value = snap_translate->get_text().to_double();
}
return snap_value;
}
float SpatialEditor::get_rotate_snap() const {
float snap_value;
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
snap_value = snap_rotate->get_text().to_double() / 3.0;
} else {
snap_value = snap_rotate->get_text().to_double();
}
return snap_value;
}
float SpatialEditor::get_scale_snap() const {
float snap_value;
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
snap_value = snap_scale->get_text().to_double() / 2.0;
} else {
snap_value = snap_scale->get_text().to_double();
}
return snap_value;
}
void SpatialEditorPlugin::_bind_methods() { void SpatialEditorPlugin::_bind_methods() {
ClassDB::bind_method("snap_cursor_to_plane", &SpatialEditorPlugin::snap_cursor_to_plane); ClassDB::bind_method("snap_cursor_to_plane", &SpatialEditorPlugin::snap_cursor_to_plane);

View File

@ -673,9 +673,9 @@ public:
ToolMode get_tool_mode() const { return tool_mode; } ToolMode get_tool_mode() const { return tool_mode; }
bool are_local_coords_enabled() const { return tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->is_pressed(); } bool are_local_coords_enabled() const { return tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->is_pressed(); }
bool is_snap_enabled() const { return snap_enabled ^ snap_key_enabled; } bool is_snap_enabled() const { return snap_enabled ^ snap_key_enabled; }
float get_translate_snap() const { return snap_translate->get_text().to_double(); } float get_translate_snap() const;
float get_rotate_snap() const { return snap_rotate->get_text().to_double(); } float get_rotate_snap() const;
float get_scale_snap() const { return snap_scale->get_text().to_double(); } float get_scale_snap() const;
Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; } Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; }
Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; } Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; }