diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/io/usd/intern/usd_capi.cc | 27 | ||||
-rw-r--r-- | source/creator/creator.c | 17 |
2 files changed, 27 insertions, 17 deletions
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc index 83b8c18d436..b5b314136ed 100644 --- a/source/blender/io/usd/intern/usd_capi.cc +++ b/source/blender/io/usd/intern/usd_capi.cc @@ -32,6 +32,7 @@ #include "DNA_scene_types.h" +#include "BKE_appdir.h" #include "BKE_blender_version.h" #include "BKE_context.h" #include "BKE_global.h" @@ -44,6 +45,17 @@ #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 { @@ -59,6 +71,19 @@ struct ExportJobData { bool export_ok; }; +static void ensure_usd_plugin_path_registered(void) +{ + static bool plugin_path_registered = false; + if (plugin_path_registered) { + return; + } + plugin_path_registered = true; + + /* 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")); +} + static void export_startjob(void *customdata, /* Cannot be const, this function implements wm_jobs_start_callback. * NOLINTNEXTLINE: readability-non-const-parameter. */ @@ -180,6 +205,8 @@ bool USD_export(bContext *C, ViewLayer *view_layer = CTX_data_view_layer(C); Scene *scene = CTX_data_scene(C); + blender::io::usd::ensure_usd_plugin_path_registered(); + blender::io::usd::ExportJobData *job = static_cast<blender::io::usd::ExportJobData *>( MEM_mallocN(sizeof(blender::io::usd::ExportJobData), "ExportJobData")); diff --git a/source/creator/creator.c b/source/creator/creator.c index 3d76d832d9f..37fbf0cf76a 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -442,23 +442,6 @@ int main(int argc, BKE_materials_init(); -#ifdef WITH_USD - /* 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/lib/plug/initConfig.cpp`. */ - extern void usd_initialise_plugin_path(const char *datafiles_usd_path); - - /* 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")); -#endif /* WITH_USD */ - if (G.background == 0) { #ifndef WITH_PYTHON_MODULE BLI_argsParse(ba, 2, NULL, NULL); |