[Bf-blender-cvs] [90e1c892b7a] universal-scene-description: USD Export: Save Blender file path to metadata.

Michael Kowalski noreply at git.blender.org
Tue Sep 27 00:21:14 CEST 2022


Commit: 90e1c892b7a1cc80de05260e7a71e2d2916ecb4d
Author: Michael Kowalski
Date:   Mon Sep 19 16:03:11 2022 -0400
Branches: universal-scene-description
https://developer.blender.org/rB90e1c892b7a1cc80de05260e7a71e2d2916ecb4d

USD Export: Save Blender file path to metadata.

Write source Blender file path to stage customData.

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

M	source/blender/editors/io/io_usd.c
M	source/blender/io/usd/intern/usd_capi_export.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 924a4b18619..09d796fc315 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -303,6 +303,8 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
 
   const bool export_blendshapes = RNA_boolean_get(op->ptr, "export_blendshapes");
 
+  const bool export_blender_metadata = RNA_boolean_get(op->ptr, "export_blender_metadata");
+
   struct USDExportParams params = {RNA_int_get(op->ptr, "start"),
                                    RNA_int_get(op->ptr, "end"),
                                    export_animation,
@@ -359,7 +361,8 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
                                    xform_op_mode,
                                    fix_skel_root,
                                    overwrite_textures,
-                                   export_blendshapes};
+                                   export_blendshapes,
+                                   export_blender_metadata};
 
   /* Take some defaults from the scene, if not specified explicitly. */
   Scene *scene = CTX_data_scene(C);
@@ -424,6 +427,7 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op)
 
   box = uiLayoutBox(layout);
   uiItemL(box, IFACE_("Attributes:"), ICON_NONE);
+  uiItemR(box, ptr, "export_blender_metadata", 0, NULL, ICON_NONE);
   uiItemR(box, ptr, "export_custom_properties", 0, NULL, ICON_NONE);
   if (RNA_boolean_get(ptr, "export_custom_properties")) {
     uiItemR(box, ptr, "add_properties_namespace", 0, NULL, ICON_NONE);
@@ -517,6 +521,7 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op)
   uiItemL(box, IFACE_("Experimental:"), ICON_NONE);
   uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE);
   uiItemR(box, ptr, "fix_skel_root", 0, NULL, ICON_NONE);
+
 }
 
 static bool wm_usd_export_check(bContext *UNUSED(C), wmOperator *op)
@@ -915,6 +920,12 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
                   "Relative Paths",
                   "Use relative paths to reference external files (i.e. textures, volumes) in "
                   "USD, otherwise use absolute paths");
+
+  RNA_def_boolean(ot->srna,
+                  "export_blender_metadata",
+                  true,
+                  "Export Blender Metadata",
+                  "Write Blender-specific information to the Stage's customLayerData");
 }
 
 /* ====== USD Import ====== */
diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc
index 645b4b12a5e..d7f719e114b 100644
--- a/source/blender/io/usd/intern/usd_capi_export.cc
+++ b/source/blender/io/usd/intern/usd_capi_export.cc
@@ -288,6 +288,25 @@ static void export_startjob(void *customdata,
   usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender v") +
                                               BKE_blender_version_string());
 
+  /* Add any Blender-specific custom export data */
+  if (data->params.export_blender_metadata && strlen(data->bmain->filepath)) {
+    auto root_layer = usd_stage->GetRootLayer();
+    char full_path[1024];
+    strcpy(full_path, data->bmain->filepath);
+
+    // make all paths uniformly unix-like
+    BLI_str_replace_char(full_path + 2, SEP, ALTSEP);
+
+    char basename[128];
+    strcpy(basename, BLI_path_basename(full_path));
+    BLI_split_dir_part(full_path, full_path, 1024);
+
+    pxr::VtDictionary custom_data;
+    custom_data.SetValueAtPath(std::string("sourceFilename"), pxr::VtValue(basename));
+    custom_data.SetValueAtPath(std::string("sourceDirPath"), pxr::VtValue(full_path));
+    root_layer->SetCustomLayerData(custom_data);
+  }
+
   /* Set up the stage for animated data. */
   if (data->params.export_animation) {
     usd_stage->SetTimeCodesPerSecond(FPS);
diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h
index 3829bbda8f4..0f32968705e 100644
--- a/source/blender/io/usd/usd.h
+++ b/source/blender/io/usd/usd.h
@@ -121,6 +121,7 @@ struct USDExportParams {
   bool fix_skel_root;
   bool overwrite_textures;
   bool export_blendshapes;
+  bool export_blender_metadata;
 };
 
 struct USDImportParams {



More information about the Bf-blender-cvs mailing list