[Bf-blender-cvs] [92565019b0b] usd-importer-T81257-merge: USDStageReader::prune_by_purpose() refactor.

makowalski noreply at git.blender.org
Tue Jun 22 04:13:35 CEST 2021


Commit: 92565019b0b050c0195d843ff44c1ace789820f8
Author: makowalski
Date:   Mon Jun 21 14:28:02 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rB92565019b0b050c0195d843ff44c1ace789820f8

USDStageReader::prune_by_purpose() refactor.

Per suggestion by Sybren in his review, flipped the samanitcs
for prune_by_purpose() to return true=include and false=exclude.
Also simplified the conditional logic to reduce nesting.

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

M	source/blender/io/usd/intern/usd_reader_stage.cc

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

diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc
index 272002498e1..7b69a7e8983 100644
--- a/source/blender/io/usd/intern/usd_reader_stage.cc
+++ b/source/blender/io/usd/intern/usd_reader_stage.cc
@@ -142,37 +142,39 @@ bool USDStageReader::prune_by_visibility(const pxr::UsdGeomImageable &imageable)
   return visibility != pxr::UsdGeomTokens->invisible;
 }
 
-/* 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. */
+/* Returns true if the given prim should be included in the
+ * traversal based on the import options and the prim's purpose
+ * attribute. E.g., return false (to exclude the prim) if the prim
+ * represents guide geometry and the 'Import Guide' option is
+ * toggled off. */
 bool USDStageReader::prune_by_purpose(const pxr::UsdGeomImageable &imageable) const
 {
-  if (!imageable) {
-    return false;
+  if (params_.import_guide && params_.import_proxy && params_.import_render) {
+    /* The options allow any purpose, so we trivially include the prim. */
+    return true;
   }
 
-  if (params_.import_guide && params_.import_proxy && params_.import_render) {
-    return false;
+  pxr::UsdAttribute purpose_attr = imageable.GetPurposeAttr();
+
+  if (!purpose_attr) {
+    /* No purpose attribute, so trivially include the prim. */
+    return true;
   }
 
-  if (pxr::UsdAttribute purpose_attr = imageable.GetPurposeAttr()) {
-    pxr::TfToken purpose;
-    if (!purpose_attr.Get(&purpose)) {
-      return false;
-    }
-    if (purpose == pxr::UsdGeomTokens->guide && !params_.import_guide) {
-      return true;
-    }
-    if (purpose == pxr::UsdGeomTokens->proxy && !params_.import_proxy) {
-      return true;
-    }
-    if (purpose == pxr::UsdGeomTokens->render && !params_.import_render) {
-      return true;
-    }
+  pxr::TfToken purpose;
+  purpose_attr.Get(&purpose);
+
+  if (purpose == pxr::UsdGeomTokens->guide) {
+    return params_.import_guide;
+  }
+  if (purpose == pxr::UsdGeomTokens->proxy) {
+    return params_.import_proxy;
+  }
+  if (purpose == pxr::UsdGeomTokens->render) {
+    return params_.import_render;
   }
 
-  return false;
+  return true;
 }
 
 /* Determine if the given reader can use the parent of the encapsulated USD prim
@@ -218,7 +220,7 @@ USDPrimReader *USDStageReader::collect_readers(Main *bmain, const pxr::UsdPrim &
   if (prim.IsA<pxr::UsdGeomImageable>()) {
     pxr::UsdGeomImageable imageable(prim);
 
-    if (prune_by_purpose(imageable)) {
+    if (!prune_by_purpose(imageable)) {
       return nullptr;
     }



More information about the Bf-blender-cvs mailing list