diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 6f5f304159d7..c745dde3de19 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -3739,6 +3739,18 @@ void Node3DEditorViewport::_menu_option(int p_option) { bool current = view_menu->get_popup()->is_item_checked(idx); view_menu->get_popup()->set_item_checked(idx, !current); } break; + case VIEW_ORIGIN: { + int idx = view_menu->get_popup()->get_item_index(VIEW_ORIGIN); + bool current = view_menu->get_popup()->is_item_checked(idx); + current = !current; + uint32_t layers = camera->get_cull_mask(); + layers &= ~(1 << GIZMO_ORIGIN_LAYER); + if (current) { + layers |= (1 << GIZMO_ORIGIN_LAYER); + } + camera->set_cull_mask(layers); + view_menu->get_popup()->set_item_checked(idx, current); + } break; case VIEW_GRID: { int idx = view_menu->get_popup()->get_item_index(VIEW_GRID); bool current = view_menu->get_popup()->is_item_checked(idx); @@ -4202,6 +4214,14 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { _menu_option(VIEW_TRANSFORM_GIZMO); } } + if (p_state.has("origin")) { + bool origin = p_state["origin"]; + + int idx = view_menu->get_popup()->get_item_index(VIEW_ORIGIN); + if (view_menu->get_popup()->is_item_checked(idx) != origin) { + _menu_option(VIEW_ORIGIN); + } + } if (p_state.has("grid")) { bool grid = p_state["grid"]; @@ -4289,6 +4309,7 @@ Dictionary Node3DEditorViewport::get_state() const { d["doppler"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUDIO_DOPPLER)); d["gizmos"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS)); d["transform_gizmo"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_TRANSFORM_GIZMO)); + d["origin"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORIGIN)); d["grid"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_GRID)); d["information"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); d["frame_time"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME)); @@ -5503,7 +5524,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p surface->set_clip_contents(true); camera = memnew(Camera3D); camera->set_disable_gizmos(true); - camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + p_index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER) | (1 << MISC_TOOL_LAYER)); + camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + p_index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER) | (1 << GIZMO_ORIGIN_LAYER) | (1 << MISC_TOOL_LAYER)); viewport->add_child(camera); camera->make_current(); surface->set_focus_mode(FOCUS_ALL); @@ -5585,6 +5606,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p 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_transform_gizmo", TTR("View Transform Gizmo")), VIEW_TRANSFORM_GIZMO); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin_lines", TTR("View Origin")), VIEW_ORIGIN); 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_fps", TTR("View Frame Time")), VIEW_FRAME_TIME); @@ -5596,6 +5618,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p 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_TRANSFORM_GIZMO), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORIGIN), true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GRID), true); view_menu->get_popup()->add_separator(); @@ -7114,7 +7137,7 @@ void fragment() { } origin_instance = RenderingServer::get_singleton()->instance_create2(origin_multimesh, get_tree()->get_root()->get_world_3d()->get_scenario()); - RS::get_singleton()->instance_set_layer_mask(origin_instance, 1 << Node3DEditorViewport::GIZMO_GRID_LAYER); + RS::get_singleton()->instance_set_layer_mask(origin_instance, 1 << Node3DEditorViewport::GIZMO_ORIGIN_LAYER); RS::get_singleton()->instance_geometry_set_flag(origin_instance, RS::INSTANCE_FLAG_IGNORE_OCCLUSION_CULLING, true); RS::get_singleton()->instance_geometry_set_flag(origin_instance, RS::INSTANCE_FLAG_USE_BAKED_LIGHT, false); diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index dd89511d2939..d5d363baad34 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -128,6 +128,7 @@ class Node3DEditorViewport : public Control { VIEW_AUDIO_DOPPLER, VIEW_GIZMOS, VIEW_TRANSFORM_GIZMO, + VIEW_ORIGIN, VIEW_GRID, VIEW_INFORMATION, VIEW_FRAME_TIME, @@ -186,7 +187,8 @@ class Node3DEditorViewport : public Control { GIZMO_BASE_LAYER = 27, GIZMO_EDIT_LAYER = 26, GIZMO_GRID_LAYER = 25, - MISC_TOOL_LAYER = 24, + GIZMO_ORIGIN_LAYER = 24, + MISC_TOOL_LAYER = 23, FRAME_TIME_HISTORY = 20, };