-
Notifications
You must be signed in to change notification settings - Fork 0
/
shenqi.py
101 lines (77 loc) · 3.04 KB
/
shenqi.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
import os
from maya import cmds as mc
import time
myFolder = 'D:/myFolder/'
folders = os.listdir(myFolder)
bb = len(folders)
name = '神器'
if mc.window(name, query=True, exists=True):
mc.deleteUI(name)
window = mc.window(name)
column = mc.columnLayout()
mc.frameLayout(label='神器进度条')
progress = mc.progressBar(width=300, step=1)
mc.showWindow()
textures = []
i = 1
for folder in folders:
name = '神器'
if mc.window(name, query=True, exists=True):
mc.deleteUI(name)
window = mc.window(name)
column = mc.columnLayout()
mc.frameLayout(label='神器进度条: 正在生成%d/%d' % (i,len(folders)))
progress = mc.progressBar(width=300, step=1)
mc.showWindow()
# 贴图
textures = os.listdir(myFolder + folder +'/Textures/')
textures.sort()
print textures
diffuse = myFolder + folder + '/Textures/' + textures[1] # 颜色
normal = myFolder + folder + '/Textures/' + textures[2] # 法线
print diffuse, normal
# 材质球部分
shader = mc.shadingNode('blinn', asShader=True) # 材质球
nodeColor = mc.shadingNode('file', asTexture=True) # 颜色贴图
nodeNormal = mc.shadingNode('file', asTexture=True) # 法线贴图
nodeBump = mc.shadingNode('bump2d', asTexture=True)
mc.setAttr(nodeColor+'.fileTextureName', diffuse, type="string") # 添加颜色贴图
mc.setAttr(nodeNormal+'.fileTextureName', normal, type="string") # 添加法线贴图
mc.setAttr(nodeNormal+'.colorSpace', 'Raw', type='string')
mc.setAttr(nodeBump+'.bumpInterp', 1)
mc.connectAttr('%s.outAlpha' %nodeNormal, '%s.bumpValue' %nodeBump) # 将法线输出给bump
mc.connectAttr('%s.outNormal' %nodeBump, '%s.normalCamera' %shader) # 将bump输出给材质球
mc.connectAttr('%s.outColor' %nodeColor, '%s.color' %shader) # 将图片输出给材质球
# 模型部分
obj = myFolder + folder +'/'+ mc.getFileList(folder=myFolder+folder, filespec='*.obj')[0] # 获取模型文件
mc.file(obj, i=True, ns='wang%02d' % i) # 导入模型
geometry = mc.ls(geometry=True) # 选择模型
mc.select(geometry[0])
print geometry
mc.hyperShade(a=shader, assign=True) # 赋予材质
mc.select(mc.listRelatives(mc.ls(geometry=True), p=True, path=True), r=True)
nodes = mc.ls(sl=True)
edges = mc.ls(mc.polyListComponentConversion(te=True),fl=True)
a = []
b = []
for edge in edges:
mc.select(edge)
uvs = mc.ls(mc.polyListComponentConversion(tuv=True),fl=True)
for uv in uvs:
p = mc.polyEditUV(uv, query=True)
a.append(p)
if len(a) == 4:
if a[0] == a[1] and a[2] == a[3]:
b.append(edge)
elif a[0] == a[2] and a[1] == a[3]:
b.append(edge)
elif a[0] == a[3] and a[1] == a[2]:
b.append(edge)
a = []
mc.progressBar(progress, edit=True, step=1, maxValue=len(edges))
mc.select(b)
mc.SewUVs()
mc.FBXExport('-file', 'C:/Users/Intime/Desktop/aa/a%d' %i) # 导出模型
mc.file(new=True, force=True) # 刷新场景
i += 1
bb -= 1