Commit: 98670cfe8242c4f69dcfbd4cc99dcbfac83fa4b1
Author: Michael Kowalski
Date:   Tue Nov 29 14:18:06 2022 -0500
Branches: universal-scene-description
https://developer.blender.org/rB98670cfe8242c4f69dcfbd4cc99dcbfac83fa4b1

USD import: Defined Primitives Only option.

New option to load defined primitives only. This may be
turned off to allow loading overrides with the Path Mask.

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

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 313e2488ace..e82aefc4383 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -1069,6 +1069,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
 
   const bool import_visible_only = RNA_boolean_get(op->ptr, 
"import_visible_only");
 
+  const bool import_defined_only = RNA_boolean_get(op->ptr, 
"import_defined_only");
+
   const bool create_collection = RNA_boolean_get(op->ptr, "create_collection");
 
   char prim_path_mask[1024];
@@ -1147,7 +1149,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
                                    .create_background_shader = 
create_background_shader,
                                    .mtl_name_collision_mode = 
mtl_name_collision_mode,
                                    .attr_import_mode = attr_import_mode,
-                                   .import_shapes = import_shapes};
+                                   .import_shapes = import_shapes,
+                                   .import_defined_only = import_defined_only};
 
   STRNCPY(params.prim_path_mask, prim_path_mask);
 
@@ -1193,6 +1196,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), 
wmOperator *op)
   uiItemR(col, ptr, "import_subdiv", 0, IFACE_("Subdivision"), ICON_NONE);
   uiItemR(col, ptr, "import_instance_proxies", 0, NULL, ICON_NONE);
   uiItemR(col, ptr, "import_visible_only", 0, NULL, ICON_NONE);
+  uiItemR(col, ptr, "import_defined_only", 0, NULL, ICON_NONE);
   uiItemR(col, ptr, "import_guide", 0, NULL, ICON_NONE);
   uiItemR(col, ptr, "import_proxy", 0, NULL, ICON_NONE);
   uiItemR(col, ptr, "import_render", 0, NULL, ICON_NONE);
@@ -1303,6 +1307,13 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
                   "Only applies to primitives with a non-animated visibility 
attribute. "
                   "Primitives with animated visibility will always be 
imported");
 
+   RNA_def_boolean(ot->srna,
+                  "import_defined_only",
+                  true,
+                  "Defined Primitives Only",
+                  "Turn this off to allow importing USD primitives which are 
not defined, "
+                  "for example, to load overrides with the Path Mask");
+
   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 052b71bfcc5..70ddcb3faa6 100644
--- a/source/blender/io/usd/intern/usd_reader_stage.cc
+++ b/source/blender/io/usd/intern/usd_reader_stage.cc
@@ -287,10 +287,14 @@ USDPrimReader *USDStageReader::collect_readers(Main 
*bmain,
     dome_lights_.push_back(pxr::UsdLuxDomeLight(prim));
   }
 
-  pxr::Usd_PrimFlagsPredicate filter_predicate = pxr::UsdPrimDefaultPredicate;
+  pxr::Usd_PrimFlagsConjunction filter_predicate = pxr::UsdPrimIsActive && 
pxr::UsdPrimIsLoaded &&
+                                                   !pxr::UsdPrimIsAbstract;
+  if (params_.import_defined_only) {
+    filter_predicate &= pxr::UsdPrimIsDefined;
+  }
 
   if (!params_.use_instancing && params_.import_instance_proxies) {
-    filter_predicate = pxr::UsdTraverseInstanceProxies(filter_predicate);
+    filter_predicate.TraverseInstanceProxies(true);
   }
 
   pxr::UsdPrimSiblingRange children = 
prim.GetFilteredChildren(filter_predicate);
diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h
index 88f65c7dfca..e62cf965424 100644
--- a/source/blender/io/usd/usd.h
+++ b/source/blender/io/usd/usd.h
@@ -176,6 +176,7 @@ struct USDImportParams {
   eUSDAttrImportMode attr_import_mode;
   bool triangulate_meshes;
   bool import_shapes;
+  bool import_defined_only;
 };
 
 /* The USD_export takes a as_background_job parameter, and returns a boolean.

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to