diff --git a/io_scene_dae/export_dae.py b/io_scene_dae/export_dae.py index e3dc7b3..f03ddf9 100644 --- a/io_scene_dae/export_dae.py +++ b/io_scene_dae/export_dae.py @@ -99,7 +99,7 @@ class DaeExporter: def validate_id(self, d): if (d.find("id-") == 0): - return "z" + d + return "z{}".format(d) return d def new_id(self, t): @@ -188,19 +188,19 @@ class DaeExporter: # folder img_tmp_path = image.filepath if img_tmp_path.lower().endswith(bpy.path.extensions_image): - image.filepath = - os.path.join(basedir, os.path.basename(img_tmp_path)) + image.filepath = os.path.join( + basedir, os.path.basename(img_tmp_path)) else: - image.filepath = - os.path.join(basedir, "{}.png".format(image.name)) + image.filepath = os.path.join( + basedir, "{}.png".format(image.name)) - dstfile = - os.path.join(basedir, os.path.basename(image.filepath)) + dstfile = os.path.join( + basedir, os.path.basename(image.filepath)) if not os.path.isfile(dstfile): image.save() - imgpath = - os.path.join("images", os.path.basename(image.filepath)) + imgpath = os.path.join( + "images", os.path.basename(image.filepath)) image.filepath = img_tmp_path else: @@ -227,10 +227,10 @@ class DaeExporter: # 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, 1, "".format( + imgid, image.name)) + self.writel(S_IMGS, 2, "{}".format(imgpath)) + self.writel(S_IMGS, 1, "") self.image_cache[image] = imgid return imgid @@ -240,9 +240,9 @@ class DaeExporter: return material_id fxid = self.new_id("fx") - self.writel(S_FX, 1, '') - self.writel(S_FX, 2, '') + self.writel(S_FX, 1, "".format( + fxid, material.name)) + self.writel(S_FX, 2, "") # Find and fetch the textures and create sources sampler_table = {} @@ -269,20 +269,20 @@ class DaeExporter: # Surface surface_sid = self.new_id("fx_surf") - self.writel(S_FX, 3, '') - self.writel(S_FX, 4, '') + self.writel(S_FX, 3, "".format(surface_sid)) + self.writel(S_FX, 4, "") # 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, '') + self.writel(S_FX, 5, "{}".format(imgid)) + self.writel(S_FX, 5, "A8R8G8B8") + self.writel(S_FX, 4, "") + self.writel(S_FX, 3, "") # Sampler, collada sure likes it difficult sampler_sid = self.new_id("fx_sampler") - self.writel(S_FX, 3, '') - self.writel(S_FX, 4, '') - self.writel(S_FX, 5, '' + surface_sid + '') - self.writel(S_FX, 4, '') - self.writel(S_FX, 3, '') + self.writel(S_FX, 3, "".format(sampler_sid)) + self.writel(S_FX, 4, "") + self.writel(S_FX, 5, "{}".format(surface_sid)) + self.writel(S_FX, 4, "") + self.writel(S_FX, 3, "") sampler_table[i] = sampler_sid if ts.use_map_color_diffuse and diffuse_tex is None: @@ -294,103 +294,104 @@ class DaeExporter: if ts.use_map_normal and normal_tex is None: normal_tex = sampler_sid - self.writel(S_FX, 3, '') + self.writel(S_FX, 3, "") shtype = "blinn" - self.writel(S_FX, 4, '<' + shtype + '>') + self.writel(S_FX, 4, "<{}>".format(shtype)) # Ambient? from where? - self.writel(S_FX, 5, '') + self.writel(S_FX, 5, "") if emission_tex is not None: - self.writel(S_FX, 6, '') + self.writel( + S_FX, 6, "" + .format(emission_tex)) else: - self.writel(S_FX, 6, '' + - numarr_alpha(material.diffuse_color, material.emit) + - ' ') # not totally right but good enough - self.writel(S_FX, 5, '') + # not totally right but good enough + self.writel(S_FX, 6, "{}".format( + numarr_alpha(material.diffuse_color, material.emit))) + 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, 5, '') + self.writel(S_FX, 5, "") + self.writel(S_FX, 6, "{}".format( + numarr_alpha(self.scene.world.ambient_color, material.ambient))) + self.writel(S_FX, 5, "") - self.writel(S_FX, 5, '') + self.writel(S_FX, 5, "") if diffuse_tex is not None: - self.writel(S_FX, 6, '') + self.writel( + S_FX, 6, "" + .format(diffuse_tex)) else: - self.writel(S_FX, 6, - '' + numarr_alpha(material.diffuse_color, - material.diffuse_intensity) + - '') - self.writel(S_FX, 5, '') + self.writel(S_FX, 6, "{}".format(numarr_alpha( + material.diffuse_color, material.diffuse_intensity))) + self.writel(S_FX, 5, "") - self.writel(S_FX, 5, '') + self.writel(S_FX, 5, "") if specular_tex is not None: - self.writel(S_FX, 6, '') + self.writel( + S_FX, 6, + "".format( + specular_tex)) else: - self.writel(S_FX, 6, '' + numarr_alpha( - material.specular_color, material.specular_intensity) + - '') - self.writel(S_FX, 5, '') + self.writel(S_FX, 6, "{}".format(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, 5, '') + self.writel(S_FX, 5, "") + self.writel(S_FX, 6, "{}".format( + 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, 5, '') + self.writel(S_FX, 5, "") + self.writel(S_FX, 6, "{}".format( + 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, 5, '') + self.writel(S_FX, 5, "") + self.writel(S_FX, 6, "{}".format(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, 5, '') + self.writel(S_FX, 5, "") + self.writel(S_FX, 6, "{}".format(material.specular_ior)) + self.writel(S_FX, 5, "") - self.writel(S_FX, 4, '') + self.writel(S_FX, 4, "".format(shtype)) - self.writel(S_FX, 4, '') - self.writel(S_FX, 5, '') + 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, 6, '') + self.writel(S_FX, 6, "") + self.writel( + S_FX, 7, + "".format( + normal_tex)) + 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, 5, '') + self.writel(S_FX, 5, "") + self.writel(S_FX, 5, "") + self.writel(S_FX, 6, "{}".format( + int(double_sided_hint))) + self.writel(S_FX, 5, "") if (material.use_shadeless): - self.writel(S_FX, 5, '') - self.writel(S_FX, 6, '1') - self.writel(S_FX, 5, '') + self.writel(S_FX, 5, "") + self.writel(S_FX, 6, "1") + self.writel(S_FX, 5, "") - self.writel(S_FX, 4, '') + self.writel(S_FX, 4, "") - self.writel(S_FX, 3, '') - self.writel(S_FX, 2, '') - self.writel(S_FX, 1, '') + self.writel(S_FX, 3, "") + self.writel(S_FX, 2, "") + self.writel(S_FX, 1, "") # Also export blender material in all it's glory (if set as active) # 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, 1, "".format( + matid, material.name)) + self.writel(S_MATS, 2, "".format(fxid)) + self.writel(S_MATS, 1, "") self.material_cache[material] = matid return matid @@ -448,18 +449,23 @@ class DaeExporter: node.show_only_shape_key = False node.active_shape_key_index = 0 - self.writel(S_MORPH, 1, '') + self.writel( + S_MORPH, 1, "".format(mid)) # if ("skin_id" in morph_targets[0]): - # self.writel(S_MORPH, 2, '') + # self.writel(S_MORPH, 2, "") # else: - self.writel(S_MORPH, 2, '') + self.writel( + S_MORPH, 2, + "".format( + morph_targets[0]["id"])) - self.writel(S_MORPH, 3, '') - self.writel(S_MORPH, 4, '') + self.writel( + S_MORPH, 3, "".format(mid)) + self.writel( + S_MORPH, 4, + "".format(mid, len(morph_targets) - 1)) marr = "" warr = "" for i in range(len(morph_targets)): @@ -476,43 +482,48 @@ class DaeExporter: 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, 4, "") + self.writel(S_MORPH, 4, "") self.writel( - S_MORPH, 6, '') - self.writel(S_MORPH, 5, '') - self.writel(S_MORPH, 4, '') - self.writel(S_MORPH, 3, '') + S_MORPH, 5, "".format( + mid, len(morph_targets) - 1)) + 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, "".format(mid)) + self.writel( + S_MORPH, 4, + "" + .format(mid, len(morph_targets) - 1)) 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, 4, "") + self.writel(S_MORPH, 4, "") self.writel( - S_MORPH, 6, '') - self.writel(S_MORPH, 5, '') - self.writel(S_MORPH, 4, '') - self.writel(S_MORPH, 3, '') + S_MORPH, 5, + "".format( + mid, len(morph_targets) - 1)) + 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, 3, "") self.writel( - S_MORPH, 4, '') + S_MORPH, 4, "".format(mid)) self.writel( - S_MORPH, 4, '') - self.writel(S_MORPH, 3, '') - self.writel(S_MORPH, 2, '') - self.writel(S_MORPH, 1, '') + S_MORPH, 4, "".format(mid)) + self.writel(S_MORPH, 3, "") + self.writel(S_MORPH, 2, "") + self.writel(S_MORPH, 1, "") if armature is not None: self.armature_for_morph[node] = armature @@ -576,7 +587,7 @@ class DaeExporter: except: self.operator.report( {"WARNING"}, - "CalcTangets failed for mesh \"{}\", no tangets will be "\ + "CalcTangets failed for mesh \"{}\", no tangets will be " "exported.".format(mesh.name)) # uv_layer_count=0 mesh.calc_normals_split() @@ -673,8 +684,8 @@ class DaeExporter: if not self.wrongvtx_report: self.operator.report( {"WARNING"}, - "Mesh for object \"{}\" has unassigned " \ - "weights. This may look wrong in exported "\ + "Mesh for object \"{}\" has unassigned " + "weights. This may look wrong in exported " "model.".format(node.name)) self.wrongvtx_report = True @@ -701,149 +712,158 @@ class DaeExporter: indices.append(vi) meshid = self.new_id("mesh") - self.writel(S_GEOM, 1, '') + self.writel( + S_GEOM, 1, "".format( + meshid, name_to_use)) - self.writel(S_GEOM, 2, '') + self.writel(S_GEOM, 2, "") # Vertex Array - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format(meshid)) float_values = "" for v in vertices: - float_values += " {} {} {}".format(v.vertex.x, v.vertex.y, v.vertex.z) - self.writel(S_GEOM, 4, '' + float_values + - '') - 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, 4, '') - self.writel(S_GEOM, 3, '') + float_values += " {} {} {}".format( + v.vertex.x, v.vertex.y, v.vertex.z) + self.writel( + S_GEOM, 4, "{}".format( + meshid, len(vertices) * 3, float_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(meshid, len(vertices))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") # Normal Array - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format(meshid)) float_values = "" for v in vertices: - float_values += " {} {} {}".format(v.normal.x, v.normal.y, v.normal.z) - self.writel(S_GEOM, 4, '' + float_values + - '') - 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, 4, '') - self.writel(S_GEOM, 3, '') + float_values += " {} {} {}".format( + v.normal.x, v.normal.y, v.normal.z) + self.writel( + S_GEOM, 4, "{}".format( + meshid, len(vertices) * 3, float_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(meshid, len(vertices))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") if (has_tangents): - self.writel(S_GEOM, 3, '') + self.writel( + S_GEOM, 3, "".format(meshid)) float_values = "" for v in vertices: - float_values += " {} {} {}".format(v.tangent.x, v.tangent.y, v.tangent.z) - self.writel(S_GEOM, 4, '' + float_values + - '') - 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, 4, '') - self.writel(S_GEOM, 3, '') + float_values += " {} {} {}".format( + v.tangent.x, v.tangent.y, v.tangent.z) + self.writel( + S_GEOM, 4, "{}".format( + meshid, len(vertices) * 3, float_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(meshid, len(vertices))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format( + meshid)) float_values = "" for v in vertices: - float_values += " {} {} {}".format(v.bitangent.x, v.bitangent.y, v.bitangent.z) - self.writel(S_GEOM, 4, '' + float_values + - '') - 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, 4, '') - self.writel(S_GEOM, 3, '') + float_values += " {} {} {}".format( + v.bitangent.x, v.bitangent.y, v.bitangent.z) + self.writel( + S_GEOM, 4, "{}".format( + meshid, len(vertices) * 3, float_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(meshid, len(vertices))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") # UV Arrays for uvi in range(uv_layer_count): - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format( + meshid, uvi)) float_values = "" for v in vertices: try: float_values += " {} {}".format(v.uv[uvi].x, v.uv[uvi].y) except: - # I don't understand this weird multi-uv-layer API, but + # 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, 5, '') - self.writel(S_GEOM, 5, '') - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 3, '') + self.writel( + S_GEOM, 4, "{}".format( + meshid, uvi, len(vertices) * 2, float_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format( + meshid, uvi, len(vertices))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") # Color Arrays if (has_colors): - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format(meshid)) float_values = "" for v in vertices: - float_values += " {} {} {}".format(v.color.x, v.color.y, v.color.z) - self.writel(S_GEOM, 4, '' + float_values + - '') - 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, 4, '') - self.writel(S_GEOM, 3, '') + float_values += " {} {} {}".format( + v.color.x, v.color.y, v.color.z) + self.writel( + S_GEOM, 4, "{}".format( + meshid, len(vertices) * 3, float_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(meshid, len(vertices))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") # Triangle Lists - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format(meshid)) self.writel( - S_GEOM, 4, '') - self.writel(S_GEOM, 3, '') + S_GEOM, 4, + "".format( + meshid)) + self.writel(S_GEOM, 3, "") prim_type = "" if (triangulate): @@ -857,35 +877,38 @@ class DaeExporter: 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 + self.writel( + S_GEOM, 3, "<{} count=\"{}\" material=\"{}\">".format( + prim_type, int(len(indices)), 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, "<{} count=\"{}\">".format( + prim_type, int(len(indices)))) # todo material - self.writel(S_GEOM, 4, '') - self.writel(S_GEOM, 4, '') + self.writel( + S_GEOM, 4, "".format(meshid)) + self.writel( + S_GEOM, 4, "".format(meshid)) for uvi in range(uv_layer_count): - self.writel(S_GEOM, 4, '') + self.writel( + S_GEOM, 4, + "".format(meshid, uvi, uvi)) if (has_colors): - self.writel(S_GEOM, 4, '') + self.writel( + S_GEOM, 4, "".format(meshid)) if (has_tangents): - self.writel(S_GEOM, 4, - '') - self.writel(S_GEOM, 4, - '') + self.writel( + S_GEOM, 4, "".format(meshid)) + self.writel( + S_GEOM, 4, "".format(meshid)) if (triangulate): int_values = "

