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

gltf2_blender_KHR_materials_sheen.py « imp « blender « io_scene_gltf2 - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa5cef759094ec0478d9f7b1410d7f6145ea0497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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