".format(v[2][0],1-v[2][1]))
file.write("\n")
for f in faces:
file.write("{} {} {}\n".format(f[0],f[1],f[2]))
#write other sections
print("===Materials summary====")
print(mtrls)
print("===Textures summary=====")
print(txtrs)
#===Write MATERIALS section=====
file.write("MATERIALS {}\n".format(len(mtrls))) #just mtrls sorted by values
temp_m=sorted(mtrls.items(),key=lambda x: x[1])
for m in temp_m:
file.write("{}\n".format(m[0]))
for m in temp_m:
file.write("MATERIAL {}\n".format(m[0]))
mat=bpy.data.materials[m[0]]
dc=mat.diffuse_color
file.write("{} {} {} {}\n".format(dc[0],dc[1],dc[2],mat.alpha))
file.write("{} {} {} {}\n".format(dc[0],dc[1],dc[2],mat.alpha))
sc=mat.specular_color
file.write("{} {} {} {} {}\n".format(sc[0],sc[1],sc[2],mat.specular_alpha,mat.specular_hardness))
file.write("{} {} {} {}\n".format(dc[0]*mat.emit,dc[1]*mat.emit,dc[2]*mat.emit,mat.alpha))
#=====Write TEXTURES section ======
file.write("TEXTURES {}\n".format(len(txtrs)))
v=os.path.split(filepath)
mshdir=v[0]
mshname=os.path.splitext(v[1])[0]
texdir=mshname+"tex"
texpath=os.path.join(mshdir,texdir)
temp_t=sorted(txtrs.items(),key=lambda x: x[1])
for t in temp_t:
tex=bpy.data.textures[t[0]]
img_fp=tex.image.filepath
tex_fname=""
if img_fp=="Untitled": #new name from tex name
tex_fname=tex.name+"."+tex.image.file_format.lower()
tex.image.save_render(os.path.join(texpath,tex_fname))
else: #image file is already saved on disk
tex_fname=os.path.split(img_fp)[1]
if tex.image.file_format=="":#if no format (dds) it will be saved as png.
tex_fname=os.path.splitext(tex_fname)[0]+".png"
tex.image.save_render(os.path.join(texpath,tex_fname))
file.write("{}\n".format(ntpath.join(texdir,os.path.splitext(tex_fname)[0]+".dd