From 4b6d620090c631dfb7d3d1dc4b88baf6c9da96f6 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 20 Mar 2023 23:18:16 +0300 Subject: [PATCH 1/3] BLEN-370: Find way not to modify PATH --- source/blender/render/hydra/python.cc | 47 +++------------------------ source/blender/render/hydra/utils.cc | 23 ------------- source/blender/render/hydra/utils.h | 1 - 3 files changed, 4 insertions(+), 67 deletions(-) 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 -- 2.30.2 From ac9a8878d05e92c888d2597c77c57d7758a0bf14 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 23 Mar 2023 13:02:57 +0300 Subject: [PATCH 2/3] added defining PXR_MTLX_STDLIB_SEARCH_PATHS to HydraRenderEngine.register() --- release/scripts/modules/bpy_hydra.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/release/scripts/modules/bpy_hydra.py b/release/scripts/modules/bpy_hydra.py index fc5700992293..d3b869df92ff 100644 --- a/release/scripts/modules/bpy_hydra.py +++ b/release/scripts/modules/bpy_hydra.py @@ -36,6 +36,10 @@ __all__ = ( "get_render_plugins", ) +import os +import platform +from pathlib import Path + import bpy import _bpy_hydra @@ -59,6 +63,9 @@ class HydraRenderEngine(bpy.types.RenderEngine): @classmethod def register(cls): _bpy_hydra.init() + mtlx_std_libs_folder = os.environ.get('PXR_MTLX_STDLIB_SEARCH_PATHS', None) + if not mtlx_std_libs_folder: + os.environ['PXR_MTLX_STDLIB_SEARCH_PATHS'] = str(Path(bpy.app.binary_path).parent) + '/materialx/libraries;' @classmethod def unregister(cls): -- 2.30.2 From 17a934fb1db002741e7b84c8f6206264e4ad598b Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 23 Mar 2023 13:15:35 +0300 Subject: [PATCH 3/3] refactoring --- release/scripts/modules/bpy_hydra.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/release/scripts/modules/bpy_hydra.py b/release/scripts/modules/bpy_hydra.py index d3b869df92ff..6b2b0a3e5cd8 100644 --- a/release/scripts/modules/bpy_hydra.py +++ b/release/scripts/modules/bpy_hydra.py @@ -37,7 +37,6 @@ __all__ = ( ) import os -import platform from pathlib import Path import bpy @@ -63,9 +62,8 @@ class HydraRenderEngine(bpy.types.RenderEngine): @classmethod def register(cls): _bpy_hydra.init() - mtlx_std_libs_folder = os.environ.get('PXR_MTLX_STDLIB_SEARCH_PATHS', None) - if not mtlx_std_libs_folder: - os.environ['PXR_MTLX_STDLIB_SEARCH_PATHS'] = str(Path(bpy.app.binary_path).parent) + '/materialx/libraries;' + 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): -- 2.30.2