From 042fbefac686666190915d206600a5dab8e03066 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Thu, 7 Jul 2022 08:03:39 +0200 Subject: glTF importer/exporter: Manage some official Khronos Extensions about Materials KHR_materials_ior KHR_materials_sheen KHR_materials_specular KHR_materials_transmission KHR_materials_variants KHR_materials_emissive_strength KHR_materials_volume Documentation update is still in progress --- .../imp/gltf2_blender_KHR_materials_sheen.py | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py') diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py new file mode 100644 index 00000000..3560d094 --- /dev/null +++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py @@ -0,0 +1,88 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2018-2022 The glTF-Blender-IO authors. + +from ...io.com.gltf2_io import TextureInfo +from .gltf2_blender_texture import texture +from .gltf2_blender_image import BlenderImage +from ..exp.gltf2_blender_image import TmpImageGuard, make_temp_image_copy +import numpy as np +import bpy + +def sheen( mh, + location_sheenColor, + location_sheenRoughness, + sheenColor_socket, + sheenRoughness_socket + ): + + x_sheenColor, y_sheenColor = location_sheenColor + x_sheenRoughness, y_sheenRoughness = location_sheenRoughness + + try: + ext = mh.pymat.extensions['KHR_materials_sheen'] + except Exception: + return + + sheenColorFactor = ext.get('sheenColorFactor', [0.0, 0.0, 0.0]) + tex_info_color = ext.get('sheenColorTexture') + if tex_info_color is not None: + tex_info_color = TextureInfo.from_dict(tex_info_color) + + sheenRoughnessFactor = ext.get('sheenRoughnessFactor', 0.0) + tex_info_roughness = ext.get('sheenRoughnessTexture') + if tex_info_roughness is not None: + tex_info_roughness = TextureInfo.from_dict(tex_info_roughness) + + if tex_info_color is None: + sheenColorFactor.extend([1.0]) + sheenColor_socket.default_value = sheenColorFactor + else: + # Mix sheenColor factor + sheenColorFactor = sheenColorFactor + [1.0] + if sheenColorFactor != [1.0, 1.0, 1.0, 1.0]: + node = mh.node_tree.nodes.new('ShaderNodeMixRGB') + node.label = 'sheenColor Factor' + node.location = x_sheenColor - 140, y_sheenColor + node.blend_type = 'MULTIPLY' + # Outputs + mh.node_tree.links.new(sheenColor_socket, node.outputs[0]) + # Inputs + node.inputs['Fac'].default_value = 1.0 + sheenColor_socket = node.inputs['Color1'] + node.inputs['Color2'].default_value = sheenColorFactor + x_sheenColor -= 200 + + texture( + mh, + tex_info=tex_info_color, + label='SHEEN COLOR', + location=(x_sheenColor, y_sheenColor), + color_socket=sheenColor_socket + ) + + if tex_info_roughness is None: + sheenRoughness_socket.default_value = sheenRoughnessFactor + else: + # Mix sheenRoughness factor + if sheenRoughnessFactor != 1.0: + node = mh.node_tree.nodes.new('ShaderNodeMath') + node.label = 'shennRoughness Factor' + node.location = x_sheenRoughness - 140, y_sheenRoughness + node.operation = 'MULTIPLY' + # Outputs + mh.node_tree.links.new(sheenRoughness_socket, node.outputs[0]) + # Inputs + sheenRoughness_socket = node.inputs[0] + node.inputs[1].default_value = sheenRoughnessFactor + x_sheenRoughness -= 200 + + texture( + mh, + tex_info=tex_info_roughness, + label='SHEEN ROUGHNESS', + location=(x_sheenRoughness, y_sheenRoughness), + is_data=True, + color_socket=None, + alpha_socket=sheenRoughness_socket + ) + return \ No newline at end of file -- cgit v1.2.3 From ae29cfd1860e53e61d1b58d9c406638927a8ab40 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Mon, 8 Aug 2022 17:03:41 +0200 Subject: glTF: Merge glTF Material Output nodes into a single one --- io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py') diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py index 3560d094..aa5cef75 100644 --- a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py @@ -4,7 +4,7 @@ from ...io.com.gltf2_io import TextureInfo from .gltf2_blender_texture import texture from .gltf2_blender_image import BlenderImage -from ..exp.gltf2_blender_image import TmpImageGuard, make_temp_image_copy +from ..exp.gltf2_blender_image import TmpImageGuard import numpy as np import bpy -- cgit v1.2.3