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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
"""
Author: Jeremy Ernst
"""
import os
import maya.cmds as cmds
import maya.mel as mel
import System.utils as utils
import System.interfaceUtils as interfaceUtils
import System.riggingUtils as riggingUtils
from ThirdParty.Qt import QtGui, QtCore, QtWidgets
class ART_BuildProgress_UI():
"""
This class kicks off building all of the rigs for the modules. It displays an interface that shows progress and
displays information about the rig build.
It exports skin weights, rebuilds the skeleton in rig pose, imports skin weights, runs any pre-script,
calls on each module's rig building code, sets up rig parenting and hierarchy, and finally runs any post-script.
.. image:: /images/buildProgress.gif
"""
def __init__(self, mainUI):
"""
Instantiates the class, getting the QSettings and then calling on the function to build the UI for the tool.
:param mainUI: The instance of the Rig Creator UI that this class was called from.
.. seealso:: ART_BuildProgressUI.buildUI
"""
# get the directory path of the tools
settings = QtCore.QSettings("Epic Games", "ARTv2")
self.toolsPath = settings.value("toolsPath")
self.projectPath = settings.value("projectPath")
self.iconsPath = settings.value("iconPath")
self.mainUI = mainUI
self.rigData = []
self.warnings = 0
self.errors = 0
# images
self.imageBkgrd = utils.returnFriendlyPath(os.path.join(self.iconsPath, "System/toolbar_background.png"))
self.imageBtnBkrd = utils.returnFriendlyPath(os.path.join(self.iconsPath, "System/blue_field_background.png"))
self.frameBackground = utils.returnFriendlyPath(os.path.join(self.iconsPath, "System/field_background.png"))
# build the UI
if cmds.window("ART_BuildProgressWin", exists=True):
cmds.deleteUI("ART_BuildProgressWin", wnd=True)
self.buildUI()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def buildUI(self):
"""
Builds the interface, which doesn't really have any user-interaction, but is there to display information
about the progress of the rig build. There are two QProgressBars that show current module build progress and
total build progress, then a QTextEdit which outputs information about what the build process is currently
working on.
After the interface is built, it sets the rig pose on the joints of each module.
"""
# create the main window
self.mainWin = QtWidgets.QMainWindow(interfaceUtils.getMainWindow())
self.mainWin.setStyleSheet("background-color: rgb(0, 0, 0);, color: rgb(0,0,0);")
styleSheetFile = utils.returnNicePath(self.toolsPath, "Core/Scripts/Interfaces/StyleSheets/mainScheme.qss")
f = open(styleSheetFile, "r")
self.style = f.read()
f.close()
self.mainWin.setStyleSheet(self.style)
# create the main widget
self.mainWidget = QtWidgets.QWidget()
self.mainWin.setCentralWidget(self.mainWidget)
# set qt object name
self.mainWin.setObjectName("ART_BuildProgressWin")
self.mainWin.setWindowTitle("Build Progress")
# font
headerFont = QtGui.QFont()
headerFont.setPointSize(8)
headerFont.setBold(True)
# set size policy
mainSizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
# create the mainLayout for the rig creator UI
self.layout = QtWidgets.QVBoxLayout(self.mainWidget)
self.mainWin.resize(500, 300)
self.mainWin.setSizePolicy(mainSizePolicy)
self.mainWin.setMinimumSize(QtCore.QSize(500, 300))
self.mainWin.setMaximumSize(QtCore.QSize(500, 300))
# create the QFrame for this page
self.background = QtWidgets.QFrame()
self.layout.addWidget(self.background)
self.mainLayout = QtWidgets.QVBoxLayout(self.background)
self.background.setObjectName("epic")
# build the progress bars:
self.currentTask = QtWidgets.QProgressBar()
self.mainLayout.addWidget(self.currentTask)
self.currentTask.setRange(0, 100)
self.currentTask.setTextVisible(True)
self.currentTask.setValue(0)
self.totalProgress = QtWidgets.QProgressBar()
self.mainLayout.addWidget(self.totalProgress)
self.totalProgress.setFormat("Total Progress..")
self.totalProgress.setRange(0, 12)
self.totalProgress.setTextVisible(True)
self.totalProgress.setValue(0)
# detailed information
self.infoText = QtWidgets.QTextEdit()
self.mainLayout.addWidget(self.infoText)
self.infoText.setMinimumHeight(200)
self.infoText.setMaximumHeight(200)
self.infoText.setText("Starting Build Process..")
self.infoText.setReadOnly(True)
# show the window
self.mainWin.show()
# start build
self.setRigPose()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def exportWeights(self):
"""
Exports all skin weights of meshes that have skinClusters to a .weights file (JSON). It also has
functionality to deal with morph targets, making sure they are preserved when history on the meshes is deleted.
.. seealso:: riggingUtils.export_skin_weights()
"""
self.infoText.append("\n")
self.infoText.append("|| EXPORTING SKIN WEIGHTS ||")
# find meshes that are weighted
weightedMeshes = []
skinClusters = cmds.ls(type='skinCluster')
for cluster in skinClusters:
geometry = cmds.skinCluster(cluster, q=True, g=True)[0]
geoTransform = cmds.listRelatives(geometry, parent=True)[0]
weightedMeshes.append([geoTransform, cluster])
# update progress bar
numMeshes = len(weightedMeshes)
self.currentTask.setRange(0, numMeshes)
self.currentTask.setValue(0)
# save out weights of meshes
for mesh in weightedMeshes:
filePath = utils.returnFriendlyPath(os.path.join(cmds.internalVar(utd=True), mesh[0] + ".WEIGHTS"))
# export skin weights
riggingUtils.export_skin_weights(filePath, mesh[0])
# CHECK FOR MORPH TARGETS
blendshapeList = []
# find blendshapes
skinCluster = riggingUtils.findRelatedSkinCluster(mesh[0])
if skinCluster is not None:
blendshapes = cmds.listConnections(skinCluster + ".input", source=True, type="blendShape")
deleteShapes = []
if blendshapes is not None:
for each in blendshapes:
attrs = cmds.listAttr(each, m=True, string="weight")
if attrs is not None:
for attr in attrs:
# if not, manually create shapes by toggling attrs and duplicating mesh
if not cmds.objExists(attr):
cmds.setAttr(each + "." + attr, 1)
dupe = cmds.duplicate(mesh[0])[0]
# parent to world
parent = cmds.listRelatives(dupe, parent=True)
if parent is not None:
cmds.parent(dupe, world=True)
# rename the duplicate mesh to the blendshape name
cmds.rename(dupe, attr)
cmds.setAttr(each + "." + attr, 0)
deleteShapes.append(attr)
# add the blendshape node name and its attrs to the master blendshape list
blendshapeList.append([each, attrs])
# delete history of meshes
cmds.delete(mesh[0], ch=True)
# reapply blendshapes
for item in blendshapeList:
bshapeName = item[0]
shapeList = item[1]
i = 1
for shape in shapeList:
if cmds.objExists(bshapeName):
cmds.blendShape(bshapeName, edit=True, t=(mesh[0], i, shape, 1.0))
else:
cmds.select([shape, mesh[0]], r=True)
cmds.blendShape(name=bshapeName)
cmds.select(clear=True)
try:
for each in deleteShapes:
cmds.delete(each)
except:
pass
# update progress and info
self.infoText.append(" Exported Skin Weights for " + mesh[0])
curVal = self.currentTask.value()
self.currentTask.setValue(curVal + 1)
# update main progress bar
self.totalProgress.setValue(1)
self.infoText.append("\n")
# rebuild the skeleton in rig pose
self.rebuildSkeleton()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def setRigPose(self):
"""
Sets the rig pose on each module's joints. Lastly, calls on ART_BuildProgressUI.exportWeights()
..seealso :: ART_BuildProgressUI.exportWeights()
"""
# set rig pose
self.infoText.append("Setting Rig Pose..")
numMods = len(self.mainUI.moduleInstances) - 1
self.currentTask.setRange(0, numMods)
self.currentTask.setValue(0)
for inst in self.mainUI.moduleInstances:
if inst.name != "root":
inst.setupForRigPose()
inst.setReferencePose("rigPose")
inst.cleanUpRigPose()
curVal = self.currentTask.value()
self.currentTask.setValue(curVal + 1)
# update main progress bar
self.totalProgress.setValue(2)
self.exportWeights()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def rebuildSkeleton(self):
"""
Rebuilds the skeleton in rig pose, meaning that all joint rotations will be zeroed in rig pose rather than
model pose. This ensures clean rigging.
Lastly, calls on ART_BuildProgressUI.importWeights() to reimport weighting back onto the meshes.
.. seealso:: riggingUtils.buildSkeleton(), ART_BuildProgressUI.importWeights()
"""
# rebuild the skeleton
cmds.delete("root")
self.infoText.append("Rebuilding Skeleton in Rig Pose..")
# build skeleton from utils
riggingUtils.buildSkeleton()
# update main progress bar
self.totalProgress.setValue(3)
# import weights
self.importWeights()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def importWeights(self):
"""
Imports skin weights back onto the asset geometry after having rebuilt the skeleton in rig pose. Then calls
on ART_BuildProgressUI.preScript().
.. seealso:: ART_BuildProgressUI.preScript()
"""
meshes = utils.findAllSkinnableGeo()
self.currentTask.setRange(0, len(meshes))
self.currentTask.setValue(0)
self.infoText.append("\n")
self.infoText.append("|| IMPORTING SKIN WEIGHTS ||")
for mesh in meshes:
filePath = utils.returnFriendlyPath(os.path.join(cmds.internalVar(utd=True), mesh + ".WEIGHTS"))
if os.path.exists(filePath):
riggingUtils.import_skin_weights(filePath, mesh, True)
# update progress and info
self.infoText.append(" Imported Skin Weights for " + mesh)
curVal = self.currentTask.value()
self.currentTask.setValue(curVal + 1)
# remove skin file
os.remove(filePath)
else:
# update progress and info
self.infoText.setTextColor(QtGui.QColor(236, 217, 0))
self.infoText.append(" Could not import weights for " + mesh)
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
self.warnings += 1
curVal = self.currentTask.value()
self.currentTask.setValue(curVal + 1)
# update main progress bar
self.totalProgress.setValue(5)
# call on the prescript
self.preScript()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# def exportMeshes(self):
#
# lodAttrs = utils.getLodData()
# exportData = utils.findExportMeshData()
#
# self.currentTask.setRange(0, len(lodAttrs))
# self.currentTask.setValue(0)
#
#
# #save the file
# saveFile = cmds.file(q = True, sceneName = True)
#
#
# try:
# cmds.file(save = True)
# except Exception, e:
# cmds.error("Could not save file. Error: " + str(e))
# return
#
#
# #for each LOD
# for each in exportData:
# meshValue = each[1]
# pathValue = each[0]
# boneValue = each[2]
# poseData = each[3]
# utils.exportMesh(self.mainUI, meshValue, pathValue, boneValue, poseData)
#
# #open the file
# cmds.file(saveFile, open = True, force = True)
#
# #update UI
# self.infoText.setTextColor(QtGui.QColor(0,255,18))
# self.infoText.append(" SUCCESS: FBX file exported.")
# self.infoText.append(" " + str(pathValue))
# self.infoText.setTextColor(QtGui.QColor(255,255,255))
#
# #update progress bar
# curVal = self.currentTask.value()
# self.currentTask.setValue(curVal + 1)
#
# #update main progress bar
# self.totalProgress.setValue(7)
#
# #run pre-script
# self.preScript()
"""
Keeping this around for now, but currently it is not being used.
Exporting is now done through edit rig -> Export Skeletal Meshes
"""
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def preScript(self):
"""
If there is a pre-script to run, this will call on ART_BuildProgressUI.executeScript() to run the pre-script.
Then it will call on ART_BuildProgressUI.buildRigs() to build each module's rigs.
.. note:: Pre-Scipts are used if you ever want to do something to your character before the rig gets built.
An example usage would be adding IK joints for UE4 in a pre-script, as you don't want or need
controls for those IK joints, and setting up those constraints.
.. seealso:: ART_BuildProgressUI.executeScript(), ART_BuildProgressUI.buildRigs()
"""
self.infoText.append(" \n")
# get pre-script path from character node, if it exists
characterNode = utils.returnCharacterModule()
if cmds.objExists(characterNode + ".preScriptPath"):
scriptPath = cmds.getAttr(characterNode + ".preScriptPath")
self.infoText.append("Executing Pre-Script..")
self.infoText.append(" " + scriptPath)
# try to execute the pre-script
status = self.executeScript(scriptPath)
if status:
self.infoText.setTextColor(QtGui.QColor(0, 255, 18))
self.infoText.append(" SUCCESS: Pre-Script Was Successfully Executed..")
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
if not status:
self.infoText.setTextColor(QtGui.QColor(255, 0, 0))
self.infoText.append(" FAILED: Pre-Script Was Not Successfully Executed..")
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
self.errors += 1
else:
self.infoText.setTextColor(QtGui.QColor(255, 255, 0))
self.infoText.append("No Pre-Script To Run..")
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
# update main progress bar
self.totalProgress.setValue(8)
# build rigs
self.buildRigs()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def buildRigs(self):
"""
First, create a driver skeleton which the rig will build upon, then calls on each module's buildCustomRig
function, which will build the rig for that module, then sets up rig parenting and hiearchy once all modules
are built.
Lastly, calls on the function to execute a post script if one was given during publish.
.. seealso:: riggingUtils.createDriverSkeleton(), ART_BuildProgressUI.postScript()
"""
self.infoText.append(" \n")
self.infoText.append("|| PREPARING TO BUILD CONTROL RIGS.. ||")
# Update Current Task bar with num modules
self.currentTask.setRange(0, len(self.mainUI.moduleInstances))
self.currentTask.setValue(0)
# create the driver skeleton
riggingUtils.createDriverSkeleton()
# Loop through modules, building rigs
for inst in self.mainUI.moduleInstances:
self.infoText.append(" \n")
self.infoText.append(" Building: " + str(inst.name))
# build module rigs
inst.buildRig(self.infoText, self)
# update progress bar
curVal = self.currentTask.value()
self.currentTask.setValue(curVal + 1)
# =======================================================================
# #Setup the rig parenting
# =======================================================================
for data in self.rigData:
createdConstraints = []
if data[1] == "driver_root":
pConst = cmds.pointConstraint("offset_anim", data[0], mo=True)[0]
oConst = cmds.orientConstraint("offset_anim", data[0], mo=True)[0]
if pConst not in createdConstraints:
createdConstraints.append(pConst)
if oConst not in createdConstraints:
createdConstraints.append(oConst)
else:
# get the connections of the passed in parent bone
connections = []
for connection in cmds.listConnections(data[1], type="constraint"):
connections.append(connection)
for connection in list(set(connections)):
constraintType = cmds.nodeType(connection)
driveAttrs = []
targetWeights = []
# get those constraint target attributes for each constraint connection
targets = cmds.getAttr(connection + ".target", mi=True)
if len(targets) >= 1:
for each in targets:
# get the names of the constraint targets
targetWeights.append(
cmds.listConnections(connection + ".target[" + str(each) + "].targetWeight",
p=True)[0])
for targetWeight in targetWeights:
name = targetWeight.rpartition(".")[2]
name = name.rpartition("W")[0]
if name not in driveAttrs:
driveAttrs.append(name)
# Setup constraint between the driveAttrs and the rigData[0] node
for attr in driveAttrs:
print attr, data[0]
if constraintType == "pointConstraint":
try:
pConst = cmds.pointConstraint(attr, data[0], mo=True)[0]
if pConst not in createdConstraints:
createdConstraints.append(pConst)
except Exception, e:
cmds.warning(str(e))
if constraintType == "orientConstraint":
try:
oConst = cmds.orientConstraint(attr, data[0], mo=True)[0]
if oConst not in createdConstraints:
createdConstraints.append(oConst)
except Exception, e:
cmds.warning(str(e))
if constraintType == "parentConstraint":
try:
paConst = cmds.parentConstraint(attr, data[0], mo=True)[0]
if paConst not in createdConstraints:
createdConstraints.append(paConst)
except Exception, e:
cmds.warning(str(e))
# get the names of the constraint targets
for const in createdConstraints:
constraintAttrs = []
targets = cmds.getAttr(const + ".target", mi=True)
for each in targets:
constraintAttrs.append(
cmds.listConnections(const + ".target[" + str(each) + "].targetWeight", p=True)[0])
# setup connections between the parent bone constraints and the newly created constraints
if len(constraintAttrs) > 0:
for i in range(len(constraintAttrs)):
try:
cmds.connectAttr(targetWeights[i], constraintAttrs[i])
except:
pass
# =======================================================================
# #set the state on the main network node
# =======================================================================
if cmds.objExists("ART_RIG_ROOT.state"):
cmds.setAttr("ART_RIG_ROOT.state", 2)
# =======================================================================
# #hide all joints
# =======================================================================
joints = cmds.ls(type="joint")
for joint in joints:
try:
cmds.setAttr(joint + ".v", lock=False)
cmds.setAttr(joint + ".v", 0, lock=True)
except:
pass
# =======================================================================
# #remove unused skin influences to optimize scene
# =======================================================================
mel.eval("removeAllUnusedSkinInfs()")
# =======================================================================
# #save the file
# =======================================================================
cmds.file(save=True, type="mayaAscii")
# update main progress bar
self.totalProgress.setValue(9)
# =======================================================================
# #execute post script
# =======================================================================
self.postScript()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def postScript(self):
"""
If there is a post-script to run, this will call on ART_BuildProgressUI.executeScript() to run the post-script.
Then it will call on ART_BuildProgressUI.completeBuild() which wraps up the build process and alerts the user
the build is done.
.. note:: Post-Scipts are used if you ever want to do something to your character after the rig gets built.
An example usage would be adding custom rigging to joints or controls in the scene, setting up custom
relationships or set-driven keys, etc.
.. seealso:: ART_BuildProgressUI.executeScript(), ART_BuildProgressUI.completeBuild()
"""
self.infoText.append(" \n")
# get pre-script path from character node, if it exists
characterNode = utils.returnCharacterModule()
if cmds.objExists(characterNode + ".postScriptPath"):
scriptPath = cmds.getAttr(characterNode + ".postScriptPath")
self.infoText.append("Executing Post-Script..")
self.infoText.append(" " + scriptPath)
# try to execute the pre-script
status = self.executeScript(scriptPath)
if status:
self.infoText.setTextColor(QtGui.QColor(0, 255, 18))
self.infoText.append(" SUCCESS: Post-Script Was Successfully Executed..")
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
if not status:
self.infoText.setTextColor(QtGui.QColor(255, 0, 0))
self.infoText.append(" FAILED: Post-Script Was Not Successfully Executed..")
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
self.errors += 1
else:
self.infoText.setTextColor(QtGui.QColor(255, 255, 0))
self.infoText.append("No Post-Script To Run..")
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
# update main progress bar
self.totalProgress.setValue(10)
# capture model pose for rig controls
cmds.file(save=True, type="mayaAscii")
self.completeBuild()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def completeBuild(self):
"""
Locks down all network nodes, saves the scene, and alerts user that the rig build is complete.
"""
self.infoText.append(" \n")
self.infoText.append("Cleaning Up..")
# go through each module instance, and lock down the nodes
cmds.select("rig_grp", hi=True)
rigNodes = cmds.ls(sl=True)
numNodes = len(rigNodes)
self.currentTask.setMaximum(numNodes)
for node in rigNodes:
curVal = self.currentTask.value()
try:
cmds.lockNode(node, lock=True)
self.currentTask.setValue(curVal + 1)
except:
pass
# save scene
cmds.file(save=True, type="mayaAscii")
# iterate total progress
self.totalProgress.setValue(12)
# add build info
font = QtGui.QFont()
font.setPointSize(20)
font.setBold(True)
self.infoText.setFont(font)
self.infoText.setTextColor(QtGui.QColor(0, 255, 18))
self.infoText.append("\n\nPUBLISH COMPLETE!")
font.setPointSize(8)
font.setBold(False)
self.infoText.setTextColor(QtGui.QColor(255, 255, 255))
self.infoText.setFont(font)
# get file name
fileName = cmds.file(q=True, sceneName=True)
iconPath = cmds.getAttr("ART_RIG_ROOT.iconPath")
self.infoText.append("Assets Created: ")
self.infoText.append(" " + fileName)
self.infoText.append(" " + iconPath)
self.infoText.append(str(self.warnings) + " warnings")
self.infoText.append(str(self.errors) + " errors")
# tell user build is complete
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Information)
msgBox.setText("Rig Build Complete!")
msgBox.addButton("New Scene", QtWidgets.QMessageBox.YesRole)
msgBox.addButton("Edit Rig", QtWidgets.QMessageBox.NoRole)
ret = msgBox.exec_()
if ret == 1:
import ART_RigCreatorUI as ART_RigCreatorUI
reload(ART_RigCreatorUI)
ART_RigCreatorUI.createUI()
cmds.refresh(force=True)
cmds.dockControl("pyArtRigCreatorDock", e=True, r=True)
else:
# if the rigCreatorUI exists delete UI
if cmds.dockControl("pyArtRigCreatorDock", q=True, exists=True):
cmds.deleteUI("pyArtRigCreatorUi")
cmds.deleteUI("pyArtRigCreatorDock", control=True)
cmds.file(new=True)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def executeScript(self, scriptPath):
"""
Takes a given script (mel or python) and runs it.
:param scriptPath: location of the script to be evaluated and ran.
:return: Whether or not the execution of the script failed or not.
.. seealso:: ART_BuildProgressUI.preScript(), ART_BuildProgressUI.postScript()
"""
sourceType = ""
status = False
if scriptPath.find(".py") != -1:
sourceType = "python"
if scriptPath.find(".mel") != -1:
sourceType = "mel"
# MEL
if sourceType == "mel":
try:
command = ""
# open the file, and for each line in the file, add it to our command string.
f = open(scriptPath, 'r')
lines = f.readlines()
for line in lines:
command += line
import maya.mel as mel
mel.eval(command)
# save the file
cmds.file(save=True, type="mayaAscii")
status = True
except:
pass
# PYTHON
if sourceType == "python":
try:
execfile("" + scriptPath + "")
# save the file
cmds.file(save=True, type="mayaAscii")
status = True
except:
pass
return status
|