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
|
"""
Author: Jeremy Ernst
"""
from functools import partial
import maya.cmds as cmds
import System.utils as utils
from ThirdParty.Qt import QtGui, QtCore, QtWidgets
class ART_AimMode():
"""
This class creates a tool that allows a rigger to toggle aim mode for a given selection of modules. Aim mode
ensures that the parent joints in a joint mover are always aiming at their children.
This tool can be called from the toolbar on the Rig Creator UI from the following button:
.. image:: /images/aimModeButton.png
The full interface looks like this:
.. image:: /images/aimMode.png
"""
def __init__(self, mainUI):
"""
Instantiates the class, getting the QSettings for the tool, and building the Aim Mode interface.
:param mainUI: The instance of the Rig Creator UI this tool was called from.
"""
# 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.buildAimModeUI()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def buildAimModeUI(self):
"""
Builds the Aim Mode interface, finding all modules that have the ability to aim, and listing those modules
as well as their current aim status.
"""
if cmds.window("ART_AimModeWin", exists=True):
cmds.deleteUI("ART_AimModeWin", wnd=True)
# launch a UI to get the name information
self.aimModeWin = QtWidgets.QMainWindow(self.mainUI)
# load stylesheet
styleSheetFile = utils.returnNicePath(self.toolsPath, "Core/Scripts/Interfaces/StyleSheets/mainScheme.qss")
f = open(styleSheetFile, "r")
self.style = f.read()
f.close()
self.aimModeWin.setStyleSheet(self.style)
# size policies
mainSizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
# create the main widget
self.aimModeWin_mainWidget = QtWidgets.QWidget()
self.aimModeWin.setCentralWidget(self.aimModeWin_mainWidget)
# set qt object name
self.aimModeWin.setObjectName("ART_AimModeWin")
self.aimModeWin.setWindowTitle("Aim Mode")
# create the mainLayout for the rig creator UI
self.aimModeWin_mainLayout = QtWidgets.QVBoxLayout(self.aimModeWin_mainWidget)
self.aimModeWin_mainLayout.setContentsMargins(0, 0, 0, 0)
self.aimModeWin.resize(400, 250)
self.aimModeWin.setSizePolicy(mainSizePolicy)
self.aimModeWin.setMinimumSize(QtCore.QSize(400, 250))
self.aimModeWin.setMaximumSize(QtCore.QSize(400, 250))
# create the background image
self.aimModeWin_frame = QtWidgets.QFrame()
self.aimModeWin_mainLayout.addWidget(self.aimModeWin_frame)
# create the layout for the widgets
self.aimModeWin_widgetLayout = QtWidgets.QHBoxLayout(self.aimModeWin_frame)
self.aimModeWin_widgetLayout.setContentsMargins(5, 5, 5, 5)
# add the QListWidget Frame
self.aimModeWin_moduleListFrame = QtWidgets.QFrame()
self.aimModeWin_moduleListFrame.setMinimumSize(QtCore.QSize(275, 200))
self.aimModeWin_moduleListFrame.setMaximumSize(QtCore.QSize(275, 200))
self.aimModeWin_moduleListFrame.setContentsMargins(20, 0, 20, 0)
# create the list widget
self.aimModeWin_moduleList = QtWidgets.QListWidget(self.aimModeWin_moduleListFrame)
self.aimModeWin_widgetLayout.addWidget(self.aimModeWin_moduleListFrame)
self.aimModeWin_moduleList.setMinimumSize(QtCore.QSize(265, 200))
self.aimModeWin_moduleList.setMaximumSize(QtCore.QSize(265, 200))
self.aimModeWin_moduleList.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.aimModeWin_moduleList.setSpacing(3)
# add the layout for the buttons
self.aimModeWin_buttonLayoutAll = QtWidgets.QVBoxLayout()
self.aimModeWin_widgetLayout.addLayout(self.aimModeWin_buttonLayoutAll)
self.aimModeWin_buttonLayoutAll.setContentsMargins(5, 20, 5, 20)
# add the selection buttons
self.aimModeWin_selectionButtonLayout = QtWidgets.QVBoxLayout()
self.aimModeWin_buttonLayoutAll.addLayout(self.aimModeWin_selectionButtonLayout)
self.aimModeWin_selectAllButton = QtWidgets.QPushButton("Select All")
self.aimModeWin_selectAllButton.setMinimumSize(QtCore.QSize(115, 25))
self.aimModeWin_selectAllButton.setMaximumSize(QtCore.QSize(115, 25))
self.aimModeWin_selectionButtonLayout.addWidget(self.aimModeWin_selectAllButton)
self.aimModeWin_selectAllButton.clicked.connect(self.aimModeWin_moduleList.selectAll)
self.aimModeWin_selectAllButton.setObjectName("blueButton")
self.aimModeWin_selectNoneButton = QtWidgets.QPushButton("Clear Selection")
self.aimModeWin_selectNoneButton.setMinimumSize(QtCore.QSize(115, 25))
self.aimModeWin_selectNoneButton.setMaximumSize(QtCore.QSize(115, 25))
self.aimModeWin_selectionButtonLayout.addWidget(self.aimModeWin_selectNoneButton)
self.aimModeWin_selectNoneButton.clicked.connect(self.aimModeWin_moduleList.clearSelection)
self.aimModeWin_selectNoneButton.setObjectName("blueButton")
# spacer
spacerItem = QtWidgets.QSpacerItem(20, 80, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.aimModeWin_selectionButtonLayout.addItem(spacerItem)
# add the buttons for reset settings and reset transforms
self.aimModeWin_turnOnAim = QtWidgets.QPushButton("On")
self.aimModeWin_turnOnAim.setMinimumSize(QtCore.QSize(115, 25))
self.aimModeWin_turnOnAim.setMaximumSize(QtCore.QSize(115, 25))
self.aimModeWin_selectionButtonLayout.addWidget(self.aimModeWin_turnOnAim)
self.aimModeWin_turnOnAim.setToolTip("Turn on Aim Mode for selected modules.")
self.aimModeWin_turnOnAim.clicked.connect(partial(self.aimModeUI_Toggle, True))
self.aimModeWin_turnOnAim.setObjectName("blueButton")
self.aimModeWin_turnOffAim = QtWidgets.QPushButton("Off")
self.aimModeWin_turnOffAim.setMinimumSize(QtCore.QSize(115, 25))
self.aimModeWin_turnOffAim.setMaximumSize(QtCore.QSize(115, 25))
self.aimModeWin_selectionButtonLayout.addWidget(self.aimModeWin_turnOffAim)
self.aimModeWin_turnOffAim.setToolTip("Turn off Aim Mode for selected modules.")
self.aimModeWin_turnOffAim.clicked.connect(partial(self.aimModeUI_Toggle, False))
self.aimModeWin_turnOffAim.setObjectName("blueButton")
# populate the list widget
modules = utils.returnRigModules()
for module in modules:
# get module name
moduleName = cmds.getAttr(module + ".moduleName")
# figure out if the module supports aimMode
canAim = False
if cmds.objExists(module + ".canAim"):
canAim = cmds.getAttr(module + ".canAim")
# see if it is currently in aimMode
aimMode = cmds.getAttr(module + ".aimMode")
# if it does, add it to the listwidget
if canAim:
# font
headerFont = QtGui.QFont()
headerFont.setPointSize(10)
headerFont.setBold(True)
# create the listWidgetItem
pixmap = QtGui.QPixmap(10, 10)
pixmap.fill(QtGui.QColor(0, 255, 0))
icon = QtGui.QIcon(pixmap)
pixmapOff = QtGui.QPixmap(10, 10)
pixmapOff.fill(QtGui.QColor(255, 0, 0))
iconOff = QtGui.QIcon(pixmapOff)
item = QtWidgets.QListWidgetItem(iconOff, moduleName)
item.setFont(headerFont)
item.setTextAlignment(QtCore.Qt.AlignCenter)
item.setData(QtCore.Qt.UserRole, [icon, iconOff])
if aimMode:
item.setIcon(icon)
self.aimModeWin_moduleList.addItem(item)
# show the window
self.aimModeWin.show()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def aimModeUI_Toggle(self, state):
"""
Calls on each selected module's aimMode function and sets the aimMode based on the passed in state.
:param state: Whether to turn aim mode on or off.
"""
selected = self.aimModeWin_moduleList.selectedItems()
items = []
for each in selected:
items.append(each.text())
if state:
each.setIcon(each.data(QtCore.Qt.UserRole)[0])
if not state:
each.setIcon(each.data(QtCore.Qt.UserRole)[1])
# call on each selected module's aimMode function
for each in self.mainUI.moduleInstances:
name = each.name
if name in items:
each.aimMode(state)
# clear selection
self.aimModeWin_moduleList.clearSelection()
|