[Bf-blender-cvs] [b8e64404305] tmp-dynamic-usd: USD export: copy textures with asset resolver.
Michael Kowalski
noreply at git.blender.org
Tue Nov 29 01:16:48 CET 2022
Commit: b8e6440430580ff79ff97738989ecfa59c5c013b
Author: Michael Kowalski
Date: Tue Nov 15 15:44:49 2022 -0500
Branches: tmp-dynamic-usd
https://developer.blender.org/rBb8e6440430580ff79ff97738989ecfa59c5c013b
USD export: copy textures with asset resolver.
Refactored the texture export code to copy the texture
by invoking the asset resolver.
===================================================================
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_common.cc
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 85cbd4cc85b..c2aa0d142ab 100644
--- a/source/blender/io/usd/intern/usd_asset_utils.cc
+++ b/source/blender/io/usd/intern/usd_asset_utils.cc
@@ -8,6 +8,7 @@
#include <pxr/usd/ar/writableAsset.h>
#include "BLI_path_util.h"
+#include "BLI_string.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -126,4 +127,22 @@ bool copy_usd_asset(const char *src, const char *dst, bool overwrite)
return std::string(usd_dir_path) + std::string("textures/");
}
+ bool usd_path_exists(const char *src)
+ {
+ return src && !pxr::ArGetResolver().Resolve(src).IsEmpty();
+ }
+
+ bool usd_paths_equal(const char *p1, const char *p2)
+ {
+ BLI_assert_msg(!BLI_path_is_rel(p1) && !BLI_path_is_rel(p2),
+ "Paths arguments must be absolute");
+
+ pxr::ArResolver &ar = pxr::ArGetResolver();
+
+ std::string resolved_p1 = ar.ResolveForNewAsset(p1).GetPathString();
+ std::string resolved_p2 = ar.ResolveForNewAsset(p2).GetPathString();
+
+ return resolved_p1 == resolved_p2;
+ }
+
} // 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 aeefde3a859..fecc1bc6572 100644
--- a/source/blender/io/usd/intern/usd_asset_utils.h
+++ b/source/blender/io/usd/intern/usd_asset_utils.h
@@ -15,4 +15,8 @@ namespace blender::io::usd {
* stage's root layer path. */
std::string get_textures_dir(const pxr::UsdStageRefPtr stage);
+ bool usd_path_exists(const char *src);
+
+ bool usd_paths_equal(const char *p1, const char *p2);
+
} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_common.cc b/source/blender/io/usd/intern/usd_common.cc
index bdb4212ece9..4c0e7db90cb 100644
--- a/source/blender/io/usd/intern/usd_common.cc
+++ b/source/blender/io/usd/intern/usd_common.cc
@@ -57,6 +57,8 @@ void USD_path_abs(char *path, const char *basepath, bool for_import)
if (!path_str.empty()) {
if (path_str.length() < FILE_MAX) {
BLI_strncpy(path, path_str.c_str(), FILE_MAX);
+ /* Use forward slash separators, which is standard for USD. */
+ BLI_str_replace_char(path, SEP, ALTSEP);
}
else {
WM_reportf(RPT_ERROR,
diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc
index 52035df6f3e..a471a9bad57 100644
--- a/source/blender/io/usd/intern/usd_writer_material.cc
+++ b/source/blender/io/usd/intern/usd_writer_material.cc
@@ -445,8 +445,7 @@ static void get_absolute_path(Image *ima, char *r_path)
{
/* Make absolute source path. */
BLI_strncpy(r_path, ima->filepath, FILE_MAX);
- BLI_path_abs(r_path, ID_BLEND_PATH_FROM_GLOBAL(&ima->id));
- BLI_path_normalize(nullptr, r_path);
+ USD_path_abs(r_path, ID_BLEND_PATH_FROM_GLOBAL(&ima->id), false /* Not for import */);
}
/* ===== Functions copied from inacessible source file
@@ -2358,20 +2357,19 @@ static void copy_single_file(Image *ima, const std::string &dest_dir, const bool
char dest_path[FILE_MAX];
BLI_path_join(dest_path, FILE_MAX, dest_dir.c_str(), file_name);
+ BLI_str_replace_char(dest_path, SEP, ALTSEP);
- if (!allow_overwrite && BLI_exists(dest_path)) {
+ if (!allow_overwrite && usd_path_exists(dest_path)) {
return;
}
- if (BLI_path_cmp_normalized(source_path, dest_path) == 0) {
+ if (usd_paths_equal(source_path, dest_path)) {
/* Source and destination paths are the same, don't copy. */
return;
}
- std::cout << "Copying texture from " << source_path << " to " << dest_path << std::endl;
-
/* Copy the file. */
- if (BLI_copy(source_path, dest_path) != 0) {
+ if (!copy_usd_asset(source_path, dest_path, allow_overwrite)) {
WM_reportf(
RPT_WARNING, "USD export: couldn't copy texture from %s to %s", source_path, dest_path);
}
More information about the Bf-blender-cvs
mailing list