forked from nizu/VB25-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes.py
280 lines (194 loc) · 6.71 KB
/
nodes.py
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
'''
V-Ray/Blender 2.5
http://vray.cgdo.ru
Time-stamp: "Monday, 08 August 2011 [18:59]"
Author: Andrey M. Izrantsev (aka bdancer)
E-Mail: izrantsev@cgdo.ru
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
All Rights Reserved. V-Ray(R) is a registered trademark of Chaos Software.
'''
''' Blender modules '''
import bpy
import mathutils
import sys
''' vb modules '''
from vb25.uvwgen import *
from vb25.texture import *
from vb25.plugins import *
from vb25.utils import *
'''
NODES
'''
def write_ShaderNodeInvert(bus, node, node_params):
ofile= bus['files']['textures']
scene= bus['scene']
node_tree= bus['ma_nodes']['node_tree']
if 'Color' not in node_params:
return None
tex_name= "TI%s" % node_params['Color']
ofile.write("\nTexInvert %s {" % tex_name)
ofile.write("\n\ttexture= %s;" % node_params['Color'])
ofile.write("\n}\n")
return tex_name
def write_BRDFDiffuse(bus, name, node, color):
ofile= bus['files']['materials']
scene= bus['scene']
comp_name= "BRDFDiffuse%s" % (name)
ofile.write("\nBRDFDiffuse %s {" % comp_name)
ofile.write("\n\tcolor= %s;" % a(scene, color))
ofile.write("\n}\n")
return comp_name
def write_ShaderNodeTexture(bus, node, input_params):
node_tree= bus['ma_nodes']['node_tree']
if not node.texture:
return None
bus['mtex']= {}
bus['mtex']['mapto']= 'node'
bus['mtex']['slot']= None
bus['mtex']['texture']= node.texture
bus['mtex']['factor']= 1.0
bus['mtex']['name']= clean_string("NT%sNO%sTE%s" % (node_tree.name,
node.name,
node.texture.name))
return write_texture(bus)
def write_ShaderNodeMaterial(bus, node, input_params):
ma= bus['material']['material']
bus['textures']= {}
bus['material']['material']= node.material
if not node.material:
return None
# Check Toon
VRayMaterial= node.material.vray
if VRayMaterial.VolumeVRayToon.use:
bus['effects']['toon']['effects'].append(
PLUGINS['SETTINGS']['SettingsEnvironment'].write_VolumeVRayToon_from_material(bus)
)
append_unique(bus['effects']['toon']['objects'], bus['node']['object'])
# Write material textures
write_material_textures(bus)
node_name= PLUGINS['BRDF'][node.material.vray.type].write(bus)
# Add BRDFBump if needed
node_name= PLUGINS['BRDF']['BRDFBump'].write(bus, base_brdf= node_name)
bus['material']['material']= ma
return node_name
def write_ShaderNodeOutput(bus, node, input_params):
ofile= bus['files']['materials']
scene= bus['scene']
ma= bus['material']['material']
params= {
'Color': "",
'Alpha': "",
}
for key in params:
# Key is mapped in input_params
if key in input_params:
params[key]= input_params[key]
else:
if key == 'Color':
c= node.inputs[key].default_value
params[key]= write_BRDFDiffuse(bus, key, node,
mathutils.Color((c[0],c[1],c[2])))
node_name= get_name(ma, prefix='MA')
brdf= params['Color']
if 'Alpha' in input_params or node.inputs['Alpha'].default_value < 1.0:
brdfs= brdf
brdf= "%sWithAlpha" % brdfs
ofile.write("\nBRDFLayered %s {" % brdf)
ofile.write("\n\tbrdfs= List(%s);" % brdfs)
if 'Alpha' in input_params:
ofile.write("\n\ttransparency_tex= %s;" % params['Alpha'])
else:
ofile.write("\n\ttransparency= %s;" % a(scene, mathutils.Color([node.inputs[key].default_value]*3)))
ofile.write("\n\tweights= List(TEDefaultBlend);")
ofile.write("\n}\n")
ofile.write("\nMtlSingleBRDF %s {" % node_name)
ofile.write("\n\tbrdf= %s;" % brdf)
ofile.write("\n}\n")
return node_name
def write_ShaderNodeMixRGB(bus, node, input_params):
ofile= bus['files']['materials']
scene= bus['scene']
node_tree= bus['ma_nodes']['node_tree']
params= {
'Color1': "",
'Color2': "",
'Fac': "",
}
for key in params:
# Key is mapped in input_params
if key in input_params:
params[key]= input_params[key]
else:
if key == 'Color1':
c= node.inputs[key].default_value
params[key]= write_BRDFDiffuse(bus, key, node,
mathutils.Color((c[0],c[1],c[2])))
elif key == 'Color2':
c= node.inputs[key].default_value
params[key]= write_BRDFDiffuse(bus, key, node,
mathutils.Color((c[0],c[1],c[2])))
elif key == 'Fac':
params[key]= write_TexAColor(bus, key, node,
mathutils.Color([node.inputs[key].default_value]*3))
node_name = "%s%s" % (get_name(bus['material']['material'], prefix='MA'), get_node_name(node_tree, node))
ofile.write("\nBRDFLayered %s {" % node_name)
ofile.write("\n\tbrdfs= List(%s, %s);" % (params['Color2'], params['Color1']))
ofile.write("\n\tweights= List(%s, TEDefaultBlend);" % params['Fac'])
ofile.write("\n}\n")
return node_name
'''
MATERIAL
'''
def write_shader_node(bus, node_tree, node):
ofile= bus['files']['materials']
scene= bus['scene']
VRayScene= scene.vray
VRayExporter= VRayScene.exporter
node_params= {}
for input_socket in node.inputs:
input_node= connected_node(node_tree, input_socket)
if not input_node:
continue
value= write_shader_node(bus, node_tree, input_node)
if value is not None:
node_params[input_socket.name]= value
if VRayExporter.debug:
print_dict(scene, "Node \"%s\"" % (node.name), node_params)
if node.type == 'MIX_RGB':
return write_ShaderNodeMixRGB(bus, node, node_params)
elif node.type == 'OUTPUT':
return write_ShaderNodeOutput(bus, node, node_params)
elif node.type in {'MATERIAL','MATERIAL_EXT'}:
return write_ShaderNodeMaterial(bus, node, node_params)
elif node.type == 'TEXTURE':
return write_ShaderNodeTexture(bus, node, node_params)
elif node.type == 'INVERT':
return write_ShaderNodeInvert(bus, node, node_params)
else:
return None
def write_node_material(bus):
ofile= bus['files']['materials']
scene= bus['scene']
ob= bus['node']['object']
base= bus['node']['base']
ma= bus['material']['material']
VRayScene= scene.vray
VRayExporter= VRayScene.exporter
node_tree= ma.node_tree
output_node= get_output_node(node_tree)
if output_node:
if VRayExporter.debug:
debug(scene, "Processing node material \"%s\":" % (ma.name))
bus['ma_nodes']= {}
bus['ma_nodes']['node_tree']= node_tree
return write_shader_node(bus, node_tree, output_node)
return bus['defaults']['material']