Skip to content

Commit 0a55b3b

Browse files
authored
Merge pull request #59 from Robert-N7/develop
Fix obj import of single bone
2 parents bb60c69 + 167a399 commit 0a55b3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3490
-217
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ preset = 'preset' preset_name;
9999
save = 'save' [filename] ['as' destination] ['overwrite']
100100
copy = 'copy' type;
101101
paste = 'paste' type;
102-
convert = 'convert' filename ['to' destination] ['--no-colors'] ['--no-normals'] ['--single-bone']
102+
convert = 'convert' filename ['to' destination] ['--no-colors'] ['--no-normals'] ['--single-bone'] ['--no-uvs']
103103
104104
selection = name ['in' container]
105105
container = ['brres' filename] ['model' name];

abmatt/__main__.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import sys
88

99
from abmatt import load_config
10-
from abmatt.autofix import AutoFix
1110

1211

1312
def main():
@@ -20,15 +19,10 @@ def main():
2019
base_path = sys.executable
2120
else:
2221
base_path = os.path.abspath(__file__)
23-
try:
24-
files = load_config.parse_args(argv, base_path)
25-
# cleanup
26-
for file in files.values():
27-
file.close()
28-
except:
29-
AutoFix.get().quit()
30-
raise
31-
AutoFix.get().quit()
22+
files = load_config.parse_args(argv, base_path)
23+
# cleanup
24+
for file in files.values():
25+
file.close()
3226

3327

3428
if __name__ == "__main__":

abmatt/autofix.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ def __init__(self, bug_level, notify_level, description, fix_des=None):
3535
self.description = description
3636
self.fix_des = fix_des
3737
self.is_resolved = False
38-
AutoFix.get().notify(self)
38+
AutoFix.notify(self)
3939

4040
# def should_fix(self):
41-
# return not self.is_resolved and AutoFix.get().should_fix(self)
41+
# return not self.is_resolved and AutoFix.should_fix(self)
4242

4343
def resolve(self):
4444
self.is_resolved = True
45-
AutoFix.get().info(f'(FIXED): {self.fix_des}', self.notify_level)
45+
AutoFix.info(f'(FIXED): {self.fix_des}', self.notify_level)
4646

4747

4848
class AutoFixAbort(BaseException):
@@ -54,6 +54,7 @@ def __init__(self):
5454

5555
class MessageReceiver:
5656
"""Interface to receive messages"""
57+
5758
def info(self, message):
5859
raise NotImplementedError()
5960

@@ -114,29 +115,32 @@ def __init__(self, fix_level=3, loudness=3):
114115
self.loudness = loudness
115116
self.fix_level = fix_level
116117
self.queue = []
117-
self.is_running = True
118+
self.is_running = False
118119
self.pipe = None # if set, output is sent to the pipe, must implement info warn and error.
119-
self.thread = Thread(target=self.run)
120120
AutoFix.__AUTO_FIXER = self
121-
self.thread.start()
122121

123122
@staticmethod
124123
def quit():
125124
a = AutoFix.__AUTO_FIXER
126125
if a is not None:
127-
a.is_running = False
128-
a.thread.join()
129-
AutoFix.__AUTO_FIXER = None
126+
if a.is_running:
127+
a.is_running = False
128+
a.thread.join()
129+
AutoFix.__AUTO_FIXER = None
130130

131131
def run(self):
132-
while self.is_running:
133-
sleep(0.01)
132+
self.is_running = True
133+
while len(self.queue):
134134
if len(self.queue):
135-
message = self.queue.pop(0)
136-
message.send(self.pipe)
135+
self.queue.pop(0).send(self.pipe)
136+
sleep(0.01)
137+
self.is_running = False
137138

138139
def enqueue(self, message):
139140
self.queue.append(message)
141+
if not self.is_running:
142+
self.thread = Thread(target=self.run)
143+
self.thread.start()
140144

141145
@staticmethod
142146
def get(fixe_level=3, loudness=3):
@@ -164,7 +168,7 @@ def log(self, message):
164168
if self.loudness >= 5:
165169
self.enqueue(self.Info(str(message)))
166170

167-
def info(self, message, loudness=2):
171+
def info(self, message, loudness=3):
168172
if self.loudness >= loudness:
169173
self.enqueue(self.Info(str(message)))
170174

@@ -178,7 +182,7 @@ def error(self, message, loudness=1):
178182

179183
def exception(self, exception=None, shutdown=False):
180184
exc_type, exc_value, exc_tb = sys.exc_info()
181-
if self.loudness >= 5: # Debug level
185+
if self.loudness >= 5: # Debug level
182186
s = traceback.format_exception(exc_type, exc_value, exc_tb)
183187
elif self.loudness >= 1:
184188
s = traceback.format_exception(exc_type, exc_value, exc_tb, 10)
@@ -244,3 +248,6 @@ def get_level(self, level_str):
244248

