-
Notifications
You must be signed in to change notification settings - Fork 1
/
BFRES Script_R4.ms
3119 lines (2932 loc) · 96 KB
/
BFRES Script_R4.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
-- Importer for Wii U BFRES Files seen in many Nintendo games.
-- Written by ItsEasyActually and Random Talking Bush (with some help from Ploaj).
-- Credit to the tockdom wiki community for the format documention
-- Special thanks to TGE for help early on with new scripting methods and getting ItsEasyActually started
-- Updated April 2nd, 2017:
-- Fixed UV mapping for models with type 519 (Riju's model in BotW, for example).
-- Fixed importing for Wind Waker HD models, which wasn't set up properly in the script in the first place. Whoops!
-- Fixed rigging being utterly broken in 3DS Max 2012 and above (thanks to sunnydavis for part of the code used). Gee, *thanks*, Autodesk...
-- Also fixed rigging for models with more than 4 bone influences (Zelda's model in BotW, for example).
-- Added support for reading normals, thanks to Ploaj for helping with the 10-bit nonsense!
-- Added type 522 for colours (signed bytes, e.g. Fire Peach's dress model in SM3DW).
fn readBEshort fstream = (bit.swapBytes (readshort fstream #unsigned) 1 2)
fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
fn readBEfloat fstream = (bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))
fn ReadBEHalfFloat Fstream = (
local BH = readByte Fstream #unsigned
local BL = 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 sign10 x = (
if (bit.shift x -9) == 1 do(
x = bit.not x
x = bit.and x 0x3FF
x += 1
x *= -1
)
return x
) --Thanks, Ploaj!
fn ReadFixedString fstream fixedLen = (
local str = ""
for i = 1 to fixedLen do
(
str += bit.intAsChar (ReadByte fstream #unsigned)
)
str
)
fn ReadOffset fstream = ((ftell fstream) + (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))
fn ReadBuffer fstream = (
long0 = ReadByte fstream
long1 = ReadByte fstream
long2 = ReadByte fstream
long = (0 + long0 + long1 + long2)
long = bit.swapBytes long 1 4
long = bit.swapBytes long 2 3
return long
)
FMDLOffset_array = #()
f = #()
p = #()
rollout BFRESImporter "Wii U BFRES model importer" width:390 height:195
(
label lblDisclaimer "This script was written by ItsEasyActually and Random Talking Bush. If you use it, consider giving us both thanks for this. If something doesn't work right, please contact RTB on The VG Resource (Random Talking Bush), Twitter, Tumblr or Steam (RandomTBush) so that any problems can be fixed." pos:[8,8] width:375 height:55
button btnLoad "Load BFRES" pos:[8,65] width:90 height:20
button btnImport "Import BFMDL" pos:[108,65] width:90 height:20
dropdownlist lstFMDL pos:[208,65] width:175 height:20 items:#() selection:0
label lblOptions "Options:" pos:[8,90] width:375 height:15
label lblTexFormat "Texture format:" pos:[8,105] width:375 height:15
radiobuttons tglTexFormat labels:#("DDS","PNG") pos:[90,105]
label lblLODs "Import LODs:" pos:[8,120] width:375 height:15
radiobuttons tglLODs labels:#("No","Yes") pos:[90,120]
label lblUVLayers "UV layering:" pos:[8,135] width:375 height:15
radiobuttons tglUVLayers labels:#("Split","Merge","No") pos:[90,135]
label lblRigModel "Import rigging:" pos:[8,150] width:375 height:15
radiobuttons tglRigModel labels:#("Yes","No") pos:[90,150]
label lblUpdate "(Updated 03/11/2017) " pos:[8,175] width:375 height:15
on btnLoad pressed do(
clearlistener()
fname = GetOpenFileName caption:"Open BFRES" types:"BFRES File(*.bfres)|*.bfres"
st = timestamp() --get start time in milliseconds
if fname != undefined do(
FMDLName_array = #()
FMDLOffset_array = #()
p = getFilenamePath fname
f = fopen fname "rb" --open file in read only format
struct fmdlh(
fmdl, -- Magic
fnameOff, -- Filename Offset
eofString, -- End of File String Offset
fsklOff, -- FSKL Offset
fvtxArrOff, -- FVTX Array Offset
fshpIndx, -- FSHP Index Offset
fmatIndx, -- FMAT Index Offset
paramOff, -- Parameter Offset
fvtxCount, -- FVTX Count (int16)
fshpCount, -- FSHP Count (int16)
fmatCount, -- FMAT Count (int16
paramCount -- Parameter Count (int16)
)
fseek f 5#seek_set
verNum = ReadByte f
print ("FMDL Version: " + verNum as string)
fseek f 26#seek_cur
FileOffset = ReadOffset f
fseek f FileOffset#seek_set
BlockSize = ReadBELong f
FMDLTotal = ReadBELong f
fseek f 0x10#seek_cur
For mdl = 1 to FMDLTotal Do (
fseek f 12#seek_cur
FMDLOffset = ReadOffset f
append FMDLOffset_array FMDLOffset
NextFMDL = ftell f
fseek f FMDLOffset#seek_set
-- F_Model Header --
fmdl_info=(fmdlh \
fmdl: (ReadFixedString f 4) \
fnameOff: (ReadOffset f) \
eofString: (ReadOffset f) \
fsklOff: (ReadOffset f) \
fvtxArrOff: (ReadOffset f) \
fshpIndx: (ReadOffset f) \
fmatIndx: (ReadOffset f) \
paramOff: (ReadOffset f) \
fvtxCount: (ReadBEShort f) \
fshpCount: (ReadBEShort f) \
fmatCount: (ReadBEShort f) \
paramCount: (ReadBEShort f) \
)
fseek f fmdl_info.fnameOff#seek_set
FMDLName = ReadString f
append FMDLName_array FMDLName
fseek f NextFMDL#seek_set
)
lstFMDL.items = FMDLName_array
lstFMDL.selection = 1
)
)
on btnImport pressed do(
if lstFMDL.selection != 0 do(
clearlistener()
st = timestamp() --get start time in milliseconds
struct fmdlh(
fmdl, -- Magic
fnameOff, -- Filename Offset
eofString, -- End of File String Offset
fsklOff, -- FSKL Offset
fvtxArrOff, -- FVTX Array Offset
fshpIndx, -- FSHP Index Offset
fmatIndx, -- FMAT Index Offset
paramOff, -- Parameter Offset
fvtxCount, -- FVTX Count (int16)
fshpCount, -- FSHP Count (int16)
fmatCount, -- FMAT Count (int16
paramCount -- Parameter Count (int16)
)
struct fvtxh(
fvtx, -- Magic
attCount, -- Attribute Count (int8)
buffCount, -- Buffer Count (int8)
sectIndx, -- Section Index (int16)
vertCount, -- Vertex Count
u1, -- Unknown (int8 or int16)
u2, -- Unknown (int16 or three bytes)
attArrOff, -- Attribute Array Offset
attIndxOff, -- Attribute Index Offset
buffArrOff, -- Buffer Array Offset
padding -- Padding (int32)
)
struct fmath(
fmat, -- Magic
matOff, -- Material Name Offset
u1, -- Unknown (int32)
sectIndx, -- Section Index (int16)
rendParamCount, -- Render Info Parameter Count (int16)
texSelCount, -- Texture Selector Count (int8)
texAttSelCount, -- Texture Attribute Selector Count (int8)
matParamCount, -- Material Parameter Count (int16)
matParamSize, -- Material Parameter Data Size
u2, -- Unknown (int32)
rendParamIndx, -- Render Info Parameter Index Group Offset
unkMatOff, -- Unknown Material Offset
shadeOff, -- Shader Control Offset
texSelOff, -- Texture Selector Offset
texAttSelOff, -- Texture Attribute Selector Offset
texAttIndxOff, -- Texture Attribute Selector Index Offset
matParamArrOff, -- Material Parameter Array Offset
matParamIndxOff, -- Material Parameter Index Offset
matParamOff, -- Material Parameter Data Offset
shadParamIndxOff -- Shadow Parameter Index Offset
)
struct fsklh(
fskl, -- Magic
u1, -- Unknown (int16)
fsklType, -- Type of Bone Data (uint16)
boneArrCount, -- Bone Array Count (int16)
invIndxArrCount, -- Inverse Index Array Count (int16)
exIndxCount, -- Extra Index Count (int16)
u3, -- Unknown (int16)
boneIndxOff, -- Bone Index Group Offset
boneArrOff, -- Bone Array Offset
invIndxArrOff, -- Inverse Index Array Offset
invMatrArrOff, -- Inverse Matric Array Offset
padding -- Padding (int32)
)
struct fshph(
fshp, -- Magic
polyNameOff, -- Polygon Name Offset
u1, -- Unknown (int32)
fvtxIndx, -- FVTX Index (int16)
fmatIndx, -- FMAT Index (int16)
fsklIndx, -- FSKL Index (int16)
sectIndx, -- Section Index (int16)
fsklIndxArrCount, -- FSKL Index Array Count (int16)
matrFlag, -- Matrix Use Flag (int8)
lodMdlCount, -- LoD Model Count (int8)
visGrpCount, -- Visibility Group Tree Node Count
u3, -- Unknown (float)
fvtxOff, -- FVTX Offset
lodMdlOff, -- LoD Model Offset
fsklIndxArrOff, -- FSKL Index Array Offset
u4, -- Unknown (int32)
visGrpNodeOff, -- Vibility Group Tree Nodes Offset
visGrpRangeOff, -- Visibility Group Tree Ranges Offset
visGrpIndxOff, -- Visibility Group Tree Indices Offset
u5 -- Unknown (int32)
)
struct attdata(
attName, -- Attribute Type
buffIndx, -- Buffer Index (u8)
buffOff, -- Buffer Offset (u16)
vertType -- Format
)
struct buffData(
buffSize, -- Size of Buffer (u32)
strideSize, -- Size of Vertex Stride (u16)
dataOffset -- Offset to Buffer (u32)
)
struct bdata(
bNameOff, -- Bone Name Offset
bIndx, -- Bone Index (int16)
parIndx1, -- Parent Index 1 (int16)
parIndx2, -- Parent Index 2 (int16)
parIndx3, -- Parent Index 3 (int16)
parIndx4, -- Parent Index 4 (int16)
u1, -- Unknown (int16)
bFlags, -- Bone Flags (int16)
u2, -- Unknown (int16)
scaleX, -- Scale X
scaleY, -- Scale Y
scaleZ, -- Scale Z
rotX, -- Rotation X
rotY, -- Rotation Y
rotZ, -- Rotation Z
rotW, -- Rotation W
posX, -- Position X
posY, -- Position Y
posZ, -- Position Z
padding, -- Padding
m11, -- Matrix
m21, -- Matrix
m31, -- Matrix
m41, -- Matrix
m12, -- Matrix
m22, -- Matrix
m32, -- Matrix
m42, -- Matrix
m13, -- Matrix
m23, -- Matrix
m33, -- Matrix
m43 -- Matrix
)
struct lodmdl(
u1, -- Unknown (int32)
faceType, -- Face Data Type (int32)
dCount, -- Visibility Group Draw Count
visGrpCount, -- Visibility Group Count (int16)
u3, -- Unknown (int16)
visGrpOff, -- Visibility Group Offset
indxBuffOff, -- Index Buffer Offset
elmSkip -- Element Skip (int32)
)
struct Bone_Info_Struct
(
bone1,
bone2,
bone3,
bone4,
bone5,
bone6,
bone7,
bone8
)
struct Weight_Info_Struct
(
weight1,
weight2,
weight3,
weight4,
weight5,
weight6,
weight7,
weight8
)
struct weight_data
(
boneids,
weights
)
struct invMatrix
(
invIndx,
invMatr
)
local TexFormat = tglTexFormat.state
local LODs = tglLODs.state
local UVLayers = tglUVLayers.state
local RigModel = tglRigModel.state
fseek f 5#seek_set
verNum = ReadByte f
fseek f FMDLOffset_array[lstFMDL.selection]#seek_set
FMDLArr = #()
FVTXArr = #()
FSKLArr = #()
FMATArr = #()
FMATNameArr = #()
FSHPArr = #()
VTXAttr = #()
BoneArray = #()
BoneFixArray = #()
invIndxArr = #()
invMatrArr = #()
Node_Array = #()
-- F_Model Header --
fmdl_info=(fmdlh \
fmdl: (ReadFixedString f 4) \
fnameOff: (ReadOffset f) \
eofString: (ReadOffset f) \
fsklOff: (ReadOffset f) \
fvtxArrOff: (ReadOffset f) \
fshpIndx: (ReadOffset f) \
fmatIndx: (ReadOffset f) \
paramOff: (ReadOffset f) \
fvtxCount: (ReadBEShort f) \
fshpCount: (ReadBEShort f) \
fmatCount: (ReadBEShort f) \
paramCount: (ReadBEShort f) \
)
append FMDLArr(fmdl_info)
-- F_Vertex Header --
fseek f fmdl_info.fvtxArrOff#seek_set
For vtx = 1 to fmdl_info.fvtxCount Do (
fvtx_info=(fvtxh \
fvtx: (ReadFixedString f 4) \
attCount: (ReadByte f) \
buffCount: (ReadByte f) \
sectIndx: (ReadBEshort f) \
vertCount: (ReadBELong f) \
u1: (ReadBEShort f) \
u2: (ReadBEShort f) \
attArrOff: (ReadOffset f) \
attIndxOff: (ReadOffset f) \
buffArrOff: (ReadOffset f) \
padding: (ReadLong f) \
)
append FVTXArr(fvtx_info)
)
-- F_Material Header --
fseek f fmdl_info.fmatIndx#seek_set
fseek f 24#seek_cur
For mat = 1 to fmdl_info.fmatCount Do (
fseek f 8#seek_cur
FMATNameOffset = ReadOffset f
Rtn = ftell f
fseek f FMATNameOffset#seek_set
FMATName = readstring f
append FMATNameArr FMATName
fseek f Rtn#seek_set
FMATOffset = ReadOffset f
Rtn = ftell f
fseek f FMATOffset#seek_set
fmat_info=(fmath \
fmat: (ReadFixedString f 4) \
matOff: (ReadOffset f) \
u1: (ReadBELong f) \
sectIndx: (ReadBEShort f) \
rendParamCount: (ReadBEshort f) \
texSelCount: (ReadByte f) \
texAttSelCount: (ReadByte f) \
matParamCount: (ReadBEShort f) \
matParamSize: (ReadBELong f) \
u2: (ReadBELong f) \
rendParamIndx: (ReadOffset f) \
unkMatOff: (ReadOffset f) \
shadeOff: (ReadOffset f) \
texSelOff: (ReadOffset f) \
texAttSelOff: (ReadOffset f) \
texAttIndxOff: (ReadOffset f) \
matParamArrOff: (ReadOffset f) \
matParamIndxOff: (ReadOffset f) \
matParamOff: (ReadOffset f) \
shadParamIndxOff: (ReadOffset f) \
)
fseek f Rtn#seek_set
append FMATArr(fmat_info)
)
-- F_Skeleton Header --
fseek f fmdl_info.fsklOff#seek_set
fskl_info=(fsklh \
fskl: (ReadFixedString f 4) \
u1: (ReadBEShort f) \
fsklType: (ReadBEShort f) \
boneArrCount: (ReadBEShort f) \
invIndxArrCount: (ReadBEShort f) \
exIndxCount: (ReadBEShort f) \
u3: (ReadBEShort f) \
boneIndxOff: (ReadOffset f) \
boneArrOff: (ReadOffset f) \
invIndxArrOff: (ReadOffset f) \
invMatrArrOff: (ReadOffset f) \
padding: (ReadLong f) \
)
append FSKLArr(fskl_info)
-- Node Setup --
fseek f fskl_info.invIndxArrOff #seek_set
for nodes = 1 to (fskl_info.invIndxArrCount + fskl_info.exIndxCount) do(
NodeID = readBEshort f + 1
append Node_Array NodeID
)
-- F_Shape Header --
fseek f fmdl_info.fshpIndx#seek_set
fseek f 24#seek_cur
For shp = 1 to fmdl_info.fshpCount Do (
fseek f 12#seek_cur
FSHPOffset = ReadOffset f
Rtn = ftell f
fseek f FSHPOffset#seek_set
fshp_info=(fshph \
fshp: (ReadFixedString f 4) \
polyNameOff: (ReadOffset f) \
u1: (ReadBELong f) \
fvtxIndx: (ReadBEShort f +1) \
fmatIndx: (ReadBEShort f +1) \
fsklIndx: (ReadBEShort f +1) \
sectIndx: (ReadBEShort f +1) \
fsklIndxArrCount: (ReadBEShort f) \
matrFlag: (ReadByte f) \
lodMdlCount: (ReadByte f) \
visGrpCount: (ReadBELong f) \
u3: (ReadBEFloat f) \
fvtxOff: (ReadOffset f) \
lodMdlOff: (ReadOffset f) \
fsklIndxArrOff: (ReadOffset f) \
u4: (ReadBELong f) \
visGrpNodeOff: (ReadOffset f) \
visGrpRangeOff: (ReadOffset f) \
visGrpIndxOff: (ReadOffset f) \
u5: (ReadBElong f) \
)
fseek f Rtn#seek_set
append FSHPArr(fshp_info)
)
-- F_Model Inverse Matrices --
--fseek f fskl_info.invMatrArrOff#seek_set
NxtMatr = 0
fseek f fskl_info.invIndxArrOff#seek_set
For indx = 1 to fskl_info.invIndxArrCount Do (
invIndx = ReadBEShort f +1
NxtIndx = ftell f
fseek f (fskl_info.invMatrArrOff + NxtMatr)#seek_set
m11 = ReadBEFloat f; m21 = ReadBEFloat f; m31 = ReadBEFloat f; m41 = ReadBEFloat f
m12 = ReadBEFloat f; m22 = ReadBEFloat f; m32 = ReadBEFloat f; m42 = ReadBEFloat f
m13 = ReadBEFloat f; m23 = ReadBEFloat f; m33 = ReadBEFloat f; m43 = ReadBEFloat f
invtfm = matrix3 [m11,m21,m31,m41] [m12,m22,m32,m42] [m13,m23,m33,m43] [0,0,0,1]
NxtMatr += 48
append invMatrArr (invMatrix invIndx:invIndx invMatr:invtfm)
fseek f NxtIndx#seek_set
)
-- F_Model Bone Creation --
fseek f fskl_info.boneArrOff#seek_set
case of (
(verNum == 0):(
For bn = 1 to fskl_info.boneArrCount Do (
boneData=( bdata \
bNameOff: (ReadOffset f) \
bIndx: (ReadBEShort f +1) \
parIndx1: (ReadBEShort f +1) \
parIndx2: (ReadBEShort f +1) \
parIndx3: (ReadBEShort f +1) \
parIndx4: (ReadBEShort f +1) \
u1: (ReadBEShort f) \
bFlags: (ReadBEShort f) \
u2: (ReadBEShort f) \
scaleX: (ReadBEFloat f) \
scaleY: (ReadBEFloat f) \
scaleZ: (ReadBEFloat f) \
rotX: (ReadBEFloat f) \
rotY: (ReadBEFloat f) \
rotZ: (ReadBEFloat f) \
rotW: (ReadBEFloat f) \
posX: (ReadBEFloat f) \
posY: (ReadBEFloat f) \
posZ: (ReadBEFloat f) \
padding: (ReadLong f) \
)
if boneData.u2 == 0x0001 then(
tfm = (quat boneData.rotX boneData.rotY boneData.rotZ boneData.rotW) as matrix3
tfm = inverse(tfm)
) else (tfm = (eulerangles (boneData.rotX*(180/pi)) (boneData.rotY*(180/pi)) (boneData.rotZ*(180/pi))) as matrix3)
tfm.row4 = [boneData.posX,boneData.posY,boneData.posZ]
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
Rtn = ftell f
fseek f boneData.bNameOff#seek_set
boneName = ReadString f
fseek f Rtn#seek_set
newBone.name = boneName
newBone.width = 0.03
newBone.height = 0.03
newBone.transform = tfm
newBone.setBoneEnable false 0
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
If boneData.parIndx1 != 65536 Do (
newBone.parent = BoneArray[boneData.parIndx1]
newBone.transform *= BoneArray[boneData.parIndx1].transform
)
append BoneArray newBone
append BoneFixArray newBone.transform
fseek f 48#seek_cur
)
)
(verNum == 2):(
For bn = 1 to fskl_info.boneArrCount Do (
boneData=( bdata \
bNameOff: (ReadOffset f) \
bIndx: (ReadBEShort f +1) \
parIndx1: (ReadBEShort f +1) \
parIndx2: (ReadBEShort f +1) \
parIndx3: (ReadBEShort f +1) \
parIndx4: (ReadBEShort f +1) \
u1: (ReadBEShort f) \
bFlags: (ReadBEShort f) \
u2: (ReadBEShort f) \
scaleX: (ReadBEFloat f) \
scaleY: (ReadBEFloat f) \
scaleZ: (ReadBEFloat f) \
rotX: (ReadBEFloat f) \
rotY: (ReadBEFloat f) \
rotZ: (ReadBEFloat f) \
rotW: (ReadBEFloat f) \
posX: (ReadBEFloat f) \
posY: (ReadBEFloat f) \
posZ: (ReadBEFloat f) \
padding: (ReadLong f) \
)
if boneData.u2 == 0x0001 then(
tfm = (quat boneData.rotX boneData.rotY boneData.rotZ boneData.rotW) as matrix3
tfm = inverse(tfm)
) else (tfm = (eulerangles (boneData.rotX*(180/pi)) (boneData.rotY*(180/pi)) (boneData.rotZ*(180/pi))) as matrix3)
tfm.row4 = [boneData.posX,boneData.posY,boneData.posZ]
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
Rtn = ftell f
fseek f boneData.bNameOff#seek_set
boneName = ReadString f
fseek f Rtn#seek_set
newBone.name = boneName
newBone.width = 0.03
newBone.height = 0.03
newBone.transform = tfm
newBone.setBoneEnable false 0
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
If boneData.parIndx1 != 65536 Do (
newBone.parent = BoneArray[boneData.parIndx1]
newBone.transform *= BoneArray[boneData.parIndx1].transform
)
append BoneArray newBone
append BoneFixArray newBone.transform
fseek f 48#seek_cur
)
)
(verNum == 3):(
For bn = 1 to fskl_info.boneArrCount Do (
boneData=( bdata \
bNameOff: (ReadOffset f) \
bIndx: (ReadBEShort f +1) \
parIndx1: (ReadBEShort f +1) \
parIndx2: (ReadBEShort f +1) \
parIndx3: (ReadBEShort f +1) \
parIndx4: (ReadBEShort f +1) \
u1: (ReadBEShort f) \
bFlags: (ReadBEShort f) \
u2: (ReadBEShort f) \
scaleX: (ReadBEFloat f) \
scaleY: (ReadBEFloat f) \
scaleZ: (ReadBEFloat f) \
rotX: (ReadBEFloat f) \
rotY: (ReadBEFloat f) \
rotZ: (ReadBEFloat f) \
rotW: (ReadBEFloat f) \
posX: (ReadBEFloat f) \
posY: (ReadBEFloat f) \
posZ: (ReadBEFloat f) \
padding: (ReadLong f) \
)
if boneData.u2 == 0x0001 then(
tfm = (quat boneData.rotX boneData.rotY boneData.rotZ boneData.rotW) as matrix3
tfm = inverse(tfm)
) else (tfm = (eulerangles (boneData.rotX*(180/pi)) (boneData.rotY*(180/pi)) (boneData.rotZ*(180/pi))) as matrix3)
tfm.row4 = [boneData.posX,boneData.posY,boneData.posZ]
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
Rtn = ftell f
fseek f boneData.bNameOff#seek_set
boneName = ReadString f
fseek f Rtn#seek_set
newBone.name = boneName
newBone.width = 0.03
newBone.height = 0.03
newBone.transform = tfm
newBone.setBoneEnable false 0
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
If boneData.parIndx1 != 65536 Do (
newBone.parent = BoneArray[boneData.parIndx1]
newBone.transform *= BoneArray[boneData.parIndx1].transform
)
append BoneArray newBone
append BoneFixArray newBone.transform
fseek f 48#seek_cur
)
)
(verNum == 4):(
For bn = 1 to fskl_info.boneArrCount Do (
boneData=( bdata \
bNameOff: (ReadOffset f) \
bIndx: (ReadBEShort f +1) \
parIndx1: (ReadBEShort f +1) \
parIndx2: (ReadBEShort f +1) \
parIndx3: (ReadBEShort f +1) \
parIndx4: (ReadBEShort f +1) \
u1: (ReadBEShort f) \
bFlags: (ReadBEShort f) \
u2: (ReadBEShort f) \
scaleX: (ReadBEFloat f) \
scaleY: (ReadBEFloat f) \
scaleZ: (ReadBEFloat f) \
rotX: (ReadBEFloat f) \
rotY: (ReadBEFloat f) \
rotZ: (ReadBEFloat f) \
rotW: (ReadBEFloat f) \
posX: (ReadBEFloat f) \
posY: (ReadBEFloat f) \
posZ: (ReadBEFloat f) \
padding: (ReadLong f) \
)
if boneData.u2 == 0x0001 then(
tfm = (quat boneData.rotX boneData.rotY boneData.rotZ boneData.rotW) as matrix3
tfm = inverse(tfm)
) else (tfm = (eulerangles (boneData.rotX*(180/pi)) (boneData.rotY*(180/pi)) (boneData.rotZ*(180/pi))) as matrix3)
tfm.row4 = [boneData.posX,boneData.posY,boneData.posZ]
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
Rtn = ftell f
fseek f boneData.bNameOff#seek_set
boneName = ReadString f
fseek f Rtn#seek_set
newBone.name = boneName
newBone.width = 0.03
newBone.height = 0.03
newBone.transform = tfm
newBone.setBoneEnable false 0
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
If boneData.parIndx1 != 65536 Do (
newBone.parent = BoneArray[boneData.parIndx1]
newBone.transform *= BoneArray[boneData.parIndx1].transform
)
append BoneArray newBone
append BoneFixArray newBone.transform
)
)
(verNum == 5):(
For bn = 1 to fskl_info.boneArrCount Do (
boneData=( bdata \
bNameOff: (ReadOffset f) \
bIndx: (ReadBEShort f +1) \
parIndx1: (ReadBEShort f +1) \
parIndx2: (ReadBEShort f +1) \
parIndx3: (ReadBEShort f +1) \
parIndx4: (ReadBEShort f +1) \
u1: (ReadBEShort f) \
bFlags: (ReadBEShort f) \
u2: (ReadBEShort f) \
scaleX: (ReadBEFloat f) \
scaleY: (ReadBEFloat f) \
scaleZ: (ReadBEFloat f) \
rotX: (ReadBEFloat f) \
rotY: (ReadBEFloat f) \
rotZ: (ReadBEFloat f) \
rotW: (ReadBEFloat f) \
posX: (ReadBEFloat f) \
posY: (ReadBEFloat f) \
posZ: (ReadBEFloat f) \
padding: (ReadLong f) \
)
if boneData.u2 == 0x0001 then(
tfm = (quat boneData.rotX boneData.rotY boneData.rotZ boneData.rotW) as matrix3
tfm = inverse(tfm)
) else (tfm = (eulerangles (boneData.rotX*(180/pi)) (boneData.rotY*(180/pi)) (boneData.rotZ*(180/pi))) as matrix3)
tfm.row4 = [boneData.posX,boneData.posY,boneData.posZ]
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
Rtn = ftell f
fseek f boneData.bNameOff#seek_set
boneName = ReadString f
fseek f Rtn#seek_set
newBone.name = boneName
newBone.width = 0.03
newBone.height = 0.03
newBone.transform = tfm
newBone.setBoneEnable false 0
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
If boneData.parIndx1 != 65536 Do (
newBone.parent = BoneArray[boneData.parIndx1]
newBone.transform *= BoneArray[boneData.parIndx1].transform
)
append BoneArray newBone
append BoneFixArray newBone.transform
)
)
)
-- Mesh Building --
For m = 1 to FSHPArr.count Do (
Vert_Array = #()
Normal_Array = #()
UV_Array = #()
UV2_Array = #()
UV3_Array = #()
UV4_Array = #()
UV5_Array = #()
Color_Array = #()
AttrArr = #()
BuffArr = #()
W1_array = #()
B1_array = #()
Weight_array = #()
fseek f FSHPArr[m].polyNameOff#seek_set
MeshName = ReadString f
fseek f FVTXArr[FSHPArr[m].fvtxIndx].attArrOff#seek_set
For att = 1 to FVTXArr[FSHPArr[m].fvtxIndx].attCount Do (
AttTypeOff = ReadOffset f
Rtn1 = ftell f
fseek f AttTypeOff#seek_set
AttType = ReadString f
fseek f Rtn1#seek_set
buffIndx = ReadByte f+1
skip = ReadByte f
buffOff = ReadBEShort f
vertType = ReadBElong f
append AttrArr (attdata attName: AttType buffIndx: buffIndx buffOff: buffOff vertType: vertType)
)
fseek f FVTXArr[FSHPArr[m].fvtxIndx].buffArrOff#seek_set
For buf = 1 to FVTXArr[FSHPArr[m].fvtxIndx].buffCount Do (
unk1 = ReadLong f
BufferSize = ReadBELong f
unk2 = ReadLong f
StrideSize = ReadBEShort f
unk3 = ReadShort f
unk4 = ReadLong f
DataOffset = ReadOffset f
append BuffArr (buffData buffSize: BufferSize strideSize: StrideSize dataOffset: DataOffset)
)
If BuffArr.count > 1 then (
For attr = 1 to AttrArr.count Do (
locPoint = ((BuffArr[AttrArr[attr].buffIndx].dataOffset) + (AttrArr[attr].buffOff))
fseek f locPoint#seek_set
For v = 1 to FVTXArr[FSHPArr[m].fvtxIndx].vertCount Do (
VertStart = ftell f
case of (
--Vertex Info--
(AttrArr[attr].attName == "_p0"):(
case of (
(AttrArr[attr].vertType == 2063):(
vx = ReadBEHalfFloat f
vy = ReadBEHalfFloat f
vz = ReadBEHalfFloat f
vw = ReadBEHalfFloat f
append vert_Array[vx,vy,vz]
)
(AttrArr[attr].vertType == 2065):(
vx = ReadBEFloat f
vy = ReadBEFloat f
vz = ReadBEFloat f
vw = ReadBEFloat f
append vert_Array[vx,vy,vz]
)
)
fseek f vertStart#seek_set
)
--Color Info--
(AttrArr[attr].attName == "_c0"):(
case of (
default: (append Color_Array [255,255,255])
(AttrArr[attr].vertType == 2063):(
colorR = (ReadBEHalfFloat f * 255)
colorG = (ReadBEHalfFloat f * 255)
colorB = (ReadBEHalfFloat f * 255)
colorA = (ReadBEHalfFloat f * 255)
if colorR < 0 do(colorR = 0)
if colorR > 255 do(colorR = 255)
if colorG < 0 do(colorG = 0)
if colorG > 255 do(colorG = 255)
if colorB < 0 do(colorB = 0)
if colorB > 255 do(colorB = 255)
if colorA < 0 do(colorA = 0)
if colorA > 255 do(colorA = 255)
-- if these colours aren't clamped they'll go neon
append Color_Array[colorR,colorG,colorB]
)
(AttrArr[attr].vertType == 2067):(
colorR = (ReadBEFloat f * 255)
colorG = (ReadBEFloat f * 255)
colorB = (ReadBEFloat f * 255)
colorA = (ReadBEFloat f * 255)
if colorR < 0 do(colorR = 0)
if colorR > 255 do(colorR = 255)
if colorG < 0 do(colorG = 0)
if colorG > 255 do(colorG = 255)
if colorB < 0 do(colorB = 0)
if colorB > 255 do(colorB = 255)
if colorA < 0 do(colorA = 0)
if colorA > 255 do(colorA = 255)
-- if these colours aren't clamped they'll go neon
append Color_Array[colorR,colorG,colorB]
)
(AttrArr[attr].vertType == 10):(
colorR = ReadByte f #unsigned
colorG = ReadByte f #unsigned
colorB = ReadByte f #unsigned
colorA = ReadByte f #unsigned
append Color_Array[colorR,colorG,colorB]
)
(AttrArr[attr].vertType == 522):(
colorR = ReadByte f * 2
colorG = ReadByte f * 2
colorB = ReadByte f * 2
colorA = ReadByte f * 2
if colorR < 0 do(colorR = 0)
if colorR > 254 do(colorR = 255)
if colorG < 0 do(colorG = 0)
if colorG > 254 do(colorG = 255)
if colorB < 0 do(colorB = 0)
if colorB > 254 do(colorB = 255)
if colorA < 0 do(colorA = 0)
if colorA > 254 do(colorA = 255)
append Color_Array[colorR,colorG,colorB]
)
)
fseek f vertStart#seek_set
)
--Normals Info--
(AttrArr[attr].attName == "_n0"):(
case of (
(AttrArr[attr].vertType == 522):(
nx = ReadByte f as float / 127
ny = ReadByte f as float / 127
nz = ReadByte f as float / 127
nw = ReadByte f as float / 127
append Normal_Array[nx,ny,nz]
)
(AttrArr[attr].vertType == 523):(
normVal = ReadBElong f
nx = sign10(bit.and (normVal) 0x3FF) as float / 511
ny = sign10(bit.and (bit.shift normVal -10) 0x3FF) as float / 511
nz = sign10(bit.and (bit.shift normVal -20) 0x3FF) as float / 511
append Normal_Array[nx,ny,nz]
)
(AttrArr[attr].vertType == 2065):(
nx = ReadBEFloat f
ny = ReadBEFloat f
nz = ReadBEFloat f
nw = ReadBEFloat f
append Normal_Array[nx,ny,nz]
)
)
fseek f vertStart#seek_set
)
--Tangent Info--
--Binormals Info--
--UV Info--