diff --git a/release/scripts/modules/bpy_hydra.py b/release/scripts/modules/bpy_hydra.py index fc5700992293..6b2b0a3e5cd8 100644 --- a/release/scripts/modules/bpy_hydra.py +++ b/release/scripts/modules/bpy_hydra.py @@ -36,6 +36,9 @@ __all__ = ( "get_render_plugins", ) +import os +from pathlib import Path + import bpy import _bpy_hydra @@ -59,6 +62,8 @@ class HydraRenderEngine(bpy.types.RenderEngine): @classmethod def register(cls): _bpy_hydra.init() + os.environ['PXR_MTLX_STDLIB_SEARCH_PATHS'] = str(Path(bpy.app.binary_path).parent / "materialx/libraries") + \ + os.pathsep + os.environ.get('PXR_MTLX_STDLIB_SEARCH_PATHS', "") @classmethod def unregister(cls): diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index c0a57d6c857d..9401a76a8f91 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -18,47 +18,24 @@ 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; - } - - set_env_paths("PXR_MTLX_STDLIB_SEARCH_PATHS", {stdlib_path}); -} - static PyObject *init_func(PyObject * /*self*/, PyObject *args) { CLOG_INFO(LOG_EN, 1, "Init"); pxr::PlugRegistry::GetInstance().RegisterPlugins(std::string(BKE_appdir_program_dir()) + "/blender.shared/usd"); - setup_usd_mtlx_environment(); Py_RETURN_NONE; } static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) { - PyObject *pyplugin_dirs, *pypath_dirs; - if (!PyArg_ParseTuple(args, "OO", &pyplugin_dirs, &pypath_dirs)) { + PyObject *pyplugin_dirs; + if (!PyArg_ParseTuple(args, "O", &pyplugin_dirs)) { Py_RETURN_NONE; } - - std::vector plugin_dirs, path_dirs; + std::vector plugin_dirs; PyObject *pyiter, *pyitem; pyiter = PyObject_GetIter(pyplugin_dirs); @@ -70,19 +47,6 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) Py_DECREF(pyiter); } - pyiter = PyObject_GetIter(pypath_dirs); - if (pyiter) { - while (pyitem = PyIter_Next(pyiter)) { - path_dirs.push_back(PyUnicode_AsUTF8(pyitem)); - Py_DECREF(pyitem); - } - Py_DECREF(pyiter); - } - - if (!path_dirs.empty()) { - set_env_paths("PATH", path_dirs); - } - pxr::PlugRegistry ®istry = pxr::PlugRegistry::GetInstance(); registry.RegisterPlugins(plugin_dirs); @@ -92,10 +56,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) for (auto &s : plugin_dirs) { ss << s << ", "; } - ss << "], path=["; - for (auto &s : path_dirs) { - ss << s << ", "; - } + ss << "]"; CLOG_INFO(LOG_EN, 1, "Register %s", ss.str().c_str()); Py_RETURN_NONE; diff --git a/source/blender/render/hydra/utils.cc b/source/blender/render/hydra/utils.cc index a1ad16654aa4..8d37a14ef7ac 100644 --- a/source/blender/render/hydra/utils.cc +++ b/source/blender/render/hydra/utils.cc @@ -99,27 +99,4 @@ std::string cache_image(Main *bmain, return tempfile; } -void set_env_paths(std::string const &name, std::vector path_dirs) -{ - const char *env = BLI_getenv(name.c_str()); - ; - std::stringstream ss; - int i = 0; - for (std::string &s : path_dirs) { - ++i; - ss << s; - if (i < path_dirs.size() || env) { -#ifdef _WIN32 - ss << ";"; -#else - ss << ":"; -#endif - } - } - if (env) { - ss << env; - } - BLI_setenv(name.c_str(), ss.str().c_str()); -} - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/utils.h b/source/blender/render/hydra/utils.h index 7bf8f3be0c97..05d7c85fc610 100644 --- a/source/blender/render/hydra/utils.h +++ b/source/blender/render/hydra/utils.h @@ -21,6 +21,5 @@ std::string cache_image(Main *bmain, ImageUser *iuser, ImageSaveOptions *opts, ReportList *reports); -void set_env_paths(std::string const &name, std::vector path_dirs); } // namespace blender::render::hydra