-
Notifications
You must be signed in to change notification settings - Fork 0
/
weightDriverEditRBF.py
1308 lines (1058 loc) · 35.5 KB
/
weightDriverEditRBF.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
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
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
@FileName : weightDriverEditRBF.py
@DateTime : 2023/06/06 11:46:17
@Author : Tian Chao
@Contact : [email protected]
"""
import pymel.core as pm
def _getShape(node):
"""---------------------------------------------------------------------
weightDriverEditRBF.mel
Weight Driver Version: 3.6
Description:
Editor for the weightDriver in generic RBF mode.
Input Arguments:
None
Return Value:
None
---------------------------------------------------------------------
---------------------------------------------------------------------
Usage:
Run by executing the following command:
weightDriverEditRBF;
---------------------------------------------------------------------
Procedure Name:
getShape
Description:
Return the shape node name of the weight driver.
Input Arguments:
string node The transform node name of the weight driver.
Return Value:
string
"""
if pm.nodeType(node) == "transform":
rel = pm.listRelatives(node, shapes=1)
return rel[0]
return node
def _getTransform(node):
"""
Procedure Name:
getTransform
Description:
Return the name of the transform node of the weight driver.
Input Arguments:
string node The shape node name of the weight driver.
Return Value:
string
"""
if pm.nodeType(node) == "weightDriver":
rel = pm.listRelatives(node, parent=1)
return rel[0]
return node
def weightDriverCloseRBFUI():
"""---------------------------------------------------------------------
cleanup
---------------------------------------------------------------------
Procedure Name:
weightDriverCloseRBFUI
Description:
Close the edit window.
Input Arguments:
None
Return Value:
None
"""
if pm.window("weightDriverEditRBFWin", exists=1):
pm.deleteUI("weightDriverEditRBFWin")
def _clearPoseItems():
"""
Procedure Name:
clearPoseItems
Description:
Remove all pose item children from the pose data layout.
Input Arguments:
None
Return Value:
None
"""
items = pm.scrollLayout("wdUI_poseDataLayout", query=1, childArray=1)
for i in items:
pm.deleteUI(i)
def _clearAll():
"""
Procedure Name:
clearAll
Description:
Clear all fields and lists in the edit window.
Input Arguments:
None
Return Value:
None
"""
pm.melGlobals.initVar("int", "gWeightDriverDriverAttrCount")
pm.melGlobals.initVar("int", "gWeightDriverDrivenAttrCount")
pm.melGlobals["gWeightDriverDriverAttrCount"] = 0
pm.melGlobals["gWeightDriverDrivenAttrCount"] = 0
pm.textField("wdUI_driverField", edit=1, text="")
pm.textField("wdUI_drivenField", edit=1, text="")
pm.iconTextScrollList("wdUI_driverAttrList", edit=1, removeAll=1)
pm.iconTextScrollList("wdUI_drivenAttrList", edit=1, removeAll=1)
_clearPoseItems()
def _buildDriverMenu():
"""---------------------------------------------------------------------
solver option menu
---------------------------------------------------------------------
Procedure Name:
buildDriverMenu
Description:
Build the option menu for the solvers and collect all weight
driver nodes in the scene.
Input Arguments:
None
Return Value:
None
"""
if pm.optionMenu("wdUI_weightDriverNodeOption", exists=1):
items = pm.optionMenu("wdUI_weightDriverNodeOption", query=1, itemListLong=1)
for c in items:
pm.deleteUI(c)
pm.menuItem(label="New", parent="wdUI_weightDriverNodeOption")
nodes = pm.ls(type="weightDriver")
for n in nodes:
if pm.getAttr(str(n) + ".type"):
pm.menuItem(label=(_getTransform(n)), parent="wdUI_weightDriverNodeOption")
if not len(nodes):
_clearAll()
def weightDriverGetSelectedNodeOption():
"""
Procedure Name:
weightDriverGetSelectedNodeOption
Description:
Return the name of the selected node from the driver option
menu.
Input Arguments:
None
Return Value:
string
"""
node = str(pm.optionMenu("wdUI_weightDriverNodeOption", query=1, value=1))
if node == "New":
node = ""
return node
def weightDriverRefreshUI():
"""
Procedure Name:
weightDriverRefreshUI
Description:
Rebuild the driver menu and clears all fields and lists.
Input Arguments:
None
Return Value:
None
"""
_buildDriverMenu()
_clearAll()
def _buildEditWindow():
"""---------------------------------------------------------------------
window
---------------------------------------------------------------------
Procedure Name:
buildEditWindow
Description:
Build the window and controls for editing the RBF solver.
Input Arguments:
None
Return Value:
None
"""
if pm.window("weightDriverEditRBFWin", exists=1):
pm.deleteUI("weightDriverEditRBFWin")
pm.window(
"weightDriverEditRBFWin", title="Edit RBF WeightDriver", widthHeight=(700, 500)
)
state = int(pm.optionVar(query="weightDriverAutoFillValues"))
pm.menuBarLayout()
pm.menu(label="Settings")
pm.menuItem(
label="Auto Fill Blend Shape Values",
checkBox=state,
command=lambda *args: pm.optionVar(iv=("weightDriverAutoFillValues", args[0])),
)
pm.setParent("..")
mainForm = str(pm.formLayout())
# -------------------
# weight driver node
# -------------------
nodeOptionForm = str(pm.formLayout())
nodeLabel = str(pm.text(label="RBF Node", align="left", width=64))
pm.optionMenu(
"wdUI_weightDriverNodeOption",
changeCommand=lambda *args: pm.mel.weightDriverGetData(),
)
pm.menuItem(label="None")
pm.popupMenu()
pm.menuItem(
label="Select Solver",
command=lambda *args: pm.mel.eval(
'if (weightDriverGetSelectedNodeOption() != "") \
select -r (weightDriverGetSelectedNodeOption());'
),
)
pm.menuItem(divider=1)
pm.menuItem(
label="Delete Solver",
command=lambda *args: pm.mel.eval(
'if (weightDriverGetSelectedNodeOption() != "") \
{ select -r (weightDriverGetSelectedNodeOption()); delete; weightDriverRefreshUI; }'
),
)
refreshButton = str(
pm.button(
label="Refresh",
width=60,
command=lambda *args: pm.mel.weightDriverRefreshUI(),
)
)
pm.formLayout(
nodeOptionForm,
edit=1,
attachForm=[
(nodeLabel, "top", 7),
(nodeLabel, "left", 5),
("wdUI_weightDriverNodeOption", "top", 5),
(refreshButton, "top", 3),
(refreshButton, "right", 5),
],
attachControl=[
("wdUI_weightDriverNodeOption", "left", 3, nodeLabel),
("wdUI_weightDriverNodeOption", "right", 15, refreshButton),
],
)
pm.setParent("..")
sep1 = str(pm.separator(style="in", height=15))
# -------------------
# rbf driver & driven
# -------------------
attrForm = str(pm.formLayout(height=182))
driverLabel = str(pm.text(label="Driver", width=60, align="left"))
pm.textField("wdUI_driverField", width=100)
driverButton = str(
pm.button(
label="Select", command=lambda *args: pm.mel.weightDriverGetNode("driver")
)
)
driverAttrLabel = str(pm.text(label="Attributes", width=60, align="left"))
driverAttrList = str(
pm.iconTextScrollList("wdUI_driverAttrList", ams=1, height=150)
)
state = int(pm.optionVar(query="weightDriverAttributeDisplayDriver"))
pm.popupMenu()
pm.menuItem(
label="Show Keyable Only",
checkBox=state,
command=lambda *args: pm.mel.eval(
"optionVar -iv weightDriverAttributeDisplayDriver #1; \
weightDriverListAttributes driver"
),
)
drivenLabel = str(pm.text(label="Driven", width=60, align="left"))
pm.textField("wdUI_drivenField", width=100)
drivenButton = str(
pm.button(
label="Select", command=lambda *args: pm.mel.weightDriverGetNode("driven")
)
)
drivenAttrLabel = str(pm.text(label="Attributes", width=60, align="left"))
drivenAttrList = str(
pm.iconTextScrollList("wdUI_drivenAttrList", allowMultiSelection=1, height=150)
)
state = int(pm.optionVar(query="weightDriverAttributeDisplayDriven"))
pm.popupMenu()
pm.menuItem(
label="Show Keyable Only",
checkBox=state,
command=lambda *args: pm.mel.eval(
"optionVar -iv weightDriverAttributeDisplayDriven #1; \
weightDriverListAttributes driven"
),
)
div = str(pm.separator(style="in", horizontal=0))
pm.formLayout(
attrForm,
edit=1,
attachForm=[
(driverLabel, "top", 5),
(driverLabel, "left", 5),
("wdUI_driverField", "top", 2),
(driverButton, "top", 0),
(driverAttrLabel, "left", 5),
(div, "top", 5),
(div, "bottom", 5),
(drivenLabel, "top", 5),
("wdUI_drivenField", "top", 2),
(drivenButton, "top", 0),
(drivenButton, "right", 5),
(drivenAttrList, "right", 5),
],
attachControl=[
("wdUI_driverField", "left", 5, driverLabel),
("wdUI_driverField", "right", 5, driverButton),
(driverAttrLabel, "top", 17, driverLabel),
(driverAttrList, "top", 10, "wdUI_driverField"),
(driverAttrList, "left", 5, driverAttrLabel),
("wdUI_drivenField", "left", 5, drivenLabel),
("wdUI_drivenField", "right", 5, drivenButton),
(drivenAttrLabel, "top", 17, drivenLabel),
(drivenAttrList, "top", 10, "wdUI_drivenField"),
(drivenAttrList, "left", 5, drivenAttrLabel),
],
attachPosition=[
(driverButton, "right", 15, 50),
(driverAttrList, "right", 15, 50),
(drivenLabel, "left", 15, 50),
(drivenAttrLabel, "left", 15, 50),
(div, "left", 0, 50),
],
)
pm.setParent("..")
sep2 = str(pm.separator(style="in", height=15))
# -------------------
# pose data
# -------------------
pm.scrollLayout("wdUI_poseDataLayout", childResizable=1)
pm.setParent("..")
sep3 = str(pm.separator(style="in", height=15))
buttonAdd = str(
pm.button(
label="Add Pose",
height=25,
command=lambda *args: pm.mel.weightDriverAddPose(),
)
)
buttonApply = str(
pm.button(
label="Apply", height=25, command=lambda *args: pm.mel.weightDriverApply(0)
)
)
buttonConnect = str(
pm.button(
label="Connect",
height=25,
command=lambda *args: pm.mel.weightDriverApply(1),
)
)
buttonCancel = str(
pm.button(
label="Close",
height=25,
command=lambda *args: pm.mel.weightDriverCloseRBFUI(),
)
)
pm.formLayout(
mainForm,
edit=1,
attachForm=[
(nodeOptionForm, "top", 5),
(nodeOptionForm, "left", 5),
(nodeOptionForm, "right", 5),
(sep1, "left", 10),
(sep1, "right", 10),
(attrForm, "left", 5),
(attrForm, "right", 5),
(sep2, "left", 10),
(sep2, "right", 10),
("wdUI_poseDataLayout", "left", 10),
("wdUI_poseDataLayout", "right", 10),
(sep3, "left", 10),
(sep3, "right", 10),
(buttonAdd, "left", 5),
(buttonAdd, "bottom", 5),
(buttonApply, "bottom", 5),
(buttonConnect, "bottom", 5),
(buttonCancel, "right", 5),
(buttonCancel, "bottom", 5),
],
attachControl=[
(sep1, "top", 0, nodeOptionForm),
(attrForm, "top", 0, sep1),
(sep2, "top", 0, attrForm),
("wdUI_poseDataLayout", "top", 0, sep2),
("wdUI_poseDataLayout", "bottom", 10, sep3),
(sep3, "bottom", 0, buttonApply),
],
attachPosition=[
(buttonAdd, "right", 5, 25),
(buttonApply, "left", 5, 25),
(buttonApply, "right", 5, 50),
(buttonConnect, "left", 5, 50),
(buttonConnect, "right", 5, 75),
(buttonCancel, "left", 5, 75),
],
)
pm.setParent("..")
pm.showWindow("weightDriverEditRBFWin")
_buildDriverMenu()
def _readPoseData(node, id):
"""---------------------------------------------------------------------
get the data from an existing setup
---------------------------------------------------------------------
Procedure Name:
readPoseData
Description:
Populate all fields based on the current solver selection.
Input Arguments:
string node The name of the solver.
int id The index of the pose to get the data from.
Return Value:
None
"""
pm.setParent("wdUI_poseDataLayout")
attrSize = int(pm.getAttr((node + ".input"), size=1))
valSize = int(pm.getAttr((node + ".output"), size=1))
if attrSize == 0 or valSize == 0:
return
pm.rowLayout(
("wdUI_poseData_" + str(id) + "_row"), numberOfColumns=(attrSize + valSize + 7)
)
pm.text(label=("Pose " + str(id)), width=60, align="left")
for i in range(0, attrSize):
v = float(
pm.getAttr(node + ".poses[" + str(id) + "].poseInput[" + str(i) + "]")
)
pm.floatField(
("wdUI_poseData_" + str(id) + "_a" + str(i)), precision=3, value=v
)
pm.separator(style="in", horizontal=0, width=25, height=20)
for i in range(0, valSize):
v = float(
pm.getAttr(node + ".poses[" + str(id) + "].poseValue[" + str(i) + "]")
)
pm.floatField(
("wdUI_poseData_" + str(id) + "_v" + str(i)), precision=3, value=v
)
pm.separator(style="none", width=10)
pm.button(
label="Recall",
width=50,
command=lambda *args: pm.mel.eval(("weightDriverRecallPose " + str(id))),
)
pm.separator(style="none", width=10)
# button -label "Update" -width 50 -command ("weightDriverUpdatePose " + $id);
pm.separator(style="none", width=77)
pm.button(
label="Delete",
command=lambda *args: pm.mel.eval(
("deleteUI wdUI_poseData_" + str(id) + "_row")
),
)
pm.setParent("..")
def weightDriverGetData():
"""
Procedure Name:
weightDriverGetData
Description:
Get the driver and driven nodes for the current solver and
gather the attributes and pose values to populate the ui.
Input Arguments:
None
Return Value:
None
"""
pm.melGlobals.initVar("int", "gWeightDriverDriverAttrCount")
pm.melGlobals.initVar("int", "gWeightDriverDrivenAttrCount")
_clearAll()
node = str(weightDriverGetSelectedNodeOption())
if node == "":
return
node = str(_getShape(node))
# driver
input = pm.listConnections(
(node + ".input"),
source=1,
destination=0,
plugs=1,
connections=1,
skipConversionNodes=1,
)
driver = ""
driverAttrs = []
for i in range(0, len(input), 2):
items = input[i + 1].split(".")
if driver == "":
driver = items[0]
driverAttrs.append(items[1])
pm.melGlobals["gWeightDriverDriverAttrCount"] = len(driverAttrs)
pm.textField("wdUI_driverField", edit=1, text=driver)
listItems = pm.mel.weightDriverListAttributes("driver")
for a in driverAttrs:
if a in listItems:
pm.iconTextScrollList("wdUI_driverAttrList", edit=1, selectItem=a)
output = pm.listConnections(
(node + ".output"),
source=0,
destination=1,
plugs=1,
connections=1,
skipConversionNodes=1,
)
# driven
driven = ""
drivenAttrs = []
for i in range(0, len(output), 2):
items = output[i + 1].split(".")
if driven == "":
driven = items[0]
drivenAttrs.append(items[1])
pm.melGlobals["gWeightDriverDrivenAttrCount"] = len(drivenAttrs)
pm.textField("wdUI_drivenField", edit=1, text=driven)
listItems = pm.mel.weightDriverListAttributes("driven")
for a in drivenAttrs:
if a in listItems:
pm.iconTextScrollList("wdUI_drivenAttrList", edit=1, selectItem=a)
poseIds = pm.getAttr((node + ".poses"), multiIndices=1)
# poses
if poseIds[0] != 0:
pm.setAttr((node + ".poses[0].poseInput[0]"), 0)
pm.setAttr((node + ".poses[0].poseValue[0]"), 0)
poseIds = pm.getAttr((node + ".poses"), multiIndices=1)
for id in poseIds:
_readPoseData(node, id)
def weightDriverGetNode(type):
"""---------------------------------------------------------------------
attribute lists
---------------------------------------------------------------------
Procedure Name:
weightDriverGetNode
Description:
Load the selected node from the scene as either a driver or
driven node and list the attributes.
Input Arguments:
string type The type of which the node should be loaded
as. Use "driver" or "driven".
Return Value:
None
"""
sel = pm.ls(selection=1)
if not len(sel):
return
if type == "driver":
pm.textField("wdUI_driverField", edit=1, text=sel[0])
else:
pm.textField("wdUI_drivenField", edit=1, text=sel[0])
pm.mel.weightDriverListAttributes(type)
def weightDriverListAttributes(type):
"""
Procedure Name:
weightDriverListAttributes
Description:
List and return the attributes of the driver or driven node
depending on the keyable/non-keyable preference setting.
Input Arguments:
string type The type usage of the node.
Use "driver" or "driven".
Return Value:
string[]
"""
list = ""
node = ""
flag = ""
if type == "driver":
list = "wdUI_driverAttrList"
node = str(pm.textField("wdUI_driverField", query=1, text=1))
if pm.optionVar(query="weightDriverAttributeDisplayDriver"):
flag = "-keyable "
else:
list = "wdUI_drivenAttrList"
node = str(pm.textField("wdUI_drivenField", query=1, text=1))
if pm.optionVar(query="weightDriverAttributeDisplayDriven"):
flag = "-keyable "
pm.iconTextScrollList(list, edit=1, removeAll=1)
cmd = "listAttr -multi " + flag + node
attributes = pm.mel.eval(cmd)
for a in attributes:
pm.iconTextScrollList(list, edit=1, append=a)
return attributes
def _getSelectedNodeAttributes(type):
"""
Procedure Name:
getSelectedNodeAttributes
Description:
Return the selected node attributes in the list.
Input Arguments:
string type The type usage of the node.
Use "driver" or "driven".
Return Value:
string[]
"""
list = ""
if type == "driver":
list = "wdUI_driverAttrList"
else:
list = "wdUI_drivenAttrList"
attributes = pm.iconTextScrollList(list, query=1, selectItem=1)
return attributes
def _getAttributes(driverAttrs, drivenAttrs):
"""
Procedure Name:
getAttributes
Description:
Get the driver and driven attributes through the given string
arrays.
Also perform a check if the attribute count matches the count of
existing pose attributes and return it.
Input Arguments:
string[] driverAttrs The attribute list of all driver
attributes for the solver.
string[] drivenAttrs The attribute list of all driven
attributes for the solver.
Return Value:
int (bool)
"""
pm.melGlobals.initVar("int", "gWeightDriverDriverAttrCount")
pm.melGlobals.initVar("int", "gWeightDriverDrivenAttrCount")
driver = str(pm.textField("wdUI_driverField", query=1, text=1))
driven = str(pm.textField("wdUI_drivenField", query=1, text=1))
if driver == "" or driven == "":
return 0
driverAttrs = str(_getSelectedNodeAttributes("driver"))
if not len(driverAttrs):
pm.mel.error("No driver attributes selected")
return 0
elif pm.melGlobals["gWeightDriverDriverAttrCount"] != 0 and pm.melGlobals[
"gWeightDriverDriverAttrCount"
] != len(driverAttrs):
pm.mel.error(
"The driver attribute count is different from the already existing poses"
)
return 0
else:
pm.melGlobals["gWeightDriverDriverAttrCount"] = len(driverAttrs)
drivenAttrs = str(_getSelectedNodeAttributes("driven"))
if not len(drivenAttrs):
pm.mel.error("No driven attributes selected")
return 0
elif pm.melGlobals["gWeightDriverDrivenAttrCount"] != 0 and pm.melGlobals[
"gWeightDriverDrivenAttrCount"
] != len(drivenAttrs):
pm.mel.error(
"The driven attribute count is different from the already existing poses"
)
return 0
else:
pm.melGlobals["gWeightDriverDrivenAttrCount"] = len(drivenAttrs)
return 1
def _getPoseIndices():
"""---------------------------------------------------------------------
poses
---------------------------------------------------------------------
Procedure Name:
getPoseIndices
Description:
Return a list of all pose indices.
Input Arguments:
None
Return Value:
int[]
"""
ids = []
items = pm.scrollLayout("wdUI_poseDataLayout", query=1, childArray=1)
for i in items:
temp = i.split("_")
ids.append(int(temp[-2]))
return ids
def _getNewPoseIndex():
"""
Procedure Name:
getNewPoseIndex
Description:
Return a new pose index.
Input Arguments:
None
Return Value:
int
"""
ids = _getPoseIndices()
if len(ids):
return ids[-1] + 1
return 0
def _hasRestPose():
"""
Procedure Name:
hasRestPose
Description:
Return true if the first row is filled with zeros.
Input Arguments:
None
Return Value:
int (bool)
"""
result = 0
if pm.rowLayout("wdUI_poseData_0_row", query=1, exists=1):
sum = float(0)
items = pm.rowLayout("wdUI_poseData_0_row", query=1, childArray=1)
for i in items:
if pm.mel.gmatch(i, "*_v*"):
sum += float(pm.floatField(i, query=1, value=1))
if sum == 0:
result = 1
return result
def _addPoseData(id, driverAttrs, drivenAttrs):
"""
Procedure Name:
addPoseData
Description:
Create a new row of pose data in the pose section of the ui.
Input Arguments:
int id The index of the pose on the solver.
string[] driverAttrs The list of driver attributes.
string[] drivenAttrs The list of driven attributes.
Return Value:
None
"""
pm.setParent("wdUI_poseDataLayout")
attrSize = len(driverAttrs)
valSize = len(drivenAttrs)
driver = str(pm.textField("wdUI_driverField", query=1, text=1))
driven = str(pm.textField("wdUI_drivenField", query=1, text=1))
if driver == "" or driven == "":
return
isBlendShape = 0
asRest = 0
hasRest = 0
if pm.nodeType(driven) == "blendShape" and pm.optionVar(
query="weightDriverAutoFillValues"
):
isBlendShape = 1
hasRest = int(_hasRestPose())
if _getNewPoseIndex() == 0:
confirm = str(
pm.confirmDialog(
title="WeightDriver",
message="Add the first pose as the rest pose?",
button=["OK", "Cancel"],
defaultButton="OK",
cancelButton="Cancel",
dismissString="Cancel",
)
)
if confirm == "OK":
asRest = 1
pm.rowLayout(
("wdUI_poseData_" + str(id) + "_row"), numberOfColumns=(attrSize + valSize + 8)
)
pm.text(label=("Pose " + str(id)), width=60, align="left")
for i in range(0, attrSize):
v = float(pm.getAttr(driver + "." + driverAttrs[i]))
pm.floatField(
("wdUI_poseData_" + str(id) + "_a" + str(i)), precision=3, value=v
)
pm.separator(style="in", horizontal=0, width=25, height=20)
for i in range(0, valSize):
v = float(0)
if not asRest:
if not isBlendShape:
v = float(pm.getAttr(driven + "." + drivenAttrs[i]))
else:
position = id - hasRest
if i == position:
v = float(1)
pm.floatField(
("wdUI_poseData_" + str(id) + "_v" + str(i)), precision=3, value=v
)
pm.separator(style="none", width=10)
pm.button(
label="Recall",
width=50,
command=lambda *args: pm.mel.eval(("weightDriverRecallPose " + str(id))),
)
pm.separator(style="none", width=10)
pm.button(
label="Update",
width=50,
command=lambda *args: pm.mel.eval(("weightDriverUpdatePose " + str(id))),
)
pm.separator(style="none", width=25)
pm.button(
label="Delete",
command=lambda *args: pm.mel.eval(
("deleteUI wdUI_poseData_" + str(id) + "_row")
),
)
pm.setParent("..")
def weightDriverAddPose():
"""
Procedure Name:
weightDriverAddPose
Description:
Create a new pose based on the scene state.
Input Arguments:
None
Return Value:
None
"""
driverAttrs = []
drivenAttrs = []
result = int(_getAttributes(driverAttrs, drivenAttrs))
if result == 0:
return
_addPoseData(_getNewPoseIndex(), driverAttrs, drivenAttrs)
def weightDriverUpdatePose(id):
"""
Procedure Name:
weightDriverUpdatePose
Description:
Update the pose values based on the current scene state.
Input Arguments:
int id The index of the pose on the solver.
Return Value:
None
"""
driverAttrs = []
drivenAttrs = []
result = int(_getAttributes(driverAttrs, drivenAttrs))
if result == 0: