USD: add export option that adds a Root 'Xform' node #104506

Closed
Ashley wants to merge 3 commits from expenses/blender:usd-root-node into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 24 additions and 1 deletions

View File

@ -137,6 +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_node = RNA_boolean_get(op->ptr, "add_root_node");
struct USDExportParams params = {
export_animation,
@ -152,6 +153,7 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
export_textures,
overwrite_textures,
relative_paths,
add_root_node,
};
bool ok = USD_export(C, filename, &params, as_background_job);
@ -179,6 +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_node", 0, NULL, ICON_NONE);
col = uiLayoutColumn(box, true);
uiItemR(col, ptr, "evaluation_mode", 0, NULL, ICON_NONE);
@ -334,6 +337,13 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
"Relative Paths",
"Use relative paths to reference external files (i.e. textures, volumes) in "
"USD, otherwise use absolute paths");
RNA_def_boolean(ot->srna,
"add_root_node",
false,
"Add Root Node",
"Add a Root 'Xform' node to the stage that can be used in other applications"

I think this would be more clear:

root_transform
Root Transform
Add root transform used to transform all primitives in the stage
I think this would be more clear: ``` root_transform Root Transform Add root transform used to transform all primitives in the stage ```
Review

I'm not sure that this would be an accurate description, as the node is just grouping all the other nodes, not changing their transformations.

I'm not sure that this would be an accurate description, as the node is just grouping all the other nodes, not changing their transformations.

It's not changing the transform, but as I understand it, the purpose is that it can then be used later on somewhere to transform the primitives? If so, perhaps:

Add root transform to the stage, that can be used in other applications to transform all primitives in the stage
It's not changing the transform, but as I understand it, the purpose is that it can then be used later on somewhere to transform the primitives? If so, perhaps: ``` Add root transform to the stage, that can be used in other applications to transform all primitives in the stage ```

Any reason not to use root_transform, Root Transform, and the more detailed that can be used in other applications to transform all primitives in the stage description?

Many things in USD files are nodes, I don't think it's necessary to put that in the name of the option.

Any reason not to use `root_transform`, `Root Transform`, and the more detailed `that can be used in other applications to transform all primitives in the stage` description? Many things in USD files are nodes, I don't think it's necessary to put that in the name of the option.
Review

Yep, you're probably right.

Yep, you're probably right.
"to transform all the primitives in the stage");
}
/* ====== USD Import ====== */

View File

@ -11,6 +11,7 @@
#include <pxr/usd/usd/primRange.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/tokens.h>
#include <pxr/usd/usdGeom/xform.h>
#include "MEM_guardedalloc.h"
@ -111,6 +112,10 @@ static void export_startjob(void *customdata,
usd_stage->SetEndTimeCode(scene->r.efra);
}
if (data->params.add_root_node) {
pxr::UsdGeomXform::Define(usd_stage, pxr::SdfPath("/Root"));
}
USDHierarchyIterator iter(data->bmain, data->depsgraph, usd_stage, data->params);
if (data->params.export_animation) {

View File

@ -77,8 +77,15 @@ 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_node) {
path = pxr::SdfPath("/Root" + context->export_path);
} else {
path = pxr::SdfPath(context->export_path);
}
return USDExporterContext{
bmain_, depsgraph_, stage_, pxr::SdfPath(context->export_path), this, params_};
bmain_, depsgraph_, stage_, path, this, params_};
}
AbstractHierarchyWriter *USDHierarchyIterator::create_transform_writer(

View File

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