USD: Fix Export progress report. #2

Closed
Bastien Montagne wants to merge 1 commits from tmp-usd-export-fix-wqprogress-report into tmp-usd-fix-deg-export-crash

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

View File

@ -215,6 +215,15 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams &params,
Scene *scene = DEG_get_input_scene(depsgraph); Scene *scene = DEG_get_input_scene(depsgraph);
Main *bmain = DEG_get_bmain(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->SetMetadata(pxr::UsdGeomTokens->metersPerUnit, double(scene->unit.scale_length));
usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender v") + usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender v") +
BKE_blender_version_string()); BKE_blender_version_string());
@ -237,9 +246,16 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams &params,
USDHierarchyIterator iter(bmain, depsgraph, usd_stage, params); USDHierarchyIterator iter(bmain, depsgraph, usd_stage, params);
if (progress) {
*progress = 0.11f;
}
if (do_update) {
*do_update = true;
}
if (params.export_animation) { if (params.export_animation) {
/* Writing the animated frames is not 100% of the work, but it's our best guess. */ /* Writing the animated frames is not 100% of the work, here it's assumed to be 75% of it. */
float progress_per_frame = 1.0f / std::max(1, (scene->r.efra - scene->r.sfra + 1)); 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++) { for (float frame = scene->r.sfra; frame <= scene->r.efra; frame++) {
if (G.is_break || (stop != nullptr && *stop)) { if (G.is_break || (stop != nullptr && *stop)) {
@ -267,6 +283,13 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams &params,
iter.iterate_and_write(); iter.iterate_and_write();
} }
if (progress) {
*progress = 0.86f;
}
if (do_update) {
*do_update = true;
}
iter.release_writers(); iter.release_writers();
/* Set the default prim if it doesn't exist */ /* Set the default prim if it doesn't exist */
@ -281,12 +304,26 @@ static pxr::UsdStageRefPtr export_to_stage(const USDExportParams &params,
call_export_hooks(usd_stage, depsgraph); 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. */ /* Finish up by going back to the keyframe that was current before we started. */
if (scene->r.cfra != orig_frame) { if (scene->r.cfra != orig_frame) {
scene->r.cfra = orig_frame; scene->r.cfra = orig_frame;
BKE_scene_graph_update_for_newframe(depsgraph); BKE_scene_graph_update_for_newframe(depsgraph);
} }
if (progress) {
*progress = 0.9f;
}
if (do_update) {
*do_update = true;
}
return usd_stage; return usd_stage;
} }
@ -314,6 +351,9 @@ static void export_startjob(void *customdata,
} }
G.is_break = false; G.is_break = false;
*progress = 0.01f;
*do_update = true;
/* Evaluate the despgraph for exporting. /* Evaluate the despgraph for exporting.
* *
* Note that, unlike with its building, this is expected to be safe to perform from worker * 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. */ * #USD_export. */
BKE_scene_graph_update_tagged(data->depsgraph, data->bmain); BKE_scene_graph_update_tagged(data->depsgraph, data->bmain);
*progress = 0.0f; *progress = 0.1f;
*do_update = true; *do_update = true;
pxr::UsdStageRefPtr usd_stage = export_to_stage( pxr::UsdStageRefPtr usd_stage = export_to_stage(
@ -340,6 +380,9 @@ static void export_startjob(void *customdata,
usd_stage->GetRootLayer()->Save(); usd_stage->GetRootLayer()->Save();
*progress = 0.98f;
*do_update = true;
if (data->targets_usdz()) { if (data->targets_usdz()) {
bool usd_conversion_success = perform_usdz_conversion(data); bool usd_conversion_success = perform_usdz_conversion(data);
if (!usd_conversion_success) { if (!usd_conversion_success) {