[Bf-blender-cvs] [f42ca488d27] universal-scene-description: USD IO options improvements

Michael Kowalski noreply at git.blender.org
Fri Sep 24 20:13:51 CEST 2021


Commit: f42ca488d274985b49359119c47536c3e0dff114
Author: Michael Kowalski
Date:   Thu Sep 23 17:25:46 2021 -0400
Branches: universal-scene-description
https://developer.blender.org/rBf42ca488d274985b49359119c47536c3e0dff114

USD IO options improvements

Added default values for the Default Prim Path,
Root Prim Path and Material Prim Path export
options. Now validating that these options are
set to well formed USD paths and raising an
error if these paths are invalid. This helps avoid
potential crashes when attempting to define
USD prims with invalid paths. Also updated import
shaders option menu tooltip.

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

M	source/blender/editors/io/io_usd.c
M	source/blender/io/usd/intern/usd_capi_export.cc

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

diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 7fd550a1254..6e34a9082f0 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -85,7 +85,7 @@ const EnumPropertyItem rna_enum_usd_import_shaders_mode_items[] = {
      "USD MDL",
      0,
      "MDL",
-     "Convert USD Preview Surface shaders to Blender Principled BSDF"},
+     "Convert MDL shaders to Blender materials"},
     {0, NULL, 0, NULL, NULL},
 };
 
@@ -262,6 +262,8 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
 
   char *material_prim_path = RNA_string_get_alloc(op->ptr, "material_prim_path", NULL, 0, NULL);
 
+  material_prim_path = usd_ensure_prim_path(material_prim_path);
+
   int global_forward = RNA_enum_get(op->ptr, "export_global_forward_selection");
   int global_up = RNA_enum_get(op->ptr, "export_global_up_selection");
 
@@ -626,19 +628,19 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
 
   RNA_def_string(ot->srna,
                  "default_prim_path",
-                 NULL,
+                 "/root",
                  1024,
                  "Default Prim Path",
                  "If set, this will set the default prim path in the usd document");
   RNA_def_string(ot->srna,
                  "root_prim_path",
-                 NULL,
+                 "/root",
                  1024,
                  "Root Prim Path",
                  "If set, all primitives will live under this path");
   RNA_def_string(ot->srna,
                  "material_prim_path",
-                 "/materials",
+                 "/root/materials",
                  1024,
                  "Material Prim Path",
                  "This specifies where all generated USD Shade Materials and Shaders get placed");
diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc
index 968d95a853a..8318b33f7e3 100644
--- a/source/blender/io/usd/intern/usd_capi_export.cc
+++ b/source/blender/io/usd/intern/usd_capi_export.cc
@@ -76,6 +76,33 @@ struct ExportJobData {
   bool export_ok;
 };
 
+/* Perform validation of export parameter settings. Returns
+ * true if the paramters are valid.  Returns false otherwise. */
+static bool validate_params(const USDExportParams &params)
+{
+  bool valid = true;
+
+  if (params.export_materials && !pxr::SdfPath::IsValidPathString(params.material_prim_path)) {
+    WM_reportf(RPT_ERROR,
+      "USD Export: invalid material prim path parameter '%s'", params.material_prim_path);
+    valid = false;
+  }
+
+  if (strlen(params.root_prim_path) != 0 && !pxr::SdfPath::IsValidPathString(params.root_prim_path)) {
+    WM_reportf(RPT_ERROR,
+      "USD Export: invalid root prim path parameter '%s'", params.root_prim_path);
+    valid = false;
+  }
+
+  if (strlen(params.default_prim_path) != 0 && !pxr::SdfPath::IsValidPathString(params.default_prim_path)) {
+    WM_reportf(RPT_ERROR,
+      "USD Export: invalid default prim path parameter '%s'", params.default_prim_path);
+    valid = false;
+  }
+
+  return valid;
+}
+
 /* Create root prim if defined. */
 static void ensure_root_prim(pxr::UsdStageRefPtr stage, const USDExportParams &params)
 {
@@ -138,6 +165,11 @@ static void export_startjob(void *customdata,
   WM_set_locked_interface(data->wm, true);
   G.is_break = false;
 
+  if (!validate_params(data->params)) {
+    data->export_ok = false;
+    return;
+  }
+
   /* Construct the depsgraph for exporting. */
   Scene *scene = DEG_get_input_scene(data->depsgraph);
   if (data->params.visible_objects_only) {
@@ -182,10 +214,13 @@ static void export_startjob(void *customdata,
     world_material_to_dome_light(data->params, scene, usd_stage);
   }
 
-  // Define material prim path as a scope
-  if (data->params.export_materials)
+  /* Define the material prim path as a scope. */
+  if (data->params.export_materials) {
+    pxr::SdfPath mtl_prim_path(data->params.material_prim_path);
+
     blender::io::usd::usd_define_or_over<pxr::UsdGeomScope>(
-        usd_stage, pxr::SdfPath(data->params.material_prim_path), data->params.export_as_overs);
+      usd_stage, mtl_prim_path, data->params.export_as_overs);
+  }
 
   pxr::VtValue upAxis = pxr::VtValue(pxr::UsdGeomTokens->z);
   if (data->params.convert_orientation) {



More information about the Bf-blender-cvs mailing list