Repository: godotengine/godot
File: editor/plugins/node_3d_editor_plugin.cpp (C++)

Code before:
		}
	}
}

void Node3DEditor::_sun_direction_input(const Ref<InputEvent> &p_event) {
	Ref<InputEventMouseMotion> mm = p_event;
	if (mm.is_valid() && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
		sun_rotation.x += mm->get_relative().y * (0.02 * EDSCALE);
		sun_rotation.y -= mm->get_relative().x * (0.02 * EDSCALE);
		sun_rotation.x = CLAMP(sun_rotation.x, -Math_TAU / 4, Math_TAU / 4);

		EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
		undo_redo->create_action(TTR("Set preview sun direction"), UndoRedo::MergeMode::MERGE_ENDS);
		undo_redo->add_do_method(sun_angle_altitude, "set_value_no_signal", -Math::rad_to_deg(sun_rotation.x));
		undo_redo->add_undo_method(sun_angle_altitude, "set_value_no_signal", sun_angle_altitude->get_value());
		undo_redo->add_do_method(sun_angle_azimuth, "set_value_no_signal", 180.0 - Math::rad_to_deg(sun_rotation.y));
		undo_redo->add_undo_method(sun_angle_azimuth, "set_value_no_signal", sun_angle_azimuth->get_value());
		undo_redo->add_do_method(this, "_preview_settings_changed");
		undo_redo->add_undo_method(this, "_preview_settings_changed");
		undo_redo->commit_action();
	}
}

void Node3DEditor::_sun_direction_set_altitude(float p_altitude) {
	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	undo_redo->create_action(TTR("Set preview sun altitude"), UndoRedo::MergeMode::MERGE_ENDS);
	undo_redo->add_do_method(sun_angle_altitude, "set_value_no_signal", p_altitude);
	undo_redo->add_undo_method(sun_angle_altitude, "set_value_no_signal", -Math::rad_to_deg(sun_rotation.x));
	undo_redo->add_do_method(this, "_preview_settings_changed");
	undo_redo->add_undo_method(this, "_preview_settings_changed");
	undo_redo->commit_action();
}

void Node3DEditor::_sun_direction_set_azimuth(float p_azimuth) {
	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	undo_redo->create_action(TTR("Set preview sun azimuth"), UndoRedo::MergeMode::MERGE_ENDS);
	undo_redo->add_do_method(sun_angle_azimuth, "set_value_no_signal", p_azimuth);
	undo_redo->add_undo_method(sun_angle_azimuth, "set_value_no_signal", 180.0 - Math::rad_to_deg(sun_rotation.y));
	undo_redo->add_do_method(this, "_preview_settings_changed");
	undo_redo->add_undo_method(this, "_preview_settings_changed");
	undo_redo->commit_action();
}

void Node3DEditor::_sun_set_color(Color p_color) {
	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	undo_redo->create_action(TTR("Set preview sun color"), UndoRedo::MergeMode::MERGE_ENDS);
	undo_redo->add_do_method(sun_color, "set_pick_color", p_color);
	undo_redo->add_undo_method(sun_color, "set_pick_color", preview_sun->get_color());
	undo_redo->add_do_method(this, "_preview_settings_changed");
	undo_redo->add_undo_method(this, "_preview_settings_changed");
	undo_redo->commit_action();

Review comment (suggestion):
We use Title Case for UndoRedo action names:

```suggestion
	undo_redo->create_action(TTR("Set Preview Sun Altitude"), UndoRedo::MergeMode::MERGE_ENDS);
```

This should also be changed for action names further below.

Code after:
		sun_rotation.x = Math::deg_to_rad(-sun_angle_altitude->get_value());
		sun_rotation.y = Math::deg_to_rad(180.0 - sun_angle_azimuth->get_value());
		Transform3D t;
		t.basis = Basis::from_euler(Vector3(sun_rotation.x, sun_rotation.y, 0));
		preview_sun->set_transform(t);
		sun_direction->queue_redraw();
		preview_sun->set_param(Light3D::PARAM_ENERGY, sun_energy->get_value());
		preview_sun->set_param(Light3D::PARAM_SHADOW_MAX_DISTANCE, sun_shadow_max_distance->get_value());
		preview_sun->set_color(sun_color->get_pick_color());
	}

	{ //preview env
		sky_material->set_energy_multiplier(environ_energy->get_value());
		Color hz_color = environ_sky_color->get_pick_color().lerp(environ_ground_color->get_pick_color(), 0.5);
		float hz_lum = hz_color.get_luminance() * 3.333;
		hz_color = hz_color.lerp(Color(hz_lum, hz_lum, hz_lum), 0.5);
		sky_material->set_sky_top_color(environ_sky_color->get_pick_color());
		sky_material->set_sky_horizon_color(hz_color);
		sky_material->set_ground_bottom_color(environ_ground_color->get_pick_color());
		sky_material->set_ground_horizon_color(hz_color);

		environment->set_ssao_enabled(environ_ao_button->is_pressed());
		environment->set_glow_enabled(environ_glow_button->is_pressed());
		environment->set_sdfgi_enabled(environ_gi_button->is_pressed());
		environment->set_tonemapper(environ_tonemap_button->is_pressed() ? Environment::TONE_MAPPER_FILMIC : Environment::TONE_MAPPER_LINEAR);
	}
}

void Node3DEditor::_load_default_preview_settings() {
	sun_environ_updating = true;

	// These default rotations place the preview sun at an angular altitude
	// of 60 degrees (must be negative) and an azimuth of 30 degrees clockwise
	// from north (or 150 CCW from south), from north east, facing south west.
	// On any not-tidally-locked planet, a sun would have an angular altitude
	// of 60 degrees as the average of all points on the sphere at noon.
	// The azimuth choice is arbitrary, but ideally shouldn't be on an axis.
	sun_rotation = Vector2(-Math::deg_to_rad(60.0), Math::deg_to_rad(150.0));

	sun_angle_altitude->set_value_no_signal(-Math::rad_to_deg(sun_rotation.x));
	sun_angle_azimuth->set_value_no_signal(180.0 - Math::rad_to_deg(sun_rotation.y));
	sun_direction->queue_redraw();
	environ_sky_color->set_pick_color(Color(0.385, 0.454, 0.55));
	environ_ground_color->set_pick_color(Color(0.2, 0.169, 0.133));
	environ_energy->set_value_no_signal(1.0);
	if (OS::get_singleton()->get_current_rendering_method() != "gl_compatibility") {
		environ_glow_button->set_pressed_no_signal(true);
	}
	environ_tonemap_button->set_pressed_no_signal(true);
	environ_ao_button->set_pressed_no_signal(false);
	environ_gi_button->set_pressed_no_signal(false);