Skip to content

Commit 8a6804b

Browse files
committed
Do not require editor restart when changing selection box color
1 parent 7893202 commit 8a6804b

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
@@ -788,8 +788,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
788788
EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
789789

790790
// Use a similar color to the 2D editor selection.
791-
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)
792-
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)
791+
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/selection_box_color", Color(1.0, 0.5, 0), "", PROPERTY_USAGE_DEFAULT)
792+
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)
793793
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)
794794
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)
795795
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
@@ -6395,38 +6395,34 @@ void Node3DEditor::_generate_selection_boxes() {
63956395
const Color selection_box_color = EDITOR_GET("editors/3d/selection_box_color");
63966396
const Color active_selection_box_color = EDITOR_GET("editors/3d/active_selection_box_color");
63976397

6398-
Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
6399-
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6400-
mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6401-
mat->set_albedo(selection_box_color);
6402-
mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6403-
st->set_material(mat);
6398+
selection_box_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6399+
selection_box_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6400+
selection_box_mat->set_albedo(selection_box_color);
6401+
selection_box_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6402+
st->set_material(selection_box_mat);
64046403
selection_box = st->commit();
64056404

6406-
Ref<StandardMaterial3D> mat_xray = memnew(StandardMaterial3D);
6407-
mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6408-
mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6409-
mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6410-
mat_xray->set_albedo(selection_box_color * Color(1, 1, 1, 0.15));
6411-
mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6412-
st_xray->set_material(mat_xray);
6405+
selection_box_mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6406+
selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6407+
selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6408+
selection_box_mat_xray->set_albedo(selection_box_color * Color(1, 1, 1, 0.15));
6409+
selection_box_mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6410+
st_xray->set_material(selection_box_mat_xray);
64136411
selection_box_xray = st_xray->commit();
64146412

6415-
Ref<StandardMaterial3D> active_mat = memnew(StandardMaterial3D);
6416-
active_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6417-
active_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6418-
active_mat->set_albedo(active_selection_box_color);
6419-
active_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6420-
active_st->set_material(active_mat);
6413+
active_selection_box_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6414+
active_selection_box_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6415+
active_selection_box_mat->set_albedo(active_selection_box_color);
6416+
active_selection_box_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6417+
active_st->set_material(active_selection_box_mat);
64216418
active_selection_box = active_st->commit();
64226419

6423-
Ref<StandardMaterial3D> active_mat_xray = memnew(StandardMaterial3D);
6424-
active_mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6425-
active_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6426-
active_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6427-
active_mat_xray->set_albedo(active_selection_box_color * Color(1, 1, 1, 0.15));
6428-
active_mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6429-
active_st_xray->set_material(active_mat_xray);
6420+
active_selection_box_mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6421+
active_selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6422+
active_selection_box_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6423+
active_selection_box_mat_xray->set_albedo(active_selection_box_color * Color(1, 1, 1, 0.15));
6424+
active_selection_box_mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6425+
active_st_xray->set_material(active_selection_box_mat_xray);
64306426
active_selection_box_xray = active_st_xray->commit();
64316427
}
64326428

@@ -8282,8 +8278,21 @@ void Node3DEditor::_notification(int p_what) {
82828278
} break;
82838279

82848280
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
8285-
// Update grid color by rebuilding grid.
82868281
if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d")) {
8282+
const Color selection_box_color = EDITOR_GET("editors/3d/selection_box_color");
8283+
const Color active_selection_box_color = EDITOR_GET("editors/3d/active_selection_box_color");
8284+
8285+
if (selection_box_color != selection_box_mat->get_albedo()) {
8286+
selection_box_mat->set_albedo(selection_box_color);
8287+
selection_box_mat_xray->set_albedo(selection_box_color * Color(1, 1, 1, 0.15));
8288+
}
8289+
8290+
if (active_selection_box_color != active_selection_box_mat->get_albedo()) {
8291+
active_selection_box_mat->set_albedo(active_selection_box_color);
8292+
active_selection_box_mat_xray->set_albedo(active_selection_box_color * Color(1, 1, 1, 0.15));
8293+
}
8294+
8295+
// Update grid color by rebuilding grid.
82878296
_finish_grid();
82888297
_init_grid();
82898298
}

editor/plugins/node_3d_editor_plugin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ class Node3DEditor : public VBoxContainer {
698698
Ref<ArrayMesh> selection_box_xray;
699699
Ref<ArrayMesh> selection_box;
700700

701+
Ref<StandardMaterial3D> selection_box_mat = memnew(StandardMaterial3D);
702+
Ref<StandardMaterial3D> selection_box_mat_xray = memnew(StandardMaterial3D);
703+
Ref<StandardMaterial3D> active_selection_box_mat = memnew(StandardMaterial3D);
704+
Ref<StandardMaterial3D> active_selection_box_mat_xray = memnew(StandardMaterial3D);
705+
701706
RID indicators;
702707
RID indicators_instance;
703708
RID cursor_mesh;

0 commit comments

Comments
 (0)