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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# Copyright 2018-2019 The glTF-Blender-IO authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ...io.com.gltf2_io import TextureInfo, MaterialNormalTextureInfoClass
from .gltf2_blender_texture import texture
# [Texture] => [Clearcoat Factor] =>
def clearcoat(mh, location, clearcoat_socket):
x, y = location
try:
ext = mh.pymat.extensions['KHR_materials_clearcoat']
except Exception:
return
clearcoat_factor = ext.get('clearcoatFactor', 0)
tex_info = ext.get('clearcoatTexture')
if tex_info is not None:
tex_info = TextureInfo.from_dict(tex_info)
if clearcoat_socket is None:
return
if tex_info is None:
clearcoat_socket.default_value = clearcoat_factor
return
# Mix clearcoat factor
if clearcoat_factor != 1:
node = mh.node_tree.nodes.new('ShaderNodeMath')
node.label = 'Clearcoat Factor'
node.location = x - 140, y
node.operation = 'MULTIPLY'
# Outputs
mh.node_tree.links.new(clearcoat_socket, node.outputs[0])
# Inputs
clearcoat_socket = node.inputs[0]
node.inputs[1].default_value = clearcoat_factor
x -= 200
# Clearcoat is in the R component; we don't need to separate it out
# since hooking a color socket up to a value socket automatically gets
# the R
texture(
mh,
tex_info=tex_info,
label='CLEARCOAT',
location=(x, y),
is_data=True,
color_socket=clearcoat_socket,
)
# [Texture] => [Seperate G] => [Roughness Factor] =>
def clearcoat_roughness(mh, location, roughness_socket):
x, y = location
try:
ext = mh.pymat.extensions['KHR_materials_clearcoat']
except Exception:
return
roughness_factor = ext.get('clearcoatRoughnessFactor', 0)
tex_info = ext.get('clearcoatRoughnessTexture')
if tex_info is not None:
tex_info = TextureInfo.from_dict(tex_info)
if roughness_socket is None:
return
if tex_info is None:
roughness_socket.default_value = roughness_factor
return
# Mix roughness factor
if roughness_factor != 1:
node = mh.node_tree.nodes.new('ShaderNodeMath')
node.label = 'Clearcoat Roughness Factor'
node.location = x - 140, y
node.operation = 'MULTIPLY'
# Outputs
mh.node_tree.links.new(roughness_socket, node.outputs[0])
# Inputs
roughness_socket = node.inputs[0]
node.inputs[1].default_value = roughness_factor
x -= 200
# Separate RGB (roughness is in G)
node = mh.node_tree.nodes.new('ShaderNodeSeparateRGB')
node.location = x - 150, y - 75
# Outputs
mh.node_tree.links.new(roughness_socket, node.outputs['G'])
# Inputs
color_socket = node.inputs[0]
x -= 200
texture(
mh,
tex_info=tex_info,
label='CLEARCOAT ROUGHNESS',
location=(x, y),
is_data=True,
color_socket=color_socket,
)
# [Texture] => [Normal Map] =>
def clearcoat_normal(mh, location, normal_socket):
x,y = location
try:
ext = mh.pymat.extensions['KHR_materials_clearcoat']
except Exception:
return
tex_info = ext.get('clearcoatNormalTexture')
if tex_info is not None:
tex_info = MaterialNormalTextureInfoClass.from_dict(tex_info)
if tex_info is None:
return
# Normal map
node = mh.node_tree.nodes.new('ShaderNodeNormalMap')
node.location = x - 150, y - 40
# Set UVMap
uv_idx = tex_info.tex_coord or 0
try:
uv_idx = tex_info.extensions['KHR_texture_transform']['texCoord']
except Exception:
pass
node.uv_map = 'UVMap' if uv_idx == 0 else 'UVMap.%03d' % uv_idx
# Set strength
scale = tex_info.scale
scale = scale if scale is not None else 1
node.inputs['Strength'].default_value = scale
# Outputs
mh.node_tree.links.new(normal_socket, node.outputs['Normal'])
# Inputs
color_socket = node.inputs['Color']
x -= 200
texture(
mh,
tex_info=tex_info,
label='CLEARCOAT NORMAL',
location=(x, y),
is_data=True,
color_socket=color_socket,
)
|