USD Import: Added an option to import only defined prims

Prims in a UsdStage can be created directly (def) or as an over. Overs
might not always be desired at import time. This patch adds the ability
to choose whether to load only defined prims (the default behaviour, and
as it exists currently in main). By unchecking this option at import
time, prims created as overs will also be imported.

Co-authored-by: Charles Wardlaw <cwardlaw@nvidia.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/121321
This commit is contained in:
Charles Wardlaw
2024-05-24 23:50:08 +02:00
committed by Jesse Yurkovich
parent 6b6657405f
commit bfa54f22ce
3 changed files with 14 additions and 2 deletions

View File

@@ -664,6 +664,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
const bool import_visible_only = RNA_boolean_get(op->ptr, "import_visible_only");
const bool import_defined_only = RNA_boolean_get(op->ptr, "import_defined_only");
const bool create_collection = RNA_boolean_get(op->ptr, "create_collection");
char *prim_path_mask = RNA_string_get_alloc(op->ptr, "prim_path_mask", nullptr, 0, nullptr);
@@ -735,6 +737,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
params.import_proxy = import_proxy;
params.import_render = import_render;
params.import_visible_only = import_visible_only;
params.import_defined_only = import_defined_only;
params.use_instancing = use_instancing;
params.import_usd_preview = import_usd_preview;
params.set_material_blend = set_material_blend;
@@ -789,6 +792,7 @@ static void wm_usd_import_draw(bContext * /*C*/, wmOperator *op)
uiItemR(col, ptr, "import_subdiv", UI_ITEM_NONE, IFACE_("Subdivision"), ICON_NONE);
uiItemR(col, ptr, "support_scene_instancing", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "import_visible_only", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "import_defined_only", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "import_guide", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "import_proxy", UI_ITEM_NONE, nullptr, ICON_NONE);
uiItemR(col, ptr, "import_render", UI_ITEM_NONE, nullptr, ICON_NONE);
@@ -1004,6 +1008,13 @@ void WM_OT_usd_import(wmOperatorType *ot)
"Validate Meshes",
"Ensure the data is valid "
"(when disabled, data may be imported which causes crashes displaying or editing)");
RNA_def_boolean(ot->srna,
"import_defined_only",
true,
"Import only defined USD primitives",
"When disabled this allows importing USD primitives which are not defined,"
"such as those with an override specifier");
}
namespace blender::ed::io {

View File

@@ -366,12 +366,12 @@ USDPrimReader *USDStageReader::collect_readers(const pxr::UsdPrim &prim,
pxr::Usd_PrimFlagsConjunction filter_flags = pxr::UsdPrimIsActive && pxr::UsdPrimIsLoaded &&
!pxr::UsdPrimIsAbstract;
if (defined_prims_only) {
filter_flags &= pxr::UsdPrimIsDefined;
}
pxr::Usd_PrimFlagsPredicate filter_predicate(filter_flags);
if (!params_.support_scene_instancing) {
filter_predicate = pxr::UsdTraverseInstanceProxies(filter_predicate);
}
@@ -457,7 +457,7 @@ void USDStageReader::collect_readers()
stage_->SetInterpolationType(pxr::UsdInterpolationType::UsdInterpolationTypeHeld);
/* Create readers, skipping over prototype prims in this pass. */
collect_readers(root, instancer_proto_paths, true, readers_);
collect_readers(root, instancer_proto_paths, params_.import_defined_only, readers_);
if (params_.support_scene_instancing) {
/* Collect the scene-graph instance prototypes. */

View File

@@ -155,6 +155,7 @@ struct USDImportParams {
float light_intensity_scale;
eUSDMtlNameCollisionMode mtl_name_collision_mode;
eUSDTexImportMode import_textures_mode;
bool import_defined_only;
char import_textures_dir[768]; /* FILE_MAXDIR */
eUSDTexNameCollisionMode tex_name_collision_mode;
bool import_all_materials;