[Bf-blender-cvs] [19a7c7f4e17] tmp-dynamic-usd: USD export: added get_textures_dir() utility.

Michael Kowalski noreply at git.blender.org
Tue Nov 29 01:16:47 CET 2022


Commit: 19a7c7f4e17ea7deb547e8122b336a576fb276d1
Author: Michael Kowalski
Date:   Mon Nov 14 20:55:20 2022 -0500
Branches: tmp-dynamic-usd
https://developer.blender.org/rB19a7c7f4e17ea7deb547e8122b336a576fb276d1

USD export: added get_textures_dir() utility.

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

M	source/blender/io/usd/intern/usd_asset_utils.cc
M	source/blender/io/usd/intern/usd_asset_utils.h
M	source/blender/io/usd/intern/usd_writer_material.cc

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

diff --git a/source/blender/io/usd/intern/usd_asset_utils.cc b/source/blender/io/usd/intern/usd_asset_utils.cc
index a01e8ae953f..85cbd4cc85b 100644
--- a/source/blender/io/usd/intern/usd_asset_utils.cc
+++ b/source/blender/io/usd/intern/usd_asset_utils.cc
@@ -7,6 +7,8 @@
 #include <pxr/usd/ar/resolver.h>
 #include <pxr/usd/ar/writableAsset.h>
 
+#include "BLI_path_util.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -110,5 +112,18 @@ bool copy_usd_asset(const char *src, const char *dst, bool overwrite)
   return bytes_written > 0;
 }
 
+ std::string get_textures_dir(const pxr::UsdStageRefPtr stage)
+{
+   pxr::SdfLayerHandle layer = stage->GetRootLayer();
+   std::string stage_path = layer->GetRealPath();
+   if (stage_path.empty()) {
+     return "";
+   }
+
+   char usd_dir_path[FILE_MAX];
+   BLI_split_dir_part(stage_path.c_str(), usd_dir_path, FILE_MAX);
+
+   return std::string(usd_dir_path) + std::string("textures/");
+ }
 
 }  // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_asset_utils.h b/source/blender/io/usd/intern/usd_asset_utils.h
index 1a4fe83c59d..aeefde3a859 100644
--- a/source/blender/io/usd/intern/usd_asset_utils.h
+++ b/source/blender/io/usd/intern/usd_asset_utils.h
@@ -2,9 +2,17 @@
  * Copyright 2021  NVIDIA Corporation. All rights reserved. */
 #pragma once
 
+#include <pxr/usd/usd/stage.h>
+
+#include <string>
+
 namespace blender::io::usd {
 
   /* Invoke the the USD asset resolver to copy assets. */
   bool copy_usd_asset(const char *src, const char *dst, bool overwrite);
 
+  /* Return the path to a 'textures' directory which is a sibling to the given
+   * stage's root layer path. */
+  std::string get_textures_dir(const pxr::UsdStageRefPtr stage);
+
 }  // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc
index 39d56e6cb44..52035df6f3e 100644
--- a/source/blender/io/usd/intern/usd_writer_material.cc
+++ b/source/blender/io/usd/intern/usd_writer_material.cc
@@ -3,6 +3,7 @@
 #include "usd_writer_material.h"
 
 #include "usd.h"
+#include "usd_asset_utils.h"
 #include "usd_exporter_context.h"
 #include "usd_umm.h"
 
@@ -2392,21 +2393,7 @@ void export_texture(bNode *node,
     return;
   }
 
-  pxr::SdfLayerHandle layer = stage->GetRootLayer();
-  std::string stage_path = layer->GetRealPath();
-  if (stage_path.empty()) {
-    return;
-  }
-
-  char usd_dir_path[FILE_MAX];
-  BLI_split_dir_part(stage_path.c_str(), usd_dir_path, FILE_MAX);
-
-  char tex_dir_path[FILE_MAX];
-  BLI_path_join(tex_dir_path, FILE_MAX, usd_dir_path, "textures", SEP_STR);
-
-  BLI_dir_create_recursive(tex_dir_path);
-
-  std::string dest_dir(tex_dir_path);
+  std::string dest_dir = get_textures_dir(stage);
 
   if (is_in_memory_texture(ima)) {
     export_in_memory_texture(ima, dest_dir, allow_overwrite);



More information about the Bf-blender-cvs mailing list