diff options
-rw-r--r-- | build_files/build_environment/patches/usd.diff | 71 | ||||
-rw-r--r-- | source/blender/io/usd/intern/usd_capi.cc | 16 | ||||
-rw-r--r-- | source/blender/io/usd/tests/usd_stage_creation_test.cc | 23 |
3 files changed, 17 insertions, 93 deletions
diff --git a/build_files/build_environment/patches/usd.diff b/build_files/build_environment/patches/usd.diff index fe767829a70..27b4955f849 100644 --- a/build_files/build_environment/patches/usd.diff +++ b/build_files/build_environment/patches/usd.diff @@ -10,77 +10,6 @@ diff -x .git -ur usd.orig/cmake/defaults/Packages.cmake external_usd/cmake/defau add_definitions(${TBB_DEFINITIONS}) # --math -diff -x .git -ur usd.orig/pxr/base/plug/initConfig.cpp external_usd/pxr/base/plug/initConfig.cpp ---- usd.orig/pxr/base/plug/initConfig.cpp.orig 2020-06-12 17:20:07.478199779 +0200 -+++ external_usd/pxr/base/plug/initConfig.cpp 2020-06-12 17:25:28.648588552 +0200 -@@ -69,10 +69,40 @@ - - ARCH_CONSTRUCTOR(Plug_InitConfig, 2, void) - { -+ /* The contents of this constructor have been moved to usd_initialise_plugin_path(...) */ -+} -+ -+}; // end of anonymous namespace -+ -+/** -+ * The contents of this function used to be in the static constructor Plug_InitConfig. -+ * This static constructor made it impossible for Blender to pass a path to the USD -+ * library at runtime, as the constructor would run before Blender's main() function. -+ * -+ * This function is wrapped in a C function of the same name (defined below), -+ * so that it can be called from Blender's main() function. -+ * -+ * The datafiles_usd_path path is used to point to the USD plugin path when Blender -+ * has been installed. The fallback_usd_path path should point to the build-time -+ * location of the USD plugin files so that Blender can be run on a development machine -+ * without requiring an installation step. -+ */ -+void -+usd_initialise_plugin_path(const char *datafiles_usd_path) -+{ - std::vector<std::string> result; - - std::vector<std::string> debugMessages; - -+ // Add Blender-specific paths. They MUST end in a slash, or symlinks will not be treated as directory. -+ if (datafiles_usd_path != NULL && datafiles_usd_path[0] != '\0') { -+ std::string datafiles_usd_path_str(datafiles_usd_path); -+ if (datafiles_usd_path_str.back() != '/') { -+ datafiles_usd_path_str += "/"; -+ } -+ result.push_back(datafiles_usd_path_str); -+ } -+ - // Determine the absolute path to the Plug shared library. Any relative - // paths specified in the plugin search path will be anchored to this - // directory, to allow for relocatability. Note that this can fail when pxr -@@ -114,9 +144,24 @@ - _AppendPathList(&result, installLocation, binaryPath); - #endif // PXR_INSTALL_LOCATION - -- Plug_SetPaths(result, debugMessages); --} -+ if (!TfGetenv("PXR_PATH_DEBUG").empty()) { -+ printf("USD Plugin paths: (%zu in total):\n", result.size()); -+ for(const std::string &path : result) { -+ printf(" %s\n", path.c_str()); -+ } -+ } - -+ Plug_SetPaths(result, debugMessages); - } - - PXR_NAMESPACE_CLOSE_SCOPE -+ -+/* Workaround to make it possible to pass a path at runtime to USD. */ -+extern "C" { -+void -+usd_initialise_plugin_path( -+ const char *datafiles_usd_path) -+{ -+ PXR_NS::usd_initialise_plugin_path(datafiles_usd_path); -+} -+} diff -Naur external_usd_base/cmake/macros/Public.cmake external_usd/cmake/macros/Public.cmake --- external_usd_base/cmake/macros/Public.cmake 2019-10-24 14:39:53 -0600 +++ external_usd/cmake/macros/Public.cmake 2020-01-11 13:33:29 -0700 diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc index b5b314136ed..52075728e3e 100644 --- a/source/blender/io/usd/intern/usd_capi.cc +++ b/source/blender/io/usd/intern/usd_capi.cc @@ -20,6 +20,7 @@ #include "usd.h" #include "usd_hierarchy_iterator.h" +#include <pxr/base/plug/registry.h> #include <pxr/pxr.h> #include <pxr/usd/usd/stage.h> #include <pxr/usd/usdGeom/tokens.h> @@ -45,17 +46,6 @@ #include "WM_api.h" #include "WM_types.h" -/* Workaround to make it possible to pass a path at runtime to USD. - * - * USD requires some JSON files, and it uses a static constructor to determine the possible - * file-system paths to find those files. This made it impossible for Blender to pass a path to - * the USD library at runtime, as the constructor would run before Blender's main() function. - * We have patched USD (see usd.diff) to avoid that particular static constructor, and have an - * initialization function instead. - * - * This function is implemented in the USD source code, `pxr/base/plug/initConfig.cpp`. */ -extern "C" void usd_initialise_plugin_path(const char *datafiles_usd_path); - namespace blender { namespace io { namespace usd { @@ -81,7 +71,9 @@ static void ensure_usd_plugin_path_registered(void) /* Tell USD which directory to search for its JSON files. If 'datafiles/usd' * does not exist, the USD library will not be able to read or write any files. */ - usd_initialise_plugin_path(BKE_appdir_folder_id(BLENDER_DATAFILES, "usd")); + const std::string blender_usd_datafiles = BKE_appdir_folder_id(BLENDER_DATAFILES, "usd"); + /* The trailing slash indicates to the USD library that the path is a directory. */ + pxr::PlugRegistry::GetInstance().RegisterPlugins(blender_usd_datafiles + "/"); } static void export_startjob(void *customdata, diff --git a/source/blender/io/usd/tests/usd_stage_creation_test.cc b/source/blender/io/usd/tests/usd_stage_creation_test.cc index e6bd0bab6ce..3d28d8f8f5a 100644 --- a/source/blender/io/usd/tests/usd_stage_creation_test.cc +++ b/source/blender/io/usd/tests/usd_stage_creation_test.cc @@ -17,6 +17,8 @@ * All rights reserved. */ #include "testing/testing.h" + +#include <pxr/base/plug/registry.h> #include <pxr/usd/usd/stage.h> #include <string> @@ -26,11 +28,6 @@ #include "BKE_appdir.h" -extern "C" { -/* Workaround to make it possible to pass a path at runtime to USD. See creator.c. */ -void usd_initialise_plugin_path(const char *datafiles_usd_path); -} - namespace blender::io::usd { class USDStageCreationTest : public testing::Test { @@ -44,9 +41,16 @@ TEST_F(USDStageCreationTest, JSONFileLoadingTest) } char usd_datafiles_dir[FILE_MAX]; - BLI_path_join(usd_datafiles_dir, FILE_MAX, release_dir.c_str(), "datafiles", "usd", nullptr); + const size_t path_len = BLI_path_join( + usd_datafiles_dir, FILE_MAX, release_dir.c_str(), "datafiles", "usd", nullptr); + + /* BLI_path_join removes trailing slashes, but the USD library requires one in order to recognise + * the path as directory. */ + BLI_assert(path_len + 1 < FILE_MAX); + usd_datafiles_dir[path_len] = '/'; + usd_datafiles_dir[path_len + 1] = '\0'; - usd_initialise_plugin_path(usd_datafiles_dir); + pxr::PlugRegistry::GetInstance().RegisterPlugins(usd_datafiles_dir); /* Simply the ability to create a USD Stage for a specific filename means that the extension * has been recognized by the USD library, and that a USD plugin has been loaded to write such @@ -61,9 +65,8 @@ TEST_F(USDStageCreationTest, JSONFileLoadingTest) unlink(filename.c_str()); } else { - FAIL() << "unable to find suitable USD plugin to write " << filename - << "; re-run with the environment variable PXR_PATH_DEBUG non-empty to see which paths " - "are considered."; + FAIL() << "unable to find suitable USD plugin to write " << filename << "; looked in " + << usd_datafiles_dir; } } |