From cf4e90cb239f7704e8c4d677eb18a07a008348aa Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 7 Jun 2023 13:17:56 +0300 Subject: [PATCH 1/3] Initial --- materialx/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/materialx/utils.py b/materialx/utils.py index 6ca461313..17e0812ac 100644 --- a/materialx/utils.py +++ b/materialx/utils.py @@ -103,7 +103,7 @@ def set_param_value(mx_param, val, nd_type, nd_output=None): elif nd_type == 'float': if isinstance(val, NodeItem): val = val.data - + if isinstance(val, tuple): val = val[0] @@ -379,7 +379,11 @@ def cache_image_file(image: bpy.types.Image, cache_check=True): scene.render.image_settings.color_mode = BLENDER_DEFAULT_COLOR_MODE try: - image.save_render(filepath=str(temp_path)) + import _bpy_hydra + + temp_path = _bpy_hydra.cache_image(bpy.context.as_pointer(), scene.as_pointer(), image.as_pointer()) + except ImportError: + print("ERROR: no Hydra scene delegate available") finally: scene.render.image_settings.file_format = user_format scene.render.image_settings.color_mode = user_color_mode @@ -655,15 +659,15 @@ def get_output_node(material): return None bl_output_node = next((node for node in material.node_tree.nodes if - node.bl_idname == 'ShaderNodeOutputMaterial' and - node.is_active_output and node.inputs['Surface'].links), None) + node.bl_idname == 'ShaderNodeOutputMaterial' and + node.is_active_output and node.inputs['Surface'].links), None) if bl_output_node: return bl_output_node mx_output_node = next((node for node in material.node_tree.nodes if - node.bl_idname == with_prefix('MxNode_STD_surfacematerial') and - node.inputs['surfaceshader'].links), None) + node.bl_idname == with_prefix('MxNode_STD_surfacematerial') and + node.inputs['surfaceshader'].links), None) return mx_output_node -- 2.30.2 From 12c5653e4abe4cf37d2a9d538f7cb689c42773aa Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 8 Jun 2023 14:44:26 +0300 Subject: [PATCH 2/3] Fix print message --- materialx/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/materialx/utils.py b/materialx/utils.py index 17e0812ac..f3df8d99f 100644 --- a/materialx/utils.py +++ b/materialx/utils.py @@ -383,7 +383,7 @@ def cache_image_file(image: bpy.types.Image, cache_check=True): temp_path = _bpy_hydra.cache_image(bpy.context.as_pointer(), scene.as_pointer(), image.as_pointer()) except ImportError: - print("ERROR: no Hydra scene delegate available") + print("ERROR: No Hydra scene delegate available") finally: scene.render.image_settings.file_format = user_format scene.render.image_settings.color_mode = user_color_mode -- 2.30.2 From 772a4578fbc71889a9ca12a930f23b2de9191607 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Tue, 13 Jun 2023 08:45:33 +0300 Subject: [PATCH 3/3] Moved calling _bpy_hydra.cache_or_get_image_file() to the beginning of the cache_image_file() --- materialx/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/materialx/utils.py b/materialx/utils.py index f3df8d99f..31ad5f168 100644 --- a/materialx/utils.py +++ b/materialx/utils.py @@ -347,6 +347,14 @@ READONLY_IMAGE_FORMATS = {".dds"} # blender can read these formats, but can't w def cache_image_file(image: bpy.types.Image, cache_check=True): + try: + import _bpy_hydra + return _bpy_hydra.cache_or_get_image_file(bpy.context.as_pointer(), image.as_pointer()) + + except ImportError: + # without bpy_hydra we are going to cache image through python + pass + image_path = Path(image.filepath_from_user()) if not image.packed_file and image.source != 'GENERATED': if not image_path.is_file(): @@ -379,11 +387,8 @@ def cache_image_file(image: bpy.types.Image, cache_check=True): scene.render.image_settings.color_mode = BLENDER_DEFAULT_COLOR_MODE try: - import _bpy_hydra + image.save_render(filepath=str(temp_path)) - temp_path = _bpy_hydra.cache_image(bpy.context.as_pointer(), scene.as_pointer(), image.as_pointer()) - except ImportError: - print("ERROR: No Hydra scene delegate available") finally: scene.render.image_settings.file_format = user_format scene.render.image_settings.color_mode = user_color_mode -- 2.30.2