[Bf-blender-cvs] [64ee14d4523] usd-importer-T81257-merge: Added USDStageReader::handle_prim() function.

makowalski noreply at git.blender.org
Fri Jun 18 03:43:34 CEST 2021


Commit: 64ee14d4523abc553d424aa5acff75a532c791b6
Author: makowalski
Date:   Thu Jun 17 21:32:42 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rB64ee14d4523abc553d424aa5acff75a532c791b6

Added USDStageReader::handle_prim() function.

Per suggestion by Sybren in his review, moved code from
the static _handlePrim() function to a USDStageReader private
member function.  This helps simplify the code as the new
function requires fewer argumants.  Also performed minor
cleanup of the function implementation.

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

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

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

diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc
index c0e4b29f416..c0b772681d7 100644
--- a/source/blender/io/usd/intern/usd_reader_stage.cc
+++ b/source/blender/io/usd/intern/usd_reader_stage.cc
@@ -214,28 +214,23 @@ static bool _merge_with_parent(USDPrimReader *reader)
   return true;
 }
 
-static USDPrimReader *_handlePrim(Main *bmain,
-                                  pxr::UsdStageRefPtr stage,
-                                  const USDImportParams &params,
-                                  pxr::UsdPrim prim,
-                                  std::vector<USDPrimReader *> &readers,
-                                  const ImportSettings &settings)
+USDPrimReader *USDStageReader::handle_prim(Main *bmain, const pxr::UsdPrim &prim)
 {
   if (prim.IsA<pxr::UsdGeomImageable>()) {
     pxr::UsdGeomImageable imageable(prim);
 
-    if (_prune_by_purpose(imageable, params)) {
+    if (_prune_by_purpose(imageable, params_)) {
       return nullptr;
     }
 
-    if (_prune_by_visibility(imageable, params)) {
+    if (_prune_by_visibility(imageable, params_)) {
       return nullptr;
     }
   }
 
   pxr::Usd_PrimFlagsPredicate filter_predicate = pxr::UsdPrimDefaultPredicate;
 
-  if (params.import_instance_proxies) {
+  if (params_.import_instance_proxies) {
     filter_predicate = pxr::UsdTraverseInstanceProxies(filter_predicate);
   }
 
@@ -244,12 +239,15 @@ static USDPrimReader *_handlePrim(Main *bmain,
   std::vector<USDPrimReader *> child_readers;
 
   for (const auto &childPrim : children) {
-    USDPrimReader *child_reader = _handlePrim(bmain, stage, params, childPrim, readers, settings);
-    if (child_reader) {
+    if (USDPrimReader *child_reader = handle_prim(bmain, childPrim)) {
       child_readers.push_back(child_reader);
     }
   }
 
+  if (prim.IsPseudoRoot()) {
+    return nullptr;
+  }
+
   /* Check if we can merge an Xform with its child prim. */
   if (child_readers.size() == 1) {
 
@@ -260,24 +258,20 @@ static USDPrimReader *_handlePrim(Main *bmain,
     }
   }
 
-  USDPrimReader *reader = nullptr;
-
-  if (!prim.IsPseudoRoot()) {
-    reader = USDStageReader::create_reader(prim, params, settings);
+  USDPrimReader *reader = USDStageReader::create_reader(prim, params_, settings_);
 
-    if (reader == nullptr) {
-      return nullptr;
-    }
+  if (!reader) {
+    return nullptr;
+  }
 
-    reader->create_object(bmain, 0.0);
+  reader->create_object(bmain, 0.0);
 
-    readers.push_back(reader);
-    reader->incref();
+  readers_.push_back(reader);
+  reader->incref();
 
-    /* Set each child reader's parent. */
-    for (USDPrimReader *child_reader : child_readers) {
-      child_reader->parent(reader);
-    }
+  /* Set each child reader's parent. */
+  for (USDPrimReader *child_reader : child_readers) {
+    child_reader->parent(reader);
   }
 
   return reader;
@@ -315,7 +309,7 @@ void USDStageReader::collect_readers(Main *bmain,
   }
 
   stage_->SetInterpolationType(pxr::UsdInterpolationType::UsdInterpolationTypeHeld);
-  _handlePrim(bmain, stage_, params, root, readers_, settings);
+  handle_prim(bmain, root);
 }
 
 void USDStageReader::clear_readers(bool decref)
diff --git a/source/blender/io/usd/intern/usd_reader_stage.h b/source/blender/io/usd/intern/usd_reader_stage.h
index f3e79ab5867..159b7429834 100644
--- a/source/blender/io/usd/intern/usd_reader_stage.h
+++ b/source/blender/io/usd/intern/usd_reader_stage.h
@@ -93,6 +93,9 @@ class USDStageReader {
   {
     return readers_;
   };
+
+ private:
+  USDPrimReader *handle_prim(Main *bmain, const pxr::UsdPrim &prim);
 };
 
 };  // namespace blender::io::usd



More information about the Bf-blender-cvs mailing list