-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPokemonSwitch_GFBMDL-TRMDL.ms
4059 lines (3943 loc) · 183 KB
/
PokemonSwitch_GFBMDL-TRMDL.ms
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
-- Nintendo Switch Pokémon (Let's Go! Pikachu & Eevee, Sword & Shield, Legends: Arceus, Scarlet & Violet) model importer by Random Talking Bush.
-- #TeamEevee
-- Changelog:
-- November 26, 2022: Fixed common trainer models from Scarlet & Violet ("model_vr") not importing due to an oversight.
-- November 20, 2022: Added support for Pokémon Scarlet & Violet.
-- February 6, 2022: Fixed models with more than 65536 vertices on a single mesh group (e.g. objects_area04_building01) failing to import. (Thanks, New3DsSuchti!)
-- Fixed trainer models erroring in non-ancient 3DS Max versions when importing out of the intended order. (Thanks, FreohrWeohnataKausta!)
-- Added an option to "simplify" materials upon importing, to assist with using the Render to Texture function to re-bake colourized Pokémon textures.
-- January 30th, 2022: Tweaked Pokémon Legends: Arceus models to correctly use Physical materials if using 3DS Max 2017 or above, and build / assign roughness and metalness maps accordingly.
-- January 28th, 2022: Added support for Pokémon Legends: Arceus.
-- Fixed models refusing to import in 3DS Max 2021 (the "twoSided" error was due to it trying to apply "Standard" material settings to a "Physical" material, which apparently is the new default).
-- November 15th, 2019: Fixed issues with the script preventing Sword/Shield models from loading.
rollout ModelImporter "Nintendo Switch Pokémon Model Importer" width:330 height:345
(
button btnImportGFBMDL "Import *.GFBMDL" pos:[7,8] width:155 height:50 tooltip: "Let's Go! Pikachu / Eevee, Sword / Shield"
button btnImportTRMDL "Import *.TRMDL" pos:[168,8] width:155 height:50 tooltip: "Pokémon Legends: Arceus, Scarlet / Violet"
groupBox OptionsBox "Options (General)" pos:[7,65] width:316 height:60
groupBox OptionsBoxPLA "Options (Legends: Arceus, Scarlet/Violet)" pos:[7,130] width:316 height:95
label lblVertColors "Vertex colors:" pos:[17,80]
radiobuttons tglVertColors labels:#("Default","Set 2","Off") pos:[17,100]
checkbox tglMat "Print material information?" pos:[170,80] checked: false tooltip: "Enable this to print all of the model's material parameters to the Listener window. While not entirely necessary for Let's Go or Sword/Shield models, it's pretty much mandatory for Legends: Arceus due to everything using color masks."
checkbox tglDebug "Print debug information?" pos:[170,100] checked: false tooltip: "Enable this to print useless information to the Listener window."
checkbox tglArceusLODs "Import LOD models?" pos:[17,145] checked: false tooltip: "If enabled, this will also import the two lower-poly Level-of-Detail models that Pokémon and NPC characters have alongside the base model."
checkbox tglArceusScale "Scale to LG/SwSh models?" pos:[170,145] checked: true tooltip: "Pokémon Legends: Arceus and Scarlet/Violet's models are normally 1:100th the scale of the respective models in Let's Go, Sword/Shield and the 3DS games. Enabling this will scale them up 100x to match them. Note that this will break any animation imports."
checkbox tglArceusMaskSplit "Use split texture masks?" pos:[17,165] checked: false tooltip: "Enable this option if you've taken the time to split the ''lym'' texture files into four separate greyscaled ''lym'' textures (suffixed with '''lym_A'', ''lym_B'', ''lym_C'' and ''lym_D'' for red/green/blue/alpha respectively) to use those instead of the original, merged RGBA images."
checkbox tglArceusShiny "Use Shiny material?" pos:[170,165] checked: false tooltip: "If enabled, the model will use the respective Shiny (''rare'') material files for Pokémon instead, if applicable."
checkbox tglArceusSimpleMat "Simplify materials?" pos:[170,185] checked: false tooltip: "If enabled, the model will ignore any material that isn't diffuse, enable self-illumination and will force Standard on 3DS Max 2017 or higher. Should make texture baking a little less complicated for Legends: Arceus."
spinner spnArceusColorMult "Color multiplier:" width:80 pos:[65,185] range: [0,255,100] tooltip: "While the default is 100%, the material colors are naturally dark (e.g. shades of white being only 44% brightness). Recommended range is around double the original amount. Don't adjust this value for Scarlet/Violet as its color values are already proper amounts." -- Assuming 0.39 = 1 in RGB, 255 should be the absolute maximum it should be without the textures going nuclear.
label lblTrainerMerge "Trainer model fixes:" pos:[17,205]
radiobuttons tglTrainerMerge labels:#("Legends: Arceus","Scarlet / Violet") pos:[118,205]
label lblCred "This script was written by Random Talking Bush for use with the Switch Pokémon games (Let's Go! Pikachu/Eevee, Sword/Shield, Legends: Arceus and Scarlet/Violet). If used, please consider giving thanks to me, Nintendo, Game Freak and The Pokémon Company. If something doesn't work right, please contact me on The VG Resource (Random Talking Bush), XeNTaX, Twitter or Steam (RandomTBush) so I can fix it." pos:[8,230] width:317 height:90
label lblUpdate "(Updated: 11-26-2022)" pos:[ModelImporter.width-120,ModelImporter.height-19] width:115
fn readHalfFloat fstream = (
local BL = readByte Fstream #unsigned
local BH = readByte Fstream #unsigned
local N = BH*256 + BL
local S = floor((mod N 65536) / 32768)
local Ef = floor((mod N 32768) / 1024)
local M = mod N 1024
if (Ef==0)AND(M==0) then return ( (-1.0)^S * 0.0 )
if (Ef==0)AND(M!= 0) then return ( (-1.0)^S * 2.0^-14 * (M / 2.0^10) )
if (Ef>0)AND(Ef<31) then return ( (-1.0)^S * 2.0^(Ef-15) * (1 + M/2.0^10) )
if (Ef==31)AND(M==0) then return ( (-1.0)^S * 1/0.0 )
if (Ef==31)AND(M!= 0) then return 0 --hack-- should be #inf
)
fn ReadFixedString bstream fixedLen = (
local str = ""
for i = 1 to fixedLen do
(
str += bit.intAsChar (ReadByte bstream #unsigned)
)
str
)
fn printDebug pr = (if tglDebug.state do print(pr))
fn printMat pr = (if tglMat.state do print(pr))
fn TrainerRigLink CharaCheck = (
-- Trainer models expect their base skeletons imported first. This sets up the placeholder names that it expects so things import correctly.
global BoneRigArray = #()
case CharaCheck of (
default:(
-- Overrides node IDs for player and common NPC character models in this game, this needs to be hardcoded so that additional model parts won't have broken rigging or bone positions.
-- IDs from 1 to 72 are assigned to the base skeleton file for common NPC characters (cc_base0001_00_young_m, and yes you're reading that right, *every single NPC* uses the same bones).
BoneRigArray[1] = "foot_base"
BoneRigArray[2] = "waist"
BoneRigArray[3] = "spine_01"
BoneRigArray[4] = "spine_02"
BoneRigArray[5] = "spine_03"
BoneRigArray[6] = "neck"
BoneRigArray[7] = "look"
BoneRigArray[8] = "head"
BoneRigArray[9] = "left_shoulder"
BoneRigArray[10] = "left_arm_width"
BoneRigArray[11] = "left_arm_01"
BoneRigArray[12] = "left_arm_02"
BoneRigArray[13] = "left_hand"
BoneRigArray[14] = "left_thumb_01"
BoneRigArray[15] = "left_thumb_02"
BoneRigArray[16] = "left_thumb_03"
BoneRigArray[17] = "left_index_01"
BoneRigArray[18] = "left_index_02"
BoneRigArray[19] = "left_index_03"
BoneRigArray[20] = "left_middle_01"
BoneRigArray[21] = "left_middle_02"
BoneRigArray[22] = "left_middle_03"
BoneRigArray[23] = "left_ring_01"
BoneRigArray[24] = "left_ring_02"
BoneRigArray[25] = "left_ring_03"
BoneRigArray[26] = "left_pinky_01"
BoneRigArray[27] = "left_pinky_02"
BoneRigArray[28] = "left_pinky_03"
BoneRigArray[29] = "left_attach_off"
BoneRigArray[30] = "left_attach_on"
BoneRigArray[31] = "left_hand_roll"
BoneRigArray[32] = "left_arm_02_sub"
BoneRigArray[33] = "left_arm_02_roll"
BoneRigArray[34] = "left_arm_01_roll"
BoneRigArray[35] = "right_shoulder"
BoneRigArray[36] = "right_arm_width"
BoneRigArray[37] = "right_arm_01"
BoneRigArray[38] = "right_arm_02"
BoneRigArray[39] = "right_hand"
BoneRigArray[40] = "right_thumb_01"
BoneRigArray[41] = "right_thumb_02"
BoneRigArray[42] = "right_thumb_03"
BoneRigArray[43] = "right_index_01"
BoneRigArray[44] = "right_index_02"
BoneRigArray[45] = "right_index_03"
BoneRigArray[46] = "right_middle_01"
BoneRigArray[47] = "right_middle_02"
BoneRigArray[48] = "right_middle_03"
BoneRigArray[49] = "right_ring_01"
BoneRigArray[50] = "right_ring_02"
BoneRigArray[51] = "right_ring_03"
BoneRigArray[52] = "right_pinky_01"
BoneRigArray[53] = "right_pinky_02"
BoneRigArray[54] = "right_pinky_03"
BoneRigArray[55] = "right_attach_off"
BoneRigArray[56] = "right_attach_on"
BoneRigArray[57] = "right_hand_roll"
BoneRigArray[58] = "right_arm_02_sub"
BoneRigArray[59] = "right_arm_02_roll"
BoneRigArray[60] = "right_arm_01_roll"
BoneRigArray[61] = "hips"
BoneRigArray[62] = "leg_width"
BoneRigArray[63] = "left_leg_01"
BoneRigArray[64] = "left_leg_02"
BoneRigArray[65] = "left_foot"
BoneRigArray[66] = "left_toe"
BoneRigArray[67] = "left_leg_02_sub"
BoneRigArray[68] = "right_leg_01"
BoneRigArray[69] = "right_leg_02"
BoneRigArray[70] = "right_foot"
BoneRigArray[71] = "right_toe"
BoneRigArray[72] = "right_leg_02_sub"
-- IDs from 73 to 137 are assigned to the face skeleton file. We can leave these blank as they're not shared with other models.
BoneRigArray[73] = ""
BoneRigArray[74] = ""
BoneRigArray[75] = ""
BoneRigArray[76] = ""
BoneRigArray[77] = ""
BoneRigArray[78] = ""
BoneRigArray[79] = ""
BoneRigArray[80] = ""
BoneRigArray[81] = ""
BoneRigArray[82] = ""
BoneRigArray[83] = ""
BoneRigArray[84] = ""
BoneRigArray[85] = ""
BoneRigArray[86] = ""
BoneRigArray[87] = ""
BoneRigArray[88] = ""
BoneRigArray[89] = ""
BoneRigArray[90] = ""
BoneRigArray[91] = ""
BoneRigArray[92] = ""
BoneRigArray[93] = ""
BoneRigArray[94] = ""
BoneRigArray[95] = ""
BoneRigArray[96] = ""
BoneRigArray[97] = ""
BoneRigArray[98] = ""
BoneRigArray[99] = ""
BoneRigArray[100] = ""
BoneRigArray[101] = ""
BoneRigArray[102] = ""
BoneRigArray[103] = ""
BoneRigArray[104] = ""
BoneRigArray[105] = ""
BoneRigArray[106] = ""
BoneRigArray[107] = ""
BoneRigArray[108] = ""
BoneRigArray[109] = ""
BoneRigArray[110] = ""
BoneRigArray[111] = ""
BoneRigArray[112] = ""
BoneRigArray[113] = ""
BoneRigArray[114] = ""
BoneRigArray[115] = ""
BoneRigArray[116] = ""
BoneRigArray[117] = ""
BoneRigArray[118] = ""
BoneRigArray[119] = ""
BoneRigArray[120] = ""
BoneRigArray[121] = ""
BoneRigArray[122] = ""
BoneRigArray[123] = ""
BoneRigArray[124] = ""
BoneRigArray[125] = ""
BoneRigArray[126] = ""
BoneRigArray[127] = ""
BoneRigArray[128] = ""
BoneRigArray[129] = ""
BoneRigArray[130] = ""
BoneRigArray[131] = ""
BoneRigArray[132] = ""
BoneRigArray[133] = ""
BoneRigArray[134] = ""
BoneRigArray[135] = ""
BoneRigArray[136] = ""
BoneRigArray[137] = ""
-- IDs from 138 and so on are assigned to the outfit skeleton file(s), and are also different depending on the respective model.
-- We don't need placeholders for these, as they're filled in as necessary by the outfits themselves.
)
"FlorianJuliana":(
-- IDs from 1 to 72 are assigned to the base skeleton file, Florian and Juliana use the exact same skeleton file (model_pc_base/model/p0_base).
-- It's essentially the same as the default NPCs from both Arceus or Scarlet & Violet, but we're duplicating it anyway.
BoneRigArray[1] = "foot_base"
BoneRigArray[2] = "waist"
BoneRigArray[3] = "spine_01"
BoneRigArray[4] = "spine_02"
BoneRigArray[5] = "spine_03"
BoneRigArray[6] = "neck"
BoneRigArray[7] = "look"
BoneRigArray[8] = "head"
BoneRigArray[9] = "left_shoulder"
BoneRigArray[10] = "left_arm_width"
BoneRigArray[11] = "left_arm_01"
BoneRigArray[12] = "left_arm_02"
BoneRigArray[13] = "left_hand"
BoneRigArray[14] = "left_thumb_01"
BoneRigArray[15] = "left_thumb_02"
BoneRigArray[16] = "left_thumb_03"
BoneRigArray[17] = "left_index_01"
BoneRigArray[18] = "left_index_02"
BoneRigArray[19] = "left_index_03"
BoneRigArray[20] = "left_middle_01"
BoneRigArray[21] = "left_middle_02"
BoneRigArray[22] = "left_middle_03"
BoneRigArray[23] = "left_ring_01"
BoneRigArray[24] = "left_ring_02"
BoneRigArray[25] = "left_ring_03"
BoneRigArray[26] = "left_pinky_01"
BoneRigArray[27] = "left_pinky_02"
BoneRigArray[28] = "left_pinky_03"
BoneRigArray[29] = "left_attach_off"
BoneRigArray[30] = "left_attach_on"
BoneRigArray[31] = "left_hand_roll"
BoneRigArray[32] = "left_arm_02_sub"
BoneRigArray[33] = "left_arm_02_roll"
BoneRigArray[34] = "left_arm_01_roll"
BoneRigArray[35] = "right_shoulder"
BoneRigArray[36] = "right_arm_width"
BoneRigArray[37] = "right_arm_01"
BoneRigArray[38] = "right_arm_02"
BoneRigArray[39] = "right_hand"
BoneRigArray[40] = "right_thumb_01"
BoneRigArray[41] = "right_thumb_02"
BoneRigArray[42] = "right_thumb_03"
BoneRigArray[43] = "right_index_01"
BoneRigArray[44] = "right_index_02"
BoneRigArray[45] = "right_index_03"
BoneRigArray[46] = "right_middle_01"
BoneRigArray[47] = "right_middle_02"
BoneRigArray[48] = "right_middle_03"
BoneRigArray[49] = "right_ring_01"
BoneRigArray[50] = "right_ring_02"
BoneRigArray[51] = "right_ring_03"
BoneRigArray[52] = "right_pinky_01"
BoneRigArray[53] = "right_pinky_02"
BoneRigArray[54] = "right_pinky_03"
BoneRigArray[55] = "right_attach_off"
BoneRigArray[56] = "right_attach_on"
BoneRigArray[57] = "right_hand_roll"
BoneRigArray[58] = "right_arm_02_sub"
BoneRigArray[59] = "right_arm_02_roll"
BoneRigArray[60] = "right_arm_01_roll"
BoneRigArray[61] = "hips"
BoneRigArray[62] = "leg_width"
BoneRigArray[63] = "left_leg_01"
BoneRigArray[64] = "left_leg_02"
BoneRigArray[65] = "left_foot"
BoneRigArray[66] = "left_toe"
BoneRigArray[67] = "left_leg_02_sub"
BoneRigArray[68] = "right_leg_01"
BoneRigArray[69] = "right_leg_02"
BoneRigArray[70] = "right_foot"
BoneRigArray[71] = "right_toe"
BoneRigArray[72] = "right_leg_02_sub"
-- IDs from 73 to 92 are assigned to the hair models (p0_hrs*).
-- The names for these are irrelevant as outfits never use 'em, but they need to be filled in to prevent errors.
BoneRigArray[73] = ""
BoneRigArray[74] = ""
BoneRigArray[75] = ""
BoneRigArray[76] = ""
BoneRigArray[77] = ""
BoneRigArray[78] = ""
BoneRigArray[79] = ""
BoneRigArray[80] = ""
BoneRigArray[81] = ""
BoneRigArray[82] = ""
BoneRigArray[83] = ""
BoneRigArray[84] = ""
BoneRigArray[85] = ""
BoneRigArray[86] = ""
BoneRigArray[87] = ""
BoneRigArray[88] = ""
BoneRigArray[89] = ""
BoneRigArray[90] = ""
BoneRigArray[91] = ""
BoneRigArray[92] = ""
-- IDs from 93 to 104 are assigned to the face skeleton file (p0_face0000_heroine).
-- We don't *have* to fill these in since nothing links directly to it unlike in Legends: Arceus, but I'm doing so anyway because I can.
BoneRigArray[93] = "root_face"
BoneRigArray[94] = "eyescale"
BoneRigArray[95] = "left_eyeball_segoff"
BoneRigArray[96] = "left_pupil_01"
BoneRigArray[97] = "left_pupil_02"
BoneRigArray[98] = "left_eyehilight_01"
BoneRigArray[99] = "left_eyehilight_02"
BoneRigArray[100] = "right_eyeball_segoff"
BoneRigArray[101] = "right_pupil_01"
BoneRigArray[102] = "right_pupil_02"
BoneRigArray[103] = "right_eyehilight_01"
BoneRigArray[104] = "right_eyehilight_02"
-- IDs from 105 to 114 are assigned to the bags (p0_bag*), and are different on a model-by-model basis just like the hair is.
BoneRigArray[105] = ""
BoneRigArray[106] = ""
BoneRigArray[107] = ""
BoneRigArray[108] = ""
BoneRigArray[109] = ""
BoneRigArray[110] = ""
BoneRigArray[111] = ""
BoneRigArray[112] = ""
BoneRigArray[113] = ""
BoneRigArray[114] = ""
-- IDs from 105 to 114 are assigned to the outfits (p1_drs0000_uniform and p2_drs0000_uniform), and are also different just like everything above.
BoneRigArray[115] = ""
BoneRigArray[116] = ""
BoneRigArray[117] = ""
BoneRigArray[118] = ""
BoneRigArray[119] = ""
BoneRigArray[120] = ""
BoneRigArray[121] = ""
BoneRigArray[122] = ""
BoneRigArray[123] = ""
BoneRigArray[124] = ""
-- IDs from 125 and so on are assigned to the headwear (p0_hdw0000_default and p0_hdw0013_porkpie), and... if you're reading up to there, you should already know what I'm gonna say.
-- We don't need placeholders for these, as they're filled in as necessary by the hats themselves.
)
"Rei":(
-- IDs from 1 to 74 are assigned to the base skeleton file, Rei and Akari both use the exact same skeleton file (p2_base0001_00_default).
BoneRigArray[1] = "foot_base"
BoneRigArray[2] = "waist"
BoneRigArray[3] = "spine_01"
BoneRigArray[4] = "spine_02"
BoneRigArray[5] = "spine_03"
BoneRigArray[6] = "neck"
BoneRigArray[7] = "look"
BoneRigArray[8] = "head"
BoneRigArray[9] = "left_shoulder"
BoneRigArray[10] = "left_arm_width"
BoneRigArray[11] = "left_arm_01"
BoneRigArray[12] = "left_arm_02"
BoneRigArray[13] = "left_hand"
BoneRigArray[14] = "left_thumb_01"
BoneRigArray[15] = "left_thumb_02"
BoneRigArray[16] = "left_thumb_03"
BoneRigArray[17] = "left_index_01"
BoneRigArray[18] = "left_index_02"
BoneRigArray[19] = "left_index_03"
BoneRigArray[20] = "left_middle_01"
BoneRigArray[21] = "left_middle_02"
BoneRigArray[22] = "left_middle_03"
BoneRigArray[23] = "left_ring_01"
BoneRigArray[24] = "left_ring_02"
BoneRigArray[25] = "left_ring_03"
BoneRigArray[26] = "left_pinky_01"
BoneRigArray[27] = "left_pinky_02"
BoneRigArray[28] = "left_pinky_03"
BoneRigArray[29] = "left_attach_off"
BoneRigArray[30] = "left_attach_on"
BoneRigArray[31] = "left_hand_roll"
BoneRigArray[32] = "left_arm_02_sub"
BoneRigArray[33] = "left_arm_02_roll"
BoneRigArray[34] = "left_arm_01_roll"
BoneRigArray[35] = "right_shoulder"
BoneRigArray[36] = "right_arm_width"
BoneRigArray[37] = "right_arm_01"
BoneRigArray[38] = "right_arm_02"
BoneRigArray[39] = "right_hand"
BoneRigArray[40] = "right_thumb_01"
BoneRigArray[41] = "right_thumb_02"
BoneRigArray[42] = "right_thumb_03"
BoneRigArray[43] = "right_index_01"
BoneRigArray[44] = "right_index_02"
BoneRigArray[45] = "right_index_03"
BoneRigArray[46] = "right_middle_01"
BoneRigArray[47] = "right_middle_02"
BoneRigArray[48] = "right_middle_03"
BoneRigArray[49] = "right_ring_01"
BoneRigArray[50] = "right_ring_02"
BoneRigArray[51] = "right_ring_03"
BoneRigArray[52] = "right_pinky_01"
BoneRigArray[53] = "right_pinky_02"
BoneRigArray[54] = "right_pinky_03"
BoneRigArray[55] = "right_attach_off"
BoneRigArray[56] = "right_attach_on"
BoneRigArray[57] = "right_hand_roll"
BoneRigArray[58] = "right_arm_02_sub"
BoneRigArray[59] = "right_arm_02_roll"
BoneRigArray[60] = "right_arm_01_roll"
BoneRigArray[61] = "bag"
BoneRigArray[62] = "bag_a"
BoneRigArray[63] = "hips"
BoneRigArray[64] = "leg_width"
BoneRigArray[65] = "left_leg_01"
BoneRigArray[66] = "left_leg_02"
BoneRigArray[67] = "left_foot"
BoneRigArray[68] = "left_toe"
BoneRigArray[69] = "left_leg_02_sub"
BoneRigArray[70] = "right_leg_01"
BoneRigArray[71] = "right_leg_02"
BoneRigArray[72] = "right_foot"
BoneRigArray[73] = "right_toe"
BoneRigArray[74] = "right_leg_02_sub"
-- IDs from 75 to 125 are assigned to the face skeleton file (p1_face0001_00_default). Rei has a few less face bones compared to Akari, and requires placeholders because of which.
BoneRigArray[75] = "lower_head"
BoneRigArray[76] = "upper_jaw"
BoneRigArray[77] = "upper_lip"
BoneRigArray[78] = "left_upper_lip_a"
BoneRigArray[79] = "right_upper_lip_a"
BoneRigArray[80] = "upper_teeth"
BoneRigArray[81] = "lower_jaw"
BoneRigArray[82] = "lower_lip"
BoneRigArray[83] = "left_lower_lip_a"
BoneRigArray[84] = "right_lower_lip_a"
BoneRigArray[85] = "lower_teeth"
BoneRigArray[86] = "tongue"
BoneRigArray[87] = "left_side_lip"
BoneRigArray[88] = "right_side_lip"
BoneRigArray[89] = "upper_head"
BoneRigArray[90] = "left_root_eyeball"
BoneRigArray[91] = "left_eyeball"
BoneRigArray[92] = "left_eyehilight"
BoneRigArray[93] = "left_upper_eyelid_a"
BoneRigArray[94] = "left_upper_eyelid_b"
BoneRigArray[95] = "left_upper_eyelid_c"
BoneRigArray[96] = "left_lower_eyelid_a"
BoneRigArray[97] = "left_lower_eyelid_b"
BoneRigArray[98] = "left_lower_eyelid_c"
BoneRigArray[99] = "left_side_eyelid_a"
BoneRigArray[100] = "left_side_eyelid_b"
BoneRigArray[101] = "right_root_eyeball"
BoneRigArray[102] = "right_eyeball"
BoneRigArray[103] = "right_eyehilight"
BoneRigArray[104] = "right_upper_eyelid_a"
BoneRigArray[105] = "right_upper_eyelid_b"
BoneRigArray[106] = "right_upper_eyelid_c"
BoneRigArray[107] = "right_lower_eyelid_a"
BoneRigArray[108] = "right_lower_eyelid_b"
BoneRigArray[109] = "right_lower_eyelid_c"
BoneRigArray[110] = "right_side_eyelid_a"
BoneRigArray[111] = "right_side_eyelid_b"
BoneRigArray[112] = "left_eyebrow_a"
BoneRigArray[113] = "left_eyebrow_b"
BoneRigArray[114] = "left_eyebrow_c"
BoneRigArray[115] = "left_eyebrow_d"
BoneRigArray[116] = "right_eyebrow_a"
BoneRigArray[117] = "right_eyebrow_b"
BoneRigArray[118] = "right_eyebrow_c"
BoneRigArray[119] = "right_eyebrow_d"
BoneRigArray[120] = ""
BoneRigArray[121] = ""
BoneRigArray[122] = ""
BoneRigArray[123] = ""
BoneRigArray[124] = ""
BoneRigArray[125] = ""
-- IDs from 126 to 147 are assigned to the hair skeleton file, and are different on a model-by-model basis.
-- The names for these are irrelevant as outfits never use 'em, but they need to be filled in to prevent errors.
BoneRigArray[126] = ""
BoneRigArray[127] = ""
BoneRigArray[128] = ""
BoneRigArray[129] = ""
BoneRigArray[130] = ""
BoneRigArray[131] = ""
BoneRigArray[132] = ""
BoneRigArray[133] = ""
BoneRigArray[134] = ""
BoneRigArray[135] = ""
BoneRigArray[136] = ""
BoneRigArray[137] = ""
BoneRigArray[138] = ""
BoneRigArray[139] = ""
BoneRigArray[140] = ""
BoneRigArray[141] = ""
BoneRigArray[142] = ""
BoneRigArray[143] = ""
BoneRigArray[144] = ""
BoneRigArray[145] = ""
BoneRigArray[146] = ""
BoneRigArray[147] = ""
-- IDs from 148 and so on are assigned to the outfit skeleton file(s), and are also different depending on the respective model.
-- We don't need placeholders for these, as they're filled in as necessary by the outfits themselves.
)
"Akari":(
-- IDs from 1 to 74 are assigned to the base skeleton file, Rei and Akari both use the exact same skeleton file (p2_base0001_00_default).
BoneRigArray[1] = "foot_base"
BoneRigArray[2] = "waist"
BoneRigArray[3] = "spine_01"
BoneRigArray[4] = "spine_02"
BoneRigArray[5] = "spine_03"
BoneRigArray[6] = "neck"
BoneRigArray[7] = "look"
BoneRigArray[8] = "head"
BoneRigArray[9] = "left_shoulder"
BoneRigArray[10] = "left_arm_width"
BoneRigArray[11] = "left_arm_01"
BoneRigArray[12] = "left_arm_02"
BoneRigArray[13] = "left_hand"
BoneRigArray[14] = "left_thumb_01"
BoneRigArray[15] = "left_thumb_02"
BoneRigArray[16] = "left_thumb_03"
BoneRigArray[17] = "left_index_01"
BoneRigArray[18] = "left_index_02"
BoneRigArray[19] = "left_index_03"
BoneRigArray[20] = "left_middle_01"
BoneRigArray[21] = "left_middle_02"
BoneRigArray[22] = "left_middle_03"
BoneRigArray[23] = "left_ring_01"
BoneRigArray[24] = "left_ring_02"
BoneRigArray[25] = "left_ring_03"
BoneRigArray[26] = "left_pinky_01"
BoneRigArray[27] = "left_pinky_02"
BoneRigArray[28] = "left_pinky_03"
BoneRigArray[29] = "left_attach_off"
BoneRigArray[30] = "left_attach_on"
BoneRigArray[31] = "left_hand_roll"
BoneRigArray[32] = "left_arm_02_sub"
BoneRigArray[33] = "left_arm_02_roll"
BoneRigArray[34] = "left_arm_01_roll"
BoneRigArray[35] = "right_shoulder"
BoneRigArray[36] = "right_arm_width"
BoneRigArray[37] = "right_arm_01"
BoneRigArray[38] = "right_arm_02"
BoneRigArray[39] = "right_hand"
BoneRigArray[40] = "right_thumb_01"
BoneRigArray[41] = "right_thumb_02"
BoneRigArray[42] = "right_thumb_03"
BoneRigArray[43] = "right_index_01"
BoneRigArray[44] = "right_index_02"
BoneRigArray[45] = "right_index_03"
BoneRigArray[46] = "right_middle_01"
BoneRigArray[47] = "right_middle_02"
BoneRigArray[48] = "right_middle_03"
BoneRigArray[49] = "right_ring_01"
BoneRigArray[50] = "right_ring_02"
BoneRigArray[51] = "right_ring_03"
BoneRigArray[52] = "right_pinky_01"
BoneRigArray[53] = "right_pinky_02"
BoneRigArray[54] = "right_pinky_03"
BoneRigArray[55] = "right_attach_off"
BoneRigArray[56] = "right_attach_on"
BoneRigArray[57] = "right_hand_roll"
BoneRigArray[58] = "right_arm_02_sub"
BoneRigArray[59] = "right_arm_02_roll"
BoneRigArray[60] = "right_arm_01_roll"
BoneRigArray[61] = "bag"
BoneRigArray[62] = "bag_a"
BoneRigArray[63] = "hips"
BoneRigArray[64] = "leg_width"
BoneRigArray[65] = "left_leg_01"
BoneRigArray[66] = "left_leg_02"
BoneRigArray[67] = "left_foot"
BoneRigArray[68] = "left_toe"
BoneRigArray[69] = "left_leg_02_sub"
BoneRigArray[70] = "right_leg_01"
BoneRigArray[71] = "right_leg_02"
BoneRigArray[72] = "right_foot"
BoneRigArray[73] = "right_toe"
BoneRigArray[74] = "right_leg_02_sub"
-- IDs from 75 to 125 are assigned to the face skeleton file (p2_face0001_00_default). Akari has a few extra face bones compared to Rei, for her eyelashes.
BoneRigArray[75] = "lower_head"
BoneRigArray[76] = "upper_jaw"
BoneRigArray[77] = "upper_lip"
BoneRigArray[78] = "left_upper_lip_a"
BoneRigArray[79] = "right_upper_lip_a"
BoneRigArray[80] = "upper_teeth"
BoneRigArray[81] = "lower_jaw"
BoneRigArray[82] = "lower_lip"
BoneRigArray[83] = "left_lower_lip_a"
BoneRigArray[84] = "right_lower_lip_a"
BoneRigArray[85] = "lower_teeth"
BoneRigArray[86] = "tongue"
BoneRigArray[87] = "left_side_lip"
BoneRigArray[88] = "right_side_lip"
BoneRigArray[89] = "upper_head"
BoneRigArray[90] = "left_root_eyeball"
BoneRigArray[91] = "left_eyeball"
BoneRigArray[92] = "left_eyehilight"
BoneRigArray[93] = "left_upper_eyelid_a"
BoneRigArray[94] = "left_eyelash_a"
BoneRigArray[95] = "left_eyelash_b"
BoneRigArray[96] = "left_upper_eyelid_b"
BoneRigArray[97] = "left_eyelash_c"
BoneRigArray[98] = "left_upper_eyelid_c"
BoneRigArray[99] = "left_lower_eyelid_a"
BoneRigArray[100] = "left_lower_eyelid_b"
BoneRigArray[101] = "left_lower_eyelid_c"
BoneRigArray[102] = "left_side_eyelid_a"
BoneRigArray[103] = "left_side_eyelid_b"
BoneRigArray[104] = "right_root_eyeball"
BoneRigArray[105] = "right_eyeball"
BoneRigArray[106] = "right_eyehilight"
BoneRigArray[107] = "right_upper_eyelid_a"
BoneRigArray[108] = "right_eyelash_a"
BoneRigArray[109] = "right_eyelash_b"
BoneRigArray[110] = "right_upper_eyelid_b"
BoneRigArray[111] = "right_eyelash_c"
BoneRigArray[112] = "right_upper_eyelid_c"
BoneRigArray[113] = "right_lower_eyelid_a"
BoneRigArray[114] = "right_lower_eyelid_b"
BoneRigArray[115] = "right_lower_eyelid_c"
BoneRigArray[116] = "right_side_eyelid_a"
BoneRigArray[117] = "right_side_eyelid_b"
BoneRigArray[118] = "left_eyebrow_a"
BoneRigArray[119] = "left_eyebrow_b"
BoneRigArray[120] = "left_eyebrow_c"
BoneRigArray[121] = "left_eyebrow_d"
BoneRigArray[122] = "right_eyebrow_a"
BoneRigArray[123] = "right_eyebrow_b"
BoneRigArray[124] = "right_eyebrow_c"
BoneRigArray[125] = "right_eyebrow_d"
-- IDs from 126 to 147 are assigned to the hair skeleton file, and are different on a model-by-model basis.
-- The names for these are irrelevant as outfits never use 'em, but they need to be filled in to prevent errors.
BoneRigArray[126] = ""
BoneRigArray[127] = ""
BoneRigArray[128] = ""
BoneRigArray[129] = ""
BoneRigArray[130] = ""
BoneRigArray[131] = ""
BoneRigArray[132] = ""
BoneRigArray[133] = ""
BoneRigArray[134] = ""
BoneRigArray[135] = ""
BoneRigArray[136] = ""
BoneRigArray[137] = ""
BoneRigArray[138] = ""
BoneRigArray[139] = ""
BoneRigArray[140] = ""
BoneRigArray[141] = ""
BoneRigArray[142] = ""
BoneRigArray[143] = ""
BoneRigArray[144] = ""
BoneRigArray[145] = ""
BoneRigArray[146] = ""
BoneRigArray[147] = ""
-- IDs from 148 and so on are assigned to the outfit skeleton file(s), and are also different depending on the respective model.
-- We don't need placeholders for these, as they're filled in as necessary by the outfits themselves.
)
)
)
on btnImportGFBMDL pressed do (
fname = getOpenFileName \
caption:"Nintendo Switch Pokémon Model File" \
types:"Nintendo Switch Pokémon LGPE / SwSh Model File (*.gfbmdl)|*.gfbmdl" \
historyCategory:"GFBMDLPresets"
if fname != undefined do (
f = fopen fname "rb"
p = getFilenamePath fname
g = getFilenameFile fname
clearlistener()
st = timestamp()
struct Bone_Info_Struct (Bone1, Bone2, Bone3, Bone4)
struct Weight_Info_Struct (Weight1, Weight2, Weight3, Weight4)
struct weight_data (boneids, weights)
struct MatData_Struct (MatName, MatCol0, MatUVScaleU, MatUVScaleV, MatUVTrsU, MatUVTrsV, MatUVRot, MatUVScale2U, MatUVScale2V, MatUVTrs2U, MatUVTrs2V, MatUVRot2)
local VertColors = tglVertColors.state
BoneArray = #()
BoneRigArray = #()
BoneName_array = #()
VisGroupBone_array = #()
MatStringArray = #()
TexStringArray = #()
MatData_array = #()
fseek f 0x04 #seek_set
SwShCheck = readshort f #unsigned
if SwShCheck == 0x00 then (fseek f 0x28 #seek_set)
else (fseek f 0x2C #seek_set)
TexNameDataOffset = (ftell f) + readlong f
MatNameDataOffset = (ftell f) + readlong f
Unk2DataOffset = (ftell f) + readlong f
Unk1DataOffset = (ftell f) + readlong f
ShaderDataOffset = (ftell f) + readlong f
VisGroupDataOffset = (ftell f) + readlong f
VertDataOffset = (ftell f) + readlong f
BoneDataOffset = (ftell f) + readlong f
printDebug ("Unknown1 (materials) offset: " + Unk1DataOffset as string)
printDebug ("Unknown2 (blank?) offset: " + Unk2DataOffset as string)
fseek f MatNameDataOffset #seek_set
MatNameCount = readlong f
for m = 1 to MatNameCount do (
MatNameOffset = (ftell f) + readlong f
MatRet = (ftell f)
fseek f MatNameOffset #seek_set
MatNameLength = readlong f
MatName = readstring f
append MatStringArray MatName
fseek f MatRet #seek_set
)
printDebug ("--------------------")
printDebug ("Material names:")
printDebug (MatStringArray)
printDebug ("--------------------")
fseek f TexNameDataOffset #seek_set
TexNameCount = readlong f
for t = 1 to TexNameCount do (
TexNameOffset = (ftell f) + readlong f
TexRet = (ftell f)
fseek f TexNameOffset #seek_set
TexNameLength = readlong f
TexName = readstring f
append TexStringArray TexName
fseek f TexRet #seek_set
)
printDebug ("Texture names:")
printDebug (TexStringArray)
printDebug ("--------------------")
fseek f BoneDataOffset #seek_set
BoneCount = readlong f
for b = 1 to BoneCount do (
BoneOffset = (ftell f) + readlong f
BoneRet = (ftell f)
fseek f BoneOffset #seek_set
printDebug ("Bone " + b as string + " start: " + BoneOffset as string)
BoneInfoOffset = (ftell f) - readlong f
fseek f BoneInfoOffset #seek_set
BoneInfoLength = readshort f #unsigned
BoneStringStart = readshort f #unsigned
BoneUnk2Start = readshort f #unsigned
BoneUnk1Start = readshort f #unsigned
BoneParentStart = readshort f #unsigned
BoneBlank3Start = readshort f #unsigned
BoneByteStart = readshort f #unsigned
BoneSclStart = readshort f #unsigned
BoneRotStart = readshort f #unsigned
BoneTrsStart = readshort f #unsigned
BoneRigFlag2 = readshort f #unsigned -- 16 = "rigged", 20 = "unrigged"
BoneRigFlag1 = readshort f #unsigned -- 4 = "rigged", 8 = "unrigged"
fseek f (BoneOffset + BoneTrsStart) #seek_set
BoneTX = readfloat f; BoneTY = readfloat f; BoneTZ = readfloat f
fseek f (BoneOffset + BoneRotStart) #seek_set
BoneRX = readfloat f; BoneRY = readfloat f; BoneRZ = readfloat f
fseek f (BoneOffset + BoneSclStart) #seek_set
BoneSX = readfloat f; BoneSY = readfloat f; BoneSZ = readfloat f
if BoneParentStart != 0x00 then (
fseek f (BoneOffset + BoneParentStart) #seek_set
BoneParent = readlong f + 1
) else (
BoneParent = 1
)
fseek f (BoneOffset + BoneStringStart) #seek_set
BoneStrLen = readlong f
BoneName = readstring f
if BoneRigFlag1 == 4 do (append BoneRigArray BoneName)
append BoneName_array BoneName
tfm = scaleMatrix [BoneSX,BoneSY,BoneSZ]
tfm = tfm * (rotateXMatrix (radToDeg BoneRX)) * (rotateYMatrix (radToDeg BoneRY)) * (rotateZMatrix (radToDeg BoneRZ))
tfm.row4 = [BoneTX, BoneTY, BoneTZ]
if (getNodeByName BoneName) != undefined do (
append BoneArray (getNodeByName BoneName)
)
if (getNodeByName BoneName) == undefined do (
if (BoneParent != 0) do (
tfm = tfm * BoneArray[(BoneParent)].objecttransform
)
)
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
newBone.name = BoneName
newBone.width = 0.01
newBone.height = 0.01
newBone.transform = tfm
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.setBoneEnable false 0
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
if (BoneParent != 0) then
newBone.parent = BoneArray[(BoneParent)]
append BoneArray newBone
fseek f BoneRet #seek_set
)
fseek f VisGroupDataOffset #seek_set
VisGroupCount = readlong f
for v = 1 to VisGroupCount do (
VisGroupOffset = (ftell f) + readlong f
VisGroupRet = (ftell f)
fseek f VisGroupOffset #seek_set
printDebug ("VisGroup " + v as string + " start: " + (ftell f) as string)
VisPtr = (ftell f) - readlong f
fseek f VisPtr #seek_set
VisGroupHeadLen = readshort f #unsigned
case VisGroupHeadLen of (
default:(throw ("Unknown header length!"))
0x000A:(
VisGroupUnk1Ptr = readshort f #unsigned
VisGroupVisBonePtr = readshort f #unsigned
VisGroupUnk2Ptr = readshort f #unsigned
VisGroupBoundPtr = readshort f #unsigned
VisGroupUnk3Ptr = 0
)
0x000C:(
VisGroupUnk1Ptr = readshort f #unsigned
VisGroupVisBonePtr = readshort f #unsigned
VisGroupUnk2Ptr = readshort f #unsigned
VisGroupBoundPtr = readshort f #unsigned
VisGroupUnk3Ptr = readshort f #unsigned
)
)
fseek f (VisGroupOffset + VisGroupBoundPtr) #seek_set
VisBoundMinX = readfloat f
VisBoundMinY = readfloat f
VisBoundMinZ = readfloat f
VisBoundMaxX = readfloat f
VisBoundMaxY = readfloat f
VisBoundMaxZ = readfloat f
fseek f (VisGroupOffset + VisGroupVisBonePtr) #seek_set
VisBoneName = readlong f + 1
fseek f (VisGroupOffset + VisGroupUnk2Ptr) #seek_set
VisBoneUnk = readlong f + 1
append VisGroupBone_array BoneName_array[VisBoneName]
printDebug ("VisGroup " + v as string + " end: " + (ftell f) as string)
fseek f VisGroupRet #seek_set
)
fseek f ShaderDataOffset #seek_set
MatShadCount = readlong f
for x = 1 to MatShadCount do (
MatCol0 = "null"; MatUVScaleU = 1.0; MatUVScaleV = 1.0; MatUVTrsU = 0; MatUVTrsV = 0; MatUVRot = 0; MatUVScale2U = 1.0; MatUVScale2V = 1.0; MatUVTrs2U = 0; MatUVTrs2V = 0; MatUVRot2 = 0
MatShadOffset = (ftell f) + readlong f
MatRet = (ftell f)
fseek f MatShadOffset #seek_set
MatShadPropOff = (ftell f) - readlong f
fseek f MatShadPropOff #seek_set
MatShadPropHeadLen = readshort f #unsigned
MatShadPropProp = readshort f #unsigned
MatShadPropMatString = readshort f #unsigned
MatShadPropShadString = readshort f #unsigned
MatShadPropUnk1 = readshort f #unsigned -- always 0?
MatShadPropUnk2 = readshort f #unsigned
MatShadPropUnk3 = readshort f #unsigned
MatShadPropParam1 = readshort f #unsigned
MatShadPropParam2 = readshort f #unsigned
MatShadPropParam3 = readshort f #unsigned
MatShadPropParam4 = readshort f #unsigned
MatShadPropParam5 = readshort f #unsigned
MatShadPropParam6 = readshort f #unsigned
MatShadPropTexList = readshort f #unsigned
MatShadPropParamA = readshort f #unsigned
MatShadPropParamB = readshort f #unsigned
MatShadPropParamC = readshort f #unsigned
MatShadPropUnk4 = readshort f #unsigned
MatShadPropUnk5 = readshort f #unsigned
MatShadPropUnk6 = readshort f #unsigned -- always 0?
MatShadPropUnk7 = readshort f #unsigned
MatShadPropUnk8 = readshort f #unsigned -- always 0?
MatShadPropPointer = readshort f #unsigned
fseek f (MatShadOffset + MatShadPropMatString) #seek_set
MatShadStringPtr = (ftell f) + readlong f
fseek f MatShadStringPtr #seek_set
MatShadMatStringLen = readlong f
MatShadMatString = readstring f
print ("Textures used for " + MatShadMatString as string + ":")
fseek f (MatShadOffset + MatShadPropTexList) #seek_set
MatTexPtr = (ftell f) + readlong f
fseek f MatTexPtr #seek_set
MatTexCount = readlong f
for y = 1 to MatTexCount do (
MatTexOffset = (ftell f) + readlong f
MatTexRet = (ftell f)
fseek f MatTexOffset #seek_set
MatTexLytPtr = (ftell f) - readlong f
fseek f MatTexLytPtr #seek_set
MatTexLytHeadLen = readshort f #unsigned
case MatTexLytHeadLen of (
default: (throw ("Unknown header length!"))
0x0A:(
MatTexLytStrPtr = readshort f #unsigned
MatTexLytHdrPtr = readshort f #unsigned
MatTexLytIDPtr = readshort f #unsigned
MatTexLytUnkPtr = readshort f #unsigned
)
)
fseek f (MatTexOffset + MatTexLytStrPtr) #seek_set
MatTexStrLen = readlong f
MatTexString = readstring f
if MatTexLytIDPtr != 0 then (
fseek f (MatTexOffset + MatTexLytIDPtr) #seek_set
MatTexID = TexStringArray[readlong f + 1]
) else (MatTexID = TexStringArray[1])
print (MatTexString as string + ": " + MatTexID as string)
fseek f MatTexRet #seek_set
if MatTexString == "Col0Tex" or MatTexString == "L0ColTex" or MatTexString == "Texture01" or MatTexString == "TextureMap01" do (MatCol0 = MatTexID)
)
printMat("--------------------")
printMat ("Material properties for " + MatShadMatString as string + ":")
fseek f (MatShadOffset + MatShadPropParamA) #seek_set
MatPropAPtr = (ftell f) + readlong f
fseek f MatPropAPtr #seek_set
MatPropACount = readlong f
for y = 1 to MatPropACount do (
MatPropAStart = (ftell f) + readlong f
MatPropRet = (ftell f)
fseek f MatPropAStart #seek_set
MatPropAPropPtr = (ftell f) - readlong f
fseek f MatPropAPropPtr #seek_set
MatPropAHeadLen = readshort f #unsigned
case MatPropAHeadLen of (
default:(throw ("Unknown header length!"))
0x06:(
MatPropAStringPtr = readshort f #unsigned
MatPropAFmtPtr = readshort f #unsigned
MatPropAVarPtr = 0
)
0x08:(
MatPropAStringPtr = readshort f #unsigned
MatPropAFmtPtr = readshort f #unsigned
MatPropAVarPtr = readshort f #unsigned
)
)
fseek f (MatPropAStart + MatPropAStringPtr) #seek_set
MatPropAStrLen = readlong f
MatPropAString = readstring f
fseek f (MatPropAStart + MatPropAFmtPtr) #seek_set
MatPropAFmt = readlong f
if MatPropAVarPtr != 0 then (
fseek f (MatPropAStart + MatPropAVarPtr) #seek_set
case MatPropAFmt of (
default:(throw ("Unknown format!"))
4:(MatPropAVar = readbyte f #unsigned; if MatPropAVar == 1 do (MatPropAVar = "True"))
)
) else (MatPropAVar = "False")
printMat (MatPropAString as string + ": " + MatPropAVar as string)
fseek f MatPropRet #seek_set
)
fseek f (MatShadOffset + MatShadPropParamB) #seek_set
MatPropBPtr = (ftell f) + readlong f
fseek f MatPropBPtr #seek_set
MatPropBCount = readlong f
for y = 1 to MatPropBCount do (
MatPropBStart = (ftell f) + readlong f
MatPropRet = (ftell f)
fseek f MatPropBStart #seek_set
MatPropBPropPtr = (ftell f) - readlong f
fseek f MatPropBPropPtr #seek_set
MatPropBHeadLen = readshort f #unsigned
case MatPropBHeadLen of (
default:(throw ("Unknown header length!"))
0x06:(
MatPropBStringPtr = readshort f #unsigned
MatPropBFmtPtr = readshort f #unsigned
MatPropBVarPtr = 0
)
0x08:(
MatPropBStringPtr = readshort f #unsigned
MatPropBFmtPtr = readshort f #unsigned
MatPropBVarPtr = readshort f #unsigned
)
)
fseek f (MatPropBStart + MatPropBStringPtr) #seek_set
MatPropBStrLen = readlong f
MatPropBString = readstring f
if MatPropBFmtPtr != 0 do (
fseek f (MatPropBStart + MatPropBFmtPtr) #seek_set
MatPropBFmt = readlong f
)
fseek f (MatPropBStart + MatPropBVarPtr) #seek_set
if MatPropBVarPtr != 0 then (
case MatPropBFmt of (
default:(throw ("Unknown format!"))
4:(MatPropBVar = readlong f)
8:(MatPropBVar = readfloat f)
)
) else (MatPropBVar = 0)