diff --git a/io_scene_3ds/export_3ds.py b/io_scene_3ds/export_3ds.py index 24013243d093143a390f62e2b9b9de2fdc5a39cf..5a4672971c54f937efd9847dc7e544d661b352dd 100644 --- a/io_scene_3ds/export_3ds.py +++ b/io_scene_3ds/export_3ds.py @@ -89,23 +89,24 @@ import struct # So 3ds max can open files, limit names to 12 in length # this is verry annoying for filenames! -name_unique = [] -name_mapping = {} +name_unique = [] # stores str, ascii only +name_mapping = {} # stores {orig: byte} mapping def sane_name(name): name_fixed = name_mapping.get(name) if name_fixed is not None: return name_fixed - new_name = name[:12] - + # strip non ascii chars + new_name_clean = new_name = name.encode("ASCII", "replace").decode("ASCII")[:12] i = 0 while new_name in name_unique: - new_name = new_name[:-4] + '.%.3d' % i + new_name = new_name_clean + ".%.3d" % i i+=1 + # note, appending the 'str' version. name_unique.append(new_name) - name_mapping[name] = new_name + name_mapping[name] = new_name = new_name.encode("ASCII", "replace") return new_name def uv_key(uv): @@ -167,7 +168,8 @@ class _3ds_string(object): '''Class representing a zero-terminated string for a 3ds file.''' __slots__ = ('value', ) def __init__(self, val): - self.value=val + assert(type(val) == bytes) + self.value = val def get_size(self): return (len(self.value)+1)