Moved check of existing MaterialX addon from bpy_hydra.py to material.cc and log warning only once. #83

Merged
Bogdan Nagirniak merged 3 commits from hydra-matx-check into hydra-render 2023-08-02 07:45:13 +02:00
2 changed files with 26 additions and 7 deletions
Showing only changes of commit ca2b63a567 - Show all commits

View File

@ -6,11 +6,7 @@ __all__ = (
def export_mtlx(material): def export_mtlx(material):
""" Exports material to .mtlx file. It is called from Blender source code. """ """ Exports material to .mtlx file. It is called from Blender source code. """
try:
import materialx.utils as mx_utils import materialx.utils as mx_utils
except ImportError:
print("ERROR: no MaterialX addon available")
return ""
doc = mx_utils.export(material, None) doc = mx_utils.export(material, None)
if not doc: if not doc:

View File

@ -113,9 +113,32 @@ pxr::HdCullStyle MaterialData::cull_style() const
void MaterialData::export_mtlx() void MaterialData::export_mtlx()
{ {
/* Call of python function hydra.export_mtlx() */
PyGILState_STATE gstate; PyGILState_STATE gstate;
/* Checking materialx addon */
static bool matx_addon_checked = false;
static bool has_matx_addon = false;
if (!matx_addon_checked) {
gstate = PyGILState_Ensure();
PyObject *mx_module = PyImport_ImportModule("materialx");
has_matx_addon = mx_module != nullptr;
Py_XDECREF(mx_module);
if (!has_matx_addon) {
PyErr_Print();
CLOG_WARN(LOG_RENDER_HYDRA_SCENE, "No MaterialX addon, materials won't be exported.");
}
PyGILState_Release(gstate);
matx_addon_checked = true;
}
if (!has_matx_addon) {
return;
}
/* Call of python function bpy_hydra.export_mtlx() */
gstate = PyGILState_Ensure(); gstate = PyGILState_Ensure();
PyObject *module, *dict, *func, *result; PyObject *module, *dict, *func, *result;