USD import: Defined Primitives Only option.

New option to load defined primitives only. This may be
turned off to allow loading overrides with the Path Mask.
This commit is contained in:
Michael Kowalski 2022-11-29 14:18:06 -05:00
parent 90f1d1f4b6
commit 98670cfe82
3 changed files with 19 additions and 3 deletions

View File

@ -1069,6 +1069,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[1024];
@ -1147,7 +1149,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
.create_background_shader = create_background_shader,
.mtl_name_collision_mode = mtl_name_collision_mode,
.attr_import_mode = attr_import_mode,
.import_shapes = import_shapes};
.import_shapes = import_shapes,
.import_defined_only = import_defined_only};
STRNCPY(params.prim_path_mask, prim_path_mask);
@ -1193,6 +1196,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
uiItemR(col, ptr, "import_subdiv", 0, IFACE_("Subdivision"), ICON_NONE);
uiItemR(col, ptr, "import_instance_proxies", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "import_visible_only", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "import_defined_only", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "import_guide", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "import_proxy", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "import_render", 0, NULL, ICON_NONE);
@ -1303,6 +1307,13 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
"Only applies to primitives with a non-animated visibility attribute. "
"Primitives with animated visibility will always be imported");
RNA_def_boolean(ot->srna,
"import_defined_only",
true,
"Defined Primitives Only",
"Turn this off to allow importing USD primitives which are not defined, "
"for example, to load overrides with the Path Mask");
RNA_def_boolean(ot->srna,
"create_collection",
false,

View File

@ -287,10 +287,14 @@ USDPrimReader *USDStageReader::collect_readers(Main *bmain,
dome_lights_.push_back(pxr::UsdLuxDomeLight(prim));
}
pxr::Usd_PrimFlagsPredicate filter_predicate = pxr::UsdPrimDefaultPredicate;
pxr::Usd_PrimFlagsConjunction filter_predicate = pxr::UsdPrimIsActive && pxr::UsdPrimIsLoaded &&
!pxr::UsdPrimIsAbstract;
if (params_.import_defined_only) {
filter_predicate &= pxr::UsdPrimIsDefined;
}
if (!params_.use_instancing && params_.import_instance_proxies) {
filter_predicate = pxr::UsdTraverseInstanceProxies(filter_predicate);
filter_predicate.TraverseInstanceProxies(true);
}
pxr::UsdPrimSiblingRange children = prim.GetFilteredChildren(filter_predicate);

View File

@ -176,6 +176,7 @@ struct USDImportParams {
eUSDAttrImportMode attr_import_mode;
bool triangulate_meshes;
bool import_shapes;
bool import_defined_only;
};
/* The USD_export takes a as_background_job parameter, and returns a boolean.