Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add secondary light to 3D Advanced Import Settings #76140

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/icons/PreviewRotate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 68 additions & 4 deletions editor/import/3d/scene_import_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion editor/import/3d/scene_import_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions scene/3d/node_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions scene/3d/node_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class Node3D : public Node {
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);
Expand Down
Loading