[Bf-blender-cvs] [57c32a52488] usd-importer-T81257-merge: USD Import: Visible Prims Only flag.

makowalski noreply at git.blender.org
Thu Feb 11 00:22:45 CET 2021


Commit: 57c32a52488c6265a4bc04467c3e64ddf449fe0e
Author: makowalski
Date:   Wed Feb 10 18:10:31 2021 -0500
Branches: usd-importer-T81257-merge
https://developer.blender.org/rB57c32a52488c6265a4bc04467c3e64ddf449fe0e

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.

===================================================================

M	source/blender/editors/io/io_usd.c
M	source/blender/io/usd/intern/usd_reader_stage.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 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);
@@ -403,6 +406,9 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
   row = uiLayoutRow(box, false);
   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);
 
@@ -535,6 +541,14 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
                   "If enabled, USD instances will be traversed with instance proxies, "
                   "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,
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.



More information about the Bf-blender-cvs mailing list