-
Notifications
You must be signed in to change notification settings - Fork 0
/
FacialSetUp.py
166 lines (146 loc) · 8.39 KB
/
FacialSetUp.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
# -*- coding: utf-8 -*-
#import fit_positon
from maya import cmds
from maya import mel
from maya import OpenMayaUI as OMUI
import os
from inspect import getsourcefile
try:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtUiTools import *
from shiboken2 import wrapInstance
except ImportError:
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtUiTools import *
from shiboken import wrapInstance
mayaMainWindowPtr = OMUI.MQtUtil.mainWindow()
mayaMainWindow = wrapInstance(long(mayaMainWindowPtr), QWidget)
class AIFAE_FacialSetup(QWidget):
def __init__(self, *args, **kwargs):
super(AIFAE_FacialSetup, self).__init__(*args, **kwargs)
self.setParent(mayaMainWindow)
self.setWindowFlags(Qt.Window)
self.setWindowTitle("AI FAE Facial Setup Window")
self.initUI()
def initUI(self):
loader = QUiLoader()
file_path = os.path.abspath(getsourcefile(lambda : 0)) #获取脚本的绝对路径
currentUI = file_path.replace(".py", ".ui") #获取UI的的绝对路径
#print (file_path)
file = QFile( currentUI)
file.open(QFile.ReadOnly)
self.ui = loader.load(file, parentWidget=self)
self.ui.createControllerBtn.clicked.connect(self.auto_create_controller)
self.ui.fitPositionBtn.clicked.connect(self.fit_position)
self.ui.parentConstraintBtn.clicked.connect(self.doParentConstraint)
self.ui.pointConstraintBtn.clicked.connect(self.doPointConstraint)
self.ui.setDrivenKeyBtn.clicked.connect(self.doSetDrivenKey)
self.ui.deleteConstraintBtn.clicked.connect(self.doDeleteConstraint)
self.ui.parentConstraintBtn_2.clicked.connect(self.doParentConstraint2)
self.ui.pointConstraintBtn_2.clicked.connect(self.doPointConstraint2)
def auto_create_controller(self):
print ("Done!")
def fit_position(self):
print ("Fit position done!")
def doParentConstraint(self): #遍历场景根据名称进行约束
driverName = self.ui.driverNameLine.text()
drivenName = self.ui.drivenNameLine.text()
print (driverName, drivenName)
transformsObjects = cmds.ls(tr = True)
for driverObj in transformsObjects: #遍历场景中的物体
if driverName in driverObj: #查找驱动物体
drivenObj = driverObj.replace(driverName,drivenName) #设置驱动物体名称
if cmds.objExists(drivenObj): #确认被驱动物体是否存在
cmds.parentConstraint(driverObj, drivenObj , mo = True) #约束物体
def doPointConstraint(self): #遍历场景根据名称进行约束
driverName = self.ui.driverNameLine.text()
drivenName = self.ui.drivenNameLine.text()
print (driverName,drivenName)
transformsObjects = cmds.ls(tr = True)
for driverObj in transformsObjects: #遍历场景中的物体
if driverName in driverObj: #查找驱动物体
drivenObj = driverObj.replace(driverName,drivenName) #设置驱动物体名称
if cmds.objExists(drivenObj): #确认被驱动物体是否存在
#print driverObj,drivenObj
cmds.pointConstraint(driverObj,drivenObj , mo = True) #约束物体
def doParentConstraint2(self): #遍历场景根据名称进行约束
driverName = self.ui.driverNameLineSecond.text()
drivenName = self.ui.drivenNameLineSecond.text()
print (driverName, drivenName)
transformsObjects = cmds.ls(tr = True)
for driverObj in transformsObjects: #遍历场景中的物体
if driverName in driverObj: #查找驱动物体
drivenObj = driverObj.replace(driverName,drivenName) #设置驱动物体名称
if cmds.objExists(drivenObj): #确认被驱动物体是否存在
cmds.parentConstraint(driverObj, drivenObj , mo = True) #约束物体
def doPointConstraint2(self): #遍历场景根据名称进行约束
driverName = self.ui.driverNameLine.text()
drivenName = self.ui.drivenNameLine.text()
print (driverName,drivenName)
transformsObjects = cmds.ls(tr = True)
for driverObj in transformsObjects: #遍历场景中的物体
if driverName in driverObj: #查找驱动物体
drivenObj = driverObj.replace(driverName,drivenName) #设置驱动物体名称
if cmds.objExists(drivenObj): #确认被驱动物体是否存在
#print driverObj,drivenObj
cmds.pointConstraint(driverObj,drivenObj , mo = True) #约束物体
def doDeleteConstraint2(self): # 遍历场景根据名称进行删除
# driverName = self.ui.driverNameLine.text()
drivenName = self.ui.drivenNameLineSecond.text()
# print driverName
transformsObjects = cmds.ls(tr=True)
for obj in transformsObjects:
if "Constraint" in obj and drivenName in obj: # 确认被约束物体
cmds.delete(obj) # 删除约束
def doDeleteConstraint(self):#遍历场景根据名称进行删除
#driverName = self.ui.driverNameLine.text()
drivenName = self.ui.drivenNameLine.text()
#print driverName
transformsObjects = cmds.ls(tr=True)
for obj in transformsObjects:
if "Constraint" in obj and drivenName in obj: #确认被约束物体
cmds.delete(obj) #删除约束
def doSetDrivenKey(self):#遍历场景根据名称进行驱动
driverName = self.ui.driverNameLine_2.text()
drivenName = self.ui.drivenNameLine_2.text()
driverAttrA = self.ui.driverAttrA.text()
driverAttrB = self.ui.driverAttrB.text()
drivenAttrA = self.ui.drivenAttrA.text()
drivenAttrB = self.ui.drivenAttrB.text()
minRotateX = self.ui.minSpinBoxX.value()
midRotateX = self.ui.midSpinBoxX.value()
maxRotateX = self.ui.maxSpinBoxX.value()
minRotateY = self.ui.minSpinBoxY.value()
midRotateY = self.ui.midSpinBoxY.value()
maxRotateY = self.ui.maxSpinBoxY.value()
#print (minRotateX, midRotateX, maxRotateX, minRotateY, midRotateY, maxRotateY)
drivers = cmds.ls(sl=True) #选择驱动关键帧的控制器
if len(drivers)!=0:
for driver in drivers:
drivenObj = driver.replace(driverName, drivenName) #查找被驱动物体名称
if cmds.objExists(drivenObj): #如果被驱动物体存在,设置驱动关键帧
cmds.setDrivenKeyframe(drivenObj + ".%s"%drivenAttrA, currentDriver=driver+driverAttrA,
driverValue=-1, value=minRotateX)
cmds.setDrivenKeyframe(drivenObj + ".%s" % drivenAttrA, currentDriver=driver + driverAttrA,
driverValue=0, value=midRotateX)
cmds.setDrivenKeyframe(drivenObj + ".%s"%drivenAttrA, currentDriver=driver+driverAttrA,
driverValue=1, value=maxRotateX)
cmds.setDrivenKeyframe(drivenObj + ".%s"%drivenAttrB, currentDriver=driver+driverAttrB,
driverValue=-1, value=minRotateY)
cmds.setDrivenKeyframe(drivenObj + ".%s" % drivenAttrB, currentDriver=driver + driverAttrA,
driverValue=0, value=midRotateY)
cmds.setDrivenKeyframe(drivenObj + ".%s"%drivenAttrB, currentDriver=driver+driverAttrB,
driverValue=1, value=maxRotateY)
else:
print ("Your select %s is not exists!"%drivenObj)
else:
print ("No object is selected!")
def main():
ui = AIFAE_FacialSetup()
ui.show()
return ui
if __name__ == '__main__':
main()