-
Notifications
You must be signed in to change notification settings - Fork 27
/
storm_engine_script.py
118 lines (87 loc) · 4.04 KB
/
storm_engine_script.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
from inc_noesis import *
# Storm Engine Noesis script
# Created by Bartlomiej Duda (Ikskoks)
# License: GPL-3.0 License
# Ver Date Author Comment
# v0.1 18.11.2023 Bartlomiej Duda -
# v0.2 21.11.2023 Bartlomiej Duda/BloodRaynare -
# fmt: off
debug_mode_enabled = False
def registerNoesisTypes():
handle = noesis.register("STORM ENGINE TX FILES", ".tx")
noesis.setHandlerTypeCheck(handle, image_check_type)
noesis.setHandlerLoadRGBA(handle, image_load)
if debug_mode_enabled:
noesis.logPopup()
return 1
def image_check_type(file_data):
return 1
def image_load(image_file_data, tex_list):
bs = NoeBitStream(image_file_data)
base_name = rapi.getInputName().split('\\')[-1].split('.')[0]
print("base_name: ", base_name)
i = 0
# header parsing
flags = bs.readUInt()
img_width = bs.readUInt()
img_height = bs.readUInt()
number_of_mipmaps = bs.readUInt()
tx_format = bs.readUInt()
mip0_size = bs.readUInt()
print("tx_format: " + str(tx_format))
if tx_format == 21: # TXF_A8R8G8B8
bytes_per_pixel = 4
pixel_size = img_width * img_height * bytes_per_pixel
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeRaw(pixel_data, img_width, img_height, "b8 g8 r8 a8")
elif tx_format == 22: # TXF_X8R8G8B8
bytes_per_pixel = 4
pixel_size = img_width * img_height * bytes_per_pixel
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeRaw(pixel_data, img_width, img_height, "b8 g8 r8 p8")
elif tx_format == 23: # TXF_R5G6B5
bytes_per_pixel = 2
pixel_size = img_width * img_height * bytes_per_pixel
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeRaw(pixel_data, img_width, img_height, "b5 g6 r5")
elif tx_format == 25: # TXF_A1R5G5B5
bytes_per_pixel = 2
pixel_size = img_width * img_height * bytes_per_pixel
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeRaw(pixel_data, img_width, img_height, "b5 g5 r5 a1")
elif tx_format == 26: # TXF_A4R4G4B4
bytes_per_pixel = 2
pixel_size = img_width * img_height * bytes_per_pixel
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeRaw(pixel_data, img_width, img_height, "b4 g4 r4 a4")
elif tx_format == 827611204: # DXT1
pixel_size = (img_width * img_height)
if pixel_size >= len(image_file_data):
pixel_size = len(image_file_data) - 24
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeDXT(pixel_data, img_width, img_height, noesis.FOURCC_DXT1)
elif tx_format == 844388420: # DXT2
pixel_size = (img_width * img_height)
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeDXT(pixel_data, img_width, img_height, noesis.FOURCC_DXT2)
elif tx_format == 861165636: # DXT3
pixel_size = (img_width * img_height)
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeDXT(pixel_data, img_width, img_height, noesis.FOURCC_DXT3)
elif tx_format == 877942852: # DXT4
pixel_size = (img_width * img_height)
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeDXT(pixel_data, img_width, img_height, noesis.FOURCC_DXT4)
elif tx_format == 894720068: # DXT5
pixel_size = (img_width * img_height)
pixel_data = bs.readBytes(pixel_size)
pixel_data = rapi.imageDecodeDXT(pixel_data, img_width, img_height, noesis.FOURCC_DXT5)
else:
message = "TX type " + str(tx_format) + " is not supported!"
noesis.messagePrompt(message)
return 0
texture_format = noesis.NOESISTEX_RGBA32
texture_name = "%s_%d" % (base_name, i)
tex_list.append(NoeTexture(texture_name, img_width, img_height, pixel_data, texture_format))
print("\n")
return 1