forked from TianD/TianD_arnold_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateNodeGroup.py
305 lines (241 loc) · 7.75 KB
/
CreateNodeGroup.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#coding:utf-8
'''
Created on 2015年10月21日 下午2:27:40
@author: TianD
@E-mail: [email protected]
@Q Q: 298081132
@Description: create node group or shader
'''
import pymel.core as pm
ARNOLD_IDP_TYPE = {'R':[(1,0,0),0,(1,0,0)],
'G':[(0,1,0),0,(0,1,0)],
'B':[(0,0,1),0,(0,0,1)],
'Y':[(1,1,0),0,(1,1,0)],
'C':[(0,1,1),0,(0,1,1)],
'P':[(1,0,1),0,(1,0,1)],
'A':[(0,0,0),1,(1,1,1)],
'Maeet':[(0,0,0),0,(0.2,0.2,0.2)],
}
IDP1_TYPE_DIC = {
'R': ['_body_','_head_',],
'B': ['eye'],
'G': ['hair','eyebrow'],
'Y': ['outfit'],
'P': ['tooth'],
'A': ['mouth'],
}
IDP2_TYPE_LIST = ['R', 'G', 'B', 'C', 'Y', 'P', 'A']
IDP3_TYPE_DIC = {
'R': ['SetRigGrp',],
'G': ['charRigGrp', 'PropRigGrp', 'CharRigGrp'],
}
def createZ(out = None):
#创建Z通道节点组合
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
samplerInfo = pm.createNode('samplerInfo', name = 'z_samplerInfo_arnold')
multiplyDivide = pm.createNode('multiplyDivide', name = 'z_multiplyDivide_arnold')
setRange = pm.createNode('setRange', name = 'z_setRange_arnold')
aiUtility, SG = pm.createSurfaceShader('aiUtility', name = 'zdp_arnold')
#修改属性
multiplyDivide.input2X.set(-1)
setRange.minX.set(1)
setRange.oldMinX.set(0.1)
setRange.oldMaxX.set(500)
aiUtility.shadeMode.set(2)
#属性链接
samplerInfo.pointCameraZ >> multiplyDivide.input1X
multiplyDivide.outputX >> setRange.valueX
setRange.message >> aiUtility.colorR
setRange.message >> aiUtility.colorG
setRange.message >> aiUtility.colorB
if out :
aiUtility.outColor >> out
else :
pass
return aiUtility, SG
def createFresnel(out = None):
#创建菲涅尔节点组合
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
samplerInfo = pm.createNode('samplerInfo', name = 'Fre_samplerInfo_arnold')
ramp = pm.createNode('ramp', name = 'Fre_ramp_arnold')
aiUtility, SG = pm.createSurfaceShader('aiUtility', name = 'Fresnel_arnold')
#修改属性
ramp.interpolation.set("Exponential Down")
ramp.colorEntryList[2].remove(b=1)
ramp.colorEntryList[1].position.set(1)
ramp.colorEntryList[0].color.set(1,1,1)
ramp.colorEntryList[1].color.set(0,0,0)
aiUtility.shadeMode.set(2)
#链接属性
samplerInfo.facingRatio >> ramp.uvCoord.uCoord
samplerInfo.facingRatio >> ramp.uvCoord.vCoord
ramp.outColor >> aiUtility.color
if out :
aiUtility.outColor >> out
else :
pass
return aiUtility, SG
def createAO(out = None):
#创建AO材质球
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
aiAO, SG = pm.createSurfaceShader('aiAmbientOcclusion', name = 'ao_arnold')
#修改属性
aiAO.samples.set(5)
if out :
aiAO.outColor >> out
else :
pass
return aiAO, SG
def createNOM(out = None):
#创建NOM材质球
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
aiUtility, SG = pm.createSurfaceShader('aiUtility', name = 'nom_arnold')
#修改属性
aiUtility.shadeMode.set(2)
aiUtility.colorMode.set(3)
if out:
aiUtility.outColor >> out
else :
pass
return aiUtility, SG
def createIDPNode(key, out = None):
#创建IDP材质组合
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
if ARNOLD_IDP_TYPE.has_key(key):
try:
idp_shader = pm.PyNode(key)
SG = pm.PyNode('{0}SG'.format(key))
except:
idp_shader, SG = pm.createSurfaceShader('aiStandard', name = key)
idp_shader.aiEnableMatte.set(1)
aiMatteColor = ARNOLD_IDP_TYPE[key][0]
aiMatteColorA = ARNOLD_IDP_TYPE[key][1]
diffColor = ARNOLD_IDP_TYPE[key][2]
idp_shader.aiMatteColor.set(aiMatteColor)
idp_shader.aiMatteColorA.set(aiMatteColorA)
idp_shader.color.set(diffColor)
else :
return False
if out:
idp_shader.outColor >> out
else :
pass
return idp_shader, SG
def createCOCC(out = None):
#创建AO材质球
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
aiAO, SG = pm.createSurfaceShader('aiAmbientOcclusion', name = 'cocc_arnold')
#修改属性
aiAO.samples.set(5)
if out :
aiAO.outColor >> out
else :
pass
return aiAO, SG
def createFOGlight(out = None):
#创建FOGlight材质组合
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
FOGlight_arnold, SG = pm.createSurfaceShader("aiStandard", name = "FOGlight_arnold")
FOGlight_arnold.aiEnableMatte.set(1)
FOGlight_arnold.color.set(0,0,0)
if out :
FOGlight_arnold.outColor >> out
else :
pass
return FOGlight_arnold, SG
def createRGBlight(out = None):
#创建RGBlight材质组合
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
RGBlight_shader, SG = pm.createSurfaceShader("aiUtility", name = "RGBlight_arnold")
RGBlight_shader.shadeMode.set(1)
if out :
RGBlight_shader.outColor >> out
else :
pass
return RGBlight_shader, SG
def createShadow(out = None):
#创建shadow材质组合
#
#参数out: 属性输出给哪个节点, 连接属性
#
#创建节点
shadow_shader, SG = pm.createSurfaceShader("aiShadowCatcher", name = "shadow_arnold")
shadow_shader.shadowColor.set(1,1,1)
shadow_shader.hardwareColor.set(0,1,0)
if out :
shadow_shader.outColor >> out
else :
pass
return shadow_shader, SG
def assignShader(obj, shader, sg):
#给物体赋予材质球
#
#参数obj: 模型对象
#
#参数shader: 材质球对象
#
#参数sg: shadingEngine对象
#
#创建节点
pm.waitCursor(state=1)
pm.sets(sg, forceElement = obj)
pm.waitCursor(state=0)
return shader
def makeidp1Dic():
idp_dic = dict()
geos = [i.getParent() for i in pm.ls(type = "mesh") if not i.isIntermediate() and (i.isVisible() == 1) and ('charRigGrp' in i.fullPath() or 'CharRigGrp' in i.fullPath()) and not 'norender' in i.fullPath()]
had = []
for geo in geos:
for key, value in IDP1_TYPE_DIC.items():
for v in value:
if v in geo.fullPath():
idp_dic.setdefault(key, list()).append(geo.name())
had.append(geo)
break
no = list(set(geos) - set(had))
idp_dic.setdefault('C',no)
return idp_dic
def makeidp2Dic():
idp_dic = dict()
geos = [i for i in pm.ls(assemblies = 1) if 'charRigGrp' in i.name() or 'CharRigGrp' in i.name()]
if len(geos) > 7:
geos = geos[:7]
for i in range(len(geos)):
idp_dic.setdefault(IDP2_TYPE_LIST[i], geos[i])
return idp_dic
def makeidp3Dic():
idp_dic = dict()
geos = pm.ls(assemblies = 1)
for geo in geos:
for key, value in IDP3_TYPE_DIC.items():
for v in value:
if v in geo.name():
idp_dic.setdefault(key, list()).append(geo)
return idp_dic
if __name__ == "__main__":
#createFresnel()
createZ()