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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
"""
Author: Jeremy Ernst
"""
from functools import partial
import maya.cmds as cmds
import maya.mel as mel
import System.riggingUtils as riggingUtils
import System.utils as utils
from ThirdParty.Qt import QtGui, QtCore, QtWidgets
class ART_AddOrRemoveInfluences():
"""
This class is used to list influences in or out of the current skinCluster, and then remove or add said
influences given current selection.
It is called from this button, found after finalizing your setup:
.. image:: /images/addRemoveInfsButton.png
This is what the full interface looks like:
.. image:: /images/addRemoveInfs.png
"""
def __init__(self, mainUI):
"""
Instantiates the class, taking in the instance of the rig creator skin tools interface. Get settings values
from QSettings. Build the interface.
:param mainUI: Instance of the skin tools interface.
"""
# get the directory path of the tools
settings = QtCore.QSettings("Epic Games", "ARTv2")
self.toolsPath = settings.value("toolsPath")
self.iconsPath = settings.value("iconPath")
self.mainUI = mainUI
# build the UI
self.buildInterface()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def buildInterface(self):
"""
Builds the interface for the tool, finding all joints that compose the asset, comparing them to joints in the
skinCluster, then separating the initial list into joints in the cluster, and joints not in the cluster.
"""
if cmds.window("ART_addRemoveInfsWin", exists=True):
cmds.deleteUI("ART_addRemoveInfsWin", wnd=True)
# launch a UI to get the name information
self.addRemoveInfsWin = QtWidgets.QMainWindow(self.mainUI)
# size policies
mainSizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
# create the main widget
self.addRemoveInfsWin_mainWidget = QtWidgets.QWidget()
self.addRemoveInfsWin.setCentralWidget(self.addRemoveInfsWin_mainWidget)
# load stylesheet
styleSheetFile = utils.returnNicePath(self.toolsPath, "Core/Scripts/Interfaces/StyleSheets/mainScheme.qss")
f = open(styleSheetFile, "r")
self.style = f.read()
f.close()
# set qt object name
self.addRemoveInfsWin.setObjectName("ART_addRemoveInfsWin")
self.addRemoveInfsWin.setWindowTitle("Add/Remove Influences")
# create the mainLayout for the ui
self.addRemoveInfsWin_mainLayout = QtWidgets.QVBoxLayout(self.addRemoveInfsWin_mainWidget)
self.addRemoveInfsWin_mainLayout.setContentsMargins(5, 5, 5, 5)
self.addRemoveInfsWin.resize(300, 450)
self.addRemoveInfsWin.setSizePolicy(mainSizePolicy)
self.addRemoveInfsWin.setMinimumSize(QtCore.QSize(300, 450))
self.addRemoveInfsWin.setMaximumSize(QtCore.QSize(300, 450))
# create the background image
self.addRemoveInfsWin_frame = QtWidgets.QFrame()
self.addRemoveInfsWin_mainLayout.addWidget(self.addRemoveInfsWin_frame)
self.addRemoveInfsWin_frame.setObjectName("dark")
# create the main layout for the widgets
self.addRemoveInfsWin_widgetLayout = QtWidgets.QHBoxLayout(self.addRemoveInfsWin_frame)
# two layouts needed for the widget layout. left side = vertical layout for filters,
# search, and list. right layout = vertical layout for buttons
self.addRemoveInfsWin_leftSideLayout = QtWidgets.QVBoxLayout()
self.addRemoveInfsWin_widgetLayout.addLayout(self.addRemoveInfsWin_leftSideLayout)
self.addRemoveInfsWin_rightSideLayout = QtWidgets.QVBoxLayout()
self.addRemoveInfsWin_widgetLayout.addLayout(self.addRemoveInfsWin_rightSideLayout)
# left side: filters, search, list
self.addRemoveInfsWin_filters = QtWidgets.QComboBox()
self.addRemoveInfsWin_leftSideLayout.addWidget(self.addRemoveInfsWin_filters)
self.addRemoveInfsWin_filters.addItem("Show Influences In Skin")
self.addRemoveInfsWin_filters.addItem("Show Influences Not In Skin")
self.addRemoveInfsWin_filters.currentIndexChanged.connect(partial(self.addOrRemoveInfs_ShowInfsFilter))
self.addRemoveInfsWin_search = QtWidgets.QLineEdit()
self.addRemoveInfsWin_leftSideLayout.addWidget(self.addRemoveInfsWin_search)
self.addRemoveInfsWin_search.setPlaceholderText("Search...")
self.addRemoveInfsWin_search.textChanged.connect(partial(self.addOrRemoveInfs_Search))
self.addRemoveInfsWin_infList = QtWidgets.QListWidget()
self.addRemoveInfsWin_leftSideLayout.addWidget(self.addRemoveInfsWin_infList)
self.addRemoveInfsWin_infList.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
# right side: add button, remove button, prune weights, remove unused button
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
self.addRemoveInfsWin_refreshSelBtn = QtWidgets.QPushButton("Refresh")
self.addRemoveInfsWin_rightSideLayout.addWidget(self.addRemoveInfsWin_refreshSelBtn)
self.addRemoveInfsWin_refreshSelBtn.setMinimumSize(110, 35)
self.addRemoveInfsWin_refreshSelBtn.setMaximumSize(110, 35)
self.addRemoveInfsWin_refreshSelBtn.setFont(font)
self.addRemoveInfsWin_refreshSelBtn.clicked.connect(partial(self.addOrRemoveInfs_RefreshSelection))
self.addRemoveInfsWin_refreshSelBtn.setObjectName("blueButton")
self.addRemoveInfsWin_rightSideLayout.addSpacerItem(
QtWidgets.QSpacerItem(100, 300, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed))
self.addRemoveInfsWin_addInfBtn = QtWidgets.QPushButton("Add")
self.addRemoveInfsWin_rightSideLayout.addWidget(self.addRemoveInfsWin_addInfBtn)
self.addRemoveInfsWin_addInfBtn.setMinimumSize(110, 35)
self.addRemoveInfsWin_addInfBtn.setMaximumSize(110, 35)
self.addRemoveInfsWin_addInfBtn.setFont(font)
self.addRemoveInfsWin_addInfBtn.clicked.connect(partial(self.addOrRemoveInfs_addInf, True, False))
self.addRemoveInfsWin_addInfBtn.setObjectName("blueButton")
self.addRemoveInfsWin_removeInfBtn = QtWidgets.QPushButton("Remove")
self.addRemoveInfsWin_rightSideLayout.addWidget(self.addRemoveInfsWin_removeInfBtn)
self.addRemoveInfsWin_removeInfBtn.setMinimumSize(110, 35)
self.addRemoveInfsWin_removeInfBtn.setMaximumSize(110, 35)
self.addRemoveInfsWin_removeInfBtn.setFont(font)
self.addRemoveInfsWin_removeInfBtn.clicked.connect(partial(self.addOrRemoveInfs_addInf, False, False))
self.addRemoveInfsWin_removeInfBtn.setObjectName("blueButton")
self.addRemoveInfsWin_removeUnusedInfBtn = QtWidgets.QPushButton("Remove Unused")
self.addRemoveInfsWin_rightSideLayout.addWidget(self.addRemoveInfsWin_removeUnusedInfBtn)
self.addRemoveInfsWin_removeUnusedInfBtn.setMinimumSize(110, 35)
self.addRemoveInfsWin_removeUnusedInfBtn.setMaximumSize(110, 35)
self.addRemoveInfsWin_removeUnusedInfBtn.setFont(font)
self.addRemoveInfsWin_removeUnusedInfBtn.clicked.connect(partial(self.addOrRemoveInfs_addInf, False, True))
self.addRemoveInfsWin_removeUnusedInfBtn.setObjectName("blueButton")
self.addRemoveInfsWin_pruneBtn = QtWidgets.QPushButton("Prune Weights")
self.addRemoveInfsWin_rightSideLayout.addWidget(self.addRemoveInfsWin_pruneBtn)
self.addRemoveInfsWin_pruneBtn.setMinimumSize(110, 35)
self.addRemoveInfsWin_pruneBtn.setMaximumSize(110, 35)
self.addRemoveInfsWin_pruneBtn.setFont(font)
self.addRemoveInfsWin_pruneBtn.clicked.connect(partial(self.addOrRemoveInfs_prune))
self.addRemoveInfsWin_pruneBtn.setObjectName("blueButton")
# populate infList
self.addOrRemoveInfs_RefreshSelection()
# show window
self.addRemoveInfsWin.show()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def addOrRemoveInfs_RefreshSelection(self):
"""
Regenerate the lists comparing all joints of the rig to joints in the skin cluster and joints not in the
skinCluster. Clear the listWidgets and refresh with new data.
"""
self.addRemoveInfsWin_infList.clear()
# get selection, find skin cluster, find influences in skinCluster, and populate listWidget
selection = cmds.ls(sl=True)
if len(selection) > 0:
skinCluster = riggingUtils.findRelatedSkinCluster(selection[0])
if skinCluster is not None:
skinInfs = cmds.skinCluster(skinCluster, q=True, inf=True)
for inf in skinInfs:
self.addRemoveInfsWin_infList.addItem(inf)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def addOrRemoveInfs_ShowInfsFilter(self):
"""
Change what is displayed in the QListWidget based on the QComboBox setting of which joints to show: those in
the skinCluster, or those not in the skinCluster.
"""
self.addRemoveInfsWin_infList.clear()
currentIndex = self.addRemoveInfsWin_filters.currentIndex()
selection = cmds.ls(sl=True)
if len(selection) > 0:
skinCluster = riggingUtils.findRelatedSkinCluster(selection[0])
if skinCluster is not None:
skinInfs = cmds.skinCluster(skinCluster, q=True, inf=True)
# if filter set to show infs in cluster:
if currentIndex == 0:
for each in skinInfs:
self.addRemoveInfsWin_infList.addItem(each)
# if filter set to show non-skinned infs
if currentIndex == 1:
# get full path
dagPath = cmds.ls(skinInfs[0], long=True)[0]
rootJoint = dagPath.partition("|")[2].partition("|")[0]
currentSelection = cmds.ls(sl=True)[0]
# get all joints
cmds.select(rootJoint, hi=True)
skeleton = cmds.ls(sl=True)
cmds.select(currentSelection)
# compare all joints to infs list
for each in skeleton:
if each not in skinInfs:
self.addRemoveInfsWin_infList.addItem(each)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def addOrRemoveInfs_Search(self):
"""
Hides all items in the QListWidget, then compares the QLineEdit search text with each item in the QListWidget,
and if the search text is found in the text of an item, show that QListWidgetItem.
"""
searchKey = self.addRemoveInfsWin_search.text()
# get all items in the joint list
allItems = []
for i in range(self.addRemoveInfsWin_infList.count()):
item = self.addRemoveInfsWin_infList.item(i)
itemName = item.text()
allItems.append([item, itemName])
# hide all items in list
for item in allItems:
item[0].setHidden(True)
item[0].setSelected(False)
# find items in list with search key and show item
if searchKey.find("*") == 0:
matchedItems = self.addRemoveInfsWin_infList.findItems(searchKey, QtCore.Qt.MatchFlag.MatchWildcard)
for item in matchedItems:
item.setHidden(False)
item.setSelected(True)
else:
matchedItems = self.addRemoveInfsWin_infList.findItems(searchKey, QtCore.Qt.MatchFlag.MatchContains)
for item in matchedItems:
item.setHidden(False)
item.setSelected(True)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def addOrRemoveInfs_addInf(self, add, removeUnused):
"""
Either add, or remove, selected influences from the QListWidget to/from the skinCluster. (the main function)
:param add: Whether or not to add or remove.
:param removeUnused: If this flag is set, remove any unweighted influences in the skinCluster.
"""
# get current selection in scene
currentSelection = cmds.ls(sl=True)
# get selected items in infList
selectedItems = self.addRemoveInfsWin_infList.selectedItems()
# find the skinCluster
selection = cmds.ls(sl=True)
if len(selection) > 0:
skinCluster = riggingUtils.findRelatedSkinCluster(selection[0])
# removed unused influences
if removeUnused:
weightedInfs = cmds.skinCluster(skinCluster, q=True, weightedInfluence=True)
allInfs = cmds.skinCluster(skinCluster, q=True, inf=True)
for inf in allInfs:
if inf not in weightedInfs:
cmds.skinCluster(skinCluster, edit=True, ri=inf)
cmds.select(currentSelection)
self.addOrRemoveInfs_RefreshSelection()
self.addOrRemoveInfs_ShowInfsFilter()
return
# add selectedItems to the skinCluster
for item in selectedItems:
if add:
cmds.skinCluster(skinCluster, edit=True, ai=item.text(), wt=0, lw=True)
if not add:
cmds.skinCluster(skinCluster, edit=True, ri=item.text())
# refresh list
cmds.select(currentSelection)
self.addOrRemoveInfs_RefreshSelection()
self.addOrRemoveInfs_ShowInfsFilter()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def addOrRemoveInfs_prune(self):
"""
Calls on Maya's built in prune skin weights tool.
"""
mel.eval("PruneSmallWeightsOptions;")
# get current selection in scene
currentSelection = cmds.ls(sl=True)
# refresh lists
cmds.select(currentSelection)
self.addOrRemoveInfs_RefreshSelection()
self.addOrRemoveInfs_ShowInfsFilter()
|