Skip to content

Commit

Permalink
wrap MTL parsing and fix py2 str issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Dec 14, 2018
1 parent d19eaee commit e755ecb
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions trimesh/io/wavefront.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def parse_mtl(mtl):
'map_Kd': None}

# use universal newline splitting
for line in str.splitlines(mtl.strip()):
for line in str.splitlines(str(mtl).strip()):
# clean leading/trailing whitespace and split
line_split = line.strip().split()
# needs to be at least two values
Expand Down Expand Up @@ -180,9 +180,8 @@ def append_mesh():
# save vertex texture with correct ordering
loaded['metadata']['vertex_texture'] = texture[vert_order]
except ValueError:
log.warning(
'Texture information seems broken: %s' % file_obj.name
)
log.warning('texture information seems broken'.format(
file_obj.name))

# build face groups information
# faces didn't move around so we don't have to reindex
Expand Down Expand Up @@ -272,19 +271,19 @@ def append_mesh():

# the name of the referenced material file
mtl_name = line_split[1]
# bytes containing MTL data
try:
# fetch bytes containing MTL data
mtl_data = resolver.get(mtl_name)
except:
log.error('unable to load material:', mtl_name)
# load into a dict
mtllib = parse_mtl(mtl_data)
# save new materials
if 'newmtl' in mtllib:
mtllibs[mtllib['newmtl']] = mtllib
except BaseException:
log.error('unable to load material: {}'.format(mtl_name),
exc_info=True)
continue

# loaded into a dict
mtllib = parse_mtl(mtl_data)

if 'newmtl' in mtllib:
mtllibs[mtllib['newmtl']] = mtllib

elif line_split[0] == 'usemtl':
current['usemtl'].append(line_split[1])

Expand Down

0 comments on commit e755ecb

Please sign in to comment.