From c973f3a1da9fbb7ba816455b761c6cc3f9535b78 Mon Sep 17 00:00:00 2001 From: Nobody Really Date: Sat, 9 Jul 2016 12:25:21 +0200 Subject: Flake8 compliance (except for unused variables) --- tools/export/blender25/io_scene_dae/__init__.py | 33 +- tools/export/blender25/io_scene_dae/export_dae.py | 1527 ++++++++++++--------- 2 files changed, 926 insertions(+), 634 deletions(-) (limited to 'tools/export/blender25/io_scene_dae') diff --git a/tools/export/blender25/io_scene_dae/__init__.py b/tools/export/blender25/io_scene_dae/__init__.py index 3bde01f2df..0b82e1537b 100644 --- a/tools/export/blender25/io_scene_dae/__init__.py +++ b/tools/export/blender25/io_scene_dae/__init__.py @@ -18,35 +18,30 @@ # +import bpy +from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty + +from bpy_extras.io_utils import ExportHelper bl_info = { "name": "Better Collada Exporter", "author": "Juan Linietsky", "blender": (2, 5, 8), "api": 38691, "location": "File > Import-Export", - "description": ("Export DAE Scenes, This plugin actually works better! otherwise contact me."), + "description": ("Export DAE Scenes, This plugin actually works better! " + "otherwise contact me."), "warning": "", "wiki_url": ("http://www.godotengine.org"), "tracker_url": "", "support": 'OFFICIAL', "category": "Import-Export"} - if "bpy" in locals(): import imp if "export_dae" in locals(): imp.reload(export_dae) -import bpy -from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty - -from bpy_extras.io_utils import (ExportHelper, - path_reference_mode, - axis_conversion, - ) - - class ExportDAE(bpy.types.Operator, ExportHelper): '''Selection to DAE''' bl_idname = "export_scene.dae" @@ -74,7 +69,8 @@ class ExportDAE(bpy.types.Operator, ExportHelper): use_export_selected = BoolProperty( name="Selected Objects", - description="Export only selected objects (and visible in active layers if that applies).", + description="Export only selected objects (and visible in active " + "layers if that applies).", default=False, ) use_mesh_modifiers = BoolProperty( @@ -84,7 +80,8 @@ class ExportDAE(bpy.types.Operator, ExportHelper): ) use_tangent_arrays = BoolProperty( name="Tangent Arrays", - description="Export Tangent and Binormal arrays (for normalmapping).", + description="Export Tangent and Binormal arrays " + "(for normalmapping).", default=False, ) use_triangles = BoolProperty( @@ -92,6 +89,7 @@ class ExportDAE(bpy.types.Operator, ExportHelper): description="Export Triangles instead of Polygons.", default=False, ) + use_copy_images = BoolProperty( name="Copy Images", description="Copy Images (create images/ subfolder)", @@ -109,12 +107,14 @@ class ExportDAE(bpy.types.Operator, ExportHelper): ) use_anim_action_all = BoolProperty( name="All Actions", - description=("Export all actions for the first armature found in separate DAE files"), + description=("Export all actions for the first armature found " + "in separate DAE files"), default=False, ) use_anim_skip_noexp = BoolProperty( name="Skip (-noexp) Actions", - description="Skip exporting of actions whose name end in (-noexp). Useful to skip control animations.", + description="Skip exporting of actions whose name end in (-noexp)." + " Useful to skip control animations.", default=True, ) use_anim_optimize = BoolProperty( @@ -140,7 +140,8 @@ class ExportDAE(bpy.types.Operator, ExportHelper): @property def check_extension(self): - return True # return self.batch_mode == 'OFF' + # return self.batch_mode == 'OFF' + return True def check(self, context): return True diff --git a/tools/export/blender25/io_scene_dae/export_dae.py b/tools/export/blender25/io_scene_dae/export_dae.py index 0b90a60eb8..9f8458c0da 100644 --- a/tools/export/blender25/io_scene_dae/export_dae.py +++ b/tools/export/blender25/io_scene_dae/export_dae.py @@ -46,101 +46,105 @@ import bpy import bmesh from mathutils import Vector, Matrix -# according to collada spec, order matters -S_ASSET=0 -S_IMGS=1 -S_FX=2 -S_MATS=3 -S_GEOM=4 -S_MORPH=5 -S_SKIN=6 -S_CONT=7 -S_CAMS=8 -S_LAMPS=9 -S_ANIM_CLIPS=10 -S_NODES=11 -S_ANIM=12 - -CMP_EPSILON=0.0001 +# According to collada spec, order matters +S_ASSET = 0 +S_IMGS = 1 +S_FX = 2 +S_MATS = 3 +S_GEOM = 4 +S_MORPH = 5 +S_SKIN = 6 +S_CONT = 7 +S_CAMS = 8 +S_LAMPS = 9 +S_ANIM_CLIPS = 10 +S_NODES = 11 +S_ANIM = 12 + +CMP_EPSILON = 0.0001 + def snap_tup(tup): - ret=() + ret = () for x in tup: - ret+=( x-math.fmod(x, 0.0001), ) + ret += (x - math.fmod(x, 0.0001), ) return tup def strmtx(mtx): - s=" " + s = " " for x in range(4): for y in range(4): - s+=str(mtx[x][y]) - s+=" " - s+=" " + s += str(mtx[x][y]) + s += " " + s += " " return s + def numarr(a, mult=1.0): - s=" " + s = " " for x in a: - s+=" "+str(x*mult) - s+=" " + s += " " + str(x * mult) + s += " " return s def numarr_alpha(a, mult=1.0): - s=" " + s = " " for x in a: - s+=" "+str(x*mult) + s += " " + str(x * mult) if len(a) == 3: - s+=" 1.0" - s+=" " + s += " 1.0" + s += " " return s def strarr(arr): - s=" " + s = " " for x in arr: - s+=" "+str(x) - s+=" " + s += " " + str(x) + s += " " return s class DaeExporter: def validate_id(self, d): - if (d.find("id-")==0): - return "z"+d + if (d.find("id-") == 0): + return "z" + d return d def new_id(self, t): - self.last_id+=1 - return "id-"+t+"-"+str(self.last_id) + self.last_id += 1 + return "id-" + t + "-" + str(self.last_id) class Vertex: - def close_to(v): - if ( (self.vertex-v.vertex).length() > CMP_EPSILON ): + def close_to(self, v): + if self.vertex - v.vertex.length() > CMP_EPSILON: return False - if ( (self.normal-v.normal).length() > CMP_EPSILON ): + if self.normal - v.normal.length() > CMP_EPSILON: return False - if ( (self.uv-v.uv).length() > CMP_EPSILON ): + if self.uv - v.uv.length() > CMP_EPSILON: return False - if ( (self.uv2-v.uv2).length() > CMP_EPSILON ): + if self.uv2 - v.uv2.length() > CMP_EPSILON: return False return True def get_tup(self): - tup = (self.vertex.x, self.vertex.y, self.vertex.z, self.normal.x, self.normal.y, self.normal.z) + tup = (self.vertex.x, self.vertex.y, self.vertex.z, self.normal.x, + self.normal.y, self.normal.z) for t in self.uv: tup = tup + (t.x, t.y) - if (self.color!=None): + if self.color is not None: tup = tup + (self.color.x, self.color.y, self.color.z) - if (self.tangent!=None): + if self.tangent is not None: tup = tup + (self.tangent.x, self.tangent.y, self.tangent.z) - if (self.bitangent!=None): - tup = tup + (self.bitangent.x, self.bitangent.y, self.bitangent.z) + if self.bitangent is not None: + tup = tup + (self.bitangent.x, self.bitangent.y, + self.bitangent.z) for t in self.bones: tup = tup + (float(t), ) for t in self.weights: @@ -149,23 +153,23 @@ class DaeExporter: return tup def __init__(self): - self.vertex = Vector( (0.0, 0.0, 0.0) ) - self.normal = Vector( (0.0, 0.0, 0.0) ) + self.vertex = Vector((0.0, 0.0, 0.0)) + self.normal = Vector((0.0, 0.0, 0.0)) self.tangent = None self.bitangent = None self.color = None self.uv = [] - self.uv2 = Vector( (0.0, 0.0) ) - self.bones=[] - self.weights=[] + self.uv2 = Vector((0.0, 0.0)) + self.bones = [] + self.weights = [] def writel(self, section, indent, text): if (not (section in self.sections)): - self.sections[section]=[] - line="" + self.sections[section] = [] + line = "" for x in range(indent): - line+="\t" - line+=text + line += "\t" + line += text self.sections[section].append(line) def export_image(self, image): @@ -173,62 +177,72 @@ class DaeExporter: return self.image_cache[image] imgpath = image.filepath - if (imgpath.find("//")==0 or imgpath.find("\\\\")==0): - #if relative, convert to absolute + if (imgpath.find("//") == 0 or imgpath.find("\\\\") == 0): + # If relative, convert to absolute imgpath = bpy.path.abspath(imgpath) - #path is absolute, now do something! + # Path is absolute, now do something! + if (self.config["use_copy_images"]): - #copy image - basedir = os.path.dirname(self.path)+"/images" + # copy image + basedir = os.path.dirname(self.path) + "/images" if (not os.path.isdir(basedir)): os.makedirs(basedir) if os.path.isfile(imgpath): - dstfile=basedir+"/"+os.path.basename(imgpath) + dstfile = basedir + "/" + os.path.basename(imgpath) - if (not os.path.isfile(dstfile)): + if not os.path.isfile(dstfile): shutil.copy(imgpath, dstfile) - imgpath="images/"+os.path.basename(imgpath) + imgpath = "images/" + os.path.basename(imgpath) else: - ### if file is not found save it as png file in the destination folder + # If file is not found save it as png file in the destination + # folder img_tmp_path = image.filepath - if img_tmp_path.endswith((".bmp", ".rgb", ".png", ".jpeg", ".jpg", ".jp2", ".tga", ".cin", ".dpx", ".exr", ".hdr", ".tif")): - image.filepath = basedir+"/"+os.path.basename(img_tmp_path) + if img_tmp_path.endswith((".bmp", ".rgb", ".png", ".jpeg", + ".jpg", ".jp2", ".tga", ".cin", + ".dpx", ".exr", ".hdr", ".tif")): + image.filepath = basedir + "/" + \ + os.path.basename(img_tmp_path) else: - image.filepath = basedir+"/"+image.name+".png" - - dstfile=basedir+"/"+os.path.basename(image.filepath) + image.filepath = basedir + "/" + image.name + ".png" - if (not os.path.isfile(dstfile)): + dstfile = basedir + "/" + os.path.basename(image.filepath) + if not os.path.isfile(dstfile): image.save() - imgpath="images/"+os.path.basename(image.filepath) + imgpath = "images/" + os.path.basename(image.filepath) image.filepath = img_tmp_path else: - #export relative, always, no one wants absolute paths. + # Export relative, always, no one wants absolute paths. try: - imgpath = os.path.relpath(imgpath, os.path.dirname(self.path)).replace("\\", "/") # export unix compatible always + # Export unix compatible always + imgpath = os.path.relpath( + imgpath, os.path.dirname(self.path)).replace("\\", "/") except: - pass #fails sometimes, not sure why + # Fails sometimes, not sure why + pass imgid = self.new_id("image") - print("FOR: "+imgpath) + print("FOR: " + imgpath) # if (not os.path.isfile(imgpath)): # print("NOT FILE?") -# if imgpath.endswith((".bmp", ".rgb", ".png", ".jpeg", ".jpg", ".jp2", ".tga", ".cin", ".dpx", ".exr", ".hdr", ".tif")): +# if imgpath.endswith((".bmp", ".rgb", ".png", ".jpeg", ".jpg", +# ".jp2", ".tga", ".cin", ".dpx", ".exr", +# ".hdr", ".tif")): # imgpath="images/"+os.path.basename(imgpath) # else: # imgpath="images/"+image.name+".png" - self.writel(S_IMGS, 1, '') - self.writel(S_IMGS, 2, ''+imgpath+'') + self.writel(S_IMGS, 1, '') + self.writel(S_IMGS, 2, '' + imgpath + '') self.writel(S_IMGS, 1, '') - self.image_cache[image]=imgid + self.image_cache[image] = imgid return imgid def export_material(self, material, double_sided_hint=True): @@ -236,117 +250,136 @@ class DaeExporter: return self.material_cache[material] fxid = self.new_id("fx") - self.writel(S_FX, 1, '') + self.writel(S_FX, 1, '') self.writel(S_FX, 2, '') - #Find and fetch the textures and create sources - sampler_table={} - diffuse_tex=None - specular_tex=None - emission_tex=None - normal_tex=None + # Find and fetch the textures and create sources + sampler_table = {} + diffuse_tex = None + specular_tex = None + emission_tex = None + normal_tex = None for i in range(len(material.texture_slots)): - ts=material.texture_slots[i] - if (not ts): + ts = material.texture_slots[i] + if not ts: continue - if (not ts.use): + if not ts.use: continue - if (not ts.texture): + if not ts.texture: continue - if (ts.texture.type!="IMAGE"): + if ts.texture.type != "IMAGE": continue - if (ts.texture.image==None): + if ts.texture.image is None: continue - #image + # Image imgid = self.export_image(ts.texture.image) - #surface + # Surface surface_sid = self.new_id("fx_surf") - self.writel(S_FX, 3, '') + self.writel(S_FX, 3, '') self.writel(S_FX, 4, '') - self.writel(S_FX, 5, ''+imgid+'') #this is sooo weird + # This is sooo weird + self.writel(S_FX, 5, '' + imgid + '') self.writel(S_FX, 5, 'A8R8G8B8') self.writel(S_FX, 4, '') self.writel(S_FX, 3, '') - #sampler, collada sure likes it difficult + # Sampler, collada sure likes it difficult sampler_sid = self.new_id("fx_sampler") - self.writel(S_FX, 3, '') + self.writel(S_FX, 3, '') self.writel(S_FX, 4, '') - self.writel(S_FX, 5, ''+surface_sid+'') + self.writel(S_FX, 5, '' + surface_sid + '') self.writel(S_FX, 4, '') self.writel(S_FX, 3, '') - sampler_table[i]=sampler_sid + sampler_table[i] = sampler_sid - if (ts.use_map_color_diffuse and diffuse_tex==None): - diffuse_tex=sampler_sid - if (ts.use_map_color_spec and specular_tex==None): - specular_tex=sampler_sid - if (ts.use_map_emit and emission_tex==None): - emission_tex=sampler_sid - if (ts.use_map_normal and normal_tex==None): - normal_tex=sampler_sid + if ts.use_map_color_diffuse and diffuse_tex is None: + diffuse_tex = sampler_sid + if ts.use_map_color_spec and specular_tex is None: + specular_tex = sampler_sid + if ts.use_map_emit and emission_tex is None: + emission_tex = sampler_sid + if ts.use_map_normal and normal_tex is None: + normal_tex = sampler_sid self.writel(S_FX, 3, '') - shtype="blinn" - self.writel(S_FX, 4, '<'+shtype+'>') - #ambient? from where? + shtype = "blinn" + self.writel(S_FX, 4, '<' + shtype + '>') + # Ambient? from where? self.writel(S_FX, 5, '') - if (emission_tex!=None): - self.writel(S_FX, 6, '') + if emission_tex is not None: + self.writel(S_FX, 6, '') else: - self.writel(S_FX, 6, ''+numarr_alpha(material.diffuse_color, material.emit)+' ') # not totally right but good enough + self.writel(S_FX, 6, '' + + numarr_alpha(material.diffuse_color, material.emit) + + ' ') # not totally right but good enough self.writel(S_FX, 5, '') self.writel(S_FX, 5, '') - self.writel(S_FX, 6, ''+numarr_alpha(self.scene.world.ambient_color, material.ambient)+' ') + self.writel(S_FX, 6, '' + + numarr_alpha(self.scene.world.ambient_color, + material.ambient) + ' ') self.writel(S_FX, 5, '') self.writel(S_FX, 5, '') - if (diffuse_tex!=None): - self.writel(S_FX, 6, '') + if diffuse_tex is not None: + self.writel(S_FX, 6, '') else: - self.writel(S_FX, 6, ''+numarr_alpha(material.diffuse_color, material.diffuse_intensity)+'') + self.writel(S_FX, 6, + '' + numarr_alpha(material.diffuse_color, + material.diffuse_intensity) + + '') self.writel(S_FX, 5, '') self.writel(S_FX, 5, '') - if (specular_tex!=None): - self.writel(S_FX, 6, '') + if specular_tex is not None: + self.writel(S_FX, 6, '') else: - self.writel(S_FX, 6, ''+numarr_alpha(material.specular_color, material.specular_intensity)+'') + self.writel(S_FX, 6, '' + numarr_alpha( + material.specular_color, material.specular_intensity) + + '') self.writel(S_FX, 5, '') self.writel(S_FX, 5, '') - self.writel(S_FX, 6, ''+str(material.specular_hardness)+'') + self.writel(S_FX, 6, '' + str(material.specular_hardness) + + '') self.writel(S_FX, 5, '') self.writel(S_FX, 5, '') - self.writel(S_FX, 6, ''+numarr_alpha(material.mirror_color)+'') + self.writel(S_FX, 6, '' + numarr_alpha(material.mirror_color) + + '') self.writel(S_FX, 5, '') if (material.use_transparency): self.writel(S_FX, 5, '') - self.writel(S_FX, 6, ''+str(material.alpha)+'') + self.writel(S_FX, 6, '' + str(material.alpha) + '') self.writel(S_FX, 5, '') self.writel(S_FX, 5, '') - self.writel(S_FX, 6, ''+str(material.specular_ior)+'') + self.writel(S_FX, 6, '' + str(material.specular_ior) + + '') self.writel(S_FX, 5, '') - self.writel(S_FX, 4, '') + self.writel(S_FX, 4, '') self.writel(S_FX, 4, '') self.writel(S_FX, 5, '') if (normal_tex): self.writel(S_FX, 6, '') - self.writel(S_FX, 7, '') + self.writel(S_FX, 7, '') self.writel(S_FX, 6, '') self.writel(S_FX, 5, '') self.writel(S_FX, 5, '') - self.writel(S_FX, 6, ''+["0", "1"][double_sided_hint]+"") + self.writel(S_FX, 6, '' + ["0", "1"][double_sided_hint] + + "") self.writel(S_FX, 5, '') if (material.use_shadeless): @@ -364,34 +397,37 @@ class DaeExporter: # Material matid = self.new_id("material") - self.writel(S_MATS, 1, '') - self.writel(S_MATS, 2, '') + self.writel(S_MATS, 1, '') + self.writel(S_MATS, 2, '') self.writel(S_MATS, 1, '') - self.material_cache[material]=matid + self.material_cache[material] = matid return matid - def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None, custom_name=None): + def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None, + custom_name=None): mesh = node.data if (node.data in self.mesh_cache): return self.mesh_cache[mesh] - if (skeyindex==-1 and mesh.shape_keys!=None and len(mesh.shape_keys.key_blocks)): - values=[] - morph_targets=[] - md=None + if (skeyindex == -1 and mesh.shape_keys is not None and len( + mesh.shape_keys.key_blocks)): + values = [] + morph_targets = [] + md = None for k in range(0, len(mesh.shape_keys.key_blocks)): shape = node.data.shape_keys.key_blocks[k] - values+=[shape.value] #save value - shape.value=0 + values += [shape.value] # save value + shape.value = 0 mid = self.new_id("morph") for k in range(0, len(mesh.shape_keys.key_blocks)): shape = node.data.shape_keys.key_blocks[k] - node.show_only_shape_key=True + node.show_only_shape_key = True node.active_shape_key_index = k shape.value = 1.0 mesh.update() @@ -405,10 +441,10 @@ class DaeExporter: node.data = v # self.export_node(node, il, shape.name) node.data.update() - if (armature and k==0): - md=self.export_mesh(node, armature, k, mid, shape.name) + if (armature and k == 0): + md = self.export_mesh(node, armature, k, mid, shape.name) else: - md=self.export_mesh(node, None, k, None, shape.name) + md = self.export_mesh(node, None, k, None, shape.name) node.data = p node.data.update() @@ -418,84 +454,103 @@ class DaeExporter: """ shape.value = oldval """ - node.show_only_shape_key=False + node.show_only_shape_key = False node.active_shape_key_index = 0 - self.writel(S_MORPH, 1, '') - #if ("skin_id" in morph_targets[0]): - # self.writel(S_MORPH, 2, '') - #else: - self.writel(S_MORPH, 2, '') - - self.writel(S_MORPH, 3, '') - self.writel(S_MORPH, 4, '') - marr="" - warr="" + self.writel(S_MORPH, 1, '') + # if ("skin_id" in morph_targets[0]): + # self.writel(S_MORPH, 2, '') + # else: + self.writel(S_MORPH, 2, '') + + self.writel(S_MORPH, 3, '') + self.writel(S_MORPH, 4, '') + marr = "" + warr = "" for i in range(len(morph_targets)): - if (i==0): + if (i == 0): continue - elif (i>1): - marr+=" " + elif (i > 1): + marr += " " if ("skin_id" in morph_targets[i]): - marr+=morph_targets[i]["skin_id"] + marr += morph_targets[i]["skin_id"] else: - marr+=morph_targets[i]["id"] + marr += morph_targets[i]["id"] - warr+=" 0" + warr += " 0" self.writel(S_MORPH, 5, marr) self.writel(S_MORPH, 4, '') self.writel(S_MORPH, 4, '') - self.writel(S_MORPH, 5, '') - self.writel(S_MORPH, 6, '') + self.writel(S_MORPH, 5, '') + self.writel( + S_MORPH, 6, '') self.writel(S_MORPH, 5, '') self.writel(S_MORPH, 4, '') self.writel(S_MORPH, 3, '') - self.writel(S_MORPH, 3, '') - self.writel(S_MORPH, 4, '') + self.writel(S_MORPH, 3, '') + self.writel(S_MORPH, 4, '') self.writel(S_MORPH, 5, warr) self.writel(S_MORPH, 4, '') self.writel(S_MORPH, 4, '') - self.writel(S_MORPH, 5, '') - self.writel(S_MORPH, 6, '') + self.writel(S_MORPH, 5, '') + self.writel( + S_MORPH, 6, '') self.writel(S_MORPH, 5, '') self.writel(S_MORPH, 4, '') self.writel(S_MORPH, 3, '') self.writel(S_MORPH, 3, '') - self.writel(S_MORPH, 4, '') - self.writel(S_MORPH, 4, '') + self.writel( + S_MORPH, 4, '') + self.writel( + S_MORPH, 4, '') self.writel(S_MORPH, 3, '') self.writel(S_MORPH, 2, '') self.writel(S_MORPH, 1, '') - if (armature!=None): + if armature is not None: - self.armature_for_morph[node]=armature + self.armature_for_morph[node] = armature - meshdata={} + meshdata = {} if (armature): meshdata = morph_targets[0] - meshdata["morph_id"]=mid + meshdata["morph_id"] = mid else: - meshdata["id"]=morph_targets[0]["id"] - meshdata["morph_id"]=mid - meshdata["material_assign"]=morph_targets[0]["material_assign"] + meshdata["id"] = morph_targets[0]["id"] + meshdata["morph_id"] = mid + meshdata["material_assign"] = morph_targets[ + 0]["material_assign"] - self.mesh_cache[node.data]=meshdata + self.mesh_cache[node.data] = meshdata return meshdata - apply_modifiers = len(node.modifiers) and self.config["use_mesh_modifiers"] + apply_modifiers = len(node.modifiers) and self.config[ + "use_mesh_modifiers"] name_to_use = mesh.name - #print("name to use: "+mesh.name) - if (custom_name!=None and custom_name!=""): - name_to_use=custom_name + # print("name to use: "+mesh.name) + if (custom_name is not None and custom_name != ""): + name_to_use = custom_name - mesh=node.to_mesh(self.scene, apply_modifiers, "RENDER") #is this allright? + mesh = node.to_mesh(self.scene, apply_modifiers, + "RENDER") # is this allright? - triangulate=self.config["use_triangles"] + triangulate = self.config["use_triangles"] if (triangulate): bm = bmesh.new() bm.from_mesh(mesh) @@ -504,60 +559,66 @@ class DaeExporter: bm.free() mesh.update(calc_tessface=True) - vertices=[] - vertex_map={} - surface_indices={} - materials={} - - materials={} - - si=None - if (armature!=None): - si=self.skeleton_info[armature] - - has_uv=False - has_uv2=False - has_weights=armature!=None - has_tangents=self.config["use_tangent_arrays"] # could detect.. - has_colors=len(mesh.vertex_colors) - mat_assign=[] - - uv_layer_count=len(mesh.uv_textures) - if (has_tangents and len(mesh.uv_textures)): + vertices = [] + vertex_map = {} + surface_indices = {} + materials = {} + + materials = {} + + si = None + if armature is not None: + si = self.skeleton_info[armature] + + has_uv = False + has_uv2 = False + has_weights = armature is not None + has_tangents = self.config["use_tangent_arrays"] # could detect.. + has_colors = len(mesh.vertex_colors) + mat_assign = [] + + uv_layer_count = len(mesh.uv_textures) + if has_tangents and len(mesh.uv_textures): try: mesh.calc_tangents() except: - self.operator.report({'WARNING'}, 'CalcTangets failed for mesh "'+mesh.name+'", no tangets will be exported.') - #uv_layer_count=0 + self.operator.report( + {'WARNING'}, 'CalcTangets failed for mesh "' + mesh.name + + '", no tangets will be exported.') + # uv_layer_count=0 mesh.calc_normals_split() - has_tangents=False + has_tangents = False else: mesh.calc_normals_split() - has_tangents=False + has_tangents = False for fi in range(len(mesh.polygons)): - f=mesh.polygons[fi] + f = mesh.polygons[fi] - if (not (f.material_index in surface_indices)): - surface_indices[f.material_index]=[] - #print("Type: "+str(type(f.material_index))) - #print("IDX: "+str(f.material_index)+"/"+str(len(mesh.materials))) + if not (f.material_index in surface_indices): + surface_indices[f.material_index] = [] + # print("Type: " + str(type(f.material_index))) + # print("IDX: " + str(f.material_index) + "/" + str( + # len(mesh.materials))) try: - #Bizarre blender behavior i don't understand, so catching exception + # Bizarre blender behavior i don't understand, + # so catching exception mat = mesh.materials[f.material_index] except: - mat= None + mat = None - if (mat!=None): - materials[f.material_index]=self.export_material( mat, mesh.show_double_sided ) + if (mat is not None): + materials[f.material_index] = self.export_material( + mat, mesh.show_double_sided) else: - materials[f.material_index]=None #weird, has no material? + # weird, has no material? + materials[f.material_index] = None indices = surface_indices[f.material_index] - vi=[] - #vertices always 3 + vi = [] + # Vertices always 3 """ if (len(f.vertices)==3): vi.append(0) @@ -579,78 +640,92 @@ class DaeExporter: mv = mesh.vertices[ml.vertex_index] v = self.Vertex() - v.vertex = Vector( mv.co ) + v.vertex = Vector(mv.co) for xt in mesh.uv_layers: - v.uv.append( Vector( xt.data[loop_index].uv ) ) + v.uv.append(Vector(xt.data[loop_index].uv)) if (has_colors): - v.color = Vector( mesh.vertex_colors[0].data[loop_index].color ) + v.color = Vector( + mesh.vertex_colors[0].data[loop_index].color) - v.normal = Vector( ml.normal ) + v.normal = Vector(ml.normal) if (has_tangents): - v.tangent = Vector( ml.tangent ) - v.bitangent = Vector( ml.bitangent ) + v.tangent = Vector(ml.tangent) + v.bitangent = Vector(ml.bitangent) - # if (armature): - # v.vertex = node.matrix_world * v.vertex + # if (armature): + # v.vertex = node.matrix_world * v.vertex - #v.color=Vertex(mv. ??? + # v.color=Vertex(mv. ??? - if (armature!=None): - wsum=0.0 - zero_bones=[] + if armature is not None: + wsum = 0.0 + zero_bones = [] for vg in mv.groups: if vg.group >= len(node.vertex_groups): - continue; + continue name = node.vertex_groups[vg.group].name if (name in si["bone_index"]): - #could still put the weight as 0.0001 maybe - if (vg.weight>0.001): #blender has a lot of zero weight stuff + # could still put the weight as 0.0001 maybe + # blender has a lot of zero weight stuff + if (vg.weight > 0.001): v.bones.append(si["bone_index"][name]) v.weights.append(vg.weight) - wsum+=vg.weight - if (wsum==0.0): + wsum += vg.weight + if (wsum == 0.0): if not self.wrongvtx_report: - self.operator.report({'WARNING'}, 'Mesh for object "'+node.name+'" has unassigned weights. This may look wrong in exported model.') - self.wrongvtx_report=True - - #blender can have bones assigned that weight zero so they remain local - #this is the best it can be done? + self.operator.report( + {'WARNING'}, 'Mesh for object "' + node.name + + '" has unassigned weights. ' + 'This may look wrong in exported model.') + self.wrongvtx_report = True + + # blender can have bones assigned that weight zero + # so they remain local + # this is the best it can be done? v.bones.append(0) v.weights.append(1) tup = v.get_tup() idx = 0 - if (skeyindex==-1 and tup in vertex_map): #do not optmize if using shapekeys + # do not optmize if using shapekeys + if (skeyindex == -1 and tup in vertex_map): idx = vertex_map[tup] else: idx = len(vertices) vertices.append(v) - vertex_map[tup]=idx + vertex_map[tup] = idx vi.append(idx) - if (len(vi)>2): - #only triangles and above + if (len(vi) > 2): + # only triangles and above indices.append(vi) meshid = self.new_id("mesh") - self.writel(S_GEOM, 1, '') + self.writel(S_GEOM, 1, '') self.writel(S_GEOM, 2, '') # Vertex Array - self.writel(S_GEOM, 3, '') - float_values="" + self.writel(S_GEOM, 3, '') + float_values = "" for v in vertices: - float_values+=" "+str(v.vertex.x)+" "+str(v.vertex.y)+" "+str(v.vertex.z) - self.writel(S_GEOM, 4, ''+float_values+'') + float_values += " " + str(v.vertex.x) + " " + \ + str(v.vertex.y) + " " + str(v.vertex.z) + self.writel(S_GEOM, 4, '' + float_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') @@ -660,13 +735,19 @@ class DaeExporter: # Normal Array - self.writel(S_GEOM, 3, '') - float_values="" + self.writel(S_GEOM, 3, '') + float_values = "" for v in vertices: - float_values+=" "+str(v.normal.x)+" "+str(v.normal.y)+" "+str(v.normal.z) - self.writel(S_GEOM, 4, ''+float_values+'') + float_values += " " + str(v.normal.x) + " " + \ + str(v.normal.y) + " " + str(v.normal.z) + self.writel(S_GEOM, 4, '' + float_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') @@ -675,13 +756,20 @@ class DaeExporter: self.writel(S_GEOM, 3, '') if (has_tangents): - self.writel(S_GEOM, 3, '') - float_values="" + self.writel(S_GEOM, 3, '') + float_values = "" for v in vertices: - float_values+=" "+str(v.tangent.x)+" "+str(v.tangent.y)+" "+str(v.tangent.z) - self.writel(S_GEOM, 4, ''+float_values+'') + float_values += " " + \ + str(v.tangent.x) + " " + \ + str(v.tangent.y) + " " + str(v.tangent.z) + self.writel(S_GEOM, 4, '' + float_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') @@ -689,13 +777,20 @@ class DaeExporter: self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 3, '') - self.writel(S_GEOM, 3, '') - float_values="" + self.writel(S_GEOM, 3, '') + float_values = "" for v in vertices: - float_values+=" "+str(v.bitangent.x)+" "+str(v.bitangent.y)+" "+str(v.bitangent.z) - self.writel(S_GEOM, 4, ''+float_values+'') + float_values += " " + \ + str(v.bitangent.x) + " " + \ + str(v.bitangent.y) + " " + str(v.bitangent.z) + self.writel(S_GEOM, 4, '' + float_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') @@ -704,20 +799,30 @@ class DaeExporter: self.writel(S_GEOM, 3, '') # UV Arrays + for uvi in range(uv_layer_count): - self.writel(S_GEOM, 3, '') - float_values="" + self.writel(S_GEOM, 3, '') + float_values = "" for v in vertices: try: - float_values+=" "+str(v.uv[uvi].x)+" "+str(v.uv[uvi].y) + float_values += " " + \ + str(v.uv[uvi].x) + " " + str(v.uv[uvi].y) except: - # I don't understand this weird multi-uv-layer API, but with this it seems to works - float_values+=" 0 0 " - - self.writel(S_GEOM, 4, ''+float_values+'') + # I don't understand this weird multi-uv-layer API, but + # with this it seems to works + float_values += " 0 0 " + + self.writel(S_GEOM, 4, '' + + float_values + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 4, '') @@ -727,13 +832,20 @@ class DaeExporter: # Color Arrays if (has_colors): - self.writel(S_GEOM, 3, '') - float_values="" + self.writel(S_GEOM, 3, '') + float_values = "" for v in vertices: - float_values+=" "+str(v.color.x)+" "+str(v.color.y)+" "+str(v.color.z) - self.writel(S_GEOM, 4, ''+float_values+'') + float_values += " " + \ + str(v.color.x) + " " + \ + str(v.color.y) + " " + str(v.color.z) + self.writel(S_GEOM, 4, '' + float_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') @@ -742,203 +854,257 @@ class DaeExporter: self.writel(S_GEOM, 3, '') # Triangle Lists - self.writel(S_GEOM, 3, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 3, '') + self.writel( + S_GEOM, 4, '') self.writel(S_GEOM, 3, '') - prim_type="" + prim_type = "" if (triangulate): - prim_type="triangles" + prim_type = "triangles" else: - prim_type="polygons" + prim_type = "polygons" for m in surface_indices: indices = surface_indices[m] mat = materials[m] - if (mat!=None): + if (mat is not None): matref = self.new_id("trimat") - self.writel(S_GEOM, 3, '<'+prim_type+' count="'+str(int(len(indices)))+'" material="'+matref+'">') # todo material - mat_assign.append( (mat, matref) ) + self.writel(S_GEOM, 3, '<' + prim_type + ' count="' + str( + int(len(indices))) + '" material="' + matref + + '">') # todo material + mat_assign.append((mat, matref)) else: - self.writel(S_GEOM, 3, '<'+prim_type+' count="'+str(int(len(indices)))+'">') # todo material + self.writel(S_GEOM, 3, '<' + prim_type + ' count="' + + str(int(len(indices))) + '">') # todo material - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') for uvi in range(uv_layer_count): - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') if (has_colors): - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') if (has_tangents): - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, + '') + self.writel(S_GEOM, 4, + '') if (triangulate): - int_values="

