瀏覽代碼

Merge pull request #76140 from jeronimo-schreyer/add_secondary_light_to_3d_resource_importer

Added secondary light to 3D Advanced Import Settings
Rémi Verschelde 1 年之前
父節點
當前提交
42e6f9a9d8

+ 1 - 0
editor/icons/PreviewRotate.svg

@@ -0,0 +1 @@
+<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="#000" stroke-width="2" opacity=".8" stroke-linejoin="round"><circle cx="8" cy="8" r="2"/><path d="M8 1a7 7 0 00-4.982 11.998H1.911v2h4a1 1 0 00.97-1.242l-1-4-1.94.486.28 1.121a5 5 0 117.223.168l1.416 1.416A7 7 0 008 1z"/></g><g fill="#f9f9f9"><circle cx="8" cy="8" r="2"/><path d="M8 1a7 7 0 00-4.982 11.998H1.911v2h4a1 1 0 00.97-1.242l-1-4-1.94.486.28 1.121a5 5 0 117.223.168l1.416 1.416A7 7 0 008 1z"/></g></svg>

+ 68 - 4
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<InputEvent> &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<StandardMaterial3D> selection_mat;

+ 16 - 1
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<Texture2D> light_1_icon;
+		Ref<Texture2D> light_2_icon;
+		Ref<Texture2D> rotate_icon;
+	} theme_cache;
+
+	DirectionalLight3D *light1 = nullptr;
+	DirectionalLight3D *light2 = nullptr;
 	Ref<ArrayMesh> 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<InputEvent> &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:

+ 9 - 0
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;

+ 1 - 0
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);