-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
145 lines (117 loc) · 2.98 KB
/
utils.py
File metadata and controls
145 lines (117 loc) · 2.98 KB
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
from enum import IntEnum
import numpy as np
def read8(data, offset):
return data[offset]
def read16(data, offset):
return data[offset] | (data[offset + 1] << 8)
def read32(data, offset):
return data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24)
def read_str(data, offset):
end = offset
while data[end] != 0:
end += 1
return data[offset:end].tobytes().decode('ascii')
def read_dict_string(data, offset):
end = offset
while data[end] != 0:
end += 1
if (end - offset) == 16:
break
return data[offset:end].tobytes().decode('ascii')
def log(string, report_func):
report_func(type={"INFO"}, message=string)
def error(string, report_func):
report_func(type={"ERROR"}, message=string)
def debug(string, report_func):
report_func(type={"DEBUG"}, message=string)
def parse_dictionary(data):
num_entries = read8(data, 0x01)
data_offset = read16(data, 0x06)
data_size = read16(data, data_offset + 0x00)
name_offset = read16(data, data_offset + 0x02)
dictionary = {}
for i in range(num_entries):
name = read_dict_string(data, data_offset + name_offset + i * 0x10)
value = 0
if data_size == 1:
value = read8(data, data_offset + 0x04 + i * 0x01)
elif data_size == 2:
value = read16(data, data_offset + 0x04 + i * 0x02)
elif data_size == 4:
value = read32(data, data_offset + 0x04 + i * 0x04)
dictionary[name] = value
return dictionary
def fixed_to_float(value):
return float(value / 4096.0)
def to_rgb(color):
return (color & 0x1F, (color >> 5) & 0x1F, (color >> 10) & 0x1F)
def np_fixed_to_float(value):
return (value / 4096.0).astype('float')
def vec10_to_vec(value):
return np_fixed_to_float(np.array([value & 0x3FF, (value >> 10) & 0x3FF, (value >> 20) & 0x3FF]))
class PolygonMode(IntEnum):
MODULATE = 0
DECAL = 1
TOON = 2
SHADOW = 3
class CullMode(IntEnum):
NONE = 0
FRONT = 1
BACK = 2
BOTH = 3
class TexturePalette0Mode(IntEnum):
USE = 0
TRANSPARENT = 1
class TextureFlip(IntEnum):
NONE = 0
S = 1
T = 2
ST = 3
class TextureRepeat(IntEnum):
NONE = 0
S = 1
T = 2
ST = 3
class TextureTSize(IntEnum):
T8 = 0
T16 = 1
T32 = 2
T64 = 3
T128 = 4
T256 = 5
T512 = 6
T1024 = 7
class TextureSSize(IntEnum):
S8 = 0
S16 = 1
S32 = 2
S64 = 3
S128 = 4
S256 = 5
S512 = 6
S1024 = 7
class TextureConversionMode(IntEnum):
NONE = 0
TEXCOORD = 1
NORMAL = 2
VERTEX = 3
class TextureFormat(IntEnum):
NONE = 0
A3I5 = 1
PLTT4 = 2
PLTT16 = 3
PLTT256 = 4
COMP4X4 = 5
A5I3 = 6
DIRECT = 7
class PrimitiveType(IntEnum):
TRIANGLES = 0
QUADS = 1
TRIANGLE_STRIP = 2
QUAD_STRIP = 3
class TranslucentPolygonSortMode(IntEnum):
AUTO = 0
MANUAL = 1
class DepthBufferSelection(IntEnum):
Z = 0
W = 1