USD export: option to add a root prim. #107855

Merged
Michael Kowalski merged 12 commits from makowalski/blender:usd-root-prim into main 2023-05-15 16:01:06 +02:00
4 changed files with 10 additions and 9 deletions
Showing only changes of commit b4d80f0ace - Show all commits

View File

@ -137,7 +137,7 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
const bool export_textures = RNA_boolean_get(op->ptr, "export_textures");
const bool overwrite_textures = RNA_boolean_get(op->ptr, "overwrite_textures");
const bool relative_paths = RNA_boolean_get(op->ptr, "relative_paths");
const bool add_root = RNA_boolean_get(op->ptr, "add_root");
const bool add_root_node = RNA_boolean_get(op->ptr, "add_root_node");
struct USDExportParams params = {
export_animation,
@ -153,7 +153,7 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
export_textures,
overwrite_textures,
relative_paths,
add_root,
add_root_node,
};
brecht marked this conversation as resolved
Review

I see this is same convention used everywhere else, so not a problem for this PR, but just a question: it seems RNA_string_get doesn't concern itself with potential buffer overflow or null termination (which could impact the strlen operation in process_prim_path, among other things). Is this somehow handled in a clever way that I'm missing?

I see this is same convention used everywhere else, so not a problem for this PR, but just a question: it seems `RNA_string_get` doesn't concern itself with potential buffer overflow or null termination (which could impact the `strlen` operation in `process_prim_path`, among other things). Is this somehow handled in a clever way that I'm missing?

The RNA_def_string for this property sets the maximum length to FILE_MAX, so this is ok.

The `RNA_def_string` for this property sets the maximum length to `FILE_MAX`, so this is ok.
bool ok = USD_export(C, filename, &params, as_background_job);
@ -181,7 +181,7 @@ static void wm_usd_export_draw(bContext *UNUSED(C), wmOperator *op)
uiItemR(col, ptr, "export_uvmaps", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "export_normals", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "export_materials", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "add_root", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "add_root_node", 0, NULL, ICON_NONE);
col = uiLayoutColumn(box, true);
uiItemR(col, ptr, "evaluation_mode", 0, NULL, ICON_NONE);
@ -339,10 +339,11 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
"USD, otherwise use absolute paths");
RNA_def_boolean(ot->srna,
"add_root",
"add_root_node",
false,
"Add Root",
"Add a Root 'Scope' node to the stage.");
"Add Root Node",
"Add a Root 'Xform' node to the stage that can be used in other applications"
"to transform all the primitives in the stage");
}
/* ====== USD Import ====== */

View File

@ -112,7 +112,7 @@ static void export_startjob(void *customdata,
usd_stage->SetEndTimeCode(scene->r.efra);
}
brecht marked this conversation as resolved
Review

I wonder if it might be better to remove this WM_reportf? If every failure path in prim_path_valid already reports an error, then this seems superfluous, and also the error reported from prim_path_valid provides more explicit guidance to the user about the problem.

I wonder if it might be better to remove this `WM_reportf`? If every failure path in `prim_path_valid` already reports an error, then this seems superfluous, and also the error reported from `prim_path_valid` provides more explicit guidance to the user about the problem.
Review

I agree and will remove the report statement. Thanks very much for the review!

I agree and will remove the report statement. Thanks very much for the review!
if (data->params.add_root) {
if (data->params.add_root_node) {
pxr::UsdGeomXform::Define(usd_stage, pxr::SdfPath("/Root"));
}

View File

@ -78,7 +78,7 @@ const pxr::UsdTimeCode &USDHierarchyIterator::get_export_time_code() const
USDExporterContext USDHierarchyIterator::create_usd_export_context(const HierarchyContext *context)
{
pxr::SdfPath path;
if (params_.add_root) {
if (params_.add_root_node) {
path = pxr::SdfPath("/Root" + context->export_path);
} else {
path = pxr::SdfPath(context->export_path);

View File

@ -50,7 +50,7 @@ struct USDExportParams {
bool export_textures;
bool overwrite_textures;
bool relative_paths;
bool add_root;
bool add_root_node;
};
struct USDImportParams {