Mercurial > hg > Game > Cerium
diff SceneGraph/BlenderScript/export_xml.py @ 109:028ffc9c0375 draft
Cerium cvs version
author | gongo@gendarme.local |
---|---|
date | Wed, 12 Nov 2008 17:39:33 +0900 |
parents | ce5755f544c1 |
children | 58b37bd7b2d5 |
line wrap: on
line diff
--- a/SceneGraph/BlenderScript/export_xml.py Wed Nov 12 17:29:35 2008 +0900 +++ b/SceneGraph/BlenderScript/export_xml.py Wed Nov 12 17:39:33 2008 +0900 @@ -52,11 +52,14 @@ #exporting an anime -def export_anime(object_name): +###change +#def export_anime(object_name): +def export_anime(object_name,file): startF = Blender.Get('staframe') endF = Blender.Get('endframe') - str = "" - str += "\t\t<anim frame=\"%d\">\n" %(endF) + #str = "" + file.write("") + file.write("\t\t<anim frame=\"%d\">\n" %(endF) ) for i in range (startF, endF+1): Blender.Set('curframe', i) Blender.Redraw() @@ -85,15 +88,18 @@ for obj in object_list: matrix = obj.getMatrix() if obj == object_name: - str +="\t\t\t%f %f %f\n" %(matrix[3][0], matrix[3][1], matrix[3][2]) + file.write("\t\t\t%f %f %f\n" %(matrix[3][0], matrix[3][1], matrix[3][2]) ) - str += "\t\t</anim>\n" - return str + file.write("\t\t</anim>\n") + #return str # exporting a mesh -def exportMesh(mesh, obj): +##change +#def exportMesh(mesh, obj): +def exportMesh(mesh, obj, file): + vdata = [] # list of [ii0, ii1, ii2, ...] lists indexed by Blender-Vertex-index vlist = [] flist = [] @@ -129,8 +135,11 @@ flist.append([]) flist[mindex].append([index0, index1, index2]) + ###change def getFaces(): - str = "" + ##change + #str = "" + file.write("") matrix = obj.getMatrix() for mindex in range(len(flist)): @@ -139,56 +148,61 @@ parent_name = obj.getParent() if parent_name: parent_name = "%s" %parent_name - str += "\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=%s>\n" %(obj.name, len(fl)*3, parent_name[8:-1]) + ###change + #str += "\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=%s>\n" %(obj.name, len(fl)*3, parent_name[8:-1]) + file.write("\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=%s>\n" %(obj.name, len(fl)*3, parent_name[8:-1]) ) else: - str += "\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=\"NULL\">\n" %(obj.name, len(fl)*3) - - str += "\t\t<coordinate>\n" + ###change + #str += "\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=\"NULL\">\n" %(obj.name, len(fl)*3) + file.write("\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=\"NULL\">\n" %(obj.name, len(fl)*3) ) + ###change + #str += "\t\t<coordinate>\n" + file.write("\t\t<coordinate>\n") for f in fl: tri_first = vlist[f[0]] tri_second = vlist[f[1]] tri_third = vlist[f[2]] - str += "\t\t\t%f %f %f\n" %(tri_first[0][0] + matrix[3][0], tri_first[0][1] + matrix[3][1], tri_first[0][2] + matrix[3][2]) - str += "\t\t\t%f %f %f\n" %(tri_second[0][0] + matrix[3][0], tri_second[0][1] + matrix[3][1], tri_second[0][2] + matrix[3][2]) - str += "\t\t\t%f %f %f\n" %(tri_third[0][0] + matrix[3][0], tri_third[0][1] + matrix[3][1], tri_third[0][2] + matrix[3][2]) - str += "\t\t</coordinate>\n" + file.write("\t\t\t%f %f %f\n" %(tri_first[0][0] + matrix[3][0], tri_first[0][1] + matrix[3][1], tri_first[0][2] + matrix[3][2]) ) + file.write("\t\t\t%f %f %f\n" %(tri_second[0][0] + matrix[3][0], tri_second[0][1] + matrix[3][1], tri_second[0][2] + matrix[3][2]) ) + file.write("\t\t\t%f %f %f\n" %(tri_third[0][0] + matrix[3][0], tri_third[0][1] + matrix[3][1], tri_third[0][2] + matrix[3][2]) ) + file.write("\t\t</coordinate>\n") - str += "\t\t<normal>\n" + file.write("\t\t<normal>\n") for f in fl: tri_first = vlist[f[0]] tri_second = vlist[f[1]] tri_third = vlist[f[2]] - str += "\t\t\t%f %f %f\n" %(tri_first[1][0], tri_first[1][1], tri_first[1][2]) - str += "\t\t\t%f %f %f\n" %(tri_second[1][0], tri_second[1][1], tri_second[1][2]) - str += "\t\t\t%f %f %f\n" %(tri_third[1][0], tri_third[1][1], tri_third[1][2]) - str += "\t\t</normal>\n" + file.write("\t\t\t%f %f %f\n" %(tri_first[1][0], tri_first[1][1], tri_first[1][2]) ) + file.write("\t\t\t%f %f %f\n" %(tri_second[1][0], tri_second[1][1], tri_second[1][2]) ) + file.write("\t\t\t%f %f %f\n" %(tri_third[1][0], tri_third[1][1], tri_third[1][2]) ) + file.write("\t\t</normal>\n" ) - str += "\t\t<model>\n" + file.write("\t\t<model>\n" ) ###parameter of translate - str += "\t\t\t%f %f %f\n" % (matrix[3][0], matrix[3][1], matrix[3][2]) - str += "\t\t</model>\n" + file.write("\t\t\t%f %f %f\n" % (matrix[3][0], matrix[3][1], matrix[3][2]) ) + file.write("\t\t</model>\n") if tri_first[2] != []: - str += "\t\t<texture>\n" + file.write("\t\t<texture>\n") for f in fl: tri_first = vlist[f[0]] tri_second = vlist[f[1]] tri_third = vlist[f[2]] - str += "\t\t\t%f %f\n" %(tri_first[2][0], tri_first[2][1]) - str += "\t\t\t%f %f\n" %(tri_second[2][0], tri_second[2][1]) - str += "\t\t\t%f %f\n" %(tri_third[2][0], tri_third[2][1]) - str += "\t\t</texture>\n" + file.write("\t\t\t%f %f\n" %(tri_first[2][0], tri_first[2][1]) ) + file.write("\t\t\t%f %f\n" %(tri_second[2][0], tri_second[2][1]) ) + file.write("\t\t\t%f %f\n" %(tri_third[2][0], tri_third[2][1]) ) + file.write("\t\t</texture>\n") else: - str += "\t\t<texture/>\n" + file.write("\t\t<texture/>\n") ### get texture_image and change base64 data texture = mesh.faces[0].image if texture: - str += "\t\t<image name=\"%s\">\n" %(texture.getName()) + file.write("\t\t<image name=\"%s\">\n" %(texture.getName()) ) image_path = texture.getFilename() input = open(expandpath(image_path), 'r') output = open('output.txt', 'w') @@ -197,15 +211,13 @@ output.close() input = open('output.txt', 'r') for b64 in input.readlines(): - str += "\t\t\t%s" %b64 + file.write("\t\t\t%s" %b64) input.close() - str += "\t\t</image>\n" + file.write("\t\t</image>\n") else: - str += "\t\t<image/>\n" + file.write("\t\t<image/>\n") - #str += "\t</surface>\n" - - return str + #return str vdata = [] vlist = [] @@ -227,10 +239,11 @@ if len(face.v)==4: addFace(face.materialIndex, iis[2], iis[3], iis[0]) - str = "" - str += getFaces() + #str = "" + #str += getFaces() + getFaces(); - return str + #return str ###################################################### @@ -288,11 +301,15 @@ try: meshlist.index(meshname) except ValueError: - file.write(exportMesh(mesh,obj)) + ###change + #file.write(exportMesh(mesh,obj)) + exportMesh(mesh,obj,file) meshlist.append(meshname) if anim == 1: #file.write("\t\t<anim>\n") - file.write(export_anime(obj)) + ###change + #file.write(export_anime(obj)) + export_anime(obj,file) #file.write("\t\t</anim>\n") file.write("\t</surface>\n") file_h.write("#define %s scene_graph" %(obj.name))