Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix origin being included in per viewport grid visibility toggle, and add ability to hide it seperately #100435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"];

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion editor/plugins/node_3d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};
Expand Down
Loading