-
Notifications
You must be signed in to change notification settings - Fork 0
/
shotManager.py
388 lines (310 loc) · 14.8 KB
/
shotManager.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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
import maya.cmds as mc
from PySide import QtGui, QtCore
import maya.OpenMayaUI as apiUI
import shiboken
import os
import json
from functools import partial
from modules import saveAnim
from modules import createShot
from modules import importAnim
from utils import config
from utils import findAssetCategory
from modules import buildShot
from utils import jsonReader
from utils import saveSetsData
from utils import parentConstraint
from utils import keyConstraint
from modules import shotPreset
from utils import getShotData
from modules import animManager
from utils import instancer
reload(instancer)
reload(animManager)
reload(getShotData)
reload(importAnim)
reload(shotPreset)
reload(keyConstraint)
reload(parentConstraint)
reload(saveAnim)
reload(saveSetsData)
reload(jsonReader)
reload(buildShot)
reload(findAssetCategory)
reload(config)
reload(createShot)
def getMayaWindow():
"""
Get the main Maya window as a QtGui.QMainWindow instance
@return: QtGui.QMainWindow instance of the top level Maya windows
"""
ptr = apiUI.MQtUtil.mainWindow()
if ptr is not None:
return shiboken.wrapInstance(long(ptr), QtGui.QWidget)
scriptPath = os.path.dirname(__file__)
version = "0.11"
class ShotManager(QtGui.QMainWindow):
def __init__(self, parent=None):
super(ShotManager, self).__init__(parent=getMayaWindow())
# self.setSizeGripEnabled(True)
self.setObjectName("shotManagerWindow")
self.setWindowTitle("Shot Manager v%s" % version)
self.resize(1100, 950)
# menubar ----------------------------------------------------
self.menubar = QtGui.QMenuBar(self)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 18))
editManu = QtGui.QMenu(self.menubar)
editManu.setTitle("Edit")
saveManu = QtGui.QMenu(self.menubar)
saveManu.setTitle("Static Assets")
animationMenu = QtGui.QMenu(self.menubar)
animationMenu.setTitle("Animation")
constraintMenu = QtGui.QMenu(self.menubar)
constraintMenu.setTitle("Constraints")
self.shotPresetsMenu = QtGui.QMenu(self.menubar)
self.shotPresetsMenu.setTitle("Shot Presets")
self.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(self)
self.setStatusBar(self.statusbar)
createNew_menu = QtGui.QAction(self)
editCurrent_menu = QtGui.QAction(self)
copyCurrent_menu = QtGui.QAction(self)
createNew_menu.setText("Create New Shot")
editCurrent_menu.setText("Edit Current...")
copyCurrent_menu.setText("Copy Current")
editManu.addAction(createNew_menu)
editManu.addAction(editCurrent_menu)
editManu.addAction(copyCurrent_menu)
self.menubar.addAction(editManu.menuAction())
self.menubar.addAction(saveManu.menuAction())
self.menubar.addAction(animationMenu.menuAction())
self.menubar.addAction(constraintMenu.menuAction())
self.menubar.addAction(self.shotPresetsMenu.menuAction())
# save data menu actions
saveSets_menu = QtGui.QAction(self)
saveSets_menu.setText("Save Assets Transform")
createInstance_menu = QtGui.QAction(self)
createInstance_menu.setText("Duplicate Selected (Instance)")
saveManu.addAction(saveSets_menu)
saveManu.addSeparator()
saveManu.addAction(createInstance_menu)
# animation menu
saveAnimation_menu = QtGui.QAction(self)
saveAnimation_menu.setText("Save Animation for selected")
importAnimation_menu = QtGui.QAction(self)
importAnimation_menu.setText("Import Animation for selected")
animManager_menu = QtGui.QAction(self)
animManager_menu.setText("Animation Manager")
saveCamera_menu = QtGui.QAction(self)
saveCamera_menu.setText("Save Camera Animation")
importCamera_menu = QtGui.QAction(self)
importCamera_menu.setEnabled(False)
importCamera_menu.setText("Import Camera Animation")
animationMenu.addAction(saveAnimation_menu)
animationMenu.addAction(importAnimation_menu)
animationMenu.addAction(animManager_menu)
animationMenu.addSeparator()
animationMenu.addAction(saveCamera_menu)
animationMenu.addAction(importCamera_menu)
# constraints menu
parentConstraint_menu = QtGui.QAction(self)
parentConstraint_menu.setText("Create Parent Constraint")
keyConstraintOffmenu = QtGui.QAction(self)
keyConstraintOffmenu.setText("Key Constraint to 0")
keyConstraintOnmenu = QtGui.QAction(self)
keyConstraintOnmenu.setText("Key Constraint to 1")
deleteConstraint_menu = QtGui.QAction(self)
deleteConstraint_menu.setText("Delete Constraint")
constraintMenu.addAction(parentConstraint_menu)
constraintMenu.addSeparator()
constraintMenu.addAction(keyConstraintOffmenu)
constraintMenu.addAction(keyConstraintOnmenu)
constraintMenu.addSeparator()
constraintMenu.addAction(deleteConstraint_menu)
# shot presets menu
saveSelection_menu = QtGui.QAction(self)
saveSelection_menu.setText("Save Current Asset Selection")
self.shotPresetsMenu.addAction(saveSelection_menu)
self.shotPresetsMenu.addSeparator()
createNew_menu.triggered.connect(partial(self.openCreateShotWindow, mode="new"))
editCurrent_menu.triggered.connect(partial(self.openCreateShotWindow, mode="edit"))
copyCurrent_menu.triggered.connect(partial(self.openCreateShotWindow, mode="copy"))
parentConstraint_menu.triggered.connect(parentConstraint.parentConstraint)
keyConstraintOffmenu.triggered.connect(keyConstraint.keyToOff)
keyConstraintOnmenu.triggered.connect(keyConstraint.keyToOn)
deleteConstraint_menu.triggered.connect(parentConstraint.deleteConstraint)
# menubar ----------------------------------------------------
self.gui = GUI(self, [self.shotPresetsMenu])
self.setCentralWidget(self.gui)
# save sets data action
saveSets_menu.triggered.connect(partial(saveSetsData.sceneData, self.gui.shotListView))
# save animation action
saveAnimation_menu.triggered.connect(partial(saveAnim.saveAnimation, self.gui.shotListView))
saveCamera_menu.triggered.connect(partial(saveAnim.saveAnimation, self.gui.shotListView, cameraAnim=True))
# import animation action
importAnimation_menu.triggered.connect(self.importAnimation)
# anim manager window
animManager_menu.triggered.connect(self.animManager)
# instancer menu action
createInstance_menu.triggered.connect(self.makeInstance)
def makeInstance(self):
if mc.ls(sl=True):
selectedAsset = mc.ls(sl=True)[0]
instancer.instancer(assetName=selectedAsset)
def openCreateShotWindow(self, mode):
self.createShotWindow = createShot.CreateShotWindow(self.gui.shotListView, self.gui.contentsTreeView, mode)
self.createShotWindow.show()
def animManager(self):
if self.gui.shotListView.currentItem():
self.animManagerWindow = animManager.AnimationManager(self.gui.shotListView)
self.animManagerWindow.show()
else:
mc.warning("Select a shot.")
def importAnimation(self):
shotPath = getShotData.getShotFolder(self.gui.shotListView)
shotNumber = self.gui.shotListView.currentItem().text()
assetName = mc.ls(sl=True)[0].split(":")[0]
importAnim.importAnim(shotPath, assetName)
mc.inViewMessage( amg='Animation was imported from <hl>%s</hl>.' %shotNumber, pos='midCenter', fade=True )
class GUI(QtGui.QWidget):
def __init__(self, parent, menus):
super(GUI, self).__init__(parent)
self.mainWindow = parent
self.menus = menus
mainLayout = QtGui.QVBoxLayout()
self.setLayout(mainLayout)
mainGridlayout = QtGui.QGridLayout()
mainLayout.addLayout(mainGridlayout)
shotslayout = QtGui.QVBoxLayout()
shotDetailsLayout = QtGui.QVBoxLayout()
mainGridlayout.addLayout(shotslayout, 0,0)
mainGridlayout.addLayout(shotDetailsLayout, 0,1)
# shots groupBox
shotsGroupBox = QtGui.QGroupBox("Shots")
shotsGroupBoxlayout = QtGui.QVBoxLayout(shotsGroupBox)
shotslayout.addWidget(shotsGroupBox)
shotFilter_line = QtGui.QLineEdit()
shotFilter_line.setPlaceholderText("Filter shots by name...")
shotsGroupBoxlayout.addWidget(shotFilter_line)
self.shotListView = QtGui.QListWidget()
self.fontSize(11, self.shotListView)
shotsGroupBoxlayout.addWidget(self.shotListView)
# shot states
shotStates = ["WIP", "LEVEL_1", "LEVEL_2", "LEVEL_3"]
shotStateGridLayout = QtGui.QGridLayout()
shotState_lbl = QtGui.QLabel("Shot Version:")
shotState_lbl.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.shotStateCombo = QtGui.QComboBox()
for i in shotStates: self.shotStateCombo.addItem(i)
# set combo to default LEVEL 1
index = self.shotStateCombo.findText("LEVEL_1", QtCore.Qt.MatchFixedString)
if index >= 0:
self.shotStateCombo.setCurrentIndex(index)
shotStateGridLayout.addWidget(shotState_lbl, 0,0)
shotStateGridLayout.addWidget(self.shotStateCombo, 0,1)
shotsGroupBoxlayout.addLayout(shotStateGridLayout)
buildShot_bttn = QtGui.QPushButton("Build Shot")
addAsset_bttn = QtGui.QPushButton("Add Asset to Current Scene")
shotsGroupBoxlayout.addWidget(buildShot_bttn)
shotsGroupBoxlayout.addWidget(addAsset_bttn)
self.fillUpShotList()
self.shotListView.itemClicked.connect(self.fillUpContents)
# contents groupBox
contentsGroupBox = QtGui.QGroupBox("Assets")
contentsGroupBoxLayout = QtGui.QVBoxLayout(contentsGroupBox)
shotDetailsLayout.addWidget(contentsGroupBox)
self.contentsTreeView = QtGui.QTreeWidget()
self.contentsTreeView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.contentsTreeView.setHeaderHidden(True)
contentsGroupBoxLayout.addWidget(self.contentsTreeView)
self.fontSize(10, self.contentsTreeView)
# add context menu to contents
self.contentsTreeView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.contentsTreeView.customContextMenuRequested.connect(self.saveSelectionAsPresetContext)
# shotblasts groupBox
shotblastsGroupBox = QtGui.QGroupBox("Shotblasts")
shotblastsGroupBoxLayout = QtGui.QVBoxLayout(shotblastsGroupBox)
shotDetailsLayout.addWidget(shotblastsGroupBox)
self.shotblastList = QtGui.QTreeView()
self.shotblastList.doubleClicked.connect(self.openShotblast)
self.fontSize(11, self.shotblastList)
shotblast_bttn = QtGui.QPushButton("Create New Shotblast")
shotblastsGroupBoxLayout.addWidget(self.shotblastList)
shotblastsGroupBoxLayout.addWidget(shotblast_bttn)
# build shot action
buildShot_bttn.clicked.connect(partial(buildShot.buildShot, self.shotListView, self.contentsTreeView, self.shotStateCombo))
addAsset_bttn.clicked.connect(partial(buildShot.addAssetToScene, self.shotListView, self.contentsTreeView, self.shotStateCombo))
def saveSelectionAsPresetContext(self, point):
menu = QtGui.QMenu()
saveSelectionMenu = menu.addAction("Save Selection As Preset")
# connect menu actions
saveSelectionMenu.triggered.connect(self.saveSelectionAsPreset)
# show menu
menu.exec_(self.contentsTreeView.mapToGlobal(point))
def saveSelectionAsPreset(self):
shotPreset.saveSelection(self.mainWindow, self.contentsTreeView, self.menus[0], self.shotListView)
def openShotblast(self):
index = self.shotblastList.selectedIndexes()[0]
filename = self.model.filePath(index)
os.system("start "+filename)
def fontSize(self, size, widget):
font = QtGui.QFont()
font.setPointSize(size)
widget.setFont(font)
def fillUpShotList(self):
# get shot list from shot folder
shotRootFolder = config.rootFolder
shotList = os.listdir(shotRootFolder)
for i in shotList:
self.shotListView.addItem(i)
def fillUpShotblastsList(self):
rootFolder = config.rootFolder + self.shotListView.currentItem().text() + "/_shotblast"
filters = ["*.mov"]
self.model = QtGui.QFileSystemModel()
self.model.setRootPath(rootFolder)
self.model.setNameFilterDisables(False)
self.model.setNameFilters(filters)
self.shotblastList.setModel(self.model)
self.shotblastList.setRootIndex(self.model.index(rootFolder))
self.model.setFilter(QtCore.QDir.Files)
self.shotblastList.setColumnWidth(0, 200)
self.shotblastList.hideColumn(2)
def fillUpContents(self):
# clear contentView
self.contentsTreeView.clear()
# get shot number
shotName = self.shotListView.currentItem().text()
# get content data
shotDataFile = config.rootFolder + shotName + "/_shotData/shotData.json"
# clear presets menu
self.menus[0].clear()
# get presets for menu
presetsFile = config.rootFolder + shotName + "/_shotData/presets.json"
if os.path.isfile(presetsFile):
presets = jsonReader.jsonRead(presetsFile)
for presetName, value in presets.iteritems():
shotPreset.addMenuItem(self.mainWindow, self.menus[0], presetName, presetsFile, self.contentsTreeView)
data = jsonReader.jsonRead(shotDataFile)
assets = data["assets"]
for i in assets:
assetName = i
category = findAssetCategory.findCategory(assetName)
# create asset category if not exists
if not self.contentsTreeView.findItems( category, QtCore.Qt.MatchContains):
# add category to TreeView if not there
root = QtGui.QTreeWidgetItem(self.contentsTreeView, [category])
root.setExpanded(True)
root.setForeground(0,QtGui.QBrush(QtGui.QColor("#ADD8E6")))
childItem = QtGui.QTreeWidgetItem(root, [assetName])
childItem.setForeground(0,QtGui.QBrush(QtGui.QColor("#E9967A")))
else:
# find category item in list
root = self.contentsTreeView.findItems( category, QtCore.Qt.MatchContains)[0]
childItem = QtGui.QTreeWidgetItem(root, [assetName])
childItem.setForeground(0,QtGui.QBrush(QtGui.QColor("#E9967A")))
# refresh shotblast list view
self.fillUpShotblastsList()
if mc.window("shotManagerWindow", exists=True):
mc.deleteUI("shotManagerWindow")
window = ShotManager()
window.show()