/
tex_nhtex_TEX.py
56 lines (53 loc) · 1.75 KB
/
tex_nhtex_TEX.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
from inc_noesis import *
def registerNoesisTypes():
handle = noesis.register("Sakuna NHTEX Images", ".nhtex")
noesis.setHandlerTypeCheck(handle, noepyCheckType)
noesis.setHandlerLoadRGBA(handle, noepyLoadRGBA)
#noesis.logPopup()
return 1
def noepyCheckType(data):
return 1
def noepyLoadRGBA(data, texList):
bs = NoeBitStream(data)
bs.seek(0x40, NOESEEK_ABS)
imgWidth = bs.readUInt()
imgHeight = bs.readUInt()
bs.seek(0x30, NOESEEK_ABS)
imgFmt = bs.readUByte()
bs.seek(0x50, NOESEEK_ABS)
otest = bs.readUByte()
if otest == 0xb:
offset = 0x180
elif otest == 0x01:
offset = 0x90
elif otest == 0x05:
offset = 0xF0
elif otest == 0x08:
offset = 0x148
elif otest == 0x0a:
offset = 0x168
elif otest == 0x0C:
offset = 0x198
else:
offset = 0x150
datasize = len(data) - offset
bs.seek(offset, NOESEEK_ABS)
data = bs.readBytes(datasize)
#DXT1
if imgFmt == 0x47:
texFmt = noesis.NOESISTEX_DXT1
elif imgFmt == 0x4D:
texFmt = noesis.NOESISTEX_DXT5
#DXT5 packed normal map
elif imgFmt == 0x53:
data = rapi.imageDecodeDXT(data, imgWidth, imgHeight, noesis.FOURCC_ATI2)
texFmt = noesis.NOESISTEX_RGBA32
#unknown, not handled
elif imgFmt == 0x62:
data = rapi.imageDecodeDXT(data, imgWidth, imgHeight, noesis.FOURCC_BC7)
texFmt = noesis.NOESISTEX_RGBA32
else:
print("WARNING: Unhandled image format " + repr(imgFmt) + " - " + repr(imgWidth) + "x" + repr(imgHeight) + " - " + repr(len(data)))
return None
texList.append(NoeTexture(rapi.getInputName(), imgWidth, imgHeight, data, texFmt))
return 1