[Bf-blender-cvs] [2c048f117a1] usd-importer-T81257: USD importer Purpose parameters.
makowalski
noreply at git.blender.org
Sun Dec 27 22:18:14 CET 2020
Commit: 2c048f117a1691cb7642285f94ed430e4026d5ec
Author: makowalski
Date: Sun Dec 27 13:14:32 2020 -0500
Branches: usd-importer-T81257
https://developer.blender.org/rB2c048f117a1691cb7642285f94ed430e4026d5ec
USD importer Purpose parameters.
Added logic to prune prims by purpose. UI now has
toggles to enable importing guide, proxy and render
purpose geometry. Minor format fix.
===================================================================
M source/blender/editors/io/io_usd.c
M source/blender/io/usd/import/usd_prim_iterator.cc
M source/blender/io/usd/import/usd_prim_iterator.h
M source/blender/io/usd/intern/usd_capi.cc
M source/blender/io/usd/usd.h
===================================================================
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 89a5fe5149a..acc6f3a1b25 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -286,6 +286,10 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence");
const bool transform_constraint = RNA_boolean_get(op->ptr, "transform_constraint");
+ const bool import_guide = RNA_boolean_get(op->ptr, "import_guide");
+ const bool import_proxy = RNA_boolean_get(op->ptr, "import_proxy");
+ const bool import_render = RNA_boolean_get(op->ptr, "import_render");
+
/* Switch out of edit mode to avoid being stuck in it (T54326). */
Object *obedit = CTX_data_edit_object(C);
if (obedit) {
@@ -301,7 +305,10 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
light_intensity_scale,
import_usdpreview,
is_sequence,
- transform_constraint};
+ transform_constraint,
+ import_guide,
+ import_proxy,
+ import_render};
bool ok = USD_import(C, filename, ¶ms, as_background_job);
@@ -332,6 +339,12 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
uiItemR(box, ptr, "is_sequence", 0, NULL, ICON_NONE);
uiItemR(box, ptr, "transform_constraint", 0, NULL, ICON_NONE);
+ box = uiLayoutBox(layout);
+ uiItemL(box, IFACE_("Purpose"), ICON_NONE);
+ uiItemR(box, ptr, "import_guide", 0, NULL, ICON_NONE);
+ uiItemR(box, ptr, "import_proxy", 0, NULL, ICON_NONE);
+ uiItemR(box, ptr, "import_render", 0, NULL, ICON_NONE);
+
box = uiLayoutBox(layout);
uiItemL(box, IFACE_("Experimental"), ICON_NONE);
uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE);
@@ -417,6 +430,13 @@ void WM_OT_usd_import(wmOperatorType *ot)
"Transform Cache Constraint",
"When checked, create transform cache constraints for objects that have "
"time-varying transforms");
+
+ RNA_def_boolean(ot->srna, "import_guide", false, "Guide", "When checked, import guide geometry");
+
+ RNA_def_boolean(ot->srna, "import_proxy", true, "Proxy", "When checked, import proxy geometry");
+
+ RNA_def_boolean(
+ ot->srna, "import_render", true, "Render", "When checked, import final render geometry");
}
#endif /* WITH_USD */
diff --git a/source/blender/io/usd/import/usd_prim_iterator.cc b/source/blender/io/usd/import/usd_prim_iterator.cc
index 398b330e91d..55ef183f927 100644
--- a/source/blender/io/usd/import/usd_prim_iterator.cc
+++ b/source/blender/io/usd/import/usd_prim_iterator.cc
@@ -145,6 +145,33 @@ USDXformableReader *USDPrimIterator::get_object_reader(const pxr::UsdPrim &prim,
return result;
}
+/* Returns true if the given prim should be excluded from the
+ * traversal because it has a purpose which was not requested
+ * by the user; e.g., the prim represents guide geometry and
+ * the import_guide parameter is toggled off. */
+bool USDPrimIterator::filter_by_purpose(const pxr::UsdPrim &prim,
+ const USDImporterContext &context)
+{
+ if (!prim.IsPseudoRoot() && prim.IsA<pxr::UsdGeomImageable>() &&
+ !(context.import_params.import_guide && context.import_params.import_proxy &&
+ context.import_params.import_render)) {
+ pxr::UsdGeomImageable imageable(prim);
+ if (imageable) {
+ if (pxr::UsdAttribute purpose_attr = imageable.GetPurposeAttr()) {
+ pxr::TfToken purpose;
+ purpose_attr.Get(&purpose);
+ if ((!context.import_params.import_guide && purpose == pxr::UsdGeomTokens->guide) ||
+ (!context.import_params.import_proxy && purpose == pxr::UsdGeomTokens->proxy) ||
+ (!context.import_params.import_render && purpose == pxr::UsdGeomTokens->proxy)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+}
+
void USDPrimIterator::create_object_readers(const pxr::UsdPrim &prim,
const USDImporterContext &context,
std::vector<USDXformableReader *> &r_readers,
@@ -154,6 +181,19 @@ void USDPrimIterator::create_object_readers(const pxr::UsdPrim &prim,
return;
}
+ if (filter_by_purpose(prim, context)) {
+ // This prim has a purpose that was not requested
+ // by the user, so we skip it.
+ //
+ // TODO(makowalski): Here it's assumed that all the
+ // child prims should be pruned as well. Verify
+ // that this is correct; i.e., should we account
+ // for the possibility that a child prim might not
+ // inherit purpose and therefore shouldn't necessarily
+ // be pruned?
+ return;
+ }
+
std::vector<USDXformableReader *> child_readers;
/* Recursively create readers for the child prims. */
diff --git a/source/blender/io/usd/import/usd_prim_iterator.h b/source/blender/io/usd/import/usd_prim_iterator.h
index 2cdd361381e..8fd7d8a290f 100644
--- a/source/blender/io/usd/import/usd_prim_iterator.h
+++ b/source/blender/io/usd/import/usd_prim_iterator.h
@@ -67,6 +67,8 @@ class USDPrimIterator {
static USDXformableReader *get_object_reader(const pxr::UsdPrim &prim,
const USDImporterContext &context);
+ static bool filter_by_purpose(const pxr::UsdPrim &prim, const USDImporterContext &context);
+
static void create_object_readers(const pxr::UsdPrim &root,
const USDImporterContext &context,
std::vector<USDXformableReader *> &r_readers,
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc
index 7001e7d26ac..17101e670b7 100644
--- a/source/blender/io/usd/intern/usd_capi.cc
+++ b/source/blender/io/usd/intern/usd_capi.cc
@@ -447,8 +447,9 @@ static void import_endjob(void *user_data)
DEG_id_tag_update(&data->scene->id, ID_RECALC_BASE_FLAGS);
DEG_relations_tag_update(data->bmain);
- //if (data->is_background_job) {
- // /* Blender already returned from the import operator, so we need to store our own extra undo
+ // if (data->is_background_job) {
+ // /* Blender already returned from the import operator, so we need to store our own extra
+ // undo
// * step. */
// ED_undo_push(data->C, "USD Import Finished");
//}
diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h
index 1ca1358d344..c8387e32c9d 100644
--- a/source/blender/io/usd/usd.h
+++ b/source/blender/io/usd/usd.h
@@ -69,6 +69,9 @@ struct USDImportParams {
bool import_usdpreview;
bool is_sequence;
bool transform_constraint;
+ bool import_guide;
+ bool import_proxy;
+ bool import_render;
};
/* The USD_import function takes a as_background_job parameter, and returns a boolean.
More information about the Bf-blender-cvs
mailing list