Skip to content

Commit 9fe01e0

Browse files
committed
Merge pull request godotengine#76140 from jeronimo-schreyer/add_secondary_light_to_3d_resource_importer
Added secondary light to 3D Advanced Import Settings
2 parents 4cca5b4 + acc408b commit 9fe01e0

5 files changed

Lines changed: 95 additions & 5 deletions

File tree

editor/icons/PreviewRotate.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/import/3d/scene_import_settings.cpp

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,20 @@ void SceneImportSettingsDialog::_cleanup() {
11171117
set_process(false);
11181118
}
11191119

1120+
void SceneImportSettingsDialog::_on_light_1_switch_pressed() {
1121+
light1->set_visible(light_1_switch->is_pressed());
1122+
}
1123+
1124+
void SceneImportSettingsDialog::_on_light_2_switch_pressed() {
1125+
light2->set_visible(light_2_switch->is_pressed());
1126+
}
1127+
1128+
void SceneImportSettingsDialog::_on_light_rotate_switch_pressed() {
1129+
bool light_top_level = !light_rotate_switch->is_pressed();
1130+
light1->set_as_top_level_keep_local(light_top_level);
1131+
light2->set_as_top_level_keep_local(light_top_level);
1132+
}
1133+
11201134
void SceneImportSettingsDialog::_viewport_input(const Ref<InputEvent> &p_input) {
11211135
float *rot_x = &cam_rot_x;
11221136
float *rot_y = &cam_rot_y;
@@ -1232,6 +1246,13 @@ void SceneImportSettingsDialog::_re_import() {
12321246
EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, editing_animation ? "animation_library" : "scene", main_settings);
12331247
}
12341248

1249+
void SceneImportSettingsDialog::_update_theme_item_cache() {
1250+
ConfirmationDialog::_update_theme_item_cache();
1251+
theme_cache.light_1_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight1"));
1252+
theme_cache.light_2_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight2"));
1253+
theme_cache.rotate_icon = get_editor_theme_icon(SNAME("PreviewRotate"));
1254+
}
1255+
12351256
void SceneImportSettingsDialog::_notification(int p_what) {
12361257
switch (p_what) {
12371258
case NOTIFICATION_READY: {
@@ -1251,6 +1272,10 @@ void SceneImportSettingsDialog::_notification(int p_what) {
12511272
animation_play_button->set_icon(get_editor_theme_icon(SNAME("MainPlay")));
12521273
}
12531274
animation_stop_button->set_icon(get_editor_theme_icon(SNAME("Stop")));
1275+
1276+
light_1_switch->set_icon(theme_cache.light_1_icon);
1277+
light_2_switch->set_icon(theme_cache.light_2_icon);
1278+
light_rotate_switch->set_icon(theme_cache.rotate_icon);
12541279
} break;
12551280

12561281
case NOTIFICATION_PROCESS: {
@@ -1644,6 +1669,40 @@ SceneImportSettingsDialog::SceneImportSettingsDialog() {
16441669

16451670
base_viewport->set_use_own_world_3d(true);
16461671

1672+
HBoxContainer *viewport_hbox = memnew(HBoxContainer);
1673+
vp_container->add_child(viewport_hbox);
1674+
viewport_hbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);
1675+
1676+
viewport_hbox->add_spacer();
1677+
1678+
VBoxContainer *vb_light = memnew(VBoxContainer);
1679+
vb_light->set_v_size_flags(Control::SIZE_EXPAND_FILL);
1680+
viewport_hbox->add_child(vb_light);
1681+
1682+
light_rotate_switch = memnew(Button);
1683+
light_rotate_switch->set_theme_type_variation("PreviewLightButton");
1684+
light_rotate_switch->set_toggle_mode(true);
1685+
light_rotate_switch->set_pressed(true);
1686+
light_rotate_switch->set_tooltip_text(TTR("Rotate Lights With Model"));
1687+
light_rotate_switch->connect("pressed", callable_mp(this, &SceneImportSettingsDialog::_on_light_rotate_switch_pressed));
1688+
vb_light->add_child(light_rotate_switch);
1689+
1690+
light_1_switch = memnew(Button);
1691+
light_1_switch->set_theme_type_variation("PreviewLightButton");
1692+
light_1_switch->set_toggle_mode(true);
1693+
light_1_switch->set_pressed(true);
1694+
light_1_switch->set_tooltip_text(TTR("Primary Light"));
1695+
light_1_switch->connect("pressed", callable_mp(this, &SceneImportSettingsDialog::_on_light_1_switch_pressed));
1696+
vb_light->add_child(light_1_switch);
1697+
1698+
light_2_switch = memnew(Button);
1699+
light_2_switch->set_theme_type_variation("PreviewLightButton");
1700+
light_2_switch->set_toggle_mode(true);
1701+
light_2_switch->set_pressed(true);
1702+
light_2_switch->set_tooltip_text(TTR("Secondary Light"));
1703+
light_2_switch->connect("pressed", callable_mp(this, &SceneImportSettingsDialog::_on_light_2_switch_pressed));
1704+
vb_light->add_child(light_2_switch);
1705+
16471706
camera = memnew(Camera3D);
16481707
base_viewport->add_child(camera);
16491708
camera->make_current();
@@ -1675,10 +1734,15 @@ SceneImportSettingsDialog::SceneImportSettingsDialog() {
16751734
environment->set_sky_custom_fov(50.0);
16761735
camera->set_environment(environment);
16771736

1678-
light = memnew(DirectionalLight3D);
1679-
light->set_transform(Transform3D().looking_at(Vector3(-1, -2, -0.6), Vector3(0, 1, 0)));
1680-
base_viewport->add_child(light);
1681-
light->set_shadow(true);
1737+
light1 = memnew(DirectionalLight3D);
1738+
light1->set_transform(Transform3D(Basis::looking_at(Vector3(-1, -1, -1))));
1739+
light1->set_shadow(true);
1740+
camera->add_child(light1);
1741+
1742+
light2 = memnew(DirectionalLight3D);
1743+
light2->set_transform(Transform3D(Basis::looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))));
1744+
light2->set_color(Color(0.5f, 0.5f, 0.5f));
1745+
camera->add_child(light2);
16821746

16831747
{
16841748
Ref<StandardMaterial3D> selection_mat;

editor/import/3d/scene_import_settings.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,18 @@ class SceneImportSettingsDialog : public ConfirmationDialog {
8585
bool first_aabb = false;
8686
AABB contents_aabb;
8787

88-
DirectionalLight3D *light = nullptr;
88+
Button *light_1_switch = nullptr;
89+
Button *light_2_switch = nullptr;
90+
Button *light_rotate_switch = nullptr;
91+
92+
struct ThemeCache {
93+
Ref<Texture2D> light_1_icon;
94+
Ref<Texture2D> light_2_icon;
95+
Ref<Texture2D> rotate_icon;
96+
} theme_cache;
97+
98+
DirectionalLight3D *light1 = nullptr;
99+
DirectionalLight3D *light2 = nullptr;
89100
Ref<ArrayMesh> selection_mesh;
90101
MeshInstance3D *node_selected = nullptr;
91102

@@ -180,6 +191,9 @@ class SceneImportSettingsDialog : public ConfirmationDialog {
180191
void _mesh_tree_selected();
181192
void _scene_tree_selected();
182193
void _cleanup();
194+
void _on_light_1_switch_pressed();
195+
void _on_light_2_switch_pressed();
196+
void _on_light_rotate_switch_pressed();
183197

184198
void _viewport_input(const Ref<InputEvent> &p_input);
185199

@@ -222,6 +236,7 @@ class SceneImportSettingsDialog : public ConfirmationDialog {
222236
Timer *update_view_timer = nullptr;
223237

224238
protected:
239+
virtual void _update_theme_item_cache() override;
225240
void _notification(int p_what);
226241

227242
public:

scene/3d/node_3d.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,15 @@ void Node3D::set_as_top_level(bool p_enabled) {
753753
data.top_level = p_enabled;
754754
}
755755

756+
void Node3D::set_as_top_level_keep_local(bool p_enabled) {
757+
ERR_THREAD_GUARD;
758+
if (data.top_level == p_enabled) {
759+
return;
760+
}
761+
data.top_level = p_enabled;
762+
_propagate_transform_changed(this);
763+
}
764+
756765
bool Node3D::is_set_as_top_level() const {
757766
ERR_READ_THREAD_GUARD_V(false);
758767
return data.top_level;

scene/3d/node_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class Node3D : public Node {
227227
void clear_gizmos();
228228

229229
void set_as_top_level(bool p_enabled);
230+
void set_as_top_level_keep_local(bool p_enabled);
230231
bool is_set_as_top_level() const;
231232

232233
void set_disable_scale(bool p_enabled);

0 commit comments

Comments
 (0)