Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py')
-rw-r--r--io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_sheen.py88
1 files changed, 88 insertions, 0 deletions
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..aa5cef75
--- /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
+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