diff options
author | Fabian Schempp <fabianschempp@googlemail.com> | 2022-04-18 23:28:08 +0300 |
---|---|---|
committer | Fabian Schempp <fabianschempp@googlemail.com> | 2022-04-18 23:28:08 +0300 |
commit | 01616f9ed2da14b5cad40efac03d1a22dbb759f3 (patch) | |
tree | 4955ad12f260e557aa1c0f724a320e565f8bce5c /source/blender/io/usd/tests/usd_tests_common.cc | |
parent | f06d361da1249c93568153bae88bcdf43b4774a1 (diff) | |
parent | 314b27850ccb6d103cf5c73855187cfc11ec48d8 (diff) |
Merge branch 'master' into soc-2021-porting-modifiers-to-nodes-remesh-voxel
Diffstat (limited to 'source/blender/io/usd/tests/usd_tests_common.cc')
-rw-r--r-- | source/blender/io/usd/tests/usd_tests_common.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/io/usd/tests/usd_tests_common.cc b/source/blender/io/usd/tests/usd_tests_common.cc new file mode 100644 index 00000000000..9f18a289433 --- /dev/null +++ b/source/blender/io/usd/tests/usd_tests_common.cc @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 Blender Foundation. All rights reserved. */ + +#include "usd_tests_common.h" + +#include "testing/testing.h" + +#include <pxr/base/plug/registry.h> + +#include "BLI_path_util.h" +#include "BLI_utildefines.h" + +#include "BKE_appdir.h" + +namespace blender::io::usd { + +std::string register_usd_plugins_for_tests() +{ + static char usd_datafiles_dir[FILE_MAX] = {'\0'}; + static bool plugin_path_registered = false; + if (plugin_path_registered) { + return usd_datafiles_dir; + } + plugin_path_registered = true; + + const std::string &release_dir = blender::tests::flags_test_release_dir(); + if (release_dir.empty()) { + return ""; + } + + 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 + * recognize the path as directory. */ + BLI_assert(path_len + 1 < FILE_MAX); + usd_datafiles_dir[path_len] = '/'; + usd_datafiles_dir[path_len + 1] = '\0'; + + pxr::PlugRegistry::GetInstance().RegisterPlugins(usd_datafiles_dir); + + return usd_datafiles_dir; +} + +} // namespace blender::io::usd |