245249
def set_loudness(self, level_str):
246250
self.loudness = self.get_level(level_str)
251+
252+
253+
AutoFix = AutoFix()

abmatt/brres/brres.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ def save(self, filename=None, overwrite=None, check=True):
159159
if overwrite is None:
160160
overwrite = self.OVERWRITE
161161
if not overwrite and os.path.exists(filename):
162-
AutoFix.get().error('File {} already exists!'.format(filename), 1)
162+
AutoFix.error('File {} already exists!'.format(filename), 1)
163163
else:
164164
if check:
165165
self.check()
166166
f = BinFile(filename, mode="w")
167167
self.pack(f)
168168
if f.commitWrite():
169-
AutoFix.get().info("Wrote file '{}'".format(filename), 2)
169+
AutoFix.info("Wrote file '{}'".format(filename), 2)
170170
self.rename(filename)
171171
self.has_new_model = False
172172
self.mark_unmodified()
@@ -179,7 +179,7 @@ def get_trace(self):
179179
return self.name
180180

181181
def info(self, key=None, indentation_level=0):
182-
AutoFix.get().info('{}{}:\t{} model(s)\t{} texture(s)'.format(' ' * indentation_level + '>',
182+
AutoFix.info('{}{}:\t{} model(s)\t{} texture(s)'.format(' ' * indentation_level + '>',
183183
self.name, len(self.models), len(self.textures)), 1)
184184
indentation_level += 2
185185
self.sub_info('MDL0', self.models, key, indentation_level)
@@ -257,7 +257,7 @@ def add_tex0(self, tex0, replace=True, mark_modified=True):
257257
if not replace:
258258
return False
259259
self.remove_tex0(tex0.name)
260-
AutoFix.get().info('Replaced tex0 {}'.format(tex0.name))
260+
AutoFix.info('Replaced tex0 {}'.format(tex0.name))
261261
if tex0.parent is not None and tex0.parent is not self:
262262
t = Tex0(tex0.name, self)
263263
t.paste(tex0)
@@ -315,7 +315,7 @@ def remove_tex0(self, name):
315315
self.textures.remove(tex)
316316
self.mark_modified()
317317
except KeyError:
318-
AutoFix.get().warn('No texture {} in {}'.format(name, self.name))
318+
AutoFix.warn('No texture {} in {}'.format(name, self.name))
319319

320320
def remove_tex0_i(self, i):
321321
tex = self.textures.pop(i)
@@ -351,7 +351,7 @@ def pack(self, binfile):
351351

352352
# --------------------------------------------------------------------------
353353
def check(self):
354-
AutoFix.get().info('checking file {}'.format(self.name), 4)
354+
AutoFix.info('checking file {}'.format(self.name), 4)
355355
expected = self.get_expected_mdl_name()
356356
for mdl in self.models:
357357
mdl.check(expected)

abmatt/brres/lib/decoder.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def decode_data(color):
4040

4141
@staticmethod
4242
def decode_rgb565(color_data, num_colors):
43-
data = unpack('>{}H'.format(num_colors), color_data)
43+
data = unpack_from('>{}H'.format(num_colors), color_data, 0)
4444
colors = []
4545
for color in data:
46-
colors.append(((color >> 8) & 0xf8, (color >> 3) & 0xfc, (color & 0x1f) << 3, 0xff))
46+
colors.append(((color >> 8) & 0xf8 | 0x7, (color >> 3) & 0xfc | 0x3, (color & 0x1f) << 3 | 0x7, 0xff))
4747
return colors
4848

4949
@staticmethod
@@ -69,10 +69,10 @@ def decode_rgba8(data, num_colors):
6969
@staticmethod
7070
def decode_rgba4(data, num_colors):
7171
colors = []
72-
c_data = unpack('>{}H'.format(num_colors), data)
72+
c_data = unpack_from('>{}H'.format(num_colors), data, 0)
7373
for color in c_data:
74-
colors.append((color >> 8 & 0xf0, color >> 4 & 0xf0,
75-
color & 0xf0, color << 4 & 0xf0))
74+
colors.append((color >> 8 & 0xf0 | 0xf, color >> 4 & 0xf0 | 0xf,
75+
color & 0xf0 | 0xf, color << 4 & 0xf0 | 0xf))
7676
return colors
7777

7878
@staticmethod
@@ -81,8 +81,8 @@ def decode_rgba6(data, num_colors):
8181
offset = 0
8282
for i in range(num_colors):
8383
d = unpack_from('>3B', data, offset)
84-
colors.append((d[0] & 0xfc, (d[0] & 0x3) << 6 | (d[1] & 0xf0) >> 2,
85-
d[1] << 4 & 0xf0 | d[2] >> 4 & 0xc, d[2] << 2 & 0xfc))
84+
colors.append((d[0] & 0xfc | 0x3, (d[0] & 0x3) << 6 | (d[1] & 0xf0) >> 2 | 0x3,
85+
d[1] << 4 & 0xf0 | d[2] >> 4 & 0xc | 0x3, d[2] << 2 & 0xfc | 0x3))
8686
offset += 3
8787
return colors
8888

@@ -147,13 +147,13 @@ def decode_polygon(polygon, influences=None):
147147
influence_collection = InfluenceCollection({0: influence})
148148
for x in polygon.uv_mtx_indices:
149149
if x >= 0:
150-
AutoFix.get().warn('{} uv matrices data lost in export.'.format(polygon.name))
150+
AutoFix.warn('{} uv matrices data lost in export.'.format(polygon.name))
151151
indices = face_point_indices[:, :, x] // 3
152152
if (indices < 10).any():
153153
print('Less than 10!')
154154
from abmatt.converters.geometry import Geometry
155155
geometry = Geometry(polygon.name, polygon.get_material().name, g_verts,
156-
triangles=face_point_indices[:, :, vertex_index:], influences=influence_collection,
156+
triangles=None, influences=influence_collection,
157157
linked_bone=linked_bone)
158158
# create the point collections
159159
if normals:
@@ -254,7 +254,7 @@ def decode_indices(polygon, fmt_str):
254254
else:
255255
raise error.ConvertError('Texture matrices not supported')
256256
elif cmd == 0x00:
257-
AutoFix.get().warn('Finished parsing {} indices early, possible bug?'.format(polygon.name))
257+
AutoFix.warn('Finished parsing {} indices early, possible bug?'.format(polygon.name))
258258
break
259259
else:
260260
raise ValueError('Unsupported draw cmd {}'.format(cmd))
@@ -295,7 +295,7 @@ def decode_pos_mtx_indices(all_influences, weight_groups, vertices, pos_mtx_indi
295295
influences[vertex_index] = influence = all_influences[weight_indices[i]]
296296
points[vertex_index] = influence.apply_to(points[vertex_index], decode=True)
297297
elif influences[vertex_index].influence_id != weight_indices[i]:
298-
AutoFix.get().warn(f'vertex {vertex_index} has multiple different influences!')
298+
AutoFix.warn(f'vertex {vertex_index} has multiple different influences!')
299299
influences[vertex_index] = all_influences[weight_indices[i]]
300300

301301
# assert len(influences) == len(points)

abmatt/brres/lib/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def info(self, key='', indentation_level=0):
176176
else:
177177
key += ':' + self.get_str(key)
178178
start = '>' + indentation_level * ' '
179-
AutoFix.get().info('{}{}> {}'.format(start, self.name, key), 1)
179+
AutoFix.info('{}{}> {}'.format(start, self.name, key), 1)
180180

181181
def get_full_path(self):
182182
return os.path.join(self.parent.get_full_path(), self.name)

abmatt/brres/lib/unpacking/unpack_brres.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def generate_srt_collections(self, srt0_anims):
4141
anim_collections.append(collection)
4242
mdl = brres.get_model(key)
4343
if not mdl:
44-
AutoFix.get().info('No model found matching srt0 animation {} in {}'.format(key, brres.name), 3)
44+
AutoFix.info('No model found matching srt0 animation {} in {}'.format(key, brres.name), 3)
4545
else:
4646
mdl.set_srt0(collection)
4747
return anim_collections
@@ -57,7 +57,7 @@ def generate_pat0_collections(self, pat0_anims):
5757
anim_collections.append(collection)
5858
mdl = brres.get_model(key)
5959
if not mdl:
60-
AutoFix.get().info('No model found matching pat0 animation {} in {}'.format(key, brres.name), 3)
60+
AutoFix.info('No model found matching pat0 animation {} in {}'.format(key, brres.name), 3)
6161
else:
6262
mdl.set_pat0(collection)
6363
return anim_collections

abmatt/brres/lib/unpacking/unpack_mdl0/unpack_point.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def unpack(self, pt, binfile):
2222
binfile.advance(4)
2323
pt.index, pt.comp_count, pt.format, pt.divisor, pt.stride, pt.count = binfile.read('3I2BH', 16)
2424
if not self.is_valid_comp_count(pt.comp_count):
25-
AutoFix.get().error('{} has invalid component count {}, using default {}'.format(pt.name, pt.comp_count,
25+
AutoFix.error('{} has invalid component count {}, using default {}'.format(pt.name, pt.comp_count,
2626
pt.default_comp_count))
2727
pt.comp_count = pt.default_comp_count
2828
if not is_valid_format(pt.format):
@@ -37,7 +37,7 @@ def unpack(self, pt, binfile):
3737
pt.format = point.FMT_INT16
3838
else:
3939
pt.format = point.FMT_INT8
40-
AutoFix.get().error('{} has invalid format {}, using format {}'.format(pt.name, old_format,
40+
AutoFix.error('{} has invalid format {}, using format {}'.format(pt.name, old_format,
4141
point.FMT_STR[pt.format]))
4242
# print(self)
4343

0 commit comments

Comments
 (0)