From f6f2b0897a5bccbbd7b501ea0f88ab3fd5312f81 Mon Sep 17 00:00:00 2001 From: Dario Date: Mon, 11 Sep 2023 09:14:39 -0300 Subject: [PATCH] Propagate error correctly when max texture size for lightmaps is too small. Add error handling for BAKE_ERROR_LIGHTMAP_TOO_SMALL, which was previously ignored. Fixes #81453. (cherry picked from commit 7dfb854556f0a69672f5e112e3bfbe7f507db3b0) --- doc/classes/LightmapGI.xml | 3 +++ editor/plugins/lightmap_gi_editor_plugin.cpp | 3 +++ scene/3d/lightmap_gi.cpp | 5 ++++- scene/3d/lightmap_gi.h | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/classes/LightmapGI.xml b/doc/classes/LightmapGI.xml index 55c6ef5eb5de..2b7875a939dc 100644 --- a/doc/classes/LightmapGI.xml +++ b/doc/classes/LightmapGI.xml @@ -117,6 +117,9 @@ The user aborted the lightmap baking operation (typically by clicking the [b]Cancel[/b] button in the progress dialog). + + Lightmap baking failed as the maximum texture size is too small to fit some of the meshes marked for baking. + Ignore environment lighting when baking lightmaps. diff --git a/editor/plugins/lightmap_gi_editor_plugin.cpp b/editor/plugins/lightmap_gi_editor_plugin.cpp index b549a958e69c..7fc462edbbbf 100644 --- a/editor/plugins/lightmap_gi_editor_plugin.cpp +++ b/editor/plugins/lightmap_gi_editor_plugin.cpp @@ -103,6 +103,9 @@ void LightmapGIEditorPlugin::_bake_select_file(const String &p_file) { case LightmapGI::BAKE_ERROR_FOREIGN_DATA: { EditorNode::get_singleton()->show_warning(TTR("Lightmap data is not local to the scene.")); } break; + case LightmapGI::BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL: { + EditorNode::get_singleton()->show_warning(TTR("Maximum texture size is too small for the lightmap images.")); + } break; default: { } break; } diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp index 3ee08fd5485f..237c3ef953eb 100644 --- a/scene/3d/lightmap_gi.cpp +++ b/scene/3d/lightmap_gi.cpp @@ -1081,7 +1081,9 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa Lightmapper::BakeError bake_err = lightmapper->bake(Lightmapper::BakeQuality(bake_quality), use_denoiser, bounces, bias, max_texture_size, directional, Lightmapper::GenerateProbes(gen_probes), environment_image, environment_transform, _lightmap_bake_step_function, &bsud, exposure_normalization); - if (bake_err == Lightmapper::BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES) { + if (bake_err == Lightmapper::BAKE_ERROR_LIGHTMAP_TOO_SMALL) { + return BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL; + } else if (bake_err == Lightmapper::BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES) { return BAKE_ERROR_MESHES_INVALID; } @@ -1565,6 +1567,7 @@ void LightmapGI::_bind_methods() { BIND_ENUM_CONSTANT(BAKE_ERROR_MESHES_INVALID); BIND_ENUM_CONSTANT(BAKE_ERROR_CANT_CREATE_IMAGE); BIND_ENUM_CONSTANT(BAKE_ERROR_USER_ABORTED); + BIND_ENUM_CONSTANT(BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL); BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_DISABLED); BIND_ENUM_CONSTANT(ENVIRONMENT_MODE_SCENE); diff --git a/scene/3d/lightmap_gi.h b/scene/3d/lightmap_gi.h index b9e33cf30044..02123ef7ba65 100644 --- a/scene/3d/lightmap_gi.h +++ b/scene/3d/lightmap_gi.h @@ -132,6 +132,7 @@ class LightmapGI : public VisualInstance3D { BAKE_ERROR_MESHES_INVALID, BAKE_ERROR_CANT_CREATE_IMAGE, BAKE_ERROR_USER_ABORTED, + BAKE_ERROR_TEXTURE_SIZE_TOO_SMALL, }; enum EnvironmentMode {