-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMayaPandaUI.py
3130 lines (2757 loc) · 129 KB
/
MayaPandaUI.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
"""
Python converted version of MayaPandaUI by Loonatic (Created December 2024)
Tested on Maya 2022
You will need to run pip install natsort on your mayapy.exe in order to use this!
"""
from enum import IntEnum
import pymel.core as pm
import os
import time
from natsort import natsorted
from typing import List
from dataclasses import dataclass, field
from functools import partial
# region GLOBALS
EGG_OBJECT_TYPE_ARRAY = "gMP_PY_EggObjectTypeArray"
PANDA_FILE_VERSIONS = "gMP_PY_PandaFileVersions"
PANDA_SDK_NOTICE = "gMP_PY_ChoosePandaFileNotice"
ADDON_RELEASE_VERSION = "gMP_PY_ReleaseRevision"
MAYA_VER_SHORT = "gMP_PY_MayaVersionShort"
# endregion
"""
https://help.autodesk.com/cloudhelp/2023/CHS/Maya-Tech-Docs/PyMel/generated/functions/pymel.core.windows/pymel.core
.windows.button.html?highlight=button#pymel.core.windows.button
"""
# region Color utils
def hex_to_rgb(hex_color):
"""Converts a hex color code to RGB values (0-255)."""
# Remove the '#' if present
hex_color = hex_color.lstrip('#')
# Convert hex values to integers
r = int(hex_color[0:2], 16)
g = int(hex_color[2:4], 16)
b = int(hex_color[4:6], 16)
return r, g, b
def hex_to_rgb_normalized(hex_color):
"""Converts a hex color code to normalized RGB values (0-1)."""
r, g, b = hex_to_rgb(hex_color)
return r / 255, g / 255, b / 255
# endregion
# region Object Type Category Definitions
"""
Categories are meant to make it easier to find certain object types by context.
Each ObjectType can only be assigned to one category.
In the add object type UI, the categories are displayed as collapsible sections.
"""
class OTCategory(IntEnum):
NoCategory = 0
EmptyAttr = 100
CollisionAttr = 200
TriggerAttr = 250
AlphaBlendAttr = 300
AlphaOpAttr = 350
DCSAttr = 400
TagAttr = 500
SeqAttr = 600
BinAttr = 700
BillboardAttr = 800
ToontownAttr = 900 # specific to toontown
@dataclass
class ObjectTypeCategoryDefinition:
name: str
type_id: OTCategory
friendly_name: str
color: str
color_alt: str = ""
text_color: str = "white"
children: List["ObjectTypeDefinition"] = field(default_factory = lambda: list())
# Maya ui control holder
FrameLayout = None
def get_children(self):
return natsorted(self.children, key = lambda x: x.name.lower())
## Define custom categories ##
NoCategory = ObjectTypeCategoryDefinition("none", OTCategory.NoCategory, "No Category", "#514e52")
CollideCategory = ObjectTypeCategoryDefinition("Collide", OTCategory.CollisionAttr, "Collision", "#ac4a78")
TriggerCategory = ObjectTypeCategoryDefinition("Trigger", OTCategory.TriggerAttr, "Trigger", "#ac2e37", "#482526")
AlphaBlendModeCategory = ObjectTypeCategoryDefinition("AlphaBlend", OTCategory.AlphaBlendAttr, "Alpha Blend", "#2f4e79")
AlphaOperationCategory = ObjectTypeCategoryDefinition("AlphaOp", OTCategory.AlphaOpAttr, "Alpha Operation", "#433d79")
DCSCategory = ObjectTypeCategoryDefinition("DCS", OTCategory.DCSAttr, "DCS", "#244a14", "#354638")
SequenceCategory = ObjectTypeCategoryDefinition("Sequence", OTCategory.SeqAttr, "Sequence", "#7e4a1f")
BinCategory = ObjectTypeCategoryDefinition("Bin", OTCategory.BinAttr, "Bin", "#555eff", "#3d4351")
BillboardCategory = ObjectTypeCategoryDefinition(
"Billboard", OTCategory.BillboardAttr, "Billboard", "#7a4a79", "#6e5a6a"
)
TagCategory = ObjectTypeCategoryDefinition("Tag", OTCategory.TagAttr, "Tag", "#a9ffb6")
ToontownCategory = ObjectTypeCategoryDefinition("Toontown", OTCategory.ToontownAttr, "Toontown", "#baa05e", "#ffb31f")
# Add custom categories here so that they can be presented in the UI
CategoryDefs = {
OTCategory.NoCategory: NoCategory,
OTCategory.CollisionAttr: CollideCategory,
OTCategory.TriggerAttr: TriggerCategory,
OTCategory.AlphaBlendAttr: AlphaBlendModeCategory,
OTCategory.AlphaOpAttr: AlphaOperationCategory,
OTCategory.DCSAttr: DCSCategory,
# OTCategory.TagAttr: TagCategory,
OTCategory.SeqAttr: SequenceCategory,
OTCategory.BinAttr: BinCategory,
OTCategory.BillboardAttr: BillboardCategory,
OTCategory.ToontownAttr: ToontownCategory
}
# endregion
# region Object-Type Definitions
@dataclass
class ObjectTypeDefinition:
name: str
description: List[str] = field(default_factory = lambda: list()) # Newlines separated list of strings
flags: List[str] = field(default_factory = lambda: list()) # ['<Header> Key { Value }'] ; etc
category: ObjectTypeCategoryDefinition = NoCategory
friendly_name: str = ""
text_color: str = ""
@property
def color(self):
if not self.text_color:
return self.category.color_alt if self.category.color_alt else self.category.color
return self.text_color
# Maya controllers
mel_id = -1 # todo? meant to be stored as the internal enum value when defined into a mel global attr
Button = None # Used in the add ot window to store the button object
###
OT_NEW = [
ObjectTypeDefinition(
name = "barrier",
description = [
'Creates a barrier that other objects cannot pass through.',
'The collision is active on the "Normals" side of the object(s)'
],
category = CollideCategory,
flags = ['<Collide> { Polyset descend }']
),
ObjectTypeDefinition(
name = "barrier-no-mask",
description = [],
category = CollideCategory,
flags = ['<Collide> { Polyset descend }']
),
ObjectTypeDefinition(
name = "floor",
description = [
'Creates a collision from the object(s) that "Avatars" can walk on.',
'If the surface is angled, the Avatar will not slide down it.',
'The collision is active on the "Normals" side of the object(s)'
],
category = CollideCategory,
flags = ['<Scalar> collide-mask { 0x02 }', '<Collide> { Polyset descend level }']
),
ObjectTypeDefinition(
name = "floor-collide",
description = [],
category = CollideCategory,
flags = ['<Scalar> collide-mask { 0x06 }']
),
ObjectTypeDefinition(
name = "shadow",
description = [
'Define a "shadow" object type, so we can render all shadows in their own bin '
'and have them not fight with other transparent geometry.'
],
flags = ['<Scalar> bin { shadow }', '<Scalar> alpha { blend-no-occlude }'],
category = BinCategory,
),
ObjectTypeDefinition(
name = "shadow-cast",
description = [
'Gives the selected object(s) the required attributes so that an "Avatar\'s" shadow can be cast over it.',
'Commonly used for casting an "Avatar\'s" shadow onto floors.'
],
flags = ['<Tag> cam { shground }', '<Scalar> draw-order { 0 }', '<Scalar> bin { ground }'],
category = BinCategory,
),
ObjectTypeDefinition(
name = "bin-fixed",
flags = ['<Scalar> bin { fixed }'],
category = BinCategory,
friendly_name = "Fixed"
),
ObjectTypeDefinition(
name = "bin-gui-popup",
flags = ['<Scalar> bin { gui-popup }'],
category = BinCategory,
friendly_name = "GUI Popup"
),
ObjectTypeDefinition(
name = "bin-unsorted",
flags = ['<Scalar> bin { unsorted }'],
category = BinCategory,
friendly_name = "Unsorted"
),
ObjectTypeDefinition(
name = "bin-opaque",
flags = ['<Scalar> bin { opaque }'],
category = BinCategory,
friendly_name = "Opaque"
),
ObjectTypeDefinition(
name = "bin-background",
flags = ['<Scalar> bin { background }'],
category = BinCategory,
friendly_name = "Background"
),
ObjectTypeDefinition(
name = "bin-transparent",
flags = ['<Scalar> bin { transparent }'],
category = BinCategory,
friendly_name = "Transparent"
),
ObjectTypeDefinition(
name = "dupefloor",
description = [
'This type first creates a duplicate of the selected object(s).',
'Then, creates a floor collision from the duplicate object(s) that "Avatars" can walk on.',
'If the surface is angled, the Avatar will not slide down it.',
'The collision is active on the "Normals" side of the object(s)'
],
category = CollideCategory,
flags = ['<Collide> { Polyset keep descend level }']
),
ObjectTypeDefinition(
name = "smooth-floors",
description = ['Makes floors smooth for the "Avatars" to walk and stand on.'],
flags = [
'<Collide> { Polyset descend }',
'<Scalar> from-collide-mask { 0x000fffff }',
'<Scalar> into-collide-mask { 0x00000002 }'
],
category = CollideCategory,
),
ObjectTypeDefinition(
name = "camera-collide",
description = ['Allows only the camera to collide with the geometry.'],
flags = [
'<Scalar> collide-mask { 0x04 }',
'<Collide> { Polyset descend }'
],
category = CollideCategory,
),
ObjectTypeDefinition(
name = "sphere",
description = [
'Creates a "minimum-sized" sphere collision around the selected object(s), '
'that other objects cannot enter into.'
],
flags = ['<Collide> { Sphere descend }'],
category = CollideCategory,
),
ObjectTypeDefinition(
name = "tube",
description = [
'Creates a "minimum-sized" tube collision around the selected object(s), '
'that other objects cannot enter into.'
],
flags = ['<Collide> { Tube descend }'],
category = CollideCategory,
),
ObjectTypeDefinition(
name = "trigger",
description = [
'Creates a collision that can be used as a "Trigger", which can be used to activate, or deactivate, '
'specific processes.',
'The collision is active on the "Normals" side of the object(s)'
],
flags = ['<Collide> { Polyset descend intangible }'],
category = TriggerCategory,
),
ObjectTypeDefinition(
name = "trigger-sphere",
description = [
'Creates a "minimum-sized" sphere collision that can be used as a "Trigger", which can be used to activate,'
' or deactivate, specific processes.',
'The collision is active on the "Normals" side of the object(s)'
],
flags = ['<Collide> { Sphere descend intangible }'],
category = TriggerCategory,
),
ObjectTypeDefinition(
name = "invsphere",
description = [
'Creates a "minimum-sized" inverse-sphere collision around the selected object(s). '
'Any object inside the sphere will be prevented from exiting the sphere.'
],
flags = ['<Collide> { InvSphere descend }'],
category = CollideCategory,
),
ObjectTypeDefinition(
name = "bubble",
description = [
'"bubble" puts a Sphere collision around the geometry, but does not otherwise remove the geometry.'
],
flags = ['<Collide> { Sphere keep descend }'],
category = CollideCategory,
),
ObjectTypeDefinition(
name = "dual",
description = [
'Normally attached to polygons that have transparency, '
'that are in the scene by themselves, such as a Tree or Flower.'
],
flags = ['<Scalar> alpha { dual }'],
category = AlphaBlendModeCategory,
),
ObjectTypeDefinition(
name = "multisample",
flags = ['<Scalar> alpha { ms }'],
category = AlphaBlendModeCategory,
),
ObjectTypeDefinition(
name = "blend",
flags = ['<Scalar> alpha { blend }'],
category = AlphaBlendModeCategory,
),
ObjectTypeDefinition(
name = "decal",
flags = ['<Scalar> decal { 1 }']
),
ObjectTypeDefinition(
name = "ghost",
description = [
'"ghost" turns off the normal collide bit that is set on visible geometry by default, '
'so that if you are using visible geometry for collisions, '
'this particular geometry will not be part of those collisions--'
'it is ghostlike. Characters will pass through it.'
],
flags = ['<Scalar> collide-mask { 0 }']
),
ObjectTypeDefinition(
name = "glass",
flags = ['<Scalar> alpha { blend_no_occlude }'],
category = AlphaBlendModeCategory,
),
ObjectTypeDefinition(
name = "glow",
description = [
'"glow" is useful for halo effects and things of that ilk. It renders the object in add mode instead '
'of the normal opaque mode.'
],
flags = ['<Scalar> blend { add }'],
friendly_name = "Add",
category = AlphaOperationCategory
),
ObjectTypeDefinition(
name = "binary",
description = [
'This mode of alpha sets transparency pixels to either on or off. No blending is used.'
],
flags = ['<Scalar> alpha { binary }'],
category = AlphaBlendModeCategory,
),
ObjectTypeDefinition(
name = "indexed",
flags = ['<Scalar> indexed { 1 }']
),
ObjectTypeDefinition(
name = "model",
description = [
'This creates a ModelNode at the corresponding level, which is guaranteed not to be removed by any '
'flatten operation. However, its transform might still be changed.'
],
flags = ['<Model> { 1 }']
),
ObjectTypeDefinition(
name = "dcs",
description = [
'Indicates the node should not be flattened out of the hierarchy during conversion. '
'The node\'s transform is important and should be preserved.'
],
flags = ['<DCS> { 1 }'],
category = DCSCategory,
),
ObjectTypeDefinition(
name = "netdcs",
flags = ['<DCS> { net }'],
category = DCSCategory,
friendly_name = "Net"
),
ObjectTypeDefinition(
name = "localdcs",
flags = ['<DCS> { local }'],
category = DCSCategory,
friendly_name = "Local"
),
ObjectTypeDefinition(
name = "notouch",
description = [
'Indicates the node, and below, should not be flattened out of the hierarchy during the conversion process.'
],
flags = ['<DCS> { no-touch }'],
category = DCSCategory,
),
ObjectTypeDefinition(
name = "double-sided",
description = [
'Defines whether the polygon will be rendered double-sided (i.e., its back face will be visible).'
],
flags = ['<BFace> { 1 }']
),
ObjectTypeDefinition(
name = "billboard",
description = [
'Rotates the geometry to always face the camera. Geometry will rotate on its local axis.'
],
flags = ['<Billboard> { axis }'],
friendly_name = "BB-Axis",
category = BillboardCategory,
),
ObjectTypeDefinition(
name = "seq2",
description = [
'Indicates a series of animation frames that should be consecutively displayed at 2 fps.'
],
flags = ['<Switch> { 1 }', '<Scalar> fps { 2 }'],
category = SequenceCategory,
),
ObjectTypeDefinition(
name = "seq4",
description = [
'Indicates a series of animation frames that should be consecutively displayed at 4 fps.'
],
flags = ['<Switch> { 1 }', '<Scalar> fps { 4 }'],
category = SequenceCategory,
),
ObjectTypeDefinition(
name = "seq6",
description = [
'Indicates a series of animation frames that should be consecutively displayed at 6 fps.'
],
flags = ['<Switch> { 1 }', '<Scalar> fps { 6 }'],
category = SequenceCategory,
),
ObjectTypeDefinition(
name = "seq8",
description = [
'Indicates a series of animation frames that should be consecutively displayed at 8 fps.'
],
flags = ['<Switch> { 1 }', '<Scalar> fps { 8 }'],
category = SequenceCategory,
),
ObjectTypeDefinition(
name = "seq10",
description = [
'Indicates a series of animation frames that should be consecutively displayed at 10 fps.'
],
flags = ['<Switch> { 1 }', '<Scalar> fps { 10 }'],
category = SequenceCategory,
),
ObjectTypeDefinition(
name = "seq12",
description = [
'Indicates a series of animation frames that should be consecutively displayed at 12 fps.'
],
flags = ['<Switch> { 1 }', '<Scalar> fps { 12 }'],
category = SequenceCategory,
),
ObjectTypeDefinition(
name = "seq24",
description = [
'Indicates a series of animation frames that should be consecutively displayed at 24 fps.'
],
flags = ['<Switch> { 1 }', '<Scalar> fps { 24 }'],
category = SequenceCategory,
),
ObjectTypeDefinition(
name = "ground",
flags = ['<Scalar> bin { ground }'],
category = BinCategory,
),
ObjectTypeDefinition(
name = "invisible",
flags = []
),
ObjectTypeDefinition(
name = "catch-grab",
flags = ['<Scalar> collide-mask { 0x08 }'],
description = ['Things the magnet can pick up in the Cashbot CFO battle (same as CatchGameBitmask)'],
category = ToontownCategory,
),
ObjectTypeDefinition(
name = "pet",
flags = ['<Scalar> collide-mask { 0x10 }'],
description = ['Pets avoid this'],
category = ToontownCategory,
),
ObjectTypeDefinition(
name = "furniture-side",
flags = ['<Scalar> collide-mask { 0x20 }'],
category = ToontownCategory,
),
ObjectTypeDefinition(
name = "furniture-top",
flags = ['<Scalar> collide-mask { 0x40 }'],
category = ToontownCategory,
),
ObjectTypeDefinition(
name = "furniture-drag",
flags = ['<Scalar> collide-mask { 0x80 }'],
category = ToontownCategory,
),
ObjectTypeDefinition(
name = "pie",
flags = ['<Scalar> collide-mask { 0x100 }'],
category = ToontownCategory,
description = ['Things we can throw a pie at.'],
),
]
def getOTNames(sortby=None):
names = [ot.name for ot in OT_NEW]
if sortby == "alphabetical":
names = natsorted(names)
elif sortby == "category":
def sorting_key(item):
category_id = item.category.type_id if item.category is not None else NoCategory.type_id
name_lower = item.name.lower()
return category_id, name_lower
names = [ot.name for ot in natsorted(OT_NEW, key = sorting_key)]
return names
# Populates categories with children
for OTEntry in OT_NEW:
OTEntry.category.children.append(OTEntry)
# endregion
# region Main Functions
def MP_PY_PandaVersion(option):
"""
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_PY_PandaFileVersions ARRAY ENTRY: "Default","bam2egg","egg2bam","pview"
"""
pm.melGlobals.initVar("string[]", PANDA_FILE_VERSIONS)
executableToUse = ""
selectedBamVersion = str(pm.optionMenu("MP_PY_BamVersionOptionMenu", query = 1, value = 1))
for i in range(0, len(pm.melGlobals[PANDA_FILE_VERSIONS])):
if selectedBamVersion == pm.melGlobals[PANDA_FILE_VERSIONS][i]:
if option == "getBam2Egg":
executableToUse = pm.melGlobals[PANDA_FILE_VERSIONS][i + 1]
elif option == "getEgg2Bam":
executableToUse = pm.melGlobals[PANDA_FILE_VERSIONS][i + 2]
elif option == "getPview":
executableToUse = pm.melGlobals[PANDA_FILE_VERSIONS][i + 3]
break
return executableToUse
def MP_PY_ConfirmationDialog(title, message, dialog_type):
"""
Shows a confirmation dialog with the given title, message, and button type.
:param title: Title of the dialog.
:param message: Message displayed in the dialog.
:param dialog_type: Type of dialog (e.g., "ok", "okcancel", "yesno", etc.).
:returns: The value of the button pressed by the user.
"""
if isinstance(message, list):
message = "\n".join(message)
# would be nice sometime in the future to have message be a list of strings, combined with \n separator
# Define button configurations based on the dialog type
button_configs = {
"ok": {"buttons": ["OK"], "default": "OK", "cancel": "CANCEL"},
"okcancel": {"buttons": ["OK", "CANCEL"], "default": "OK", "cancel": "CANCEL"},
"selectcancel": {"buttons": ["SELECT", "CANCEL"], "default": "SELECT", "cancel": "CANCEL"},
"yesno": {"buttons": ["YES", "NO"], "default": "YES", "cancel": "NO"},
"downloadcancel": {"buttons": ["DOWNLOAD", "CANCEL"], "default": "DOWNLOAD", "cancel": "CANCEL"},
}
# Get the configuration for the dialog type
config = button_configs.get(dialog_type)
if not config:
raise ValueError(f"Unknown dialog type: {dialog_type}")
# Show the confirmation dialog
return str(
pm.confirmDialog(
title = title,
message = message,
button = config["buttons"],
defaultButton = config["default"],
cancelButton = config["cancel"],
dismissString = config["cancel"],
)
)
def MP_PY_PlaceholderFunc(*args, **kwargs):
return MP_PY_ConfirmationDialog(
"Not implemented!",
[
"Sorry, this feature is not implemented yet.",
],
"ok",
)
def MP_PY_AddEggObjectFlags(eggObjectType):
"""
Add an egg-object-type to poly
"""
pm.melGlobals.initVar("string[]", EGG_OBJECT_TYPE_ARRAY)
# global egg-object-type array
# generate attribute enumeration list from the array
enumerationList = ":".join(pm.melGlobals[EGG_OBJECT_TYPE_ARRAY])
# Verify the eggObjectType that was passed to this process exists in the $gMP_PY_EggObjectTypeArray array
# If it does not, we skip processing and warn user.
eggTypeInArray = eggObjectType in pm.melGlobals[EGG_OBJECT_TYPE_ARRAY]
if eggTypeInArray == 1:
indexNumber = -1
# String version of array index number.
# This is necessary, so we can verify the index number is not null/empty
# 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 in range(0, len(pm.melGlobals[EGG_OBJECT_TYPE_ARRAY])):
if pm.melGlobals[EGG_OBJECT_TYPE_ARRAY][n] == eggObjectType:
indexNumber = int(n)
selectedNodes = pm.ls(sl = 1)
# Variable to hold all currently selected nodes
# Iterate through each selected node one-by-one
if len(selectedNodes) == 0:
return MP_PY_ConfirmationDialog(
"Selection Error!",
[
"You must first make a selection!",
"Please select at least one node, then try again."
],
"ok",
)
for node in selectedNodes:
for i in range(1, 11):
if pm.objExists(str(node) + ".eggObjectTypes" + str(i)) == 1:
# At the very moment, we set our egg tag limit to 10 per node.
# There's not really a reason right now for why a user will get to this limit, but
# due to some prior hard-coded values with egg object types, we are capping it at 10.
if i == 10:
MP_PY_ConfirmationDialog(
"Egg-Object-Type Error!",
[
"Limit of 10 egg-object-types has already been reached.",
"No More Egg Object Types Supported for this node."
],
"ok",
)
else:
MP_PY_SetEggObjectTypeAttribute(enumerationList, eggObjectType, indexNumber, i, node)
break
else:
MP_PY_ConfirmationDialog(
"Egg-Object-Type Error!",
[
"The selected egg-object-type was not found in the $gMP_PY_EggObjectTypeArray",
"Please verify the object-type being passed and update the $gMP_PY_EggObjectTypeArray",
"to include the egg-object-type if the type is the correct one needed.",
"If you modify the $gMP_PY_EggObjectTypeArray DO NOT forget to update your PRC files.",
"to include a reference of the egg-object-type you are adding."
],
"ok",
)
# Message to user that the passed egg-object-type is NOT in the $gMP_PY_EggObjectTypeArray array
if pm.window("MP_PY_DeleteEggObjectTypesWindow", exists = 1):
MP_PY_GetEggObjectTypes()
# Method to update the DeleteEggObjectTypesWindow window if it is currently being shown
def MP_PY_TexPathOptionsUI():
"""
Updates the UI based on the selected texture path option.
"""
selected_option = pm.radioCollection("MP_PY_TexPathOptionsRC", query = True, select = True)
output_file_type = pm.radioCollection("MP_PY_OutputPandaFileTypeRC", query = True, select = True)
# Default settings for text fields and buttons
def set_fields(egg_enable=False, bam_enable=False, egg_clear=False, bam_clear=False):
pm.textField("MP_PY_CustomEggTexPathTF", edit = True, enable = egg_enable, text = "" if egg_clear else None)
pm.textField("MP_PY_CustomBamTexPathTF", edit = True, enable = bam_enable, text = "" if bam_clear else None)
pm.button("MP_PY_BrowseEggTexPathBTN", edit = True, enable = egg_enable)
pm.button("MP_PY_BrowseBamTexPathBTN", edit = True, enable = bam_enable)
if selected_option == "MP_PY_ChooseDefaultTexPathRB":
print("Default Texture Path Chosen\n")
set_fields(egg_enable = False, bam_enable = False, egg_clear = True, bam_clear = True)
elif selected_option == "MP_PY_ChooseCustomRefPathRB":
print("Custom Texture Reference Path Chosen\n")
if output_file_type == "MP_PY_ChooseEggRB":
set_fields(egg_enable = True, bam_enable = False, bam_clear = True)
elif output_file_type == "MP_PY_ChooseEggBamRB":
set_fields(egg_enable = False, bam_enable = True, egg_clear = True)
elif selected_option == "MP_PY_ChooseCustomTexPathRB":
print("Custom Texture Path Chosen\n")
set_fields(
egg_enable = output_file_type in {"MP_PY_ChooseEggRB", "MP_PY_ChooseEggBamRB"},
bam_enable = output_file_type == "MP_PY_ChooseEggBamRB"
)
def MP_PY_OutputPathOptionsUI():
"""
Updates the UI when a radio button is chosen
"""
selectedRB = str(pm.radioCollection("MP_PY_OutputPathOptionsRC", query = 1, select = 1))
if selectedRB == "MP_PY_ChooseDefaultOutputPathRB":
print("Default Export File Path Chosen\n")
pm.textField("MP_PY_CustomOutputPathTF", edit = 1, text = "", enable = 0)
pm.button("MP_PY_BrowseOutputPathBTN", edit = 1, enable = 0)
elif selectedRB == "MP_PY_ChooseCustomOutputPathRB":
print("Custom Export File Path Chosen\n")
pm.textField("MP_PY_CustomOutputPathTF", edit = 1, enable = 1)
pm.button("MP_PY_BrowseOutputPathBTN", edit = 1, enable = 1)
def MP_PY_OutputFilenameOptionsUI():
"""
Updates the UI when a radio button is chosen
"""
selectedRB = str(
pm.radioCollection("MP_PY_OutputFilenameOptionsRC", query = 1, select = 1)
)
if selectedRB == "MP_PY_ChooseOriginalFilenameRB":
print("Default Export Filename Chosen\n")
pm.textField("MP_PY_CustomFilenameTF", edit = 1, text = "", enable = 0)
pm.button("MP_PY_BrowseFilenameBTN", edit = 1, enable = 0)
elif selectedRB == "MP_PY_ChooseCustomFilenameRB":
print("Custom Export Filename Chosen\n")
pm.textField("MP_PY_CustomFilenameTF", edit = 1, enable = 1)
pm.button("MP_PY_BrowseFilenameBTN", edit = 1, enable = 1)
def MP_PY_TransformModeUI():
"""
Updates the UI when a radio button is chosen
Specifies which transforms in the Maya file should be converted to transforms in the egg file.
The option may be one of all, model, dcs, or none.
The Panda default is model, which means only transforms on nodes that have the model or dcs flag are preserved in
the converted egg file.
"""
selectedRB = str(pm.radioCollection("MP_PY_TransformModeRC", query = 1, select = 1))
if selectedRB == "MP_PY_ChooseTransformNoneRB":
print("Saves no transform information\n")
elif selectedRB == "MP_PY_ChooseTransformAllRB":
print(
"Save transforms of all objects, PRESERVES local pivot, orientation, scale, and shear"
+ "\nAll transform will remain when loaded into Panda3D\n"
)
elif selectedRB == "MP_PY_ChooseTransformDCSRB":
print(
"Save transforms of objects which have dcs-flag only," +
"\nCLEARS local pivot, orientation, scale, and shear of the other objects." +
"\nAll transform will be frozen to the vertices and will be 0 when loaded into Panda3D\n"
)
elif selectedRB == "MP_PY_ChooseTransformModelRB":
print(
"Save transforms of objects which have model-flag or dcs-flag only,"
+ "\nCLEARS local pivot, "
"orientation, "
"scale, and shear of the other "
"objects"
+ "\nAll transform will be frozen to the vertices and will be 0 when loaded into Panda3D\n"
)
def MP_PY_SetEggObjectTypeAttribute(enumerationList, eggObjectType, indexNumber, attributeNumber, node):
# Determining variable on whether we can add egg-object-type attribute to node
# 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 in range(1, 11):
if pm.objExists(node + ".eggObjectTypes" + str(i)):
if pm.getAttr((node + ".eggObjectTypes" + str(i)), asString = 1) == eggObjectType:
MP_PY_ConfirmationDialog(
"Egg-Object-Type Error!",
[
f'egg-object-type - "{eggObjectType}"',
f"Already attached on node attribute:",
f"{node}.eggObjectTypes{i}",
],
"ok",
)
return
# Attribute exists, check if attributes matches the passed egg-object-type
# Message to user that the egg-object-type is already assigned to node
# Since attribute already exists on node, set our determining variable to 0 to skip adding it again
# pm.color(node, rgbColor=hex_to_rgb_normalized(defObj.category.color), ud=1)
pm.addAttr(
node,
ln = ("eggObjectTypes" + str(attributeNumber)),
enumName = enumerationList,
attributeType = "enum",
keyable = 1,
)
# Adds the egg-object-type attribute to node if it was not already attached
pm.setAttr((node + ".eggObjectTypes" + str(attributeNumber)), indexNumber)
def generate_objtype_syntax(object_type):
# egg-object-type XXXXX
return f"egg-object-type-{object_type.name} " + " ".join(object_type.flags)
def MP_PY_InspectEggObjectType(object_type: ObjectTypeDefinition):
# modify the inspect/creator section to show the object type information
pm.textField("MP_PY_OTGEN_NAMEINPUT", edit = True, text = object_type.name)
pm.scrollField("MP_PY_OTGEN_DEFINPUT", edit = True, text = '\n'.join(object_type.flags))
pm.scrollField("MP_PY_OTGEN_DESCINPUT", edit = True, text = '\n'.join(object_type.description))
pm.textField("MP_PY_OTGEN_ATTRDEFTXT", edit = True, text = generate_objtype_syntax(object_type))
idlist = pm.optionMenu("MP_PY_OTGEN_CATMENU", query = True, ils = True)
objIndex = idlist.index(f"MP_PY_OTGEN_CATMENU_ITEM_{object_type.category.name}")
pm.optionMenu("MP_PY_OTGEN_CATMENU", edit = True, select = objIndex + 1)
# print(idlist[pm.optionMenu("MP_PY_OTGEN_CATMENU", query=True, select=True, value=True) - 1])
def MP_PY_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_PY_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.
"""
pm.melGlobals.initVar("string[]", EGG_OBJECT_TYPE_ARRAY)
# Delete any current instances of the AddEggObjectTypesWindow window
if pm.window("MP_PY_AddEggObjectTypesWindow", exists = 1):
pm.deleteUI("MP_PY_AddEggObjectTypesWindow", window = 1)
pm.window(
"MP_PY_AddEggObjectTypesWindow",
retain = 1,
sizeable = 1,
visible = 1,
resizeToFitChildren = True,
title = "Panda Exporter - Add Egg-Object-Types",
)
# region Add OT Tags
def createOTTagsSection():
pm.columnLayout(adjustableColumn = True, columnAttach = ("left", 0), rowSpacing = 0)
with pm.frameLayout(
font = "obliqueLabelFont",
collapsable = True,
backgroundColor = hex_to_rgb_normalized("#809933"),
label = "Add Egg-Object-Type Tags to Selected Nodes",
):
def callback_add_ot(obj_name):
# hack: need this function otherwise it will pass True/False
return lambda *args: MP_PY_AddEggObjectFlags(obj_name)
def callback_inspect_ot(obj_name):
# hack: need this function otherwise it will pass True/False
return lambda *args: MP_PY_InspectEggObjectType(obj_name)
def addEggTypeTagsNew():
for category_def in CategoryDefs.values():
numChildren = len(category_def.children)
with pm.frameLayout(
font = "boldLabelFont",
collapsable = True,
collapse = True,
label = category_def.friendly_name,
backgroundShade = True,
# backgroundColor = hex_to_rgb_normalized(category_def.color),
) as frame:
category_def.FrameLayout = frame
with pm.columnLayout(adjustableColumn = True):
for ot in category_def.get_children():
annotation = str(MP_PY_GetObjectTypeAnnotationNEW(ot))
labelName = ot.friendly_name if ot.friendly_name else ot.name
ot.Button = pm.button(
f"MP_PY_AttEggATTR_{ot.name}",
width = 100,
height = 17,
command = callback_add_ot(ot.name), # Pass the current objName
annotation = annotation,
label = labelName,
backgroundColor = hex_to_rgb_normalized(ot.color)
)
pm.popupMenu()
pm.menuItem(
label = f"Inspect {ot.name}",
command = callback_inspect_ot(ot),
)
pm.setParent(u = 1)
addEggTypeTagsNew()
pm.setParent(u = 1)
createOTTagsSection()
# endregion
# region OT Information Label
def createOTInformationLabel():
pm.separator(style = "none", height = 5)
with pm.rowLayout(nc = 2, columnAttach = (1, "both", 100), adjustableColumn = True):
pm.text(
bgc = hex_to_rgb_normalized("#59D1F2"),
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."
),
)
pm.setParent(u = 1)
pm.setParent(u = 1)
createOTInformationLabel()
# endregion
# region Create OT Tags
def createOTTagGeneratorSection():
with pm.frameLayout(
font = "obliqueLabelFont",
collapsable = True,
label = "OT Tag Creator",
backgroundColor = hex_to_rgb_normalized("#30991b"),
):
with pm.columnLayout(columnAttach = ("both", 15), rowSpacing = 0, adjustableColumn = True):
with pm.rowLayout(nc = 3, adjustableColumn = True):
pm.text(
font = "smallBoldLabelFont",
label = "Create and define custom ObjectTypes here. Press 'CREATE' to generate.",
)