Skip to content

Commit 3c03566

Browse files
committed
Merge pull request #102281 from ryevdokimov/selection-box-color-no-restart
Do not require editor restart when changing selection box color
2 parents ea892d9 + 8a6804b commit 3c03566

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-29
lines changed

editor/editor_settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
789789
EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
790790

791791
// Use a similar color to the 2D editor selection.
792-
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/selection_box_color", Color(1.0, 0.5, 0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
793-
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/active_selection_box_color", Color(1.5, 0.75, 0, 1.0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
792+
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/selection_box_color", Color(1.0, 0.5, 0), "", PROPERTY_USAGE_DEFAULT)
793+
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/active_selection_box_color", Color(1.5, 0.75, 0, 1.0), "", PROPERTY_USAGE_DEFAULT)
794794
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
795795
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
796796
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/aabb", Color(0.28, 0.8, 0.82), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)

editor/plugins/node_3d_editor_plugin.cpp

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6426,38 +6426,34 @@ void Node3DEditor::_generate_selection_boxes() {
64266426
const Color selection_box_color = EDITOR_GET("editors/3d/selection_box_color");
64276427
const Color active_selection_box_color = EDITOR_GET("editors/3d/active_selection_box_color");
64286428

6429-
Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
6430-
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6431-
mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6432-
mat->set_albedo(selection_box_color);
6433-
mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6434-
st->set_material(mat);
6429+
selection_box_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6430+
selection_box_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6431+
selection_box_mat->set_albedo(selection_box_color);
6432+
selection_box_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6433+
st->set_material(selection_box_mat);
64356434
selection_box = st->commit();
64366435

6437-
Ref<StandardMaterial3D> mat_xray = memnew(StandardMaterial3D);
6438-
mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6439-
mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6440-
mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6441-
mat_xray->set_albedo(selection_box_color * Color(1, 1, 1, 0.15));
6442-
mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6443-
st_xray->set_material(mat_xray);
6436+
selection_box_mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6437+
selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6438+
selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6439+
selection_box_mat_xray->set_albedo(selection_box_color * Color(1, 1, 1, 0.15));
6440+
selection_box_mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6441+
st_xray->set_material(selection_box_mat_xray);
64446442
selection_box_xray = st_xray->commit();
64456443

6446-
Ref<StandardMaterial3D> active_mat = memnew(StandardMaterial3D);
6447-
active_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6448-
active_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6449-
active_mat->set_albedo(active_selection_box_color);
6450-
active_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6451-
active_st->set_material(active_mat);
6444+
active_selection_box_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6445+
active_selection_box_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6446+
active_selection_box_mat->set_albedo(active_selection_box_color);
6447+
active_selection_box_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6448+
active_st->set_material(active_selection_box_mat);
64526449
active_selection_box = active_st->commit();
64536450

6454-
Ref<StandardMaterial3D> active_mat_xray = memnew(StandardMaterial3D);
6455-
active_mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6456-
active_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6457-
active_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6458-
active_mat_xray->set_albedo(active_selection_box_color * Color(1, 1, 1, 0.15));
6459-
active_mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6460-
active_st_xray->set_material(active_mat_xray);
6451+
active_selection_box_mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6452+
active_selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6453+
active_selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6454+
active_selection_box_mat_xray->set_albedo(active_selection_box_color * Color(1, 1, 1, 0.15));
6455+
active_selection_box_mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6456+
active_st_xray->set_material(active_selection_box_mat_xray);
64616457
active_selection_box_xray = active_st_xray->commit();
64626458
}
64636459

@@ -8313,8 +8309,21 @@ void Node3DEditor::_notification(int p_what) {
83138309
} break;
83148310

83158311
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
8316-
// Update grid color by rebuilding grid.
83178312
if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d")) {
8313+
const Color selection_box_color = EDITOR_GET("editors/3d/selection_box_color");
8314+
const Color active_selection_box_color = EDITOR_GET("editors/3d/active_selection_box_color");
8315+
8316+
if (selection_box_color != selection_box_mat->get_albedo()) {
8317+
selection_box_mat->set_albedo(selection_box_color);
8318+
selection_box_mat_xray->set_albedo(selection_box_color * Color(1, 1, 1, 0.15));
8319+
}
8320+
8321+
if (active_selection_box_color != active_selection_box_mat->get_albedo()) {
8322+
active_selection_box_mat->set_albedo(active_selection_box_color);
8323+
active_selection_box_mat_xray->set_albedo(active_selection_box_color * Color(1, 1, 1, 0.15));
8324+
}
8325+
8326+
// Update grid color by rebuilding grid.
83188327
_finish_grid();
83198328
_init_grid();
83208329
}

editor/plugins/node_3d_editor_plugin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,11 @@ class Node3DEditor : public VBoxContainer {
706706
Ref<ArrayMesh> selection_box_xray;
707707
Ref<ArrayMesh> selection_box;
708708

709+
Ref<StandardMaterial3D> selection_box_mat = memnew(StandardMaterial3D);
710+
Ref<StandardMaterial3D> selection_box_mat_xray = memnew(StandardMaterial3D);
711+
Ref<StandardMaterial3D> active_selection_box_mat = memnew(StandardMaterial3D);
712+
Ref<StandardMaterial3D> active_selection_box_mat_xray = memnew(StandardMaterial3D);
713+
709714
RID indicators;
710715
RID indicators_instance;
711716
RID cursor_mesh;

0 commit comments

Comments
 (0)