1
1

Merge branch 'universal-scene-description' into tmp-dynamic-usd

This commit is contained in:
2022-12-07 14:36:08 -05:00
4 changed files with 33 additions and 17 deletions

View File

@@ -1084,6 +1084,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];
@@ -1171,7 +1173,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
.attr_import_mode = attr_import_mode,
.import_shapes = import_shapes,
.import_textures = import_textures,
.overwrite_textures = overwrite_textures};
.overwrite_textures = overwrite_textures,
.import_defined_only = import_defined_only};
STRNCPY(params.prim_path_mask, prim_path_mask);
STRNCPY(params.import_textures_dir, import_textures_dir);
@@ -1221,6 +1224,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);
@@ -1341,6 +1345,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

@@ -382,8 +382,21 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float
*data->do_update = true;
*data->progress = 0.1f;
pxr::UsdStageRefPtr stage = pxr::UsdStage::Open(data->filepath);
std::string prim_path_mask(data->params.prim_path_mask);
pxr::UsdStagePopulationMask pop_mask;
if (!prim_path_mask.empty()) {
const std::vector<std::string> mask_tokens = pxr::TfStringTokenize(prim_path_mask, " ,;");
for (const std::string &tok : mask_tokens) {
pxr::SdfPath prim_path(tok);
if (!prim_path.IsEmpty()) {
pop_mask.Add(prim_path);
}
}
}
pxr::UsdStageRefPtr stage = pop_mask.IsEmpty() ?
pxr::UsdStage::Open(data->filepath) :
pxr::UsdStage::OpenMasked(data->filepath, pop_mask);
if (!stage) {
WM_reportf(RPT_ERROR, "USD Import: unable to open stage to read %s", data->filepath);
data->import_ok = 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);
@@ -353,19 +357,6 @@ void USDStageReader::collect_readers(Main *bmain)
/* Iterate through the stage. */
pxr::UsdPrim root = stage_->GetPseudoRoot();
std::string prim_path_mask(params_.prim_path_mask);
if (!prim_path_mask.empty()) {
pxr::UsdPrim prim = stage_->GetPrimAtPath(pxr::SdfPath(prim_path_mask));
if (prim.IsValid()) {
root = prim;
}
else {
std::cerr << "WARNING: Prim Path Mask " << prim_path_mask
<< " does not specify a valid prim.\n";
}
}
stage_->SetInterpolationType(pxr::UsdInterpolationType::UsdInterpolationTypeHeld);
pxr::UsdGeomXformCache xf_cache;

View File

@@ -179,6 +179,7 @@ struct USDImportParams {
bool import_textures;
char import_textures_dir[1024];
bool overwrite_textures;
bool import_defined_only;
};
/* The USD_export takes a as_background_job parameter, and returns a boolean.