Add ability to Hide Editor Transform Gizmo

This commit is contained in:
Robert Yevdokimov 2024-01-31 13:44:20 -05:00
parent cae2f853dc
commit c9e9bd4a68
2 changed files with 17 additions and 2 deletions

View File

@ -1809,7 +1809,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
{ {
int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS);
int idx2 = view_menu->get_popup()->get_item_index(VIEW_TRANSFORM_GIZMO);
can_select_gizmos = can_select_gizmos && view_menu->get_popup()->is_item_checked(idx); can_select_gizmos = can_select_gizmos && view_menu->get_popup()->is_item_checked(idx);
transform_gizmo_visible = view_menu->get_popup()->is_item_checked(idx2);
} }
// Gizmo handles // Gizmo handles
@ -3526,6 +3528,15 @@ void Node3DEditorViewport::_menu_option(int p_option) {
view_menu->get_popup()->set_item_checked(idx, current); view_menu->get_popup()->set_item_checked(idx, current);
} break; } break;
case VIEW_TRANSFORM_GIZMO: {
int idx = view_menu->get_popup()->get_item_index(VIEW_TRANSFORM_GIZMO);
bool current = view_menu->get_popup()->is_item_checked(idx);
current = !current;
transform_gizmo_visible = current;
spatial_editor->update_transform_gizmo();
view_menu->get_popup()->set_item_checked(idx, current);
} break;
case VIEW_HALF_RESOLUTION: { case VIEW_HALF_RESOLUTION: {
int idx = view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION); int idx = view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION);
bool current = view_menu->get_popup()->is_item_checked(idx); bool current = view_menu->get_popup()->is_item_checked(idx);
@ -3890,7 +3901,7 @@ void Node3DEditorViewport::update_transform_gizmo_view() {
return; return;
} }
bool show_gizmo = spatial_editor->is_gizmo_visible() && !_edit.instant; bool show_gizmo = spatial_editor->is_gizmo_visible() && !_edit.instant && transform_gizmo_visible;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Transform3D axis_angle; Transform3D axis_angle;
if (xform.basis.get_column(i).normalized().dot(xform.basis.get_column((i + 1) % 3).normalized()) < 1.0) { if (xform.basis.get_column(i).normalized().dot(xform.basis.get_column((i + 1) % 3).normalized()) < 1.0) {
@ -3921,7 +3932,7 @@ void Node3DEditorViewport::update_transform_gizmo_view() {
xform.orthonormalize(); xform.orthonormalize();
xform.basis.scale(scale); xform.basis.scale(scale);
RenderingServer::get_singleton()->instance_set_transform(rotate_gizmo_instance[3], xform); RenderingServer::get_singleton()->instance_set_transform(rotate_gizmo_instance[3], xform);
RenderingServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[3], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE)); RenderingServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[3], spatial_editor->is_gizmo_visible() && transform_gizmo_visible && (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE));
} }
void Node3DEditorViewport::set_state(const Dictionary &p_state) { void Node3DEditorViewport::set_state(const Dictionary &p_state) {
@ -5298,6 +5309,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_separator();
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_transform_gizmo", TTR("View Transform Gizmo")), VIEW_TRANSFORM_GIZMO);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid_lines", TTR("View Grid")), VIEW_GRID); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid_lines", TTR("View Grid")), VIEW_GRID);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_fps", TTR("View Frame Time")), VIEW_FRAME_TIME); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_fps", TTR("View Frame Time")), VIEW_FRAME_TIME);
@ -5308,6 +5320,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Enable Doppler")), VIEW_AUDIO_DOPPLER); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Enable Doppler")), VIEW_AUDIO_DOPPLER);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_TRANSFORM_GIZMO), true);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GRID), true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GRID), true);
view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_separator();

View File

@ -124,6 +124,7 @@ class Node3DEditorViewport : public Control {
VIEW_AUDIO_LISTENER, VIEW_AUDIO_LISTENER,
VIEW_AUDIO_DOPPLER, VIEW_AUDIO_DOPPLER,
VIEW_GIZMOS, VIEW_GIZMOS,
VIEW_TRANSFORM_GIZMO,
VIEW_GRID, VIEW_GRID,
VIEW_INFORMATION, VIEW_INFORMATION,
VIEW_FRAME_TIME, VIEW_FRAME_TIME,
@ -235,6 +236,7 @@ private:
bool orthogonal; bool orthogonal;
bool auto_orthogonal; bool auto_orthogonal;
bool lock_rotation; bool lock_rotation;
bool transform_gizmo_visible = true;
real_t gizmo_scale; real_t gizmo_scale;
bool freelook_active; bool freelook_active;