Skip to content

Commit d2357a1

Browse files
Added secondary light to 3D Advanced Import Settings
Added a second light for the 3D Preview Viewport and UI toggle buttons which resemble the ones in the EditorMaterialPreviewPlugin On branch add_secondary_light_to_3d_resource_importer Changes to be committed: modified: editor/import/scene_import_settings.cpp modified: editor/import/scene_import_settings.h
1 parent a7276f1 commit d2357a1

2 files changed

Lines changed: 73 additions & 5 deletions

File tree

editor/import/scene_import_settings.cpp

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,16 @@ void SceneImportSettings::_scene_tree_selected() {
884884
_select(scene_tree, type, import_id);
885885
}
886886

887+
void SceneImportSettings::_light_button_pressed(Node *p_button) {
888+
if (p_button == light_1_switch) {
889+
light1->set_visible(!light_1_switch->is_pressed());
890+
}
891+
892+
if (p_button == light_2_switch) {
893+
light2->set_visible(!light_2_switch->is_pressed());
894+
}
895+
}
896+
887897
void SceneImportSettings::_viewport_input(const Ref<InputEvent> &p_input) {
888898
float *rot_x = &cam_rot_x;
889899
float *rot_y = &cam_rot_y;
@@ -995,6 +1005,15 @@ void SceneImportSettings::_re_import() {
9951005
EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, editing_animation ? "animation_library" : "scene", main_settings);
9961006
}
9971007

1008+
void SceneImportSettings::_update_theme_item_cache() {
1009+
ConfirmationDialog::_update_theme_item_cache();
1010+
1011+
theme_cache.light_1_on = get_theme_icon(SNAME("MaterialPreviewLight1"), SNAME("EditorIcons"));
1012+
theme_cache.light_1_off = get_theme_icon(SNAME("MaterialPreviewLight1Off"), SNAME("EditorIcons"));
1013+
theme_cache.light_2_on = get_theme_icon(SNAME("MaterialPreviewLight2"), SNAME("EditorIcons"));
1014+
theme_cache.light_2_off = get_theme_icon(SNAME("MaterialPreviewLight2Off"), SNAME("EditorIcons"));
1015+
}
1016+
9981017
void SceneImportSettings::_notification(int p_what) {
9991018
switch (p_what) {
10001019
case NOTIFICATION_READY: {
@@ -1005,6 +1024,11 @@ void SceneImportSettings::_notification(int p_what) {
10051024
action_menu->add_theme_style_override("normal", get_theme_stylebox("normal", "Button"));
10061025
action_menu->add_theme_style_override("hover", get_theme_stylebox("hover", "Button"));
10071026
action_menu->add_theme_style_override("pressed", get_theme_stylebox("pressed", "Button"));
1027+
1028+
light_1_switch->set_texture_normal(theme_cache.light_1_on);
1029+
light_1_switch->set_texture_pressed(theme_cache.light_1_off);
1030+
light_2_switch->set_texture_normal(theme_cache.light_2_on);
1031+
light_2_switch->set_texture_pressed(theme_cache.light_2_off);
10081032
} break;
10091033

10101034
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
@@ -1347,6 +1371,32 @@ SceneImportSettings::SceneImportSettings() {
13471371

13481372
base_viewport->set_use_own_world_3d(true);
13491373

1374+
HBoxContainer *hb = memnew(HBoxContainer);
1375+
vp_container->add_child(hb);
1376+
hb->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);
1377+
1378+
hb->add_spacer();
1379+
1380+
VBoxContainer *vb_toolbar = memnew(VBoxContainer);
1381+
vb_toolbar->set_v_size_flags(Control::SIZE_EXPAND_FILL);
1382+
hb->add_child(vb_toolbar);
1383+
1384+
light_1_switch = memnew(TextureButton);
1385+
light_1_switch->set_toggle_mode(true);
1386+
light_1_switch->set_tooltip_text(TTR("Primary Light"));
1387+
light_1_switch->set_stretch_mode(TextureButton::STRETCH_KEEP_ASPECT_CENTERED);
1388+
light_1_switch->set_custom_minimum_size(Size2(20, 20));
1389+
vb_toolbar->add_child(light_1_switch);
1390+
light_1_switch->connect("pressed", callable_mp(this, &SceneImportSettings::_light_button_pressed).bind(light_1_switch));
1391+
1392+
light_2_switch = memnew(TextureButton);
1393+
light_2_switch->set_toggle_mode(true);
1394+
light_2_switch->set_tooltip_text(TTR("Secondary Light"));
1395+
light_2_switch->set_stretch_mode(TextureButton::STRETCH_KEEP_ASPECT_CENTERED);
1396+
light_2_switch->set_custom_minimum_size(Size2(20, 20));
1397+
vb_toolbar->add_child(light_2_switch);
1398+
light_2_switch->connect("pressed", callable_mp(this, &SceneImportSettings::_light_button_pressed).bind(light_2_switch));
1399+
13501400
camera = memnew(Camera3D);
13511401
base_viewport->add_child(camera);
13521402
camera->make_current();
@@ -1356,10 +1406,15 @@ SceneImportSettings::SceneImportSettings() {
13561406
camera->set_attributes(camera_attributes);
13571407
}
13581408

1359-
light = memnew(DirectionalLight3D);
1360-
light->set_transform(Transform3D().looking_at(Vector3(-1, -2, -0.6), Vector3(0, 1, 0)));
1361-
base_viewport->add_child(light);
1362-
light->set_shadow(true);
1409+
light1 = memnew(DirectionalLight3D);
1410+
light1->set_transform(Transform3D().looking_at(Vector3(-1, -2, -0.6), Vector3(0, 1, 0)));
1411+
base_viewport->add_child(light1);
1412+
light1->set_shadow(true);
1413+
1414+
light2 = memnew(DirectionalLight3D);
1415+
light2->set_transform(Transform3D().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
1416+
base_viewport->add_child(light2);
1417+
light2->set_color(Color(0.7, 0.7, 0.7));
13631418

13641419
{
13651420
Ref<StandardMaterial3D> selection_mat;

editor/import/scene_import_settings.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,18 @@ class SceneImportSettings : public ConfirmationDialog {
7878
bool first_aabb = false;
7979
AABB contents_aabb;
8080

81-
DirectionalLight3D *light = nullptr;
81+
TextureButton *light_1_switch = nullptr;
82+
TextureButton *light_2_switch = nullptr;
83+
84+
struct ThemeCache {
85+
Ref<Texture2D> light_1_on;
86+
Ref<Texture2D> light_1_off;
87+
Ref<Texture2D> light_2_on;
88+
Ref<Texture2D> light_2_off;
89+
} theme_cache;
90+
91+
DirectionalLight3D *light1 = nullptr;
92+
DirectionalLight3D *light2 = nullptr;
8293
Ref<ArrayMesh> selection_mesh;
8394
MeshInstance3D *node_selected = nullptr;
8495

@@ -154,6 +165,7 @@ class SceneImportSettings : public ConfirmationDialog {
154165
void _material_tree_selected();
155166
void _mesh_tree_selected();
156167
void _scene_tree_selected();
168+
void _light_button_pressed(Node *p_button);
157169

158170
void _viewport_input(const Ref<InputEvent> &p_input);
159171

@@ -196,6 +208,7 @@ class SceneImportSettings : public ConfirmationDialog {
196208
Timer *update_view_timer = nullptr;
197209

198210
protected:
211+
virtual void _update_theme_item_cache() override;
199212
void _notification(int p_what);
200213

201214
public:

0 commit comments

Comments
 (0)