diff --git a/blender2minecraft.py b/blender2minecraft.py index 15fbca2..0a8892c 100644 --- a/blender2minecraft.py +++ b/blender2minecraft.py @@ -25,7 +25,6 @@ nl = os.linesep tab = " " -particle = "" toRound = 2 @@ -97,9 +96,14 @@ def getDir(face): return ["west", [y, z]] raise Exception("This should never happen") +class attrdict(dict): + def __init__(self, *args, **kwargs): + dict.__init__(self, *args, **kwargs) + self.__dict__ = self def write_to_file(context, filepath, include_textures, ambientocclusion, firsttrans, firstscale, firstrot, thirdtrans, thirdscale, thirdrot, invtrans, invscale, invrot): textures = [] + particle = "" scene = context.scene objects = scene.objects file = open(filepath,'w', encoding='utf-8') @@ -203,10 +207,12 @@ def write_to_file(context, filepath, include_textures, ambientocclusion, firsttr if len(face.loops) == 4: direction, toUse = getDir(face) - uvs = [] - for i in range(0, len(face.loops)): - uvs.append([face.loops[i][uv_layer].uv[x] * 16, face.loops[i][uv_layer].uv[y] * 16]) - + try: + uvs = [] + for i in range(0, len(face.loops)): + uvs.append([face.loops[i][uv_layer].uv[x] * 16, face.loops[i][uv_layer].uv[y] * 16]) + except AttributeError: + uvs = [[16,16],[ 0,16],[ 0, 0],[16, 0]] max, min = getMaxMin(uvs, [x, y]) @@ -292,7 +298,11 @@ def write_to_file(context, filepath, include_textures, ambientocclusion, firsttr print(rot) print(mirror) - image = data.uv_textures.active.data[face.index].image + try: + image = data.uv_textures.active.data[face.index].image + except AttributeError: + image = attrdict(name=["texture"], filepath="") + name = [""] for c in image.name: if c != '.': @@ -713,7 +723,7 @@ def execute(self, context): # Only needed if you want to add into a dynamic menu def menu_func_export(self, context): - self.layout.operator(ExportBlockModel.bl_idname, text="Export to Minecraft") + self.layout.operator(ExportBlockModel.bl_idname, text="Minecraft model (.json)") def register():