" + int_values = "

" for p in indices: for i in p: - int_values+=" "+str(i) - int_values+="

" + int_values += " " + str(i) + int_values += "

" self.writel(S_GEOM, 4, int_values) else: for p in indices: - int_values="

" + int_values = "

" for i in p: - int_values+=" "+str(i) - int_values+="

" + int_values += " " + str(i) + int_values += "

" self.writel(S_GEOM, 4, int_values) - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, '') self.writel(S_GEOM, 2, '
') self.writel(S_GEOM, 1, '
') - meshdata={} - meshdata["id"]=meshid - meshdata["material_assign"]=mat_assign - if (skeyindex==-1): - self.mesh_cache[node.data]=meshdata + meshdata = {} + meshdata["id"] = meshid + meshdata["material_assign"] = mat_assign + if (skeyindex == -1): + self.mesh_cache[node.data] = meshdata # Export armature data (if armature exists) - if (armature!=None and (skel_source!=None or skeyindex==-1)): + + if (armature is not None and ( + skel_source is not None or skeyindex == -1)): contid = self.new_id("controller") - self.writel(S_SKIN, 1, '') - if (skel_source!=None): - self.writel(S_SKIN, 2, '') + self.writel(S_SKIN, 1, '') + if (skel_source is not None): + self.writel(S_SKIN, 2, '') else: - self.writel(S_SKIN, 2, '') + self.writel(S_SKIN, 2, '') - self.writel(S_SKIN, 3, ''+strmtx(node.matrix_world)+'') - #Joint Names - self.writel(S_SKIN, 3, '') - name_values="" + self.writel(S_SKIN, 3, '' + + strmtx(node.matrix_world) + '') + # Joint Names + self.writel(S_SKIN, 3, '') + name_values = "" for v in si["bone_names"]: - name_values+=" "+v + name_values += " " + v - self.writel(S_SKIN, 4, ''+name_values+'') + self.writel(S_SKIN, 4, '' + name_values + + '') self.writel(S_SKIN, 4, '') - self.writel(S_SKIN, 4, '') + self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 5, '') self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 3, '') - #Pose Matrices! - self.writel(S_SKIN, 3, '') - pose_values="" + # Pose Matrices! + self.writel(S_SKIN, 3, '') + pose_values = "" for v in si["bone_bind_poses"]: - pose_values+=" "+strmtx(v) + pose_values += " " + strmtx(v) - self.writel(S_SKIN, 4, ''+pose_values+'') + self.writel(S_SKIN, 4, '' + + pose_values + '') self.writel(S_SKIN, 4, '') - self.writel(S_SKIN, 4, '') + self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 5, '') self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 3, '') - #Skin Weights! - self.writel(S_SKIN, 3, '') - skin_weights="" - skin_weights_total=0 + # Skin Weights! + self.writel(S_SKIN, 3, '') + skin_weights = "" + skin_weights_total = 0 for v in vertices: - skin_weights_total+=len(v.weights) + skin_weights_total += len(v.weights) for w in v.weights: - skin_weights+=" "+str(w) + skin_weights += " " + str(w) - self.writel(S_SKIN, 4, ''+skin_weights+'') + self.writel(S_SKIN, 4, '' + skin_weights + + '') self.writel(S_SKIN, 4, '') - self.writel(S_SKIN, 4, '') + self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 5, '') self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 4, '') self.writel(S_SKIN, 3, '') self.writel(S_SKIN, 3, '') - self.writel(S_SKIN, 4, '') - self.writel(S_SKIN, 4, '') + self.writel( + S_SKIN, 4, '') + self.writel( + S_SKIN, 4, '') self.writel(S_SKIN, 3, '') - self.writel(S_SKIN, 3, '') - self.writel(S_SKIN, 4, '') - self.writel(S_SKIN, 4, '') - vcounts="" - vs="" - vcount=0 + self.writel(S_SKIN, 3, '') + self.writel(S_SKIN, 4, '') + self.writel(S_SKIN, 4, '') + vcounts = "" + vs = "" + vcount = 0 for v in vertices: - vcounts+=" "+str(len(v.weights)) + vcounts += " " + str(len(v.weights)) for b in v.bones: - vs+=" "+str(b) - vs+=" "+str(vcount) - vcount+=1 - self.writel(S_SKIN, 4, ''+vcounts+'') - self.writel(S_SKIN, 4, ''+vs+'') + vs += " " + str(b) + vs += " " + str(vcount) + vcount += 1 + self.writel(S_SKIN, 4, '' + vcounts + '') + self.writel(S_SKIN, 4, '' + vs + '') self.writel(S_SKIN, 3, '') self.writel(S_SKIN, 2, '') self.writel(S_SKIN, 1, '') - meshdata["skin_id"]=contid + meshdata["skin_id"] = contid return meshdata def export_mesh_node(self, node, il): - if (node.data==None): + if (node.data is None): return - armature=None - armcount=0 + armature = None + armcount = 0 for n in node.modifiers: - if (n.type=="ARMATURE"): - armcount+=1 - - if (node.parent!=None): - if (node.parent.type=="ARMATURE"): - armature=node.parent - if (armcount>1): - self.operator.report({'WARNING'}, 'Object "'+node.name+'" refers to more than one armature! This is unsupported.') - if (armcount==0): - self.operator.report({'WARNING'}, 'Object "'+node.name+'" is child of an armature, but has no armature modifier.') - - if (armcount>0 and not armature): - self.operator.report({'WARNING'}, 'Object "'+node.name+'" has armature modifier, but is not a child of an armature. This is unsupported.') - - if (node.data.shape_keys!=None): - sk = node.data.shape_keys - if (sk.animation_data): - #print("HAS ANIM") - #print("DRIVERS: "+str(len(sk.animation_data.drivers))) - for d in sk.animation_data.drivers: - if (d.driver): - for v in d.driver.variables: - for t in v.targets: - if (t.id!=None and t.id.name in self.scene.objects): - #print("LINKING "+str(node)+" WITH "+str(t.id.name)) - self.armature_for_morph[node]=self.scene.objects[t.id.name] + if (n.type == "ARMATURE"): + armcount += 1 + + if (node.parent is not None): + if (node.parent.type == "ARMATURE"): + armature = node.parent + if (armcount > 1): + self.operator.report({'WARNING'}, 'Object "' + node.name + + '" refers to more than one armature! ' + 'This is unsupported.') + if (armcount == 0): + self.operator.report({'WARNING'}, 'Object "' + node.name + + '" is child of an armature, but has ' + 'no armature modifier.') + + if (armcount > 0 and not armature): + self.operator.report({'WARNING'}, 'Object "' + node.name + + '" has armature modifier, but is not a child ' + 'of an armature. This is unsupported.') + + if (node.data.shape_keys is not None): + sk = node.data.shape_keys + if (sk.animation_data): + # print("HAS ANIM") + # print("DRIVERS: "+str(len(sk.animation_data.drivers))) + for d in sk.animation_data.drivers: + if (d.driver): + for v in d.driver.variables: + for t in v.targets: + if (t.id is not None and + t.id.name in self.scene.objects): + # print("LINKING " + str(node) + " WITH " + + # str(t.id.name)) + self.armature_for_morph[ + node] = self.scene.objects[t.id.name] meshdata = self.export_mesh(node, armature) - close_controller=False + close_controller = False if ("skin_id" in meshdata): - close_controller=True - self.writel(S_NODES, il, '') + close_controller = True + self.writel(S_NODES, il, '') for sn in self.skeleton_info[armature]["skeleton_nodes"]: - self.writel(S_NODES, il+1, '#'+sn+'') + self.writel(S_NODES, il + 1, '#' + + sn + '') elif ("morph_id" in meshdata): - self.writel(S_NODES, il, '') - close_controller=True - elif (armature==None): - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, '') + close_controller = True + elif (armature is None): + self.writel(S_NODES, il, '') - if (len(meshdata["material_assign"])>0): + if (len(meshdata["material_assign"]) > 0): - self.writel(S_NODES, il+1, '') - self.writel(S_NODES, il+2, '') + self.writel(S_NODES, il + 1, '') + self.writel(S_NODES, il + 2, '') for m in meshdata["material_assign"]: - self.writel(S_NODES, il+3, '') + self.writel(S_NODES, il + 3, '') - self.writel(S_NODES, il+2, '') - self.writel(S_NODES, il+1, '') + self.writel(S_NODES, il + 2, '') + self.writel(S_NODES, il + 1, '') if (close_controller): self.writel(S_NODES, il, '') @@ -948,143 +1114,179 @@ class DaeExporter: def export_armature_bone(self, bone, il, si): boneid = self.new_id("bone") boneidx = si["bone_count"] - si["bone_count"]+=1 - bonesid = si["id"]+"-"+str(boneidx) + si["bone_count"] += 1 + bonesid = si["id"] + "-" + str(boneidx) if (bone.name in self.used_bones): if (self.config["use_anim_action_all"]): - self.operator.report({'WARNING'}, 'Bone name "'+bone.name+'" used in more than one skeleton. Actions might export wrong.') + self.operator.report({'WARNING'}, 'Bone name "' + bone.name + + '" used in more than one skeleton. ' + 'Actions might export wrong.') else: self.used_bones.append(bone.name) - si["bone_index"][bone.name]=boneidx - si["bone_ids"][bone]=boneid + si["bone_index"][bone.name] = boneidx + si["bone_ids"][bone] = boneid si["bone_names"].append(bonesid) - self.writel(S_NODES, il, '') - il+=1 + self.writel(S_NODES, il, '') + il += 1 xform = bone.matrix_local si["bone_bind_poses"].append((si["armature_xform"] * xform).inverted()) - if (bone.parent!=None): + if (bone.parent is not None): xform = bone.parent.matrix_local.inverted() * xform else: si["skeleton_nodes"].append(boneid) - self.writel(S_NODES, il, ''+strmtx(xform)+'') + self.writel(S_NODES, il, '' + + strmtx(xform) + '') for c in bone.children: self.export_armature_bone(c, il, si) - il-=1 + il -= 1 self.writel(S_NODES, il, '') def export_armature_node(self, node, il): - if (node.data==None): + if (node.data is None): return self.skeletons.append(node) armature = node.data - self.skeleton_info[node]={ "bone_count":0, "id":self.new_id("skelbones"), "name":node.name, "bone_index":{}, "bone_ids":{}, "bone_names":[], "bone_bind_poses":[], "skeleton_nodes":[], "armature_xform":node.matrix_world } + self.skeleton_info[node] = { + "bone_count": 0, + "id": self.new_id("skelbones"), + "name": node.name, "bone_index": {}, + "bone_ids": {}, "bone_names": [], "bone_bind_poses": [], + "skeleton_nodes": [], + "armature_xform": node.matrix_world} for b in armature.bones: - if (b.parent!=None): + if (b.parent is not None): continue self.export_armature_bone(b, il, self.skeleton_info[node]) if (node.pose): for b in node.pose.bones: for x in b.constraints: - if (x.type=='ACTION'): + if (x.type == 'ACTION'): self.action_constraints.append(x.action) def export_camera_node(self, node, il): - if (node.data==None): + if (node.data is None): return - camera=node.data - camid=self.new_id("camera") - self.writel(S_CAMS, 1, '') + camera = node.data + camid = self.new_id("camera") + self.writel(S_CAMS, 1, '') self.writel(S_CAMS, 2, '') self.writel(S_CAMS, 3, '') - if (camera.type=="PERSP"): + if (camera.type == "PERSP"): self.writel(S_CAMS, 4, '') - self.writel(S_CAMS, 5, ' '+str(math.degrees(camera.angle))+' ') # I think? - self.writel(S_CAMS, 5, ' '+str(self.scene.render.resolution_x / self.scene.render.resolution_y)+' ') - self.writel(S_CAMS, 5, ' '+str(camera.clip_start)+' ') - self.writel(S_CAMS, 5, ' '+str(camera.clip_end)+' ') + self.writel(S_CAMS, 5, ' ' + + # I think? + str(math.degrees(camera.angle)) + ' ') + self.writel(S_CAMS, 5, ' ' + + str(self.scene.render.resolution_x / + self.scene.render.resolution_y) + + ' ') + self.writel(S_CAMS, 5, ' ' + + str(camera.clip_start) + ' ') + self.writel(S_CAMS, 5, ' ' + + str(camera.clip_end) + ' ') self.writel(S_CAMS, 4, '') else: self.writel(S_CAMS, 4, '') - self.writel(S_CAMS, 5, ' '+str(camera.ortho_scale*0.5)+' ') # I think? - self.writel(S_CAMS, 5, ' '+str(self.scene.render.resolution_x / self.scene.render.resolution_y)+' ') - self.writel(S_CAMS, 5, ' '+str(camera.clip_start)+' ') - self.writel(S_CAMS, 5, ' '+str(camera.clip_end)+' ') + self.writel(S_CAMS, 5, ' ' + + str(camera.ortho_scale * 0.5) + ' ') # I think? + self.writel(S_CAMS, 5, ' ' + str( + self.scene.render.resolution_x / + self.scene.render.resolution_y) + ' ') + self.writel(S_CAMS, 5, ' ' + + str(camera.clip_start) + ' ') + self.writel(S_CAMS, 5, ' ' + + str(camera.clip_end) + ' ') self.writel(S_CAMS, 4, '') self.writel(S_CAMS, 3, '') self.writel(S_CAMS, 2, '') self.writel(S_CAMS, 1, '') - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, '') def export_lamp_node(self, node, il): - if (node.data==None): + if (node.data is None): return - light=node.data - lightid=self.new_id("light") - self.writel(S_LAMPS, 1, '') - #self.writel(S_LAMPS, 2, '') + light = node.data + lightid = self.new_id("light") + self.writel(S_LAMPS, 1, '') + # self.writel(S_LAMPS, 2, '') self.writel(S_LAMPS, 3, '') - if (light.type=="POINT"): + if (light.type == "POINT"): self.writel(S_LAMPS, 4, '') - self.writel(S_LAMPS, 5, ''+strarr(light.color)+'') - att_by_distance = 2.0 / light.distance # convert to linear attenuation - self.writel(S_LAMPS, 5, ''+str(att_by_distance)+'') + self.writel(S_LAMPS, 5, '' + + strarr(light.color) + '') + # convert to linear attenuation + att_by_distance = 2.0 / light.distance + self.writel(S_LAMPS, 5, '' + + str(att_by_distance) + '') if (light.use_sphere): - self.writel(S_LAMPS, 5, ''+str(light.distance)+'') + self.writel(S_LAMPS, 5, '' + + str(light.distance) + '') self.writel(S_LAMPS, 4, '') - elif (light.type=="SPOT"): + elif (light.type == "SPOT"): self.writel(S_LAMPS, 4, '') - self.writel(S_LAMPS, 5, ''+strarr(light.color)+'') - att_by_distance = 2.0 / light.distance # convert to linear attenuation - self.writel(S_LAMPS, 5, ''+str(att_by_distance)+'') - self.writel(S_LAMPS, 5, ''+str(math.degrees(light.spot_size/2))+'') + self.writel(S_LAMPS, 5, '' + + strarr(light.color) + '') + # convert to linear attenuation + att_by_distance = 2.0 / light.distance + self.writel(S_LAMPS, 5, '' + + str(att_by_distance) + '') + self.writel(S_LAMPS, 5, '' + + str(math.degrees(light.spot_size / 2)) + + '') self.writel(S_LAMPS, 4, '') - else: #write a sun lamp for everything else (not supported) + else: # write a sun lamp for everything else (not supported) self.writel(S_LAMPS, 4, '') - self.writel(S_LAMPS, 5, ''+strarr(light.color)+'') + self.writel(S_LAMPS, 5, '' + + strarr(light.color) + '') self.writel(S_LAMPS, 4, '') self.writel(S_LAMPS, 3, '') - #self.writel(S_LAMPS, 2, '') + # self.writel(S_LAMPS, 2, '') self.writel(S_LAMPS, 1, '') - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, '') def export_empty_node(self, node, il): self.writel(S_NODES, 4, '') self.writel(S_NODES, 5, '') - self.writel(S_NODES, 6, ''+node.empty_draw_type+'') + self.writel(S_NODES, 6, '' + + node.empty_draw_type + '') self.writel(S_NODES, 5, '') self.writel(S_NODES, 4, '') def export_curve(self, curve): splineid = self.new_id("spline") - self.writel(S_GEOM, 1, '') + self.writel(S_GEOM, 1, '') self.writel(S_GEOM, 2, '') - points=[] - interps=[] - handles_in=[] - handles_out=[] - tilts=[] + points = [] + interps = [] + handles_in = [] + handles_out = [] + tilts = [] for cs in curve.splines: - if (cs.type=="BEZIER"): + if (cs.type == "BEZIER"): for s in cs.bezier_points: points.append(s.co[0]) points.append(s.co[1]) @@ -1115,73 +1317,103 @@ class DaeExporter: tilts.append(s.tilt) interps.append("LINEAR") - self.writel(S_GEOM, 3, '') - position_values="" + self.writel(S_GEOM, 3, '') + position_values = "" for x in points: - position_values+=" "+str(x) - self.writel(S_GEOM, 4, ''+position_values+'') + position_values += " " + str(x) + self.writel(S_GEOM, 4, '' + position_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 3, '') - self.writel(S_GEOM, 3, '') - intangent_values="" + self.writel(S_GEOM, 3, '') + intangent_values = "" for x in handles_in: - intangent_values+=" "+str(x) - self.writel(S_GEOM, 4, ''+intangent_values+'') + intangent_values += " " + str(x) + self.writel(S_GEOM, 4, '' + intangent_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 3, '') - self.writel(S_GEOM, 3, '') - outtangent_values="" + self.writel(S_GEOM, 3, '') + outtangent_values = "" for x in handles_out: - outtangent_values+=" "+str(x) - self.writel(S_GEOM, 4, ''+outtangent_values+'') + outtangent_values += " " + str(x) + self.writel(S_GEOM, 4, '' + outtangent_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 3, '') - self.writel(S_GEOM, 3, '') - interpolation_values="" + self.writel(S_GEOM, 3, '') + interpolation_values = "" for x in interps: - interpolation_values+=" "+x - self.writel(S_GEOM, 4, ''+interpolation_values+'') + interpolation_values += " " + x + self.writel(S_GEOM, 4, '' + interpolation_values + + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 3, '') - self.writel(S_GEOM, 3, '') - tilt_values="" + self.writel(S_GEOM, 3, '') + tilt_values = "" for x in tilts: - tilt_values+=" "+str(x) - self.writel(S_GEOM, 4, ''+tilt_values+'') + tilt_values += " " + str(x) + self.writel(S_GEOM, 4, '' + tilt_values + '') self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 5, '') self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 3, '') self.writel(S_GEOM, 3, '') - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel( + S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') + self.writel(S_GEOM, 4, '') self.writel(S_GEOM, 3, '') self.writel(S_GEOM, 2, '') @@ -1190,56 +1422,59 @@ class DaeExporter: return splineid def export_curve_node(self, node, il): - if (node.data==None): + if (node.data is None): return curveid = self.export_curve(node.data) - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, '') self.writel(S_NODES, il, '') def export_node(self, node, il): - if (not node in self.valid_nodes): + if (node not in self.valid_nodes): return prev_node = bpy.context.scene.objects.active bpy.context.scene.objects.active = node - self.writel(S_NODES, il, '') - il+=1 + self.writel(S_NODES, il, '') + il += 1 - self.writel(S_NODES, il, ''+strmtx(node.matrix_local)+'') - #print("NODE TYPE: "+node.type+" NAME: "+node.name) - if (node.type=="MESH"): + self.writel(S_NODES, il, '' + + strmtx(node.matrix_local) + '') + # print("NODE TYPE: "+node.type+" NAME: "+node.name) + if (node.type == "MESH"): self.export_mesh_node(node, il) - elif (node.type=="CURVE"): + elif (node.type == "CURVE"): self.export_curve_node(node, il) - elif (node.type=="ARMATURE"): + elif (node.type == "ARMATURE"): self.export_armature_node(node, il) - elif (node.type=="CAMERA"): + elif (node.type == "CAMERA"): self.export_camera_node(node, il) - elif (node.type=="LAMP"): + elif (node.type == "LAMP"): self.export_lamp_node(node, il) - elif (node.type=="EMPTY"): + elif (node.type == "EMPTY"): self.export_empty_node(node, il) for x in node.children: self.export_node(x, il) - il-=1 + il -= 1 self.writel(S_NODES, il, '') - bpy.context.scene.objects.active = prev_node #make previous node active again + # make previous node active again + bpy.context.scene.objects.active = prev_node def is_node_valid(self, node): - if (not node.type in self.config["object_types"]): + if (node.type not in self.config["object_types"]): return False if (self.config["use_active_layers"]): - valid=False + valid = False # print("NAME: "+node.name) for i in range(20): - if (node.layers[i] and self.scene.layers[i]): - valid=True + if (node.layers[i] and self.scene.layers[i]): + valid = True break if (not valid): return False @@ -1251,7 +1486,8 @@ class DaeExporter: def export_scene(self): self.writel(S_NODES, 0, '') - self.writel(S_NODES, 1, '') + self.writel(S_NODES, 1, '') # validate nodes for obj in self.scene.objects: @@ -1259,13 +1495,13 @@ class DaeExporter: continue if (self.is_node_valid(obj)): n = obj - while (n!=None): - if (not n in self.valid_nodes): + while (n is not None): + if (n not in self.valid_nodes): self.valid_nodes.append(n) - n=n.parent + n = n.parent for obj in self.scene.objects: - if (obj in self.valid_nodes and obj.parent==None): + if (obj in self.valid_nodes and obj.parent is None): self.export_node(obj, 2) self.writel(S_NODES, 1, '') @@ -1275,37 +1511,47 @@ class DaeExporter: self.writel(S_ASSET, 0, '') # Why is this time stuff mandatory?, no one could care less... self.writel(S_ASSET, 1, '') - self.writel(S_ASSET, 2, ' Anonymous ') #Who made Collada, the FBI ? - self.writel(S_ASSET, 2, ' Collada Exporter for Blender 2.6+, by Juan Linietsky (juan@codenix.com) ') #Who made Collada, the FBI ? + # Who made Collada, the FBI ? + self.writel(S_ASSET, 2, ' Anonymous ') + # Who made Collada, the FBI ? + self.writel( + S_ASSET, 2, ' Collada Exporter for Blender 2.6+, ' + 'by Juan Linietsky (juan@codenix.com) ') self.writel(S_ASSET, 1, '') - self.writel(S_ASSET, 1, ''+time.strftime("%Y-%m-%dT%H:%M:%SZ ")+'') - self.writel(S_ASSET, 1, ''+time.strftime("%Y-%m-%dT%H:%M:%SZ")+'') + self.writel(S_ASSET, 1, '' + + time.strftime("%Y-%m-%dT%H:%M:%SZ ") + '') + self.writel(S_ASSET, 1, '' + + time.strftime("%Y-%m-%dT%H:%M:%SZ") + '') self.writel(S_ASSET, 1, '') self.writel(S_ASSET, 1, 'Z_UP') self.writel(S_ASSET, 0, '') def export_animation_transform_channel(self, target, keys, matrices=True): - frame_total=len(keys) - anim_id=self.new_id("anim") - self.writel(S_ANIM, 1, '') + frame_total = len(keys) + anim_id = self.new_id("anim") + self.writel(S_ANIM, 1, '') source_frames = "" source_transforms = "" source_interps = "" for k in keys: - source_frames += " "+str(k[0]) + source_frames += " " + str(k[0]) if (matrices): - source_transforms += " "+strmtx(k[1]) + source_transforms += " " + strmtx(k[1]) else: - source_transforms += " "+str(k[1]) + source_transforms += " " + str(k[1]) - source_interps +=" LINEAR" + source_interps += " LINEAR" # Time Source - self.writel(S_ANIM, 2, '') - self.writel(S_ANIM, 3, ''+source_frames+'') + self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 3, '' + source_frames + '') self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 4, '') + self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 5, '') self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 3, '') @@ -1313,44 +1559,66 @@ class DaeExporter: if (matrices): # Transform Source - self.writel(S_ANIM, 2, '') - self.writel(S_ANIM, 3, ''+source_transforms+'') + self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 3, '' + source_transforms + + '') self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 4, '') + self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 5, '') self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 3, '') self.writel(S_ANIM, 2, '') else: # Value Source - self.writel(S_ANIM, 2, '') - self.writel(S_ANIM, 3, ''+source_transforms+'') + self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 3, '' + source_transforms + + '') self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 4, '') + self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 5, '') self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 3, '') self.writel(S_ANIM, 2, '') # Interpolation Source - self.writel(S_ANIM, 2, '') - self.writel(S_ANIM, 3, ''+source_interps+'') + self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 3, '' + source_interps + '') self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 4, '') + self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 5, '') self.writel(S_ANIM, 4, '') self.writel(S_ANIM, 3, '') self.writel(S_ANIM, 2, '') - self.writel(S_ANIM, 2, '') - self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 3, '') + self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 3, '') + self.writel(S_ANIM, 3, '') + self.writel(S_ANIM, 3, '') self.writel(S_ANIM, 2, '') if (matrices): - self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 2, '') else: - self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 2, '') self.writel(S_ANIM, 1, '') return [anim_id] @@ -1365,95 +1633,111 @@ class DaeExporter: frame_len = 1.0 / self.scene.render.fps frame_total = end - start + 1 frame_sub = 0 - if (start>0): - frame_sub=start*frame_len + if (start > 0): + frame_sub = start * frame_len tcn = [] - xform_cache={} - blend_cache={} + xform_cache = {} + blend_cache = {} # Change frames first, export objects last # This improves performance enormously - #print("anim from: "+str(start)+" to "+str(end)+" allowed: "+str(allowed)) - for t in range(start, end+1): + # print("anim from: " + str(start) + " to " + str(end) + " allowed: " + + # str(allowed)) + for t in range(start, end + 1): self.scene.frame_set(t) key = t * frame_len - frame_sub # print("Export Anim Frame "+str(t)+"/"+str(self.scene.frame_end+1)) for node in self.scene.objects: - if (not node in self.valid_nodes): + if (node not in self.valid_nodes): continue - if (allowed!=None and not (node in allowed)): - if (node.type=="MESH" and node.data!=None and (node in self.armature_for_morph) and (self.armature_for_morph[node] in allowed)): - pass #all good you pass with flying colors for morphs inside of action + if (allowed is not None and not (node in allowed)): + if (node.type == "MESH" and node.data is not None and + (node in self.armature_for_morph) and ( + self.armature_for_morph[node] in allowed)): + # all good you pass with flying colors for morphs + # inside of action + pass else: - #print("fail "+str((node in self.armature_for_morph))) + # print("fail "+str((node in self.armature_for_morph))) continue - if (node.type=="MESH" and node.data!=None and node.data.shape_keys!=None and (node.data in self.mesh_cache) and len(node.data.shape_keys.key_blocks)): + if (node.type == "MESH" and node.data is not None and + node.data.shape_keys is not None and ( + node.data in self.mesh_cache) and len( + node.data.shape_keys.key_blocks)): target = self.mesh_cache[node.data]["morph_id"] for i in range(len(node.data.shape_keys.key_blocks)): - if (i==0): + if (i == 0): continue - name=target+"-morph-weights("+str(i-1)+")" + name = target + "-morph-weights(" + str(i - 1) + ")" if (not (name in blend_cache)): - blend_cache[name]=[] + blend_cache[name] = [] - blend_cache[name].append( (key, node.data.shape_keys.key_blocks[i].value) ) + blend_cache[name].append( + (key, node.data.shape_keys.key_blocks[i].value)) - if (node.type=="MESH" and node.parent and node.parent.type=="ARMATURE"): + if (node.type == "MESH" and node.parent and + node.parent.type == "ARMATURE"): - continue #In Collada, nodes that have skin modifier must not export animation, animate the skin instead. + # In Collada, nodes that have skin modifier must not export + # animation, animate the skin instead. + continue - if (len(node.constraints)>0 or node.animation_data!=None): - #If the node has constraints, or animation data, then export a sampled animation track - name=self.validate_id(node.name) + if (len(node.constraints) > 0 or + node.animation_data is not None): + # If the node has constraints, or animation data, then + # export a sampled animation track + name = self.validate_id(node.name) if (not (name in xform_cache)): - xform_cache[name]=[] + xform_cache[name] = [] mtx = node.matrix_world.copy() if (node.parent): mtx = node.parent.matrix_world.inverted() * mtx - xform_cache[name].append( (key, mtx) ) + xform_cache[name].append((key, mtx)) - if (node.type=="ARMATURE"): - #All bones exported for now + if (node.type == "ARMATURE"): + # All bones exported for now for bone in node.data.bones: - bone_name=self.skeleton_info[node]["bone_ids"][bone] + bone_name = self.skeleton_info[node]["bone_ids"][bone] if (not (bone_name in xform_cache)): - #print("has bone: "+bone_name) - xform_cache[bone_name]=[] + # print("has bone: " + bone_name) + xform_cache[bone_name] = [] posebone = node.pose.bones[bone.name] - parent_posebone=None + parent_posebone = None mtx = posebone.matrix.copy() if (bone.parent): - parent_posebone=node.pose.bones[bone.parent.name] - parent_invisible=False + parent_posebone = node.pose.bones[bone.parent.name] + parent_invisible = False for i in range(3): - if (parent_posebone.scale[i]==0.0): - parent_invisible=True + if (parent_posebone.scale[i] == 0.0): + parent_invisible = True if (not parent_invisible): mtx = parent_posebone.matrix.inverted() * mtx - xform_cache[bone_name].append( (key, mtx) ) + xform_cache[bone_name].append((key, mtx)) self.scene.frame_set(frame_orig) - #export animation xml + # export animation xml for nid in xform_cache: - tcn+=self.export_animation_transform_channel(nid, xform_cache[nid], True) + tcn += self.export_animation_transform_channel( + nid, xform_cache[nid], True) for nid in blend_cache: - tcn+=self.export_animation_transform_channel(nid, blend_cache[nid], False) + tcn += self.export_animation_transform_channel( + nid, blend_cache[nid], False) return tcn @@ -1469,6 +1753,7 @@ class DaeExporter: self.writel(S_ANIM, 0, '') if (self.config["use_anim_action_all"] and len(self.skeletons)): + cached_actions = {} for s in self.skeletons: @@ -1478,31 +1763,32 @@ class DaeExporter: self.writel(S_ANIM_CLIPS, 0, '') for x in bpy.data.actions[:]: - if x.users==0 or x in self.action_constraints: + if x.users == 0 or x in self.action_constraints: continue - if (self.config["use_anim_skip_noexp"] and x.name.endswith("-noexp")): + if (self.config["use_anim_skip_noexp"] and + x.name.endswith("-noexp")): continue - bones=[] - #find bones used + bones = [] + # find bones used for p in x.fcurves: dp = str(p.data_path) base = "pose.bones[\"" - if (dp.find(base)==0): - dp=dp[len(base):] - if (dp.find('"')!=-1): - dp=dp[:dp.find('"')] - if (not dp in bones): + if (dp.find(base) == 0): + dp = dp[len(base):] + if (dp.find('"') != -1): + dp = dp[:dp.find('"')] + if (dp not in bones): bones.append(dp) - allowed_skeletons=[] + allowed_skeletons = [] for i, y in enumerate(self.skeletons): if (y.animation_data): for z in y.pose.bones: if (z.bone.name in bones): - if (not y in allowed_skeletons): + if (y not in allowed_skeletons): allowed_skeletons.append(y) - y.animation_data.action=x; + y.animation_data.action = x y.matrix_local = tmp_mat[i][0] for j, bone in enumerate(s.pose.bones): @@ -1512,25 +1798,32 @@ class DaeExporter: # print(str(x)) - tcn = self.export_animation(int(x.frame_range[0]), int(x.frame_range[1]+0.5), allowed_skeletons) - framelen=(1.0/self.scene.render.fps) - start = x.frame_range[0]*framelen - end = x.frame_range[1]*framelen - #print("Export anim: "+x.name) - self.writel(S_ANIM_CLIPS, 1, '') + tcn = self.export_animation(int(x.frame_range[0]), int( + x.frame_range[1] + 0.5), allowed_skeletons) + framelen = (1.0 / self.scene.render.fps) + start = x.frame_range[0] * framelen + end = x.frame_range[1] * framelen + # print("Export anim: "+x.name) + self.writel( + S_ANIM_CLIPS, 1, '') for z in tcn: - self.writel(S_ANIM_CLIPS, 2, '') + self.writel(S_ANIM_CLIPS, 2, + '') self.writel(S_ANIM_CLIPS, 1, '') - if (len(tcn)==0): - self.operator.report({'WARNING'}, 'Animation clip "'+x.name+'" contains no tracks.') + if (len(tcn) == 0): + self.operator.report( + {'WARNING'}, 'Animation clip "' + x.name + + '" contains no tracks.') self.writel(S_ANIM_CLIPS, 0, '') for i, s in enumerate(self.skeletons): - if (s.animation_data==None): + if (s.animation_data is None): continue if s in cached_actions: - s.animation_data.action = bpy.data.actions[cached_actions[s]] + s.animation_data.action = bpy.data.actions[ + cached_actions[s]] else: s.animation_data.action = None for j, bone in enumerate(s.pose.bones): @@ -1550,20 +1843,20 @@ class DaeExporter: self.writel(S_MATS, 0, '') self.writel(S_FX, 0, '') - self.skeletons=[] - self.action_constraints=[] + self.skeletons = [] + self.action_constraints = [] self.export_asset() self.export_scene() self.writel(S_GEOM, 0, '') - #morphs always go before skin controllers + # morphs always go before skin controllers if S_MORPH in self.sections: for l in self.sections[S_MORPH]: self.writel(S_CONT, 0, l) del self.sections[S_MORPH] - #morphs always go before skin controllers + # morphs always go before skin controllers if S_SKIN in self.sections: for l in self.sections[S_SKIN]: self.writel(S_CONT, 0, l) @@ -1585,47 +1878,45 @@ class DaeExporter: return False f.write(bytes('\n', "UTF-8")) - f.write(bytes('\n', "UTF-8")) + f.write(bytes( + '\n', "UTF-8")) - s=[] + s = [] for x in self.sections.keys(): s.append(x) s.sort() for x in s: for l in self.sections[x]: - f.write(bytes(l+"\n", "UTF-8")) + f.write(bytes(l + "\n", "UTF-8")) f.write(bytes('\n', "UTF-8")) - f.write(bytes('\t\n', "UTF-8")) + f.write(bytes('\t\n', "UTF-8")) f.write(bytes('\n', "UTF-8")) f.write(bytes('\n', "UTF-8")) return True def __init__(self, path, kwargs, operator): - self.operator=operator - self.scene=bpy.context.scene - self.last_id=0 - self.scene_name=self.new_id("scene") - self.sections={} - self.path=path - self.mesh_cache={} - self.curve_cache={} - self.material_cache={} - self.image_cache={} - self.skeleton_info={} - self.config=kwargs - self.valid_nodes=[] - self.armature_for_morph={} - self.used_bones=[] - self.wrongvtx_report=False - - -def save(operator, context, - filepath="", - use_selection=False, - **kwargs - ): - + self.operator = operator + self.scene = bpy.context.scene + self.last_id = 0 + self.scene_name = self.new_id("scene") + self.sections = {} + self.path = path + self.mesh_cache = {} + self.curve_cache = {} + self.material_cache = {} + self.image_cache = {} + self.skeleton_info = {} + self.config = kwargs + self.valid_nodes = [] + self.armature_for_morph = {} + self.used_bones = [] + self.wrongvtx_report = False + + +def save(operator, context, filepath="", use_selection=False, **kwargs): exp = DaeExporter(filepath, kwargs, operator) exp.export() -- cgit v1.2.3