-
Notifications
You must be signed in to change notification settings - Fork 5
/
GravityRush2_GFX_V2.py
1540 lines (1361 loc) · 61.9 KB
/
GravityRush2_GFX_V2.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
# Noesis Gravity Rush 2 GFX Extractor V2
# Written by 203Null
# Reverse Engineered by 203Null and FreezeCook
# Strcture Note: https://docs.google.com/document/d/1eW8BNMuE6chZebgClRnRoxRCEMDCAKPadYEhpK4AIV0/edit?usp=sharing
from inc_noesis import *
import noesis
import rapi
import os
import copy
import json
import math
from GravityRush_common import *
debug = False # please change to False out when done.
print_CSV = False
seperate_sub_mesh = True
global_scale = 100
remove_loose_vertice = True
LOD_suffix = True
reverse_binding = True
export_normal_and_tangent = True #Experimental
print_material = False
print_vertice_csv = False
material_param_as_name = False
optimize_bone_name = False
export_material_json = False #Set it to False to disable, or as export location string (<export_material_json>/<modelName>.json)
def registerNoesisTypes():
handle = noesis.register('Gravity Rush 2 GFX', '.gfx')
noesis.setHandlerTypeCheck(handle, noepyCheckType)
noesis.setHandlerLoadModel(handle, noepyLoadModel)
if debug:
noesis.logPopup()
return 1
def noepyCheckType(data):
file = NoeBitStream(data)
if len(data) < 4:
return 0
header = file.readBytes(4).decode('ASCII').rstrip("\0")
if header == 'GFX2':
return 1
return 0
def debugprint(message, end="\n"):
if(debug):
print(message, end=end)
class IndexChunk:
def __init__(self, name, typeID, offset, length):
self.name = name
self.typeID = typeID
self.offsetFromDataChunk = offset
self.length = length
def setCustomName(self, customName):
self.customName = customName
class BoneInfo:
def __init__(self, index, boneName, boneMatrix, scale, parentID, isBone, childList):
self.index = index
self.boneName = boneName
self.boneMatrix = boneMatrix
self.scale = scale
self.globalMatrix = boneMatrix
self.parentID = parentID
self.isBone = isBone
self.childList = childList
self.reverseBindingMatrix = None
self.hasRPB = False
def setReverseBindingMatrix(self, reverseBindingMatrix):
self.hasRPB = True
self.reverseBindingMatrix = reverseBindingMatrix
self.globalMatrix = reverseBindingMatrix
def setGlobalMatrix(self, globalMatrix):
self.globalMatrix = globalMatrix
def setName(self, name):
self.boneName = name
class MeshInfo:
# Infomations from 0x0400 Chunk
def __init__(self, index, name, numOfFaceChunk, parentID, indexOf0x0500Chunk, indexOf0x0600Chunk):
self.index = index # Global Index
self.name = name
self.numOfFaceChunk = numOfFaceChunk
self.parentID = parentID
self.indexOf0x0500Chunk = indexOf0x0500Chunk
self.indexOf0x0600Chunk = indexOf0x0600Chunk
self.initialize0x0600ChunkInfo()
self.boneMap = None
def initialize0x0600ChunkInfo(self):
self.indexOf0x0800Chunk = []
self.indexOf0x03000201Chunk = []
self.faceCount = []
self.faceIndex = []
self.texture = []
# Infomations from 0x0500 Chunk
def loadVertexInfo(self, vertexCount, indexOf0x03000101Chunk, vertexStruct):
self.vertexCount = vertexCount
self.indexOf0x03000101Chunk = indexOf0x03000101Chunk
self.vertexStruct = vertexStruct
# Infomations from 0x0600 Chunk
def loadFaceInfo(self, indexOf0x0800Chunk, indexOf0x03000201Chunk, faceCount, faceIndex):
self.indexOf0x0800Chunk.append(indexOf0x0800Chunk)
self.indexOf0x03000201Chunk.append(indexOf0x03000201Chunk)
self.faceCount.append(faceCount)
self.faceIndex.append(faceIndex)
# Infomations from 0x1000 Chunk
def loadBoneInfo(self, numOfBone, indexOf0x03001401Chunk, indexOf0x03000A01Chunk, boneMap):
self.numOfBone = numOfBone
self.indexOf0x03001401Chunk = indexOf0x03001401Chunk
self.indexOf0x03000A01Chunk = indexOf0x03000A01Chunk
self.boneMap = boneMap
def load2BInfo(self, numOfDataInMeshChunk0x1500, numOfDataInMeshChunk0x1600, numOfDataInMeshChunk0x1700, indexOfMeshChunk0x1500, indexOfMeshChunk0x1600, indexOfMeshChunk0x1700):
self.numOfDataInMeshChunk0x1500 = numOfDataInMeshChunk0x1500
self.numOfDataInMeshChunk0x1600 = numOfDataInMeshChunk0x1600
self.numOfDataInMeshChunk0x1700 = numOfDataInMeshChunk0x1700
self.indexOfMeshChunk0x1500 = indexOfMeshChunk0x1500
self.indexOfMeshChunk0x1600 = indexOfMeshChunk0x1600
self.indexOfMeshChunk0x1700 = indexOfMeshChunk0x1700
def loadTexture(self, texture): # Infomations from list of child 0x1100 Chunk
self.texture.append(texture)
def setName(self, name):
self.name = name
def setIndexOf0x0600Chunk(self, indexOf0x0600Chunk):
self.indexOf0x0600Chunk = indexOf0x0600Chunk
def setVertexCount(self, vertexCount):
self.vertexCount = vertexCount
class MaterialInfo:
def __init__(self, index, chunkType, name, data = []):
self.index = index
self.chunkType = chunkType
self.name = name.split("/")[-1]
self.addMaterialData(data)
self.textureList = []
def addMaterialData(self, data):
for i in range(len(data)):
if type(data[i]) == float:
data[i] = round(data[i], 3)
self.data = data
def addTextureData(self, index, data):
for value in data:
if type(value) == float:
value = round(value, 3)
self.textureList.append([index, data, "No Texture", None])
def addTexture(self, filename):
self.textureList[-1][2] = filename
def addTextureAtlas(self, data):
for i in range(len(data)):
if type(data[i]) == float:
data[i] = round(data[i], 3)
self.textureList[-1][3] = data
def noepyLoadModel(data, mdlList):
noeData = loadModel(data)
model = NoeModel(noeData[0])
model.setModelMaterials(NoeModelMaterials([], noeData[1]))
model.setBones(noeData[2])
mdlList.append(model)
if print_CSV:
printMeshCSV()
if print_material:
printMaterial()
if export_material_json != False:
exportMaterialJson()
return 1
def loadModel(data):
# Initialization
global bs
bs = NoeBitStream(data)
# Read header
bs.seek(0x08, NOESEEK_ABS)
global modelName
modelName = getNameFromHash(bs.readUInt())
bs.seek(0x0C, NOESEEK_ABS)
global fileSize
fileSize = bs.readUInt()
bs.seek(0x10, NOESEEK_ABS)
global numDataInIndexChunk
numDataInIndexChunk = bs.readUInt() - 1
bs.seek(0x14, NOESEEK_ABS)
global pointerOfDataChunk
pointerOfDataChunk = bs.readUInt()
bs.seek(0x18, NOESEEK_ABS)
global pointerOfMeshChunk
pointerOfMeshChunk = bs.readUInt()
bs.seek(0x1C, NOESEEK_ABS)
global numMeshChunk
numMeshChunk = bs.readUInt()
# Scan Index Chunk
bs.seek(0x30, NOESEEK_ABS)
global indexList
indexList = []
global meshInfos
meshInfos = []
global meshs
meshs = []
global indexBoneIDLookUpTable
indexBoneIDLookUpTable = [-1]*numDataInIndexChunk
global child0x0f00ChunkList
child0x0f00ChunkList = []
global indexOf0x2b00Chunk
indexOf0x2b00Chunk = []
global numOfBone
numOfBone = 0
global numOfMesh
numOfMesh = 0
global currentMesh
currentMesh = 0
global materialList
materialList = []
global materialInfoList
materialInfoList = []
global textureList
textureList = []
materialIndexs = []
global LOD
LOD = ""
if "lod2" in modelName:
LOD = "_LOD3"
rootBones = []
for i in range(numDataInIndexChunk):
indexList.append(IndexChunk(getNameFromHash(bs.readUInt()), bs.readUInt(), bs.readUInt(), bs.readUInt()))
if indexList[i].typeID % 0x10000 == 0x0002:
numOfBone += 1
if indexList[i].typeID == 0x010b0002: # root
rootBones.append(i)
elif indexList[i].typeID % 0x10000 == 0x0008:
materialIndexs.append(i)
elif indexList[i].typeID == 0x00000004:
numOfMesh += 1
elif indexList[i].typeID == 0x0000000f:
child0x0f00ChunkList.append(i) # Assume this is linear
elif indexList[i].typeID == 0x0000002b:
indexOf0x2b00Chunk.append(i)
for materialIndex in materialIndexs:
loadChunk(materialIndex)
global boneInfos
boneInfos = [None] * numOfBone
# Load root 0x0200 Chunk
for rootBone in rootBones:
loadChunk(rootBone)
for chunk2b in indexOf0x2b00Chunk:
loadChunk(chunk2b)
if remove_loose_vertice:
cleanUpMesh()
global bones
bones = []
for rootBone in rootBones:
compileBones(rootBone)
return [meshs, materialList, bones]
call_history = []
def loadChunk(index):
call_history.append(index)
origonalOffset = bs.tell()
result = None
if index > -1:
typeID = indexList[index].typeID
name = indexList[index].name
address = indexList[index].offsetFromDataChunk + pointerOfDataChunk
length = indexList[index].length
debugprint("Loading %s - " % hex(index), end="")
bs.seek(address, NOESEEK_ABS)
if typeID % 0x10000 == 0x0002:
debugprint("Chunk 0x0200xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x0200Chunk(index, name, length)
elif typeID % 0x10000 == 0x0003:
debugprint("Chunk 0x0300xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x0300Chunk(index, name, length)
elif typeID % 0x10000 == 0x0004:
debugprint("Chunk 0x0400xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x0400Chunk(index, name, length)
elif typeID % 0x10000 == 0x0005:
debugprint("Chunk 0x0500xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x0500Chunk(index, name, length)
elif typeID % 0x10000 == 0x0006:
debugprint("Chunk 0x0600xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x0600Chunk(index, name, length)
elif typeID % 0x10000 == 0x0008:
if "G2_" in name:
name = "G2_" + name.split("G2_")[-1] + " " + fnv1a_32_str(name)
if len(name) > 40:
name = name[:40] + ' ' + fnv1a_32_str(name)
if typeID == 0x02010008:
debugprint("Chunk 0x08000102 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08000102Chunk(index, name, length)
elif typeID == 0x02200008:
debugprint("Chunk 0x08002002 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002002Chunk(index, name, length)
elif typeID == 0x02220008:
debugprint("Chunk 0x08002202 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002202Chunk(index, name, length)
elif typeID == 0x02230008:
debugprint("Chunk 0x08002302 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002302Chunk(index, name, length)
elif typeID == 0x02240008:
debugprint("Chunk 0x08002402 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002402Chunk(index, name, length)
elif typeID == 0x02250008:
debugprint("Chunk 0x08002502 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002502Chunk(index, name, length)
elif typeID == 0x02280008:
debugprint("Chunk 0x08002802 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002802Chunk(index, name, length)
elif typeID == 0x02290008:
debugprint("Chunk 0x08002902 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002902Chunk(index, name, length)
elif typeID == 0x022A0008:
debugprint("Chunk 0x08002A02 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002A02Chunk(index, name, length)
elif typeID == 0x022B0008:
debugprint("Chunk 0x08002B02 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002B02Chunk(index, name, length)
elif typeID == 0x022C0008:
debugprint("Chunk 0x08002C02 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002C02Chunk(index, name, length)
elif typeID == 0x022D0008:
debugprint("Chunk 0x08002D02 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002D02Chunk(index, name, length)
elif typeID == 0x022E0008:
debugprint("Chunk 0x08002E02 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08002E02Chunk(index, name, length)
elif typeID == 0x02300008:
debugprint("Chunk 0x08003002 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08003002Chunk(index, name, length)
elif typeID == 0x02310008:
debugprint("Chunk 0x08003102 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08003102Chunk(index, name, length)
elif typeID == 0x02320008:
debugprint("Chunk 0x08003202 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08003202Chunk(index, name, length)
elif typeID == 0x02330008:
debugprint("Chunk 0x08003302 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x08003302Chunk(index, name, length)
else:
chunkType = hex(typeID)[2:]
while len(chunkType) != 8:
chunkType = "0" + chunkType
debugprint("\n------ Error: Unknown Material Chunk: 0x%s ------" % (chunkType[6:8]+chunkType[4:6]+chunkType[2:4]+chunkType[0:2]))
result = loadUnknownMaterialChunk(index, name, length)
elif typeID % 0x10000 == 0x0009:
debugprint("Chunk 0x0900xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x0900Chunk(index, name, length)
elif typeID % 0x10000 == 0x000f:
debugprint("Chunk 0x0f00xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x0f00Chunk(index, name, length)
elif typeID % 0x10000 == 0x0010:
debugprint("Chunk 0x1000xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x1000Chunk(index, name, length)
elif typeID % 0x10000 == 0x0011:
debugprint("Chunk 0x1100xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x1100Chunk(index, name, length)
elif typeID % 0x10000 == 0x0012:
debugprint("Chunk 0x1200xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x1200Chunk(index, name, length)
elif typeID % 0x10000 == 0x0019:
debugprint("Chunk 0x1900xxxx - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
debugprint("Skip reading")
# result = load0x1900Chunk(index, name, length)
elif typeID == 0x03030014:
debugprint("Chunk 0x14000303 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x14000303Chunk(index, name, length)
elif typeID == 0x0000002b:
debugprint("Chunk 0x2b000000 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x2b00Chunk(index, name, length)
elif typeID == 0x0000002d:
debugprint("Chunk 0x2d000000 - Name: %s - Address: %s - Length: %s" % (name, hex(address), hex(length)))
result = load0x2d00Chunk(index, name, length)
else:
chunkType = hex(typeID)[2:]
while len(chunkType) != 8:
chunkType = "0" + chunkType
debugprint("\n------ Error: Unknown Chunk type 0x%s ------" % (chunkType[6:8]+chunkType[4:6]+chunkType[2:4]+chunkType[0:2]))
loadUnknownChunk(index, name, length)
# raise Exception("unknown_chunk")
#noesis.doException("Unknown Chunk, skipped 0x %s" % chunkType[6:8]+chunkType[4:6]+chunkType[2:4]+chunkType[0:2])
bs.seek(origonalOffset, NOESEEK_ABS)
else:
debugprint("Negative Index, skipped %i" % index)
return result
def load0x0200Chunk(index, name, length): # Object/Bone tree
# Load Translation
z = bs.readFloat() * global_scale
y = bs.readFloat() * global_scale
x = bs.readFloat() * global_scale
translation = NoeVec3((z, y, x))
bs.seek(4, NOESEEK_REL)
rotation = NoeQuat.fromBytes(bs.readBytes(16))
scale = NoeVec3.fromBytes(bs.readBytes(12))
bs.seek(4, NOESEEK_REL)
# Load Extra Infomation
parentID = bs.readUInt() - 1
isBone = bs.readUShort() == 0x100
numOfChild = bs.readUShort()
bs.seek(4, NOESEEK_REL)
boneName = getNameFromHash(bs.readUInt())
if optimize_bone_name:
boneName = optimizeBoneName(boneName)
childList = []
for i in range(numOfChild):
childList.append(bs.readUInt() - 1)
boneMatrix = rotation.toMat43(transposed=1)
boneMatrix[3] = translation
boneInfos[index] = BoneInfo(index, boneName, boneMatrix, scale, parentID, isBone, childList)
if debug:
debugprint("Bone %i %s" % (index, boneName))
debugprint("Parent Bone: %i" % (parentID))
debugprint("Child Bone: ", end='')
debugprint(childList)
debugprint("Is Bone? %s" % str(isBone))
debugprint("Scale: %f, %f, %f" % (scale.getStorage()[0], scale.getStorage()[1], scale.getStorage()[2]))
if "G2PointLight" in boneName or "G2DecalLocator" in boneName:
boneName = loadChunk(childList[0]) #Pretty sure there's only gonna be 1
parentID = -1
isBone = True
boneInfos[index] = BoneInfo(index, boneName, boneMatrix, scale, parentID, isBone, childList) #Reload data bc decal need the scale info
else:
global LOD
LOD_Triggered = False
if LOD_suffix and LOD == "":
if boneName == "low":
LOD = "_LOD2"
LOD_Triggered = True
elif boneName == "middle":
LOD = "_LOD1"
LOD_Triggered = True
elif boneName == "near":
LOD = "_LOD0"
LOD_Triggered = True
elif boneName == "grass":
LOD = "_GRASS"
LOD_Triggered = True
if LOD_Triggered:
debugprint("LOD Flag set")
if parentID != -1:
debugprint("Globalizing Bone %i x %i " % (index, parentID))
boneInfos[index].setGlobalMatrix(boneMatrix * boneInfos[parentID].globalMatrix) #Globalize
for childIndex in childList:
result = loadChunk(childIndex)
if(type(result) == str):
boneName = result
boneInfos[index].setName(boneName)
if LOD_Triggered == True:
debugprint("Cleared LOD Flag")
LOD = ""
return
def load0x0300Chunk(index, name, length): # Mesh Data Pointer
bs.seek(4, NOESEEK_REL)
typeID = bs.readUInt()
offsetFromMeshChunk = bs.readUInt()
length = bs.readUInt()
bs.seek(offsetFromMeshChunk + pointerOfMeshChunk, NOESEEK_ABS)
if typeID == 0x01010000: # VertexData
debugprint("Loading Mesh Vertex - Index: %s - Name: %s - Address: %s" %(len(meshInfos), name, hex(bs.tell())))
loadMeshVertex(meshInfos[-1].vertexCount, meshInfos[-1].vertexStruct)
elif typeID == 0x01020000: # FaceData
debugprint("Loading Mesh Face - Index: %s - Name: %s - Address: %s" % (len(meshInfos), name, hex(bs.tell())))
loadMeshFace(meshInfos[-1].faceCount[-1])
elif typeID == 0x01140000: # WeightData
debugprint("Loading Vertex Weight - Index: %s - Name: %s - Address: %s" % (len(meshInfos), name, hex(bs.tell())))
if meshInfos[-1].boneMap != None:
loadMeshWeight(meshInfos[-1].vertexCount, meshInfos[-1].boneMap)
else:
debugprint("Bone map doesn't exist, skip")
elif typeID == 0x010A0000: # Reverse Binding
debugprint("Loading Reverse Binding - Index: %s - Name: %s - Address: %s" % (len(meshInfos), name, hex(bs.tell())))
loadReverseBinding(meshInfos[-1].boneMap)
elif typeID == 0x011A0000: #Tree Leaves
debugprint("Loading Leaves Vertex - Index: %s - Name: %s - Address: %s" %(len(meshInfos), name, hex(bs.tell())))
loadLeaves(meshInfos[-1].vertexCount, meshInfos[-1].vertexStruct)
elif typeID == 0x011B0000: #Grass
debugprint("Loading Grass Vertex - Index: %s - Name: %s - Address: %s" %(len(meshInfos), name, hex(bs.tell())))
loadGrass(meshInfos[-1].vertexCount, meshInfos[-1].vertexStruct)
else:
chunkType = hex(typeID)[2:]
debugprint("Unknown Data Chunk: 0x%s" % (chunkType[6:8]+chunkType[4:6]+chunkType[2:4]+chunkType[0:2]))
#skiped_0x0f00_count = 0
def load0x0400Chunk(index, name, length): # Mesh Info
global currentMesh
global skiped_0x0f00_count
# Header
numOfFaceChunk = bs.readUShort()
bs.seek(6, NOESEEK_REL)
parentID = bs.readUInt() - 1
scale = boneInfos[parentID].scale
bs.seek(4, NOESEEK_REL)
# Subchunk 1
indexOf0x0500Chunk = bs.readUInt() - 1
bs.seek(28, NOESEEK_REL)
# List of child index of 0x0600
indexOf0x0600Chunk = []
for i in range(numOfFaceChunk):
indexOf0x0600Chunk.append(bs.readUInt() - 1)
# bs.seek() TODO - seek to Subchunk 2
name = name.split('/')[-1].split("Shape")[0]
debugprint("Mesh detected - Name: %s Mesh Index: %i Global Index: %i Submesh count: %i Scale: %s " % (name, currentMesh, index, numOfFaceChunk, str(scale)), end="")
if LOD == "":
debugprint("LOD Level: None")
else:
debugprint("LOD Level: " + LOD[1:])
debugprint("Index Of 0x0500 Chunk: %s" % hex(indexOf0x0500Chunk))
debugprint("Index Of 0x0600 Chunk: ", end='')
debugprint([hex(x) for x in indexOf0x0600Chunk])
meshs.append(NoeMesh([], [], name + LOD))
meshInfos.append(MeshInfo(index, name + LOD, numOfFaceChunk, parentID, indexOf0x0500Chunk, indexOf0x0600Chunk[i]))
loadChunk(indexOf0x0500Chunk) # Load Vertex Chain
if len(child0x0f00ChunkList) > 0:
if currentMesh >= len(child0x0f00ChunkList) or loadChunk(child0x0f00ChunkList[currentMesh]) == False:
debugprint("Enumerating all 0x0f00 chunks")
for chunk in child0x0f00ChunkList:
if loadChunk(chunk):
break
debugprint("Can't find bonemap")
if seperate_sub_mesh:
meshInfos[-1].setIndexOf0x0600Chunk([indexOf0x0600Chunk[0]])
loadChunk(indexOf0x0600Chunk[0]) #Load First Chain
if numOfFaceChunk > 1:
meshs[-1].setName(name + "_0" + LOD)
meshInfos[-1].setName(meshs[-1].name)
for i in range(1, numOfFaceChunk): #Load Face Chain
meshs.append(copy.copy(meshs[-1]))
meshs[-1].setName(name + '_' + str(i) + LOD)
meshs[-1].setIndices([])
meshInfos.append(copy.copy(meshInfos[-1]))
meshInfos[-1].initialize0x0600ChunkInfo()
meshInfos[-1].setIndexOf0x0600Chunk([indexOf0x0600Chunk[0]])
meshInfos[-1].setName(meshs[-1].name)
debugprint("Loading sub mesh %s" % meshs[-1].name)
loadChunk(indexOf0x0600Chunk[i])
else:
meshs[-1].setName(name + LOD)
meshInfos.append(MeshInfo(index, meshs[-1].name, numOfFaceChunk, parentID, indexOf0x0500Chunk, indexOf0x0600Chunk))
for i in indexOf0x0600Chunk: # Load Face Chain
loadChunk(i)
currentMesh += 1
def load0x0500Chunk(index, name, length):
# Header
vertexCount = bs.readUInt()
numOfElementInStruct = bs.readUInt()
indexOf0x03000101Chunk = bs.readUInt() - 1
bs.seek(4, NOESEEK_REL)
# Reading struct
vertexStruct = []
for i in range(numOfElementInStruct):
vertexStruct.append(bs.readUByte())
debugprint("Vertex Struct Loaded: ", end='')
debugprint([hex(x) for x in vertexStruct])
# Log data and to vertex pointer
meshInfos[-1].loadVertexInfo(vertexCount, indexOf0x03000101Chunk, vertexStruct)
loadChunk(indexOf0x03000101Chunk)
def load0x0600Chunk(index, name, length):
indexOf0x0800Chunk = bs.readUInt() - 1
indexOf0x03000201Chunk = bs.readUInt() - 1
faceCount = bs.readUShort()
# Just gonna ignore those unknown data in between rn
bs.seek(12, NOESEEK_REL)
faceIndex = bs.readUShort()
meshInfos[-1].loadFaceInfo(indexOf0x0800Chunk,indexOf0x03000201Chunk, faceCount, faceIndex)
meshs[-1].setMaterial(indexList[indexOf0x0800Chunk].customName)
# Load material
#loadChunk(indexOf0x0800Chunk)
loadChunk(indexOf0x03000201Chunk)
def load0x08000102Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "01", name))
if material_param_as_name:
material = NoeMaterial("01-" + name[1:], "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
'''
header = bs.readUInt()
subchunkID = []
for i in range(3):
subchunkID.append(bs.readUInt() - 1)
debugprint("0x08000102 Chunk, %s, " % hex(header), end = '')
[debugprint(hex(x)+', ', end = '') for x in subchunkID]
debugprint()
for i in range(2):
loadChunk(subchunkID[i])
'''
addMaterial(material)
def load0x08002002Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "20", name))
if material_param_as_name:
material = NoeMaterial("20-" + name[1:], "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
addMaterial(material)
def load0x08002202Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "22", name))
header = bs.readUInt()
texture = loadChunk(bs.readUInt() - 1)
normal = loadChunk(bs.readUInt() - 1)
eye_refelection = loadChunk(bs.readUInt() - 1)
detail = loadChunk(bs.readUInt() - 1)
eye = loadChunk(bs.readUInt() - 1)
data = [header]
for i in range(64):
data.append(bs.readFloat())
materialInfoList[-1].addMaterialData(data)
if material_param_as_name:
material = NoeMaterial("22-%s-%s-%s-%s" % (texture, eye_refelection, detail, eye), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
material.setNormalTexture(normal)
#material.setUserData(b"eye refl", eye_refelection)
#material.setUserData(b"detail ", detail)
#material.setUserData(b"eye ", eye)
addMaterial(material)
def load0x08002302Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "23", name))
header1 = bs.readUInt()
header2 = bs.readUInt()
materialType = getNameFromHash(bs.readUInt())
texture = loadChunk(bs.readUInt() - 1)
normal = loadChunk(bs.readUInt() - 1)
specular = loadChunk(bs.readUInt() - 1)
texture2 = loadChunk(bs.readUInt() - 1)
normal2 = loadChunk(bs.readUInt() - 1)
data = [header1, header2, materialType]
for i in range(20):
data.append(bs.readFloat())
materialInfoList[-1].addMaterialData(data)
if material_param_as_name:
material = NoeMaterial("23-%s-%s-%s-%s" % (materialType, texture, texture2, specular), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
#material.setUserData(b"material", materialType)
material.setTexture(texture)
material.setNormalTexture(normal)
material.setSpecularTexture(specular)
#material.setUserData(b"color2 ", texture2)
#material.setUserData(b"normal2 ", normal2)
addMaterial(material)
def load0x08002402Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "24", name))
header1 = bs.readUInt()
header2 = bs.readUInt()
data = [header1, header2]
data.append("Data Chunk 1")
for i in range(17):
data.append(bs.readFloat())
effect = loadChunk(bs.readUInt() - 1)
data.append("Data Chunk 2")
for i in range(16):
data.append(bs.readFloat())
texture = loadChunk(bs.readUInt() - 1)
unknown1 = loadChunk(bs.readUInt() - 1)
unknown2 = loadChunk(bs.readUInt() - 1)
unknown3 = loadChunk(bs.readUInt() - 1)
data.append("Data Chunk 3")
for i in range(16):
data.append(bs.readFloat())
materialInfoList[-1].addMaterialData(data)
if material_param_as_name:
material = NoeMaterial("24-%s-%s-%s-%s-%s" % (texture, effect, unknown1, unknown2, unknown3), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
#material.setUserData(b'effect ', effect)
#material.setUserData(b'unknown1 ', unknown1)
#material.setUserData(b'unknown2 ', unknown2)
#material.setUserData(b'unknown3 ', unknown3)
addMaterial(material)
def load0x08002502Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "26", name))
bs.seek(16, NOESEEK_REL)
unknown1 = loadChunk(bs.readUInt() - 1)
unknown2 = loadChunk(bs.readUInt() - 1)
unknown3 = loadChunk(bs.readUInt() - 1)
unknown4 = loadChunk(bs.readUInt() - 1)
unknown5 = loadChunk(bs.readUInt() - 1)
unknown6 = loadChunk(bs.readUInt() - 1)
if material_param_as_name:
material = NoeMaterial("25-%s-%s-%s-%s-%s-%s" % (unknown1, unknown2, unknown3, unknown4, unknown5, unknown6), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(unknown1)
#material.setUserData(b'effect ', effect)
#material.setUserData(b'unknown1 ', unknown1)
#material.setUserData(b'unknown2 ', unknown2)
#material.setUserData(b'unknown3 ', unknown3)
addMaterial(material)
def load0x08002802Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "28", name))
bs.seek(0x64, NOESEEK_REL)
texture = loadChunk(bs.readUInt() - 1)
if material_param_as_name:
material = NoeMaterial("28-%s" % texture, "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
addMaterial(material)
def load0x08002902Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "29", name))
data = []
data.append("Data Chunk 1")
for i in range(7):
data.append(bs.readFloat())
subchunkID = []
texture = loadChunk(bs.readUInt() - 1)
data.append("Data Chunk 2")
for i in range(12):
data.append(bs.readFloat())
normal = loadChunk(bs.readUInt() - 1)
data.append("Data Chunk 3")
for i in range(3):
data.append(bs.readFloat())
materialInfoList[-1].addMaterialData(data)
if material_param_as_name:
material = NoeMaterial("29-%s" % (texture), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
material.setNormalTexture(normal)
addMaterial(material)
def load0x08002A02Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "2A", name))
if material_param_as_name:
material = NoeMaterial("2A-" + name[1:], "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
addMaterial(material)
def load0x08002B02Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "2B", name))
header1 = bs.readUInt()
header2 = bs.readUInt()
texture = loadChunk(bs.readUInt() - 1)
texture2 = loadChunk(bs.readUInt() - 1)
texture3 = loadChunk(bs.readUInt() - 1)
texture4 = loadChunk(bs.readUInt() - 1)
normal = loadChunk(bs.readUInt() - 1)
normal2 = loadChunk(bs.readUInt() - 1)
normal3 = loadChunk(bs.readUInt() - 1)
normal4 = loadChunk(bs.readUInt() - 1)
materialInfoList[-1].addMaterialData([header1, header2])
if material_param_as_name:
material = NoeMaterial("2B-%s-%s-%s-%s" % (texture,texture2,texture3,texture4), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
material.setNormalTexture(normal)
# material.setUserData(b'color2 ', loadChunk(bs.readUInt() - 1))
# material.setUserData(b'color3 ', loadChunk(bs.readUInt() - 1))
# material.setUserData(b'color4 ', loadChunk(bs.readUInt() - 1))
# material.setUserData(b'normal2 ', loadChunk(bs.readUInt() - 1))
# material.setUserData(b'normal3 ', loadChunk(bs.readUInt() - 1))
# material.setUserData(b'normal4 ', loadChunk(bs.readUInt() - 1))
addMaterial(material)
def load0x08002C02Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "2C", name))
bs.seek(0x8, NOESEEK_REL)
texture = loadChunk(bs.readUInt() - 1)
normal = loadChunk(bs.readUInt() - 1)
interior = loadChunk(bs.readUInt() - 1)
overlay = loadChunk(bs.readUInt() - 1)
data = []
for i in range(18):
data.append(bs.readFloat())
materialInfoList[-1].addMaterialData(data)
if material_param_as_name:
material = NoeMaterial("2C-%s-%s" % (texture,interior), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
material.setNormalTexture(normal)
addMaterial(material)
def load0x08002D02Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "2D", name))
bs.seek(0x30, NOESEEK_REL)
texture = loadChunk(bs.readUInt() - 1)
texture2 = loadChunk(bs.readUInt() - 1)
bs.seek(0x48, NOESEEK_REL)
texture3 = loadChunk(bs.readUInt() - 1)
texture4 = loadChunk(bs.readUInt() - 1)
if material_param_as_name:
material = NoeMaterial("2D-%s-%s-%s-%s" % (texture,texture2,texture3,texture4), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
addMaterial(material)
def load0x08002E02Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "2E", name))
bs.seek(0x8, NOESEEK_REL)
texture = loadChunk(bs.readUInt() - 1)
data = []
for i in range(9):
data.append(bs.readFloat())
materialInfoList[-1].addMaterialData(data)
if material_param_as_name:
material = NoeMaterial("2E-%s" % texture, "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
addMaterial(material)
def load0x08003002Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "30", name))
bs.seek(0x8, NOESEEK_REL)
texture = loadChunk(bs.readUInt() - 1)
normal = loadChunk(bs.readUInt() - 1)
if material_param_as_name:
material = NoeMaterial("30-%s" % texture, "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture)
material.setNormalTexture(normal)
addMaterial(material)
def load0x08003102Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "31", name))
bs.seek(0x8, NOESEEK_REL)
texture1 = loadChunk(bs.readUInt() - 1)
texture2 = loadChunk(bs.readUInt() - 1)
texture3 = loadChunk(bs.readUInt() - 1)
if material_param_as_name:
material = NoeMaterial("31-%s-%s-%s" % (texture1, texture2, texture3), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture1)
addMaterial(material)
def load0x08003202Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "32", name))
bs.seek(0x8, NOESEEK_REL)
texture1 = loadChunk(bs.readUInt() - 1)
texture2 = loadChunk(bs.readUInt() - 1)
if material_param_as_name:
material = NoeMaterial("32-%s-%s" % (texture1, texture2), "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
material.setTexture(texture1)
addMaterial(material)
def load0x08003302Chunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "33", name))
if material_param_as_name:
material = NoeMaterial("33-" + name[1:], "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
'''
header1 = bs.readUInt()
subchunkID = []
for i in range(4):
subchunkID.append(bs.readUInt() - 1)
data = []
for i in range(7):
data.append(bs.readFloat())
'''
addMaterial(material)
def loadUnknownMaterialChunk(index, name, length):
materialInfoList.append(MaterialInfo(index, "Unknown", name))
if material_param_as_name:
material = NoeMaterial("Unknown-" + name[1:], "")
else:
material = NoeMaterial(name.split("/")[-1], "")
indexList[index].setCustomName(material.name)
'''
header1 = bs.readUInt()
subchunkID = []
for i in range(4):
subchunkID.append(bs.readUInt() - 1)
data = []
for i in range(7):
data.append(bs.readFloat())
'''
addMaterial(material)
def load0x0900Chunk(index, name, length):
indexOf0x1100Chunk = bs.readUInt() - 1
data = [bs.readUInt(), bs.readUInt(), bs.readUInt()]
materialInfoList[-1].addTextureData(index, data)
if length == 0x30: #Atlas
atlas = []
for i in range(4):
atlas.append(bs.readFloat())
materialInfoList[-1].addTextureAtlas(atlas)
if indexOf0x1100Chunk != -1:
return loadChunk(indexOf0x1100Chunk)
return ''
def load0x1100Chunk(index, name, length):
bs.seek(12, NOESEEK_REL)