diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp index 7f53b4bd0b4..255235eeb6d 100644 --- a/editor/plugins/baked_lightmap_editor_plugin.cpp +++ b/editor/plugins/baked_lightmap_editor_plugin.cpp @@ -33,15 +33,12 @@ void BakedLightmapEditorPlugin::_bake_select_file(const String &p_file) { if (lightmap) { BakedLightmap::BakeError err; - uint32_t time_started = OS::get_singleton()->get_ticks_msec(); if (get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root() == lightmap) { err = lightmap->bake(lightmap, p_file); } else { err = lightmap->bake(lightmap->get_parent(), p_file); } - bake_func_end(time_started); - switch (err) { case BakedLightmap::BAKE_ERROR_NO_SAVE_PATH: { String scene_path = lightmap->get_filename(); @@ -173,6 +170,7 @@ BakedLightmapEditorPlugin::BakedLightmapEditorPlugin(EditorNode *p_node) { BakedLightmap::bake_step_function = bake_func_step; BakedLightmap::bake_substep_function = bake_func_substep; + BakedLightmap::bake_end_function = bake_func_end; } BakedLightmapEditorPlugin::~BakedLightmapEditorPlugin() { diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index e1f631c4be6..b40385b0f90 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -257,6 +257,7 @@ BakedLightmapData::~BakedLightmapData() { Lightmapper::BakeStepFunc BakedLightmap::bake_step_function; Lightmapper::BakeStepFunc BakedLightmap::bake_substep_function; +Lightmapper::BakeEndFunc BakedLightmap::bake_end_function; Size2i BakedLightmap::_compute_lightmap_size(const MeshesFound &p_mesh) { double area = 0; @@ -606,15 +607,21 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa } } + uint32_t time_started = OS::get_singleton()->get_ticks_msec(); + if (bake_step_function) { bool cancelled = bake_step_function(0.0, TTR("Finding meshes and lights"), nullptr, true); if (cancelled) { + bake_end_function(time_started); return BAKE_ERROR_USER_ABORTED; } } Ref lightmapper = Lightmapper::create(); - ERR_FAIL_COND_V(lightmapper.is_null(), BAKE_ERROR_NO_LIGHTMAPPER); + if (lightmapper.is_null()) { + bake_end_function(time_started); + return BAKE_ERROR_NO_LIGHTMAPPER; + } Vector lights_found; Vector meshes_found; @@ -622,6 +629,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa _find_meshes_and_lights(p_from_node ? p_from_node : get_parent(), meshes_found, lights_found); if (meshes_found.size() == 0) { + bake_end_function(time_started); return BAKE_ERROR_NO_MESHES; } @@ -630,6 +638,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa float p = (float)(m_i) / meshes_found.size(); bool cancelled = bake_step_function(p * 0.05, vformat(TTR("Preparing geometry (%d/%d)"), m_i + 1, meshes_found.size()), nullptr, false); if (cancelled) { + bake_end_function(time_started); return BAKE_ERROR_USER_ABORTED; } } @@ -818,6 +827,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa Lightmapper::BakeError bake_err = lightmapper->bake(Lightmapper::BakeQuality(bake_quality), use_denoiser, bounces, bounce_indirect_energy, bias, gen_atlas, max_atlas_size, environment_image, environment_xform, _lightmap_bake_step_function, &bsud, bake_substep_function); if (bake_err != Lightmapper::BAKE_OK) { + bake_end_function(time_started); switch (bake_err) { case Lightmapper::BAKE_ERROR_USER_ABORTED: { return BAKE_ERROR_USER_ABORTED; @@ -847,6 +857,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa if (bake_step_function) { bool cancelled = bake_step_function(0.85, TTR("Generating capture"), nullptr, true); if (cancelled) { + bake_end_function(time_started); return BAKE_ERROR_USER_ABORTED; } } @@ -926,6 +937,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa if (bake_step_function) { bool cancelled = bake_step_function(0.9, TTR("Saving lightmaps"), nullptr, true); if (cancelled) { + bake_end_function(time_started); return BAKE_ERROR_USER_ABORTED; } } @@ -1081,6 +1093,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa if (bake_step_function) { bool cancelled = bake_step_function(1.0, TTR("Done"), nullptr, true); if (cancelled) { + bake_end_function(time_started); return BAKE_ERROR_USER_ABORTED; } } @@ -1089,10 +1102,12 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa data->set_path(p_data_save_path); if (err != OK) { + bake_end_function(time_started); return BAKE_ERROR_CANT_CREATE_IMAGE; } set_light_data(data); + bake_end_function(time_started); return BAKE_ERROR_OK; } diff --git a/scene/3d/baked_lightmap.h b/scene/3d/baked_lightmap.h index 438c7a89d5c..54a85dc8eee 100644 --- a/scene/3d/baked_lightmap.h +++ b/scene/3d/baked_lightmap.h @@ -203,6 +203,7 @@ protected: public: static Lightmapper::BakeStepFunc bake_step_function; static Lightmapper::BakeStepFunc bake_substep_function; + static Lightmapper::BakeEndFunc bake_end_function; void set_light_data(const Ref &p_data); Ref get_light_data() const; diff --git a/scene/3d/lightmapper.h b/scene/3d/lightmapper.h index 80b8d1a411b..170eb2784e7 100644 --- a/scene/3d/lightmapper.h +++ b/scene/3d/lightmapper.h @@ -154,6 +154,7 @@ public: protected: public: typedef bool (*BakeStepFunc)(float, const String &, void *, bool); //progress, step description, userdata, force refresh + typedef void (*BakeEndFunc)(uint32_t); // time_started struct MeshData { struct TextureDef {