[Bf-blender-cvs] [4ab6ee68ab0] tmp-dynamic-usd: USD IO: function to resolve USD paths.
Michael Kowalski
noreply at git.blender.org
Tue Nov 29 01:16:47 CET 2022
Commit: 4ab6ee68ab09635d4065fb25f6d26c896942a35a
Author: Michael Kowalski
Date: Thu Nov 10 13:41:56 2022 -0500
Branches: tmp-dynamic-usd
https://developer.blender.org/rB4ab6ee68ab09635d4065fb25f6d26c896942a35a
USD IO: function to resolve USD paths.
Added USD_path_abs() funcion, which is similar to BLI_path_abs(),
but which also invokes the USD asset resolver to determine the
absolute path. This is necessary for resolving paths with URIs
that BLI_path_abs() would otherwise alter when attempting to
normalize the path. Now calling USD_path_abs() where needed
to resolve USD paths for import.
===================================================================
M source/blender/blenkernel/intern/cachefile.c
M source/blender/io/usd/intern/usd_capi_import.cc
M source/blender/io/usd/intern/usd_common.cc
M source/blender/io/usd/usd.h
===================================================================
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 5968a6b7296..b81d2c90502 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -387,7 +387,17 @@ bool BKE_cachefile_filepath_get(const Main *bmain,
char r_filepath[FILE_MAX])
{
BLI_strncpy(r_filepath, cache_file->filepath, FILE_MAX);
+
+#ifdef WITH_USD
+ if (BLI_path_extension_check_glob(r_filepath, "*.usd;*.usda;*.usdc;*.usdz")) {
+ USD_path_abs(r_filepath, ID_BLEND_PATH(bmain, &cache_file->id), true /* for import */);
+ }
+ else {
+ BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, &cache_file->id));
+ }
+#else
BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, &cache_file->id));
+#endif
int fframe;
int frame_len;
diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc
index ca518249c91..8e597550a51 100644
--- a/source/blender/io/usd/intern/usd_capi_import.cc
+++ b/source/blender/io/usd/intern/usd_capi_import.cc
@@ -369,7 +369,7 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float
data->view_layer, import_collection);
}
- BLI_path_abs(data->filepath, BKE_main_blendfile_path_from_global());
+ USD_path_abs(data->filepath, BKE_main_blendfile_path_from_global(), true);
*data->do_update = true;
*data->progress = 0.05f;
diff --git a/source/blender/io/usd/intern/usd_common.cc b/source/blender/io/usd/intern/usd_common.cc
index e5a83442140..f8b1fd92918 100644
--- a/source/blender/io/usd/intern/usd_common.cc
+++ b/source/blender/io/usd/intern/usd_common.cc
@@ -2,10 +2,17 @@
* Copyright 2021 Blender Foundation. All rights reserved. */
#include "usd_common.h"
+#include "usd.h"
+#include <pxr/usd/ar/resolver.h>
#include <pxr/base/plug/registry.h>
#include "BKE_appdir.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
namespace blender::io::usd {
@@ -30,3 +37,26 @@ void ensure_usd_plugin_path_registered()
}
} // namespace blender::io::usd
+
+
+void USD_path_abs(char *path, const char *basepath, bool for_import)
+{
+ if (!BLI_path_is_rel(path)) {
+ pxr::ArResolvedPath resolved_path = for_import ? pxr::ArGetResolver().Resolve(path) :
+ pxr::ArGetResolver().ResolveForNewAsset(path);
+
+ std::string path_str = resolved_path.GetPathString();
+
+ if (!path_str.empty()) {
+ if (path_str.length() < FILE_MAX) {
+ BLI_strncpy(path, path_str.c_str(), FILE_MAX);
+ return;
+ }
+ WM_reportf(RPT_ERROR, "In USD_path_abs: resolved path %s exceeds path buffer length.", path_str.c_str());
+ }
+ }
+
+ /* If we got here, the path couldn't be resolved by the ArResolver, so we
+ * fall back on the standard Blender absolute path resolution. */
+ BLI_path_abs(path, basepath);
+}
diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h
index 0d2077d3f13..1be7e5fb58f 100644
--- a/source/blender/io/usd/usd.h
+++ b/source/blender/io/usd/usd.h
@@ -203,6 +203,12 @@ bool USD_umm_module_loaded(void);
/* USD Import and Mesh Cache interface. */
+/* Similar to BLI_path_abs(), but also invokes the USD asset resolver
+ * to determine the absolute path. This is necessary for resolving
+ * paths with URIs that BLI_path_abs() would otherwise alter when
+ * attempting to normalize the path. */
+void USD_path_abs(char *path, const char *basepath, bool for_import);
+
struct CacheArchiveHandle *USD_create_handle(struct Main *bmain,
const char *filepath,
struct ListBase *object_paths);
More information about the Bf-blender-cvs
mailing list