From 7a10606c061ba557604d535a4458c323e0977f5e Mon Sep 17 00:00:00 2001 From: Kalle-Samuli Riihikoski Date: Wed, 8 Jun 2011 05:53:16 +0000 Subject: small bug fixes. Also fixed Image None issue. Thanks to Campbell for pointing this out. --- io_coat3D/coat.py | 106 ++++++++++++++++++++++++++++-------------------------- io_coat3D/tex.py | 92 +++++++++++++++++++++++++++++++---------------- 2 files changed, 118 insertions(+), 80 deletions(-) (limited to 'io_coat3D') diff --git a/io_coat3D/coat.py b/io_coat3D/coat.py index 72faf7e9..ede359df 100644 --- a/io_coat3D/coat.py +++ b/io_coat3D/coat.py @@ -218,62 +218,67 @@ class SCENE_OT_export(bpy.types.Operator): obj = scene.objects[activeobj] coa = bpy.context.scene.objects.active.coat3D - importfile = coat3D.exchangedir - texturefile = coat3D.exchangedir - importfile += ('%simport.txt'%(os.sep)) - texturefile += ('%stextures.txt'%(os.sep)) - if(os.path.isfile(texturefile)): - os.remove(texturefile) - - checkname = coa.objectdir - - if(coa.objectdir[-4:] != '.obj'): - checkname += ('%s.obj'%(activeobj)) + if(coa.objectdir == '' and (coat3D.defaultfolder)): + print('kalle osaa koodata') + coa.objectdir = coat3D.defaultfolder + else: - if(not(os.path.isfile(checkname)) or coat3D.exportover): - if(coat3D.export_pos): - bpy.ops.object.transform_apply(location=True,rotation=True,scale=True) + importfile = coat3D.exchangedir + texturefile = coat3D.exchangedir + importfile += ('%simport.txt'%(os.sep)) + texturefile += ('%stextures.txt'%(os.sep)) + if(os.path.isfile(texturefile)): + os.remove(texturefile) + + checkname = coa.objectdir + + if(coa.objectdir[-4:] != '.obj'): + checkname += ('%s.obj'%(activeobj)) - bpy.ops.export_scene.obj(filepath=checkname,use_selection=True, - use_apply_modifiers=coat3D.exportmod,use_blen_objects=False, group_by_material= True, - use_materials = False,keep_vertex_order = True,axis_forward='Y',axis_up='Z') - bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') + if(not(os.path.isfile(checkname)) or coat3D.exportover): + if(coat3D.export_pos): + bpy.ops.object.transform_apply(location=True,rotation=True,scale=True) - coa.export_on = True - else: - bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') - coat3D.loca = obj.location - coat3D.rota = obj.rotation_euler - coat3D.scal = obj.scale - obj.location = (0,0,0) - obj.rotation_euler = (0,0,0) - obj.scale = (1,1,1) - - bpy.ops.export_scene.obj(filepath=checkname,use_selection=True, - use_apply_modifiers=coat3D.exportmod,use_blen_objects=False, group_by_material= True, - use_materials = False,keep_vertex_order = True,axis_forward='Y',axis_up='Z') - - obj.location = coat3D.loca - obj.rotation_euler = coat3D.rota - obj.scale = coat3D.scal - coa.export_on = False - + bpy.ops.export_scene.obj(filepath=checkname,use_selection=True, + use_apply_modifiers=coat3D.exportmod,use_blen_objects=False, group_by_material= True, + use_materials = False,keep_vertex_order = True,axis_forward='Y',axis_up='Z') + bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') + + coa.export_on = True + else: + bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') + coat3D.loca = obj.location + coat3D.rota = obj.rotation_euler + coat3D.scal = obj.scale + obj.location = (0,0,0) + obj.rotation_euler = (0,0,0) + obj.scale = (1,1,1) + + bpy.ops.export_scene.obj(filepath=checkname,use_selection=True, + use_apply_modifiers=coat3D.exportmod,use_blen_objects=False, group_by_material= True, + use_materials = False,keep_vertex_order = True,axis_forward='Y',axis_up='Z') + + obj.location = coat3D.loca + obj.rotation_euler = coat3D.rota + obj.scale = coat3D.scal + coa.export_on = False + - if(coat3D.exportfile == False): - file = open(importfile, "w") - file.write("%s"%(checkname)) - file.write("\n%s"%(checkname)) - file.write("\n[%s]"%(coat3D.type)) - if(coa.texturefolder): - file.write("\n[TexOutput:%s"%(coa.texturefolder)) - + if(coat3D.exportfile == False): + file = open(importfile, "w") + file.write("%s"%(checkname)) + file.write("\n%s"%(checkname)) + file.write("\n[%s]"%(coat3D.type)) + if(coa.texturefolder): + file.write("\n[TexOutput:%s"%(coa.texturefolder)) + + - - - file.close() - coa.objectdir = checkname + + file.close() + coa.objectdir = checkname return('FINISHED') @@ -380,7 +385,8 @@ class SCENE_OT_import(bpy.types.Operator): for tex_slot in obj_mate.material.texture_slots: if(hasattr(tex_slot,'texture')): if(tex_slot.texture.type == 'IMAGE'): - tex_slot.texture.image.reload() + if tex_slot.texture.image is not None: + tex_slot.texture.image.reload() if(coat3D.importmod): diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py index b0fa169e..3d2c9d51 100644 --- a/io_coat3D/tex.py +++ b/io_coat3D/tex.py @@ -65,7 +65,8 @@ def gettex(mat_list, objekti, scene,export): for tex_slot in mate.material.texture_slots: if(hasattr(tex_slot,'texture')): if(tex_slot.texture.type == 'IMAGE'): - tex_slot.texture.image.reload() + if tex_slot.texture.image is not None: + tex_slot.texture.image.reload() else: coa = bpy.context.scene.objects.active.coat3D nimi = objname(coa.objectdir) @@ -142,20 +143,28 @@ def gettex(mat_list, objekti, scene,export): useold = seekco - if(useold == ''): - tex_name = setgallery() - - for num_tex in tex_name: - if(num_tex[:6] == 'Color_'): - num.append(num_tex) - luku_tex = len(num) - name_tex = ('Color_%s'%(luku_tex)) + indexx = 0 + tuli = False + lasku = False + while(lasku == False): + tuli = False + name_tex = ("Color_%s"%(indexx)) + for i in bpy.data.textures: + if(i.name == name_tex): + tuli = True + break + if(tuli): + indexx += 1 + else: + lasku = True + bpy.ops.image.new(name=name_tex) bpy.data.images[name_tex].filepath = texcoat['color'][0] bpy.data.images[name_tex].source = 'FILE' + print('name_tex: %s'%name_tex) bpy.data.textures.new(name_tex,type='IMAGE') @@ -170,8 +179,10 @@ def gettex(mat_list, objekti, scene,export): elif(useold != ''): + print('useold:%s'%useold) objekti.active_material.texture_slots[index].texture = useold + print(objekti.active_material) objekti.active_material.texture_slots[index].texture.image.filepath = texcoat['color'][0] if(objekti.data.uv_textures.active): objekti.active_material.texture_slots[index].texture_coords = 'UV' @@ -193,13 +204,20 @@ def gettex(mat_list, objekti, scene,export): if(useold == ''): - tex_name = setgallery() - - for num_tex in tex_name: - if(num_tex[:7] == 'Normal_'): - num.append(num_tex) - luku_tex = len(num) - name_tex = ('Normal_%s'%(luku_tex)) + indexx = 0 + tuli = False + lasku = False + while(lasku == False): + tuli = False + name_tex = ("Normal_%s"%(indexx)) + for i in bpy.data.textures: + if(i.name == name_tex): + tuli = True + break + if(tuli): + indexx += 1 + else: + lasku = True bpy.ops.image.new(name=name_tex) bpy.data.images[name_tex].filepath = texcoat['nmap'][0] @@ -260,13 +278,20 @@ def gettex(mat_list, objekti, scene,export): if(useold == ''): - tex_name = setgallery() - - for num_tex in tex_name: - if(num_tex[:9] == 'Specular_'): - num.append(num_tex) - luku_tex = len(num) - name_tex = ('Specular_%s'%(luku_tex)) + indexx = 0 + tuli = False + lasku = False + while(lasku == False): + tuli = False + name_tex = ("Specular_%s"%(indexx)) + for i in bpy.data.textures: + if(i.name == name_tex): + tuli = True + break + if(tuli): + indexx += 1 + else: + lasku = True bpy.ops.image.new(name=name_tex) bpy.data.images[name_tex].filepath = texcoat['specular'][0] @@ -317,13 +342,20 @@ def gettex(mat_list, objekti, scene,export): if(useold == ''): - tex_name = setgallery() - - for num_tex in tex_name: - if(num_tex[:13] == 'Displacement_'): - num.append(num_tex) - luku_tex = len(num) - name_tex = ('Displacement_%s'%(luku_tex)) + indexx = 0 + tuli = False + lasku = False + while(lasku == False): + tuli = False + name_tex = ("Displacement_%s"%(indexx)) + for i in bpy.data.textures: + if(i.name == name_tex): + tuli = True + break + if(tuli): + indexx += 1 + else: + lasku = True bpy.ops.image.new(name=name_tex) bpy.data.images[name_tex].filepath = texcoat['disp'][0] -- cgit v1.2.3