" @@ -902,10 +925,10 @@ class DaeExporter: int_values += "

" self.writel(S_GEOM, 4, int_values) - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format(prim_type)) - self.writel(S_GEOM, 2, '
') - self.writel(S_GEOM, 1, '
') + self.writel(S_GEOM, 2, "") + self.writel(S_GEOM, 1, "
") meshdata = {} meshdata["id"] = meshid @@ -920,52 +943,59 @@ class DaeExporter: contid = self.new_id("controller") - self.writel(S_SKIN, 1, '') + self.writel(S_SKIN, 1, "".format(contid)) if (skel_source is not None): - self.writel(S_SKIN, 2, '') + self.writel(S_SKIN, 2, "".format( + skel_source)) else: - self.writel(S_SKIN, 2, '') + self.writel(S_SKIN, 2, "".format(meshid)) - self.writel(S_SKIN, 3, '' + - strmtx(node.matrix_world) + '') + self.writel( + S_SKIN, 3, "{}".format( + strmtx(node.matrix_world))) # Joint Names - self.writel(S_SKIN, 3, '') + self.writel(S_SKIN, 3, "".format(contid)) name_values = "" for v in si["bone_names"]: name_values += " {}".format(v) - self.writel(S_SKIN, 4, '' + name_values + - '') - 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, 4, "{}".format( + contid, len(si["bone_names"]), name_values)) + self.writel(S_SKIN, 4, "") + self.writel( + S_SKIN, 4, "".format( + contid, len(si["bone_names"]))) + 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, '') + self.writel(S_SKIN, 3, "".format( + contid)) pose_values = "" for v in si["bone_bind_poses"]: pose_values += " {}".format(strmtx(v)) - self.writel(S_SKIN, 4, '' + - pose_values + '') - 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, 4, "{}".format( + contid, len(si["bone_bind_poses"]) * 16, pose_values)) + self.writel(S_SKIN, 4, "") + self.writel( + S_SKIN, 4, "".format( + contid, len(si["bone_bind_poses"]))) + 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, '') + self.writel(S_SKIN, 3, "".format( + contid)) skin_weights = "" skin_weights_total = 0 for v in vertices: @@ -973,33 +1003,38 @@ class DaeExporter: for w in v.weights: skin_weights += " {}".format(w) - self.writel(S_SKIN, 4, '' + skin_weights + - '') - 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, 4, "{}".format( + contid, skin_weights_total, skin_weights)) + self.writel(S_SKIN, 4, "") + self.writel( + S_SKIN, 4, "".format( + contid, skin_weights_total)) + 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, 3, "") self.writel( - S_SKIN, 4, '') + S_SKIN, 4, + "".format( + contid)) 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, '') + S_SKIN, 4, "".format(contid)) + self.writel(S_SKIN, 3, "") + self.writel( + S_SKIN, 3, "".format( + len(vertices))) + self.writel( + S_SKIN, 4, "".format(contid)) + self.writel( + S_SKIN, 4, "".format(contid)) vcounts = "" vs = "" vcount = 0 @@ -1008,12 +1043,12 @@ class DaeExporter: for b in v.bones: vs += " {} {}".format(b, vcount) vcount += 1 - self.writel(S_SKIN, 4, '' + vcounts + '') - self.writel(S_SKIN, 4, '' + vs + '') - self.writel(S_SKIN, 3, '') + self.writel(S_SKIN, 4, "{}".format(vcounts)) + self.writel(S_SKIN, 4, "{}".format(vs)) + self.writel(S_SKIN, 3, "") - self.writel(S_SKIN, 2, '') - self.writel(S_SKIN, 1, '') + self.writel(S_SKIN, 2, "") + self.writel(S_SKIN, 1, "") meshdata["skin_id"] = contid return meshdata @@ -1032,17 +1067,21 @@ class DaeExporter: if (node.parent.type == "ARMATURE"): armature = node.parent if (armcount > 1): - self.operator.report({"WARNING"}, "Object \"{}\" refers "\ - "to more than one armature! "\ - "This is unsupported.".format(node.name)) + self.operator.report( + {"WARNING"}, "Object \"{}\" refers " + "to more than one armature! " + "This is unsupported.".format(node.name)) if (armcount == 0): - self.operator.report({"WARNING"}, "Object \"{}\" is child "\ - "of an armature, but has no armature modifier.".format(node.name)) + self.operator.report( + {"WARNING"}, "Object \"{}\" is child " + "of an armature, but has no armature modifier.".format( + node.name)) if (armcount > 0 and not armature): - self.operator.report({"WARNING"}, - "Object \"{}\" has armature modifier, but is not a child of an "\ - "armature. This is unsupported.".format(node.name)) + self.operator.report( + {"WARNING"}, + "Object \"{}\" has armature modifier, but is not a child of " + "an armature. This is unsupported.".format(node.name)) if (node.data.shape_keys is not None): sk = node.data.shape_keys @@ -1065,66 +1104,76 @@ class DaeExporter: if ("skin_id" in meshdata): close_controller = True - self.writel(S_NODES, il, '') + self.writel( + S_NODES, il, "".format( + meshdata["skin_id"])) for sn in self.skeleton_info[armature]["skeleton_nodes"]: - self.writel(S_NODES, il + 1, '#' + - sn + '') + self.writel( + S_NODES, il + 1, "#{}".format(sn)) elif ("morph_id" in meshdata): - self.writel(S_NODES, il, '') + self.writel( + S_NODES, il, "".format( + meshdata["morph_id"])) close_controller = True elif (armature is None): - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, "".format( + meshdata["id"])) 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, + "".format( + m[1], m[0])) - 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, '') + self.writel(S_NODES, il, "") else: - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, "") def export_armature_bone(self, bone, il, si): - is_ctrl_bone = (bone.name.startswith("ctrl") and self.config["use_exclude_ctrl_bones"]) + is_ctrl_bone = ( + bone.name.startswith("ctrl") and + self.config["use_exclude_ctrl_bones"]) if (bone.parent is None and is_ctrl_bone is True): - self.operator.report({'WARNING'},'Root bone cannot be a control bone.') + self.operator.report( + {"WARNING"}, "Root bone cannot be a control bone.") is_ctrl_bone = False if (is_ctrl_bone is False): boneid = self.new_id("bone") boneidx = si["bone_count"] si["bone_count"] += 1 - bonesid = si["id"] + "-" + str(boneidx) + bonesid = "{}-{}".format(si["id"], 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 \"{}\" used in more than one " + "skeleton. Actions might export wrong.".format( + bone.name)) else: self.used_bones.append(bone.name) si["bone_index"][bone.name] = boneidx si["bone_ids"][bone] = boneid si["bone_names"].append(bonesid) - self.writel(S_NODES, il, '') + self.writel( + S_NODES, il, "".format(boneid, bonesid, bone.name)) if (is_ctrl_bone is False): il += 1 xform = bone.matrix_local if (is_ctrl_bone is False): - si["bone_bind_poses"].append((si["armature_xform"] * xform).inverted_safe()) + si["bone_bind_poses"].append( + (si["armature_xform"] * xform).inverted_safe()) if (bone.parent is not None): xform = bone.parent.matrix_local.inverted_safe() * xform @@ -1132,15 +1181,16 @@ class DaeExporter: si["skeleton_nodes"].append(boneid) if (is_ctrl_bone is False): - self.writel(S_NODES, il, '' + - strmtx(xform) + '') + self.writel( + S_NODES, il, "{}".format( + strmtx(xform))) for c in bone.children: self.export_armature_bone(c, il, si) if (is_ctrl_bone is False): il -= 1 - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, "") def export_armature_node(self, node, il): if (node.data is None): @@ -1178,42 +1228,39 @@ class DaeExporter: camera = node.data camid = self.new_id("camera") - self.writel(S_CAMS, 1, '') - self.writel(S_CAMS, 2, '') - self.writel(S_CAMS, 3, '') + self.writel(S_CAMS, 1, "".format( + camid, camera.name)) + self.writel(S_CAMS, 2, "") + self.writel(S_CAMS, 3, "") if (camera.type == "PERSP"): - self.writel(S_CAMS, 4, '') - 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.writel(S_CAMS, 4, "") + self.writel(S_CAMS, 5, "{}".format( + math.degrees(camera.angle))) # I think? + self.writel(S_CAMS, 5, "{}".format( 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.scene.render.resolution_y)) + self.writel(S_CAMS, 5, "{}".format( + camera.clip_start)) + self.writel(S_CAMS, 5, "{}".format(camera.clip_end)) + self.writel(S_CAMS, 4, "") + else: + self.writel(S_CAMS, 4, "") + self.writel(S_CAMS, 5, "{}".format( + camera.ortho_scale * 0.5)) # I think? + self.writel(S_CAMS, 5, "{}".format( + self.scene.render.resolution_x / + self.scene.render.resolution_y)) + self.writel(S_CAMS, 5, "{}".format( + camera.clip_start)) + self.writel(S_CAMS, 5, "{}".format(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_CAMS, 3, "") + self.writel(S_CAMS, 2, "") + self.writel(S_CAMS, 1, "") - self.writel(S_NODES, il, '') + self.writel( + S_NODES, il, "".format(camid)) def export_lamp_node(self, node, il): if (node.data is None): @@ -1221,63 +1268,71 @@ class DaeExporter: light = node.data lightid = self.new_id("light") - self.writel(S_LAMPS, 1, '') - # self.writel(S_LAMPS, 2, '') - self.writel(S_LAMPS, 3, '') + self.writel(S_LAMPS, 1, "".format( + lightid, light.name)) + # self.writel(S_LAMPS, 2, "") + self.writel(S_LAMPS, 3, "") if (light.type == "POINT"): - self.writel(S_LAMPS, 4, '') - self.writel(S_LAMPS, 5, '' + - strarr(light.color) + '') + self.writel(S_LAMPS, 4, "") + self.writel(S_LAMPS, 5, "{}".format( + 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, + "{}".format( + att_by_distance)) if (light.use_sphere): - self.writel(S_LAMPS, 5, '' + - str(light.distance) + '') + self.writel(S_LAMPS, 5, "{}".format( + light.distance)) - self.writel(S_LAMPS, 4, '') + self.writel(S_LAMPS, 4, "") elif (light.type == "SPOT"): - self.writel(S_LAMPS, 4, '') - self.writel(S_LAMPS, 5, '' + - strarr(light.color) + '') + self.writel(S_LAMPS, 4, "") + self.writel(S_LAMPS, 5, "{}".format( + 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, '') + self.writel( + S_LAMPS, 5, + "{}".format( + att_by_distance)) + self.writel( + S_LAMPS, 5, "{}".format( + math.degrees(light.spot_size / 2))) + self.writel(S_LAMPS, 4, "") 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, 4, '') + self.writel(S_LAMPS, 4, "") + self.writel(S_LAMPS, 5, "{}".format( + strarr(light.color))) + self.writel(S_LAMPS, 4, "") - self.writel(S_LAMPS, 3, '') - # self.writel(S_LAMPS, 2, '') - self.writel(S_LAMPS, 1, '') + self.writel(S_LAMPS, 3, "") + # self.writel(S_LAMPS, 2, "") + self.writel(S_LAMPS, 1, "") - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, "".format( + lightid)) 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, 5, '') - self.writel(S_NODES, 4, '') + self.writel(S_NODES, 4, "") + self.writel(S_NODES, 5, "") + self.writel( + S_NODES, 6, + "{}".format( + 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, 2, '') + self.writel( + S_GEOM, 1, "".format( + splineid, curve.name)) + self.writel(S_GEOM, 2, "") points = [] interps = [] @@ -1318,107 +1373,117 @@ class DaeExporter: tilts.append(s.tilt) interps.append("LINEAR") - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format(splineid)) position_values = "" for x in points: position_values += " {}".format(x) - self.writel(S_GEOM, 4, '' + position_values + - '') - 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, 4, "{}".format( + splineid, len(points), position_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(splineid, len(points) / 3)) + 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, '') + self.writel( + S_GEOM, 3, "".format(splineid)) intangent_values = "" for x in handles_in: intangent_values += " {}".format(x) - self.writel(S_GEOM, 4, '' + intangent_values + - '') - 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, 4, "{}".format( + splineid, len(points), intangent_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(splineid, len(points) / 3)) + 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, '') + self.writel(S_GEOM, 3, "".format( + splineid)) outtangent_values = "" for x in handles_out: outtangent_values += " {}".format(x) - self.writel(S_GEOM, 4, '' + outtangent_values + - '') - 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, 4, "{}".format( + splineid, len(points), outtangent_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(splineid, len(points) / 3)) + 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, '') + self.writel( + S_GEOM, 3, "".format(splineid)) interpolation_values = "" for x in interps: interpolation_values += " {}".format(x) - self.writel(S_GEOM, 4, '' + interpolation_values + - '') - 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, 4, "{}" + .format(splineid, len(interps), interpolation_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(splineid, len(interps))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") - self.writel(S_GEOM, 3, '') + self.writel(S_GEOM, 3, "".format(splineid)) tilt_values = "" for x in tilts: tilt_values += " {}".format(x) - self.writel(S_GEOM, 4, '' + tilt_values + '') - 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, 3, '') + S_GEOM, 4, + "{}" + .format(splineid, len(tilts), tilt_values)) + self.writel(S_GEOM, 4, "") + self.writel( + S_GEOM, 4, "".format(splineid, len(tilts))) + self.writel(S_GEOM, 5, "") + self.writel(S_GEOM, 4, "") + self.writel(S_GEOM, 3, "") - self.writel(S_GEOM, 2, '') - self.writel(S_GEOM, 1, '') + self.writel(S_GEOM, 3, "") + self.writel( + S_GEOM, 4, + "" + .format(splineid)) + self.writel( + S_GEOM, 4, + "" + .format(splineid)) + self.writel( + S_GEOM, 4, "".format(splineid)) + self.writel( + S_GEOM, 4, "".format(splineid)) + self.writel( + S_GEOM, 4, "" + .format(splineid)) + self.writel(S_GEOM, 3, "") + + self.writel(S_GEOM, 2, "") + self.writel(S_GEOM, 1, "") return splineid @@ -1428,8 +1493,9 @@ class DaeExporter: curveid = self.export_curve(node.data) - self.writel(S_NODES, il, '') - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, "".format( + curveid)) + self.writel(S_NODES, il, "") def export_node(self, node, il): if (node not in self.valid_nodes): @@ -1438,12 +1504,14 @@ class DaeExporter: prev_node = bpy.context.scene.objects.active bpy.context.scene.objects.active = node - self.writel(S_NODES, il, '') + self.writel( + S_NODES, il, "".format( + self.validate_id(node.name), node.name)) il += 1 - self.writel(S_NODES, il, '' + - strmtx(node.matrix_local) + '') + self.writel( + S_NODES, il, "{}".format( + strmtx(node.matrix_local))) # print("NODE TYPE: "+node.type+" NAME: "+node.name) if (node.type == "MESH"): self.export_mesh_node(node, il) @@ -1462,7 +1530,7 @@ class DaeExporter: self.export_node(x, il) il -= 1 - self.writel(S_NODES, il, '') + self.writel(S_NODES, il, "") # make previous node active again bpy.context.scene.objects.active = prev_node @@ -1486,9 +1554,10 @@ class DaeExporter: return True def export_scene(self): - self.writel(S_NODES, 0, '') - self.writel(S_NODES, 1, '') + self.writel(S_NODES, 0, "") + self.writel( + S_NODES, 1, "".format( + self.scene_name)) # validate nodes for obj in self.scene.objects: @@ -1505,32 +1574,32 @@ class DaeExporter: if (obj in self.valid_nodes and obj.parent is None): self.export_node(obj, 2) - self.writel(S_NODES, 1, '') - self.writel(S_NODES, 0, '') + self.writel(S_NODES, 1, "") + self.writel(S_NODES, 0, "") def export_asset(self): - self.writel(S_ASSET, 0, '') + 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, 1, "") # Who made Collada, the FBI ? - self.writel(S_ASSET, 2, ' Anonymous ') + 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, '') - self.writel(S_ASSET, 1, 'Z_UP') - self.writel(S_ASSET, 0, '') + 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, "{}".format( + time.strftime("%Y-%m-%dT%H:%M:%SZ"))) + self.writel(S_ASSET, 1, "{}".format( + 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, '') + self.writel(S_ANIM, 1, "".format(anim_id)) source_frames = "" source_transforms = "" source_interps = "" @@ -1545,82 +1614,94 @@ class DaeExporter: source_interps += " LINEAR" # Time Source - 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, 5, '') - self.writel(S_ANIM, 4, '') - self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 2, '') + self.writel(S_ANIM, 2, "".format(anim_id)) + self.writel( + S_ANIM, 3, "{}".format( + anim_id, frame_total, source_frames)) + self.writel(S_ANIM, 3, "") + self.writel( + S_ANIM, 4, "".format(anim_id, frame_total)) + self.writel(S_ANIM, 5, "") + self.writel(S_ANIM, 4, "") + self.writel(S_ANIM, 3, "") + self.writel(S_ANIM, 2, "") if (matrices): # Transform Source - 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, 5, '') - self.writel(S_ANIM, 4, '') - self.writel(S_ANIM, 3, '') - self.writel(S_ANIM, 2, '') + self.writel( + S_ANIM, 2, "".format( + anim_id)) + self.writel( + S_ANIM, 3, "{}".format( + anim_id, frame_total * 16, source_transforms)) + self.writel(S_ANIM, 3, "") + self.writel( + S_ANIM, 4, + "".format(anim_id, frame_total)) + 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, 3, '') - 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, + "".format(anim_id)) + self.writel( + S_ANIM, 3, "{}".format( + anim_id, frame_total, source_transforms)) + self.writel(S_ANIM, 3, "") + self.writel( + S_ANIM, 4, "".format(anim_id, frame_total)) + 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, 3, '') - 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, "".format( + anim_id)) + self.writel( + S_ANIM, 3, "{}".format( + anim_id, frame_total, source_interps)) + self.writel(S_ANIM, 3, "") + self.writel( + S_ANIM, 4, "".format(anim_id, frame_total)) + 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, 2, "".format(anim_id)) + self.writel( + S_ANIM, 3, + "".format(anim_id)) + self.writel( + S_ANIM, 3, "".format(anim_id)) + self.writel( + S_ANIM, 3, "".format(anim_id)) + self.writel(S_ANIM, 2, "") if (matrices): - self.writel(S_ANIM, 2, '') + self.writel( + S_ANIM, 2, "".format(anim_id, target)) else: - self.writel(S_ANIM, 2, '') - self.writel(S_ANIM, 1, '') + self.writel( + S_ANIM, 2, "".format(anim_id, target)) + self.writel(S_ANIM, 1, "") return [anim_id] @@ -1706,7 +1787,8 @@ class DaeExporter: # All bones exported for now for bone in node.data.bones: - if((bone.name.startswith("ctrl") and self.config["use_exclude_ctrl_bones"])): + if((bone.name.startswith("ctrl") and + self.config["use_exclude_ctrl_bones"])): continue bone_name = self.skeleton_info[node]["bone_ids"][bone] @@ -1722,11 +1804,16 @@ class DaeExporter: if (bone.parent): if (self.config["use_exclude_ctrl_bones"]): current_parent_posebone = bone.parent - while (current_parent_posebone.name.startswith("ctrl") and current_parent_posebone.parent): - current_parent_posebone = current_parent_posebone.parent - parent_posebone = node.pose.bones[current_parent_posebone.name] + while (current_parent_posebone.name + .startswith("ctrl") and + current_parent_posebone.parent): + current_parent_posebone = ( + current_parent_posebone.parent) + parent_posebone = node.pose.bones[ + current_parent_posebone.name] else: - parent_posebone = node.pose.bones[bone.parent.name] + parent_posebone = node.pose.bones[ + bone.parent.name] parent_invisible = False for i in range(3): @@ -1734,7 +1821,9 @@ class DaeExporter: parent_invisible = True if (not parent_invisible): - mtx = parent_posebone.matrix.inverted_safe() * mtx + mtx = ( + parent_posebone.matrix + .inverted_safe() * mtx) xform_cache[bone_name].append((key, mtx)) @@ -1759,7 +1848,7 @@ class DaeExporter: bone.matrix_basis = Matrix() tmp_mat.append([Matrix(s.matrix_local), tmp_bone_mat]) - self.writel(S_ANIM, 0, '') + self.writel(S_ANIM, 0, "") if (self.config["use_anim_action_all"] and len(self.skeletons)): @@ -1769,7 +1858,7 @@ class DaeExporter: if s.animation_data and s.animation_data.action: cached_actions[s] = s.animation_data.action.name - self.writel(S_ANIM_CLIPS, 0, '') + self.writel(S_ANIM_CLIPS, 0, "") for x in bpy.data.actions[:]: if x.users == 0 or x in self.action_constraints: @@ -1785,8 +1874,8 @@ class DaeExporter: base = "pose.bones[\"" if dp.startswith(base): dp = dp[len(base):] - if (dp.find('"') != -1): - dp = dp[:dp.find('"')] + if (dp.find("\"") != -1): + dp = dp[:dp.find("\"")] if (dp not in bones): bones.append(dp) @@ -1814,18 +1903,18 @@ class DaeExporter: end = x.frame_range[1] * framelen # print("Export anim: "+x.name) self.writel( - S_ANIM_CLIPS, 1, '') + S_ANIM_CLIPS, 1, "".format(x.name, start, end)) for z in tcn: self.writel(S_ANIM_CLIPS, 2, - '') - self.writel(S_ANIM_CLIPS, 1, '') + "".format(z)) + self.writel(S_ANIM_CLIPS, 1, "") if (len(tcn) == 0): self.operator.report( - {"WARNING"}, "Animation clip \"{}\" contains no "\ + {"WARNING"}, "Animation clip \"{}\" contains no " "tracks.".format(x.name)) - self.writel(S_ANIM_CLIPS, 0, '') + self.writel(S_ANIM_CLIPS, 0, "") for i, s in enumerate(self.skeletons): if (s.animation_data is None): @@ -1841,23 +1930,21 @@ class DaeExporter: else: self.export_animation(self.scene.frame_start, self.scene.frame_end) - self.writel(S_ANIM, 0, '') + self.writel(S_ANIM, 0, "") def export(self): - self.writel(S_GEOM, 0, '') - self.writel(S_CONT, 0, '') - self.writel(S_CAMS, 0, '') - self.writel(S_LAMPS, 0, '') - self.writel(S_IMGS, 0, '') - self.writel(S_MATS, 0, '') - self.writel(S_FX, 0, '') + self.writel(S_GEOM, 0, "") + self.writel(S_CONT, 0, "") + self.writel(S_CAMS, 0, "") + self.writel(S_LAMPS, 0, "") + self.writel(S_IMGS, 0, "") + self.writel(S_MATS, 0, "") + self.writel(S_FX, 0, "") - self.skeletons = [] - self.action_constraints = [] self.export_asset() self.export_scene() - self.writel(S_GEOM, 0, '') + self.writel(S_GEOM, 0, "") # morphs always go before skin controllers if S_MORPH in self.sections: @@ -1871,12 +1958,12 @@ class DaeExporter: self.writel(S_CONT, 0, l) del self.sections[S_SKIN] - self.writel(S_CONT, 0, '') - self.writel(S_CAMS, 0, '') - self.writel(S_LAMPS, 0, '') - self.writel(S_IMGS, 0, '') - self.writel(S_MATS, 0, '') - self.writel(S_FX, 0, '') + self.writel(S_CONT, 0, "") + self.writel(S_CAMS, 0, "") + self.writel(S_LAMPS, 0, "") + self.writel(S_IMGS, 0, "") + self.writel(S_MATS, 0, "") + self.writel(S_FX, 0, "") if (self.config["use_anim"]): self.export_animations() @@ -1886,10 +1973,10 @@ class DaeExporter: except: return False - f.write(bytes('\n', "UTF-8")) + f.write(bytes("\n", "UTF-8")) f.write(bytes( - '\n', "UTF-8")) + "\n", "UTF-8")) s = [] for x in self.sections.keys(): @@ -1899,18 +1986,19 @@ class DaeExporter: for l in self.sections[x]: f.write(bytes(l + "\n", "UTF-8")) - f.write(bytes('\n', "UTF-8")) - f.write(bytes('\t\n', "UTF-8")) - f.write(bytes('\n', "UTF-8")) - f.write(bytes('\n', "UTF-8")) + f.write(bytes("\n", "UTF-8")) + f.write(bytes( + "\t\n".format( + self.scene_name), "UTF-8")) + f.write(bytes("\n", "UTF-8")) + f.write(bytes("\n", "UTF-8")) return True __slots__ = ("operator", "scene", "last_id", "scene_name", "sections", "path", "mesh_cache", "curve_cache", "material_cache", "image_cache", "skeleton_info", "config", "valid_nodes", "armature_for_morph", "used_bones", "wrongvtx_report", - "temp_meshes") + "skeletons", "action_constraints", "temp_meshes") def __init__(self, path, kwargs, operator): self.operator = operator @@ -1930,6 +2018,8 @@ class DaeExporter: self.armature_for_morph = {} self.used_bones = [] self.wrongvtx_report = False + self.skeletons = [] + self.action_constraints = [] def __enter__(self): return self