From aaf61e2e2e350940f75777b6ad1cbfbd8f282a8b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 11 Oct 2023 13:04:52 +0200 Subject: [PATCH] USD: Fix Export progress report. This progress report was utterly broken and useless when not exporting animations, and not great either with animation export. This commit fixes: * Not generating any progress report when exporting a single frame. * Assuming actual data export covers 100% of progress. That last point is the biggest change, now actual export (be it animated or still) only covers 75% of the whole range. The rest is used to cover depsgraph building and updates (which can be noticiably slow with big scenes), stage writing, etc. Progression is still far from linear in time, but at least it gives better feedback on actual progress of the whole export. --- .../blender/io/usd/intern/usd_capi_export.cc | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index d1788f0a83e..b84a51e7838 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -215,6 +215,15 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams ¶ms, Scene *scene = DEG_get_input_scene(depsgraph); Main *bmain = DEG_get_bmain(depsgraph); + /* This whole `export_to_stage` function is assumed to cover about 80% of the whole export + * process, from 0.1f to 0.9f. */ + if (progress) { + *progress = 0.10f; + } + if (do_update) { + *do_update = true; + } + usd_stage->SetMetadata(pxr::UsdGeomTokens->metersPerUnit, double(scene->unit.scale_length)); usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender v") + BKE_blender_version_string()); @@ -237,9 +246,16 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams ¶ms, USDHierarchyIterator iter(bmain, depsgraph, usd_stage, params); + if (progress) { + *progress = 0.11f; + } + if (do_update) { + *do_update = true; + } + if (params.export_animation) { - /* Writing the animated frames is not 100% of the work, but it's our best guess. */ - float progress_per_frame = 1.0f / std::max(1, (scene->r.efra - scene->r.sfra + 1)); + /* Writing the animated frames is not 100% of the work, here it's assumed to be 75% of it. */ + float progress_per_frame = 0.75f / std::max(1, (scene->r.efra - scene->r.sfra + 1)); for (float frame = scene->r.sfra; frame <= scene->r.efra; frame++) { if (G.is_break || (stop != nullptr && *stop)) { @@ -267,6 +283,13 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams ¶ms, iter.iterate_and_write(); } + if (progress) { + *progress = 0.86f; + } + if (do_update) { + *do_update = true; + } + iter.release_writers(); /* Set the default prim if it doesn't exist */ @@ -281,12 +304,26 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams ¶ms, call_export_hooks(usd_stage, depsgraph); + if (progress) { + *progress = 0.88f; + } + if (do_update) { + *do_update = true; + } + /* Finish up by going back to the keyframe that was current before we started. */ if (scene->r.cfra != orig_frame) { scene->r.cfra = orig_frame; BKE_scene_graph_update_for_newframe(depsgraph); } + if (progress) { + *progress = 0.9f; + } + if (do_update) { + *do_update = true; + } + return usd_stage; } @@ -314,6 +351,9 @@ static void export_startjob(void *customdata, } G.is_break = false; + *progress = 0.01f; + *do_update = true; + /* Evaluate the despgraph for exporting. * * Note that, unlike with its building, this is expected to be safe to perform from worker @@ -323,7 +363,7 @@ static void export_startjob(void *customdata, * #USD_export. */ BKE_scene_graph_update_tagged(data->depsgraph, data->bmain); - *progress = 0.0f; + *progress = 0.1f; *do_update = true; pxr::UsdStageRefPtr usd_stage = export_to_stage( @@ -340,6 +380,9 @@ static void export_startjob(void *customdata, usd_stage->GetRootLayer()->Save(); + *progress = 0.98f; + *do_update = true; + if (data->targets_usdz()) { bool usd_conversion_success = perform_usdz_conversion(data); if (!usd_conversion_success) { -- 2.30.2