Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakowalski <makowalski@nvidia.com>2021-02-11 02:10:31 +0300
committermakowalski <makowalski@nvidia.com>2021-02-11 02:10:31 +0300
commit57c32a52488c6265a4bc04467c3e64ddf449fe0e (patch)
tree9c43c0fd7c56ee4273c67731128eeda284d1b955
parent63adcda7da073abcb0bb2a78921417a12afceb19 (diff)
USD Import: Visible Prims Only flag.
Added new option to prune primitives by visibility. If this option is enabled, invisible prims will be excluded from the traversal. This only applies to prims with a non-animating visibility attribute. Prims with animating visibility will always be imported.
-rw-r--r--source/blender/editors/io/io_usd.c14
-rw-r--r--source/blender/io/usd/intern/usd_reader_stage.cc60
-rw-r--r--source/blender/io/usd/usd.h1
3 files changed, 58 insertions, 17 deletions
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 7bb149b1e7b..068def29f70 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -300,6 +300,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
const bool import_instance_proxies = RNA_boolean_get(op->ptr, "import_instance_proxies");
+ const bool import_visible_only = RNA_boolean_get(op->ptr, "import_visible_only");
+
const bool create_collection = RNA_boolean_get(op->ptr, "create_collection");
char *prim_path_mask = malloc(1024);
@@ -349,6 +351,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
import_guide,
import_proxy,
import_render,
+ import_visible_only,
};
bool ok = USD_import(C, filename, &params, as_background_job);
@@ -404,6 +407,9 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
uiItemR(row, ptr, "import_instance_proxies", 0, NULL, ICON_NONE);
row = uiLayoutRow(box, false);
+ uiItemR(row, ptr, "import_visible_only", 0, NULL, ICON_NONE);
+
+ row = uiLayoutRow(box, false);
uiItemR(row, ptr, "create_collection", 0, NULL, ICON_NONE);
// row = uiLayoutRow(box, false);
@@ -536,6 +542,14 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
"creating a unique Blender object for each instance");
RNA_def_boolean(ot->srna,
+ "import_visible_only",
+ true,
+ "Visible Prims Only",
+ "If enabled, invisible USD prims won't be imported. "
+ "Only applies to prims with a non-animating visibility attribute. "
+ "Prims with animating visibility will always be imported");
+
+ RNA_def_boolean(ot->srna,
"create_collection",
false,
"Create Collection",
diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc
index bb5511c1c80..8c6023d4805 100644
--- a/source/blender/io/usd/intern/usd_reader_stage.cc
+++ b/source/blender/io/usd/intern/usd_reader_stage.cc
@@ -72,26 +72,44 @@ bool USDStageReader::valid() const
return true;
}
+
+/* Returns true if the given prim should be excluded from the
+ * traversal because it's invisible. */
+bool _prune_by_visibility(const pxr::UsdGeomImageable &imageable,
+ const USDImportParams &params)
+{
+ if (imageable && params.import_visible_only) {
+ if (pxr::UsdAttribute visibility_attr = imageable.GetVisibilityAttr()) {
+
+ // Prune if the prim has a non-animating visibility attribute and is
+ // invisible.
+ if (!visibility_attr.ValueMightBeTimeVarying()) {
+ pxr::TfToken visibility;
+ visibility_attr.Get(&visibility);
+ return visibility == pxr::UsdGeomTokens->invisible;
+ }
+ }
+ }
+
+ return false;
+}
+
+
/* 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 _filter_by_purpose(const pxr::UsdPrim &prim,
- const USDImportParams &params)
+bool _prune_by_purpose(const pxr::UsdGeomImageable &imageable,
+ const USDImportParams &params)
{
- if (prim.IsA<pxr::UsdGeomImageable>() &&
- !(params.import_guide && params.import_proxy && params.import_render)) {
-
- pxr::UsdGeomImageable imageable(prim);
- if (imageable) {
- if (pxr::UsdAttribute purpose_attr = imageable.GetPurposeAttr()) {
- pxr::TfToken purpose;
- purpose_attr.Get(&purpose);
- if ((!params.import_guide && purpose == pxr::UsdGeomTokens->guide) ||
- (!params.import_proxy && purpose == pxr::UsdGeomTokens->proxy) ||
- (!params.import_render && purpose == pxr::UsdGeomTokens->render)) {
- return true;
- }
+ if (imageable && !(params.import_guide && params.import_proxy && params.import_render)) {
+ if (pxr::UsdAttribute purpose_attr = imageable.GetPurposeAttr()) {
+ pxr::TfToken purpose;
+ purpose_attr.Get(&purpose);
+ if ((!params.import_guide && purpose == pxr::UsdGeomTokens->guide) ||
+ (!params.import_proxy && purpose == pxr::UsdGeomTokens->proxy) ||
+ (!params.import_render && purpose == pxr::UsdGeomTokens->render)) {
+ return true;
}
}
}
@@ -107,8 +125,16 @@ static USDPrimReader *_handlePrim(Main *bmain,
std::vector<USDPrimReader *> &readers,
ImportSettings &settings)
{
- if (_filter_by_purpose(prim, params)) {
- return false;
+ if (prim.IsA<pxr::UsdGeomImageable>()) {
+ pxr::UsdGeomImageable imageable(prim);
+
+ if (_prune_by_purpose(imageable, params)) {
+ return nullptr;
+ }
+
+ if (_prune_by_visibility(imageable, params)) {
+ return nullptr;
+ }
}
USDPrimReader *reader = NULL;
diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h
index a7275fae33e..edf55f3700d 100644
--- a/source/blender/io/usd/usd.h
+++ b/source/blender/io/usd/usd.h
@@ -66,6 +66,7 @@ struct USDImportParams {
bool import_guide;
bool import_proxy;
bool import_render;
+ bool import_visible_only;
};
/* The USD_export takes a as_background_job parameter, and returns a boolean.