forked from blender/blender
BLEN-356: Automatically configure PXR_MTLX_STDLIB_SEARCH_PATHS #9
@ -397,11 +397,6 @@ void USD_ensure_plugin_path_registered()
|
||||
blender::io::usd::ensure_usd_plugin_path_registered();
|
||||
}
|
||||
|
||||
void USD_setup_usd_mtlx_environment()
|
||||
{
|
||||
blender::io::usd::setup_usd_mtlx_environment();
|
||||
}
|
||||
|
||||
bool USD_import(struct bContext *C,
|
||||
const char *filepath,
|
||||
const USDImportParams *params,
|
||||
|
@ -5,11 +5,6 @@
|
||||
|
||||
#include <pxr/base/plug/registry.h>
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
namespace blender::io::usd {
|
||||
|
||||
void ensure_usd_plugin_path_registered()
|
||||
@ -35,43 +30,4 @@ void ensure_usd_plugin_path_registered()
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup_usd_mtlx_environment()
|
||||
{
|
||||
/* PXR_MTLX_STDLIB_SEARCH_PATHS - path to the MaterialX standard library
|
||||
* USD's MaterialX code expects to be set. */
|
||||
|
||||
static bool mtlx_env_set = false;
|
||||
if (mtlx_env_set) {
|
||||
return;
|
||||
}
|
||||
mtlx_env_set = true;
|
||||
|
||||
char stdlib_path[FILE_MAX] = "";
|
||||
size_t stdlib_path_len = BLI_path_join(
|
||||
stdlib_path, sizeof(stdlib_path), BKE_appdir_program_dir(), "materialx", "libraries");
|
||||
if (stdlib_path_len == 0 || !BLI_exists(stdlib_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
# define PATH_SEP ";"
|
||||
#else
|
||||
# define PATH_SEP ":"
|
||||
#endif
|
||||
|
||||
const char *env_var_name = "PXR_MTLX_STDLIB_SEARCH_PATHS";
|
||||
const char *env_var = BLI_getenv(env_var_name);
|
||||
if (!env_var) {
|
||||
BLI_setenv(env_var_name, stdlib_path);
|
||||
}
|
||||
else {
|
||||
size_t env_var_len = strlen(env_var);
|
||||
size_t combined_len = stdlib_path_len + 1 + env_var_len + 1;
|
||||
char *combined = (char *)malloc(sizeof(char) * combined_len);
|
||||
BLI_snprintf(combined, combined_len, "%s" PATH_SEP "%s", stdlib_path, env_var);
|
||||
BLI_setenv(env_var_name, combined);
|
||||
free(combined);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::io::usd
|
||||
|
@ -5,6 +5,5 @@
|
||||
namespace blender::io::usd {
|
||||
|
||||
void ensure_usd_plugin_path_registered();
|
||||
void setup_usd_mtlx_environment();
|
||||
|
||||
} // namespace blender::io::usd
|
||||
|
@ -138,7 +138,6 @@ struct CacheReader *CacheReader_open_usd_object(struct CacheArchiveHandle *handl
|
||||
void USD_CacheReader_incref(struct CacheReader *reader);
|
||||
void USD_CacheReader_free(struct CacheReader *reader);
|
||||
void USD_ensure_plugin_path_registered(void);
|
||||
void USD_setup_usd_mtlx_environment(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -13,6 +13,9 @@
|
||||
|
||||
#include "glog/logging.h"
|
||||
#include "BKE_appdir.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
#include "finalEngine.h"
|
||||
#include "viewportEngine.h"
|
||||
@ -21,12 +24,51 @@ using namespace std;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
void setup_usd_mtlx_environment()
|
||||
{
|
||||
/* PXR_MTLX_STDLIB_SEARCH_PATHS - path to the MaterialX standard library
|
||||
* USD's MaterialX code expects to be set. */
|
||||
|
||||
static bool mtlx_env_set = false;
|
||||
if (mtlx_env_set) {
|
||||
return;
|
||||
}
|
||||
mtlx_env_set = true;
|
||||
|
||||
char stdlib_path[FILE_MAX] = "";
|
||||
size_t stdlib_path_len = BLI_path_join(
|
||||
stdlib_path, sizeof(stdlib_path), BKE_appdir_program_dir(), "materialx", "libraries");
|
||||
if (stdlib_path_len == 0 || !BLI_exists(stdlib_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
# define PATH_SEP ";"
|
||||
#else
|
||||
# define PATH_SEP ":"
|
||||
#endif
|
||||
|
||||
const char *env_var_name = "PXR_MTLX_STDLIB_SEARCH_PATHS";
|
||||
const char *env_var = BLI_getenv(env_var_name);
|
||||
if (!env_var) {
|
||||
BLI_setenv(env_var_name, stdlib_path);
|
||||
}
|
||||
else {
|
||||
size_t env_var_len = strlen(env_var);
|
||||
std::string combined(stdlib_path_len + 1 + env_var_len, '\0');
|
||||
BLI_snprintf(combined.data(), combined.capacity(), "%s" PATH_SEP "%s", stdlib_path, env_var);
|
||||
BLI_setenv(env_var_name, combined.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
LOG(INFO) << "init_func";
|
||||
|
||||
pxr::PlugRegistry::GetInstance().RegisterPlugins(string(BKE_appdir_program_dir()) + "/blender.shared/usd");
|
||||
|
||||
setup_usd_mtlx_environment();
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
@ -1513,10 +1513,6 @@ if(WITH_USD)
|
||||
absolute_include_dirs(../blender/io/usd)
|
||||
endif()
|
||||
|
||||
if(WITH_MATERIALX)
|
||||
add_definitions(-DWITH_MATERIALX)
|
||||
endif()
|
||||
|
||||
# Always install USD shared library and datafiles regardless if Blender
|
||||
# itself uses them, the bundled Python module still needs it.
|
||||
if((DEFINED LIBDIR) AND TARGETDIR_LIB)
|
||||
|
@ -477,9 +477,6 @@ int main(int argc,
|
||||
|
||||
#ifdef WITH_USD
|
||||
USD_ensure_plugin_path_registered();
|
||||
# ifdef WITH_MATERIALX
|
||||
USD_setup_usd_mtlx_environment();
|
||||
# endif
|
||||
#endif
|
||||
George-Shakula marked this conversation as resolved
|
||||
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
|
Loading…
Reference in New Issue
Block a user
do we need
#ifdef WITH_MATERIALX
?It's not a requirement but it makes sense to wrap it into an #ifdef. Because if there is no mtlx there is also no usdMtlx