-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMayaPandaUI.mel
3661 lines (3388 loc) · 188 KB
/
MayaPandaUI.mel
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
///////////////////////////////////////////////////////////
// Process: MP_PandaVersion //
///////////////////////////////////////////////////////////
global proc string MP_PandaVersion(string $option)
{
global string $gMP_PandaFileVersions[];
string $executableToUse = "";
string $selectedBamVersion = `optionMenu -query -value MP_BamVersionOptionMenu`;
//Scan each loop for the value of the selected bam file version
//bam2egg executable file name should be the next value (+1) after version in the array
//egg2bam executable should be the second value (+2) after version in the array
//pview executable should be the third value (+3) after version in the array
// EXAMPLE $gMP_PandaFileVersions ARRAY ENTRY: "Default","bam2egg","egg2bam","pview"
for($i=0;$i<size($gMP_PandaFileVersions);$i++){
if($selectedBamVersion == $gMP_PandaFileVersions[$i]){
switch($option){
case "getBam2Egg":
//Get bam2egg file name
$executableToUse = $gMP_PandaFileVersions[$i+1];
break;
case "getEgg2Bam":
//Get egg2bam file name
$executableToUse = $gMP_PandaFileVersions[$i+2];
break;
case "getPview":
//Get pview file name
$executableToUse = $gMP_PandaFileVersions[$i+3];
break;
}
$i = size($gMP_PandaFileVersions);
}
}
return $executableToUse;
}
/* Shows a confirmation dialog with specified buttons to the user and returns depressed button value.
//
*/
///////////////////////////////////////////////////////////////
// Process: MP_ConfirmationDialog //
// Shows user a confirmation dialog UI //
///////////////////////////////////////////////////////////////
global proc string MP_ConfirmationDialog(string $title, string $message, string $type)
{
/*
Shows a confirmation dialog with the passed title and message
to the user.
The return value will be the value of the button that was pressed by user.
*/
string $confirmValue = "";
switch($type)
{
case "ok":
//Displays only an 'OK' button to user
$confirmValue = `confirmDialog -title $title
-message $message
-button "OK"
-defaultButton "OK"
-cancelButton "CANCEL"
-dismissString "CANCEL"`;
break;
case "okcancel":
//Displays an 'OK' and 'CANCEL' button to user
$confirmValue = `confirmDialog -title $title
-message $message
-button "OK"
-button "CANCEL"
-defaultButton "OK"
-cancelButton "CANCEL"
-dismissString "CANCEL"`;
break;
case "selectcancel":
//Displays an 'SELECT' and 'CANCEL' button to user
$confirmValue = `confirmDialog -title $title
-message $message
-button "SELECT"
-button "CANCEL"
-defaultButton "SELECT"
-cancelButton "CANCEL"
-dismissString "CANCEL"`;
break;
case "yesno":
//Displays a 'YES' and 'NO' button to user
$confirmValue = `confirmDialog -title $title
-message $message
-button "YES"
-button "NO"
-defaultButton "YES"
-cancelButton "NO"
-dismissString "NO"`;
break;
case "downloadcancel":
//Displays a 'Download' and 'Cancel' button to user
$confirmValue = `confirmDialog -title $title
-message $message
-button "DOWNLOAD"
-button "CANCEL"
-defaultButton "DOWNLOAD"
-cancelButton "CANCEL"
-dismissString "CANCEL"`;
break;
}
//Return the value
return $confirmValue;
}
///////////////////////////////////////////////////////////
// Process: MP_AddEggObjectFlags //
// Add an egg-object-type to poly //
///////////////////////////////////////////////////////////
global proc MP_AddEggObjectFlags(string $eggObjectType)
{
//global egg-object-type array
global string $gMP_EggObjectTypeArray[];
//generate attribute enumeration list from the array
string $enumerationList = stringArrayToString($gMP_EggObjectTypeArray, ":");
//Verify the eggObjectType that was passed to this process exists in the $gMP_EggObjectTypeArray array
//If it does not, we skip processing and warn user.
int $eggTypeInArray = stringArrayContains($eggObjectType, $gMP_EggObjectTypeArray);
if($eggTypeInArray == 1){
//String version of array index number.
//This is necessary so we can verify the index number is not null/empty
int $indexNumber = -1;
//Get the array index number of the $eggObjectType passed to this process
//by iterating through each array item and compare them to the $eggObjectType
for($n=0;$n<size($gMP_EggObjectTypeArray);$n++){
if($gMP_EggObjectTypeArray[$n] == $eggObjectType){
$indexNumber = $n;
}
}
//Varible to hold all currently selected nodes
string $selectedNodes[] =`ls -sl`;
//Iterate through each selected node one-by-one
if( size($selectedNodes) == 0)
{
MP_ConfirmationDialog("Selection Error!", "You must first make a selection!"
+ "\nPlease select at least one node, then try again.", "ok");
}else{
for ($node in $selectedNodes){
for($i=1;$i<11;$i++){
if(`objExists ($node + ".eggObjectTypes" + $i)` == 1){
//Notify user if the lmit of 3 tags are already assigned to node
if($i == 10){
//Message to user that the egg-object-type limit has been reached
MP_ConfirmationDialog("Egg-Object-Type Error!", "Limit of 10 egg-object-types has already been reached."
+ "\nNo More Egg Object Types Supported for this node.", "ok");
}
}else{
//Call subprocess to check/set attribute
MP_SetEggObjectTypeAttribute($enumerationList, $eggObjectType, $indexNumber, $i, $node);
//Set variable to exit loop
$i = 11;
}
}
}
}
}else{
//Message to user that the passed egg-object-type is NOT in the $gMP_EggObjectTypeArray array
MP_ConfirmationDialog("Egg-Object-Type Error!", "The selected egg-object-type was not found in the $gMP_EggObjectTypeArray"
+ "\n"
+ "\nPlease verify the object-type being passed and update the $gMP_EggObjectTypeArray"
+ "\nto include the egg-object-type if the type is the correct one needed."
+ "\n"
+ "\nIf you modify the $gMP_EggObjectTypeArray DO NOT forget to update your PRC files."
+ "\nto include a reference of the egg-object-type you are adding.", "ok");
}
//Method to update the MP_DeleteEggObjectTypesWindow window if it is currently being shown
if (`window -exists MP_DeleteEggObjectTypesWindow`){
MP_GetEggObjectTypes();
}
}
///////////////////////////////////////////////////////////
// Process: MP_SetEggObjectTypeAttribute //
// sub-process of MP_AddEggObjectFlags process //
// for setting egg-object-type attributes //
///////////////////////////////////////////////////////////
global proc MP_SetEggObjectTypeAttribute(string $enumerationList, string $eggObjectType, int $indexNumber, int $attributeNumber, string $node)
{
//Determining variable on whether we can add egg-object-type attribute to node
int $addeggObjectTypeAttribute = 0;
//Check for any currently attached egg-object-type attribute values on the node.
//If a current attribute matches passed egg-object-type,
// we skip adding it again and notify user it already exists.
for($i=1;$i<11;$i++){
if(`objExists ($node + ".eggObjectTypes" + $i)`){
//Attribute exists, check if attributes matches the passed egg-object-type
if(`getAttr -asString ($node + ".eggObjectTypes" + $i)` == $eggObjectType){
//Message to user that the egg-object-type is already assigned to node
MP_ConfirmationDialog("Egg-Object-Type Error!", "egg-object-type - \""
+ $eggObjectType
+ "\""
+ "\n"
+ "\nAlready attached on node attribute: "
+ "\n"
+ ($node + ".eggObjectTypes" + $i), "ok");
//Since attribute already exists on node, set our determining variable to 0 to skip adding it again
$addeggObjectTypeAttribute = 1;
}
}
}
//Adds the egg-object-type attribute to node if it was not already attached
if($addeggObjectTypeAttribute == 0){
addAttr -ln ("eggObjectTypes" + $attributeNumber) -keyable 1 -attributeType "enum" -enumName ($enumerationList) $node;
setAttr ($node + ".eggObjectTypes" + $attributeNumber) $indexNumber;
}
}
///////////////////////////////////////////////////////////
// Process: MP_AddEggObjectTypesGUI //
// Displays the GUI window for adding egg-object tags //
///////////////////////////////////////////////////////////
global proc MP_AddEggObjectTypesGUI()
{
/*
Constructs and displays a GUI for adding egg-object-type tags to nodes.
It is designed to read the contents in the global $eggObjectTypeArray and
automatically create rows of 5 buttons each row in a separate window.
The array can be modified in the MP_Globals process to the users liking.
User must verify that any object types added to the array are also present
in at least one of their PRC files, otherwise egg2bam will error complaining
about an unknown object-type.
*/
global string $gMP_EggObjectTypeArray[];
//Delete any current instances of the MP_AddEggObjectTypesWindow window
if (`window -exists MP_AddEggObjectTypesWindow`){
deleteUI -window MP_AddEggObjectTypesWindow;
}
window -retain -title "Panda Exporter - Add Egg-Object-Types" -resizeToFitChildren true -sizeable 1 -visible 1 MP_AddEggObjectTypesWindow;
columnLayout -columnAttach "left" 0 -adjustableColumn true -rowSpacing 0;
frameLayout -backgroundColor 0.50 0.60 0.20 //Add Egg-Type Tags
-collapsable false -font "obliqueLabelFont" -label "Add Egg-Object-Type Tags to Selected Nodes";
columnLayout -adjustableColumn true;
int $count = 0;
for($n=0;$n<(size($gMP_EggObjectTypeArray)+1)/4;$n++){
rowLayout -nc 6;
for($i=0;$i<5;$i++){ // 5 rows per col
string $eggObjectType = $gMP_EggObjectTypeArray[$count];
if($eggObjectType != ""){
//Get the defined annotation for egg-object-type
string $annotation = MP_GetObjectTypeAnnotation($eggObjectType);
button -label $eggObjectType
-width 100 -height 17
-annotation $annotation
-command ("MP_AddEggObjectFlags\"" + $eggObjectType + "\"");
$count++;
}
}
setParent -u;
}
separator -height 5 -style "none";
rowLayout -nc 1 -columnAttach 1 "left" 100;
text -bgc 0.350 0.820 0.950 -label ("Object types added to nodes can be edited by selecting the node"
+ "\n and viewing the attributes in the channels box of the node.");
setParent -u;
setParent -u;
setParent -u;
int $UVScrollFrameHeight = 125;
frameLayout -backgroundColor 0.50 0.60 0.20 -height $UVScrollFrameHeight
-collapsable false -font "obliqueLabelFont" -label "Set Texture UV Scrolling";
columnLayout -columnAttach "left" 15 -rowSpacing 0; //----- UV Scrolling
rowLayout -nc 1; //----- UV Scrolling set speed Comment
text -label "Can use [float] or -[float] to set speed and direction of scrolling" -font "smallBoldLabelFont";
setParent -u;
rowLayout -nc 6; //----- UV Scrolling Labels
text -label "scroll 'U(X)'" -font "smallBoldLabelFont";
separator -width 5 -style "none";
text -label "scroll 'V(Y)'" -font "smallBoldLabelFont";
separator -width 5 -style "none";
text -label "scroll 'R(Z)'" -font "smallBoldLabelFont";
setParent -u;
rowLayout -nc 6; //----- UV Scrolling TextFields
floatField -width 40 -precision 3 -nbg false -enable 1 -value 0 scrollUFF;
separator -width 12 -style "none";
floatField -width 40 -precision 3 -nbg false -enable 1 -value 0 scrollVFF;
separator -width 12 -style "none";
floatField -width 40 -precision 3 -nbg false -enable 1 -value 0 scrollRFF;
setParent -u;
rowLayout -nc 8; //----- UV Scrolling Buttons
button -label "Set/Update"
-width 80
-height 17
-annotation "Set or Update the scroll values of selected node."
-command ("MP_UVScrolling \"set\"")
SetCurrentUVScroll;
button -label "Get Current"
-width 80
-height 17
-annotation "Get the current UVScroll values of the selected node."
-command ("MP_UVScrolling \"get\"")
GetCurrentUVScroll;
button -label "Delete"
-width 80
-height 17
-annotation "Remove the scroll values of selected node."
-command ("MP_UVScrolling \"delete\"")
deleteCurrentUVScroll;
setParent -u;
setParent -u;
setParent -u;
setParent -u;
showWindow MP_AddEggObjectTypesWindow;
//Set window height: base height 10 + 19 per button row
int $buttonFrameHeight = ((($n+1) * 19) + 10);
window -edit -width 515 -height ($buttonFrameHeight + $UVScrollFrameHeight) MP_AddEggObjectTypesWindow;
}
///////////////////////////////////////////////////////////
// Process: MP_UVScrolling //
// Process to set/edit the UV scrolling of a texture. //
///////////////////////////////////////////////////////////
global proc MP_UVScrolling(string $Option)
{
string $item, $buff[] ;
int $numTokens ;
float $scrollU, $scrollV, $scrollR;
if (`floatField -query -value scrollUFF` == 0)
{
$scrollU = 0;
}
else
{
$scrollU = `floatField -query -value scrollUFF`;
}
if (`floatField -query -value scrollVFF` == "")
{
$scrollV = 0;
}
else
{
$scrollV = `floatField -query -value scrollVFF`;
}
if (`floatField -query -value scrollRFF` == "")
{
$scrollR = 0;
}
else
{
$scrollR = `floatField -query -value scrollRFF`;
}
string $nodeName[] =`ls -l -sl`;
if( size($nodeName) == 0)
{
MP_ConfirmationDialog("Selection Error!", "You must first make a selection!"
+ "\nPlease select at least one node, then try again.", "ok");
}
else
{
for ( $node in $nodeName )
{
$numTokens = `tokenize $node "|" $buff`;
$item = $buff[$numTokens - 1];
switch($Option)
{
case "set":
if (`attributeExists "scrollUV" $node`){
if (`attributeExists "scrollU" $node`){
if ( $scrollU != 0 ){
setAttr ($node + ".scrollU") $scrollU;
}else{
setAttr ($node + ".scrollU") 0;
}
}else{
MP_UVScrolling("set");
}
if (`attributeExists "scrollV" $node`){
if ( $scrollV != 0 ){
setAttr ($node + ".scrollV") $scrollV;
}else{
setAttr ($node + ".scrollV") 0;
}
}else{
MP_UVScrolling("set");
}
if (`attributeExists "scrollR" $node`){
if ( $scrollR != 0 ){
setAttr ($node + ".scrollR") $scrollR;
}else{
setAttr ($node + ".scrollR") 0;
}
}else{
MP_UVScrolling("set");
}
}else{
addAttr -longName "scrollUV" -attributeType double3;
if ( $scrollU != 0 ){
addAttr -longName "scrollU" -k true -defaultValue $scrollU -attributeType double -parent scrollUV;
}else{
addAttr -longName "scrollU" -k true -defaultValue 0 -attributeType double -parent scrollUV;
}
if ( $scrollV != 0 ){
addAttr -longName "scrollV" -k true -defaultValue $scrollV -attributeType double -parent scrollUV;
}else{
addAttr -longName "scrollV" -k true -defaultValue 0 -attributeType double -parent scrollUV;
}
if ( $scrollR != 0 ){
addAttr -longName "scrollR" -k true -defaultValue $scrollR -attributeType double -parent scrollUV;
}else{
addAttr -longName "scrollR" -k true -defaultValue 0 -attributeType double -parent scrollUV;
}
}
break;
case "get":
if (`attributeExists "scrollUV" $node`){
if (`attributeExists "scrollU" $node`){
floatField -edit -value `getAttr -asString ($node + ".scrollU")` scrollUFF;
}
if (`attributeExists "scrollV" $node`){
floatField -edit -value `getAttr -asString ($node + ".scrollV")` scrollVFF;
}
if (`attributeExists "scrollR" $node`){
floatField -edit -value `getAttr -asString ($node + ".scrollR")` scrollRFF;
}
}
break;
case "delete":
if (`attributeExists "scrollUV" $node`){
deleteAttr -attribute "scrollUV" -n $node;
floatField -edit -value 0 scrollUFF;
floatField -edit -value 0 scrollVFF;
floatField -edit -value 0 scrollRFF;
}
break;
}
}
}
}
///////////////////////////////////////////////////////////////
// Process: MP_GetEggObjectTypes //
// Retreives egg-object-types from selected node //
///////////////////////////////////////////////////////////////
global proc MP_GetEggObjectTypes()
{
/*
Generate an array from any egg-object-types that are currently attached to the selected node.
It then passes this array onto the MP_DeleteEggObjectTypesGUI process,
to which it then displays them in button style in a separate window
making it easier for a user to delete them from the selected node.
*/
string $currentObjectTypesArray[];
clear $currentObjectTypesArray;
//Record the currently selected nodes
string $selected[] =`ls -l -sl`;
//Verify user has selected at least one node.
if(size($selected) < 1){
//Throw a message if at least one node has not been selected.
MP_ConfirmationDialog("Selection Error!", "Nothing is currently selected"
+ "\nSelect at least one node and try again.", "ok");
}else{
//Loop through each selected node to check for and gather any egg-object-type attributes
for ($selection in $selected){
//Attribute name we are checking for
string $attributeName = "eggObjectTypes";
//Insert current selected node hierarchy into array
stringArrayInsertAtIndex(size($currentObjectTypesArray), $currentObjectTypesArray, $selection);
for($i=1;$i<4;$i++){
//Check for attributes. If present, insert contents into array
//If not, insert dummy placeholder values
if(`attributeExists ($attributeName + $i) $selection` == 1){
//Insert attribute value into array.
//Value is used for button label
stringArrayInsertAtIndex(size($currentObjectTypesArray) + 2
,$currentObjectTypesArray
,`getAttr -asString ($selection + "." + $attributeName + $i)`);
}else{
//Insert 'NONE' attribute value into array
stringArrayInsertAtIndex(size($currentObjectTypesArray) + 2, $currentObjectTypesArray, "NONE");
}
}
}
//Send array of egg-object-types to MP_DeleteEggObjectTypesGUI
MP_DeleteEggObjectTypesGUI($currentObjectTypesArray);
}
}
///////////////////////////////////////////////////////////////
// Process: MP_DeleteEggObjectTypesGUI //
// Retreives egg-object-types from selected node //
///////////////////////////////////////////////////////////////
global proc MP_DeleteEggObjectTypesGUI(string $currentObjectTypesArray[])
{
/*
Displays a separate GUI window listing.
Each object-type a node has will be shown as a button.
If a button is clicked, it will delete that object-type from the selected node and update the window.
*/
//Delete any current instances of the MP_DeleteEggObjectTypesWindow window
if (`window -exists MP_DeleteEggObjectTypesWindow`){
deleteUI -window MP_DeleteEggObjectTypesWindow;
}
//Create the window layout
window -retain -title "Delete Current Egg-Object-Types" -resizeToFitChildren true -sizeable 0 -visible 1 MP_DeleteEggObjectTypesWindow;
frameLayout -backgroundColor 0.50 0.60 0.20
-collapsable false -font "obliqueLabelFont" -label "Egg-Object-Type Tags of selected nodes";
columnLayout -adjustableColumn false -rowSpacing 0;
rowLayout -nc 1 -rowAttach 1 "top" 0;
button -label "Update Window"
-width 110
-height 20
-annotation ("Refreshes the window with information on selected nodes"
+ "\nUsed if new nodes are selected while window is visible")
-command ("MP_GetEggObjectTypes")
MP_RefreshEggTypesWindowButton;
setParent -u;
rowLayout -nc 2 -rowAttach 1 "top" 0 -rowAttach 2 "top" 0;
columnLayout -width 150 -adjustableColumn false -rowSpacing 0 nodeColumn;
rowLayout -nc 1 -rowAttach 1 "top" 0 -columnAttach1 "left" -columnOffset1 15;
text -bgc 0.350 0.820 0.950 -label ("Node Name");
setParent -u;
setParent -u;
columnLayout -width 350 -adjustableColumn false rowColumn;
rowLayout -nc 3 -rowAttach 1 "top" 0 -rowAttach 2 "top" 0 -rowAttach 3 "top" 0
-columnAttach3 "left" "left" "left" -columnOffset3 30 65 65;
text -bgc 0.350 0.820 0.950 -label ("Egg Tag 1");
text -bgc 0.350 0.820 0.950 -label ("Egg Tag 2");
text -bgc 0.350 0.820 0.950 -label ("Egg Tag 3");
setParent -u;
setParent -u;
setParent -u;
setParent -u;
setParent -u;
showWindow MP_DeleteEggObjectTypesWindow;
int $count = 0;
for($n=0;$n<(size($currentObjectTypesArray))/4;$n++){
//Parse out just the short node name as it is all we want for node labeling
string $nodeHierarchy = $currentObjectTypesArray[$count];
//Array variable to hold the split up tokens
string $hierarchyTokens[];
clear $hierarchyTokens;
//Split node hierarchy into token segments
tokenize($nodeHierarchy, "|", $hierarchyTokens);
//Define $node name from the last token segment
string $node = $hierarchyTokens[size($hierarchyTokens)-1];
//Generate the node name label
text -parent nodeColumn -font "boldLabelFont" -height 22 -label $node;
//Increase our count
$count++;
//Create new row of buttons per node selected
//One row will consist of node name label and up to three buttons.
//Each button will depict an egg-object-type assigned to node.
rowLayout -parent rowColumn -nc 3 -rowAttach ($n+1) "top" 0 ("rowLine" + $n);
for($i=0;$i<3;$i++){
string $eggType = $currentObjectTypesArray[$count];
if($eggType != "NONE"){
//Create the button
button -parent ("rowLine" + $n) -label $currentObjectTypesArray[$count]
-width 110
-height 20
-annotation ("Deletes the " + $currentObjectTypesArray[$count]
+ " egg-object-type tag from the node")
-command ("MP_DeleteEggObjectType(\"" + $nodeHierarchy + "\", \"" + ($i+1) + "\")")
($nodeHierarchy + ".eggObjectTypes" + ($i+1));
}else{
//Create a dummy placeholder button
button -parent ("rowLine" + $n) -label $eggType
-width 110
-height 20
-visible 1
-enable 0
-annotation ("")
-command ("")
($nodeHierarchy + ".eggObjectTypes" + ($i+1));
}
//Increase our count
$count++;
}
setParent -u;
}
//Set window height: base height 51 + 20 per button row
int $height = 51 + (($n * 2) + (($n + 1) * 20));
window -edit -width 500 -height $height MP_DeleteEggObjectTypesWindow;
}
///////////////////////////////////////////////////////////////
// Process: MP_DeleteEggObjectType //
// Deletes the selected egg-object-type attribute from nodes //
///////////////////////////////////////////////////////////////
global proc MP_DeleteEggObjectType(string $nodeHierarchy, int $eggTypeAttributeNumber)
{
/*
Delete the clicked object-type from the selected node and update the window.
*/
deleteAttr -attribute ("eggObjectTypes" + $eggTypeAttributeNumber) $nodeHierarchy;
//Update the current egg-object-types window
MP_GetEggObjectTypes();
}
///////////////////////////////////////////////////////////
// Process: MP_ArgsBuilder //
// constructs the arguments to pass to maya2egg //
///////////////////////////////////////////////////////////
global proc string MP_ArgsBuilder(string $FileName)
{
string $ARGS = "maya2egg";
global string $gMP_MayaVersionShort;
$ARGS += $gMP_MayaVersionShort;
$ARGS += " ";
//Increase output verbosity. More v's means more verbose.
$ARGS += "-v ";
//We always want polygons, never nurbs.
$ARGS += "-p ";
//check back face culling i.e. 'double-sided faces'
if(`checkBox -query -value MP_ExportBfaceCB`){
$ARGS += "-bface ";
}
//check Shader option
if(`checkBox -query -value MP_ExportLegacyShadersCB`){
$ARGS += "-legacy-shaders ";
}
//check Keep UV option
if(`checkBox -query -value MP_ExportKeepUvsCB`){
$ARGS += "-keep-uvs ";
}
//check Round UV option
if(`checkBox -query -value MP_ExportRoundUvsCB`){
$ARGS += "-round-uvs ";
}
//check tbnall option 'Compute tangent and binormal for all texture coordinate sets'
if(`checkBox -query -value MP_ExportTbnallCB`){
$ARGS += "-tbnall ";
}
//check lights option 'Convert all light nodes to locators.'
if(`checkBox -query -value MP_ExportLightsCB`){
$ARGS += "-convert-lights ";
}
//check cameras option 'Convert all camera nodes to locators.'
if(`checkBox -query -value MP_ExportCamerasCB`){
$ARGS += "-convert-cameras ";
}
//check Export File Type option 'none, pose, flip, strobe, model, chan, or both'
string $exportOptionsARGS = `radioCollection -query -select MP_ExportOptionsRC`;
switch($exportOptionsARGS){
case "MP_ChooseMeshRB":
$ARGS += "-a none ";
break;
case "MP_ChooseActorRB":
$ARGS += "-a model ";
break;
case "MP_ChooseAnimationRB":
$ARGS += "-a chan ";
//set the start frames
// **Does not check if start frame < end frame
// **Does not support negative values
// **Does not check if start/end frame is within bounds of the scene
if(`radioCollection -query -select MP_AnimationOptionsRC` == "MP_chooseCustomAnimationRangeRB"){
string $startFrameARGS = `intField -query -value MP_AnimationStartFrameIF`;
string $endFrameARGS = `intField -query -value MP_AnimationEndFrameIF`;
//start frame
if(`match "[0-9]+" $startFrameARGS` == $startFrameARGS && $startFrameARGS != ""){
$ARGS += ("-sf " + `match "[0-9]+" $startFrameARGS` + " ");
}else{
error "Start Frame entered data is the wrong format. Should be an integer.\n";
return "failed";
}
//end frame
if(`match "[0-9]+" $endFrameARGS` == $endFrameARGS && $endFrameARGS != ""){
$ARGS += ("-ef " + `match "[0-9]+" $endFrameARGS` + " ");
}else{
error "End Frame entered data is the wrong format. Should be an integer.\n";
return "failed";
}
}
break;
case "MP_ChooseBothRB":
$ARGS += "-a both ";
//set the start frames
// **Does not check if start frame < end frame
// **Does not support negative values
// **Does not check if start/end frame is within bounds of the scene
if(`radioCollection -query -select MP_AnimationOptionsRC` == "MP_chooseCustomAnimationRangeRB"){
string $startFrameARGS = `intField -query -value MP_AnimationStartFrameIF`;
string $endFrameARGS = `intField -query -value MP_AnimationEndFrameIF`;
//start frame
if(`match "[0-9]+" $startFrameARGS` == $startFrameARGS && $startFrameARGS != ""){
$ARGS += ("-sf " + `match "[0-9]+" $startFrameARGS` + " ");
}else{
error "Start Frame entered data is the wrong format. Should be an integer.\n";
return "failed";
}
//end frame
if(`match "[0-9]+" $endFrameARGS` == $endFrameARGS && $endFrameARGS != ""){
$ARGS += ("-ef " + `match "[0-9]+" $endFrameARGS` + " ");
}else{
error "End Frame entered data is the wrong format. Should be an integer.\n";
return "failed";
}
}
break;
case "MP_ChoosePoseRB":
$ARGS += "-a pose ";
//set the pose frame for animation
// **Does not support negative values
string $startFrameARGS = `intField -query -value MP_AnimationStartFrameIF`;
if(`match "[0-9]+" $startFrameARGS` == $startFrameARGS && $startFrameARGS != ""){
$ARGS += ("-sf " + `match "[0-9]+" $startFrameARGS` + " ");
}else{
error "Start Frame entered data is the wrong format. Should be an integer.\n";
return "failed";
}
break;
}
//Get the 'transform mode' option and append to $ARGS string
string $transformMode = `radioCollection -query -select MP_TransformModeRC`;
switch($transformMode){
case "MP_ChooseTransformModelRB":
$ARGS += "-trans model ";
break;
case "MP_ChooseTransformAllRB":
$ARGS += "-trans all ";
break;
case "MP_ChooseTransformDCSRB":
$ARGS += "-trans dcs ";
break;
case "MP_ChooseTransformNoneRB":
$ARGS += "-trans none ";
break;
}
//Check status of remove groundPlane_transform checkBox
if(`checkBox -query -value MP_RemoveGroundPlaneCB` == 1){
$ARGS += "-exclude groundPlane_transform ";
}
//get scene up axis and append to $ARGS string
string $up=`upAxis -q -axis`;
$ARGS += "-cs " + $up + "-up ";
//get units from option menu and append to $ARGS string
string $unit=`optionMenu -q -value MP_UnitMenu`;
$ARGS += "-uo " + $unit + " ";
/* -cn name
Specifies the name of the animation character. This
should match between all of the model files and all of
the channel files for a particular model and its
associated channels.
Only applied if the exported file is not a mesh type.
*/
if($exportOptionsARGS != "MP_ChooseMeshRB"){
//User has entered a character name, we use that
if(`textField -query -text MP_CharacterNameTF` != ""){
//spaces not allowed, replace with underscores
$ARGS += "-cn " + substituteAllString(`textField -query -text MP_CharacterNameTF`, " ", "_") + " ";
}else{
//User did not enter a character name, we use file name as character name
//spaces not allowed, replace with underscores
$ARGS += "-cn " + substituteAllString($FileName, " ", "_") + " ";
}
}
/* -force-joint name
Specifies the name(s) of a DAG node that maya2egg should
treat as a joint, even if it does not appear to be a
Maya joint and does not appear to be animated.
The specified DAGs have to be tagged as a DCS egg-type.
Routine checks for this and if it doesn't exist, it adds the DCS tag to it.
*/
int $mustRestart = 0;
string $joints[];
string $JointNames = `textField -query -text MP_ForceJointTF`;
int $numberEntries = `tokenize $JointNames " " $joints`;
if(`textField -query -text MP_ForceJointTF` != ""){
//iterate through each named joint and verify they have the required 'DCS' object-type flag set
//If not, we add the attribute and request restarting the export process
//We MUST restart so the export process recognizes the added object-tags
for($i=0;$i<$numberEntries;$i++){
string $eggObjectTypes1 = "", $eggObjectTypes2 = "", $eggObjectTypes3 = "";
select -r $joints[$i];
if(`attributeExists "eggObjectTypes1" $joints[$i]` == 1){
$eggObjectTypes1 = `getAttr -asString ($joints[$i] + ".eggObjectTypes1")`;
}
if(`attributeExists "eggObjectTypes2" $joints[$i]` == 1){
$eggObjectTypes2 = `getAttr -asString ($joints[$i] + ".eggObjectTypes2")`;
}
if(`attributeExists "eggObjectTypes3" $joints[$i]` == 1){
$eggObjectTypes3 = `getAttr -asString ($joints[$i] + ".eggObjectTypes3")`;
}
//If any of the current object-type attributes are DCS, append to $ARGS
//If there is no DCS attribute, add it to the node
if(($eggObjectTypes1 == "dcs") || ($eggObjectTypes2 == "dcs") || ($eggObjectTypes3 == "dcs")){
$ARGS += "-force-joint " + $joints[$i] + " ";
}else{
MP_AddEggObjectFlags("dcs");
$mustRestart += 1;
}
}
//If $mustRestart variable is greater than 0, we had to add a DCS tag.
//If we had to add a DCS tag to any nodes, we must restart exporting so it's recognized.
//Otherwise, the force-joint for that node will not export properly.
if($mustRestart != 0){
//Prompt user with confirm dialog if we had to add the DCS attribute to any of the nodes
string $confirmRestart = MP_ConfirmationDialog("File Error!", "We had to add a missing DCS flag to one or more of the \"-force-joint\" nodes."
+ "\nWe must restart the exporting process now."
+ "\nPress 'Yes' to restart, Press 'No' to exit exporting", "yesno");
if($confirmRestart == "YES"){
MP_StartSceneExport();
return "failed"; //needed to exit the previous exporting loop
}else{
error "User cancelled exporting";
return "failed";
}
}
}
//Check custom reference path and output path; append to $ARGS string
//-ps The option may be one of: rel, abs, rel_abs, strip, or keep. If either rel or rel_abs is specified,
// the files are made relative to the directory specified by -pd. The default is rel.
//Check if we are referencing textures to a path OTHER than the Maya file
if(`radioCollection -query -select MP_TexPathOptionsRC` != "MP_ChooseDefaultTexPathRB"){
$ARGS += ("-ps rel" + " ");
}
//-pd Specifies the name of a directory to make paths relative to, if '-ps rel' or '-ps rel_abs' is specified.
// If this is omitted, the directory name is taken from the name of the output file.
//-pp Adds the indicated directory name to the list of directories to search for filenames referenced by the source file.
// We always want to add the file path to the search
//-pc Copies textures and other dependent files into the indicated directory.
// If a relative pathname is specified, it is relative to the directory specified with -pd, above.
//Check if we are referencing textures to a Custom path
string $customTexPath = `textField -query -text MP_CustomEggTexPathTF`;
if(`radioCollection -query -select MP_TexPathOptionsRC` == "MP_ChooseCustomRefPathRB"){
//If we are exporting to an Egg File and Bam File, THE EGG MUST BE RELATIVE TO MAYA FILE!!
//So we skip this.
//Otherwise the bam file will be produced without textures since it can't find them during compiling
// NOTE: Bam file texture referencing is handled in the MP_Export2Bam process
//If exporting only to an Egg File, relative referencing will function as expected
// and directory path MUST start with the path to where the textures are truly located
if(`radioCollection -query -select MP_OutputPandaFileTypeRC` == "MP_ChooseEggRB"){
//Verify user entered in a path
if($customTexPath != ""){
$ARGS += ("-pd " + "\"" + $customTexPath + "\"" + " ");
$ARGS += ("-pp " + "\"" + $customTexPath + "\"" + " ");
}
}
}
//Check if we are copying and referencing textures to a Custom path
string $customOutputPath = `textField -query -text MP_CustomOutputPathTF`;
if(`radioCollection -query -select MP_TexPathOptionsRC` == "MP_ChooseCustomTexPathRB"){
if($customTexPath != ""){
$ARGS += ("-pc " + "\"" + $customTexPath + "\"" + " ");
$ARGS += ("-pp " + "\"" + $customTexPath + "\"" + " ");
}
if($customOutputPath != ""){
$ARGS += ("-pd " + "\"" + $customOutputPath + "\"" + " ");
}
}
print ("Using these arguments: " + $ARGS + "[END]\n");
return $ARGS;
}
///////////////////////////////////////////////////////////
// Process: MP_StartSceneExport //
///////////////////////////////////////////////////////////
global proc int MP_StartSceneExport()
{
/*
We need to do before calling MP_Export2Egg/BAM/Pview:
-Export a temporary MB
-Get the destination path
-Get the filename
-Get the custom arguments
*/
string $tempMBFile = "";
if(`checkBox -query -value MP_ExportSelectedCB`){
$tempMBFile = MP_ExportScene("selected"); //returns $tempScenePath as $tempMBFile
if($tempMBFile == "failed"){
return 0;
}
}else{
$tempMBFile = MP_ExportScene("all"); //returns $tempScenePath as $tempMBFile
if($tempMBFile == "failed"){
return 0;
}
}
//Determine base file name from the scene name.
string $origFileName = basenameEx(`file -q -sceneName`);
/*
Get the destination path
Get the filename
Get the custom arguments
*/
string $eggFile = MP_ExportPrep($tempMBFile, $origFileName);
//Delete the temporary Maya binary file
//sysFile -del $tempMBFile;
//Check if the eggFile passed return, else return it failed as an integer
if($eggFile == "failed"){
return 0;
}else{
return 1;
}
}
///////////////////////////////////////////////////////////
// Process: MP_ExportScene //
// exports the entire scene/selected objects //
///////////////////////////////////////////////////////////
global proc string MP_ExportScene(string $selection)
{
string $scenePath = dirname(`file -q -sceneName`); //gets the current scene filename and path if present.
string $fileName = basenameEx(`file -q -sceneName`); //cut off the file extension
string $fileExtension = fileExtension(`file -q -sceneName`); //Returns file extension
string $tempScenePath = "";
//Processes if exporting file with original file name and default output path
if((`radioCollection -query -select MP_OutputFilenameOptionsRC` == "MP_ChooseOriginalFilenameRB") &&
(`radioCollection -query -select MP_OutputPathOptionsRC` == "MP_ChooseDefaultOutputPathRB")){
if(($scenePath == "")||($fileName == "")){
MP_ConfirmationDialog("File Error!", "It appears you have not yet saved this scene. Please save your scene first"
+ "\nOR, specify a Custom Output Directory AND Custom Filename.", "ok");
return "failed";
}else{
$tempScenePath = ($scenePath + "/" + $fileName + "_temp.mb");
}
}
//Processes if exporting file with original file name and custom output path
if((`radioCollection -query -select MP_OutputFilenameOptionsRC` == "MP_ChooseOriginalFilenameRB") &&
(`radioCollection -query -select MP_OutputPathOptionsRC` == "MP_ChooseCustomOutputPathRB")){
if($fileName == ""){
MP_ConfirmationDialog("File Error!", "It appears you have not yet saved this scene. Please save your scene first"
+ "\nOR, specify a Custom Output Directory AND Custom Filename.", "ok");
return "failed";
}else{
string $TempPath = `textField -query -text MP_CustomOutputPathTF`;
if($TempPath == ""){