From c3bc768d64d93db8848d2c04c2b2e72193f43b12 Mon Sep 17 00:00:00 2001 From: Jeronimo Schreyer Date: Sun, 16 Apr 2023 13:53:27 -0300 Subject: [PATCH] Make Advanced Import lights more like the mesh and material editors Co-authored-by: Aaron Franke --- editor/icons/PreviewRotate.svg | 1 + editor/import/3d/scene_import_settings.cpp | 72 ++++++++++++++++++++-- editor/import/3d/scene_import_settings.h | 17 ++++- scene/3d/node_3d.cpp | 9 +++ scene/3d/node_3d.h | 1 + 5 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 editor/icons/PreviewRotate.svg diff --git a/editor/icons/PreviewRotate.svg b/editor/icons/PreviewRotate.svg new file mode 100644 index 00000000000..9e0da461692 --- /dev/null +++ b/editor/icons/PreviewRotate.svg @@ -0,0 +1 @@ + diff --git a/editor/import/3d/scene_import_settings.cpp b/editor/import/3d/scene_import_settings.cpp index 620ebce44b3..325525be1b6 100644 --- a/editor/import/3d/scene_import_settings.cpp +++ b/editor/import/3d/scene_import_settings.cpp @@ -1117,6 +1117,20 @@ void SceneImportSettingsDialog::_cleanup() { set_process(false); } +void SceneImportSettingsDialog::_on_light_1_switch_pressed() { + light1->set_visible(light_1_switch->is_pressed()); +} + +void SceneImportSettingsDialog::_on_light_2_switch_pressed() { + light2->set_visible(light_2_switch->is_pressed()); +} + +void SceneImportSettingsDialog::_on_light_rotate_switch_pressed() { + bool light_top_level = !light_rotate_switch->is_pressed(); + light1->set_as_top_level_keep_local(light_top_level); + light2->set_as_top_level_keep_local(light_top_level); +} + void SceneImportSettingsDialog::_viewport_input(const Ref &p_input) { float *rot_x = &cam_rot_x; float *rot_y = &cam_rot_y; @@ -1232,6 +1246,13 @@ void SceneImportSettingsDialog::_re_import() { EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, editing_animation ? "animation_library" : "scene", main_settings); } +void SceneImportSettingsDialog::_update_theme_item_cache() { + ConfirmationDialog::_update_theme_item_cache(); + theme_cache.light_1_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight1")); + theme_cache.light_2_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight2")); + theme_cache.rotate_icon = get_editor_theme_icon(SNAME("PreviewRotate")); +} + void SceneImportSettingsDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { @@ -1251,6 +1272,10 @@ void SceneImportSettingsDialog::_notification(int p_what) { animation_play_button->set_icon(get_editor_theme_icon(SNAME("MainPlay"))); } animation_stop_button->set_icon(get_editor_theme_icon(SNAME("Stop"))); + + light_1_switch->set_icon(theme_cache.light_1_icon); + light_2_switch->set_icon(theme_cache.light_2_icon); + light_rotate_switch->set_icon(theme_cache.rotate_icon); } break; case NOTIFICATION_PROCESS: { @@ -1644,6 +1669,40 @@ SceneImportSettingsDialog::SceneImportSettingsDialog() { base_viewport->set_use_own_world_3d(true); + HBoxContainer *viewport_hbox = memnew(HBoxContainer); + vp_container->add_child(viewport_hbox); + viewport_hbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2); + + viewport_hbox->add_spacer(); + + VBoxContainer *vb_light = memnew(VBoxContainer); + vb_light->set_v_size_flags(Control::SIZE_EXPAND_FILL); + viewport_hbox->add_child(vb_light); + + light_rotate_switch = memnew(Button); + light_rotate_switch->set_theme_type_variation("PreviewLightButton"); + light_rotate_switch->set_toggle_mode(true); + light_rotate_switch->set_pressed(true); + light_rotate_switch->set_tooltip_text(TTR("Rotate Lights With Model")); + light_rotate_switch->connect("pressed", callable_mp(this, &SceneImportSettingsDialog::_on_light_rotate_switch_pressed)); + vb_light->add_child(light_rotate_switch); + + light_1_switch = memnew(Button); + light_1_switch->set_theme_type_variation("PreviewLightButton"); + light_1_switch->set_toggle_mode(true); + light_1_switch->set_pressed(true); + light_1_switch->set_tooltip_text(TTR("Primary Light")); + light_1_switch->connect("pressed", callable_mp(this, &SceneImportSettingsDialog::_on_light_1_switch_pressed)); + vb_light->add_child(light_1_switch); + + light_2_switch = memnew(Button); + light_2_switch->set_theme_type_variation("PreviewLightButton"); + light_2_switch->set_toggle_mode(true); + light_2_switch->set_pressed(true); + light_2_switch->set_tooltip_text(TTR("Secondary Light")); + light_2_switch->connect("pressed", callable_mp(this, &SceneImportSettingsDialog::_on_light_2_switch_pressed)); + vb_light->add_child(light_2_switch); + camera = memnew(Camera3D); base_viewport->add_child(camera); camera->make_current(); @@ -1675,10 +1734,15 @@ SceneImportSettingsDialog::SceneImportSettingsDialog() { environment->set_sky_custom_fov(50.0); camera->set_environment(environment); - light = memnew(DirectionalLight3D); - light->set_transform(Transform3D().looking_at(Vector3(-1, -2, -0.6), Vector3(0, 1, 0))); - base_viewport->add_child(light); - light->set_shadow(true); + light1 = memnew(DirectionalLight3D); + light1->set_transform(Transform3D(Basis::looking_at(Vector3(-1, -1, -1)))); + light1->set_shadow(true); + camera->add_child(light1); + + light2 = memnew(DirectionalLight3D); + light2->set_transform(Transform3D(Basis::looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)))); + light2->set_color(Color(0.5f, 0.5f, 0.5f)); + camera->add_child(light2); { Ref selection_mat; diff --git a/editor/import/3d/scene_import_settings.h b/editor/import/3d/scene_import_settings.h index 17d6616fc0a..c2a5151432d 100644 --- a/editor/import/3d/scene_import_settings.h +++ b/editor/import/3d/scene_import_settings.h @@ -85,7 +85,18 @@ class SceneImportSettingsDialog : public ConfirmationDialog { bool first_aabb = false; AABB contents_aabb; - DirectionalLight3D *light = nullptr; + Button *light_1_switch = nullptr; + Button *light_2_switch = nullptr; + Button *light_rotate_switch = nullptr; + + struct ThemeCache { + Ref light_1_icon; + Ref light_2_icon; + Ref rotate_icon; + } theme_cache; + + DirectionalLight3D *light1 = nullptr; + DirectionalLight3D *light2 = nullptr; Ref selection_mesh; MeshInstance3D *node_selected = nullptr; @@ -180,6 +191,9 @@ class SceneImportSettingsDialog : public ConfirmationDialog { void _mesh_tree_selected(); void _scene_tree_selected(); void _cleanup(); + void _on_light_1_switch_pressed(); + void _on_light_2_switch_pressed(); + void _on_light_rotate_switch_pressed(); void _viewport_input(const Ref &p_input); @@ -222,6 +236,7 @@ class SceneImportSettingsDialog : public ConfirmationDialog { Timer *update_view_timer = nullptr; protected: + virtual void _update_theme_item_cache() override; void _notification(int p_what); public: diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index 5c081a0b47d..131128b854e 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -753,6 +753,15 @@ void Node3D::set_as_top_level(bool p_enabled) { data.top_level = p_enabled; } +void Node3D::set_as_top_level_keep_local(bool p_enabled) { + ERR_THREAD_GUARD; + if (data.top_level == p_enabled) { + return; + } + data.top_level = p_enabled; + _propagate_transform_changed(this); +} + bool Node3D::is_set_as_top_level() const { ERR_READ_THREAD_GUARD_V(false); return data.top_level; diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h index 7f8c3e6e686..c1667221df9 100644 --- a/scene/3d/node_3d.h +++ b/scene/3d/node_3d.h @@ -227,6 +227,7 @@ public: void clear_gizmos(); void set_as_top_level(bool p_enabled); + void set_as_top_level_keep_local(bool p_enabled); bool is_set_as_top_level() const; void set_disable_scale(bool p_enabled);