Mercurial > hg > Game > Cerium
changeset 1236:bf913abaed15 draft
fix blender script for blender 2.59
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 20 Oct 2011 23:35:23 +0900 |
parents | 1bb43068289b |
children | 3c7e09953326 |
files | SceneGraph/BlenderScript/export_xml3.py |
diffstat | 1 files changed, 25 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/SceneGraph/BlenderScript/export_xml3.py Thu Oct 20 19:08:41 2011 +0900 +++ b/SceneGraph/BlenderScript/export_xml3.py Thu Oct 20 23:35:23 2011 +0900 @@ -36,6 +36,9 @@ #from Blender import sys as bsys, Mathutils, Draw, BGL #from Blender.sys import * +import sys +import codecs + global anim anim = 0 @@ -169,9 +172,7 @@ ###change def getFaces(): ##change - #str = "" file.write("") - # matrix = obj.matrix # already calcurated? matrix = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] @@ -182,14 +183,11 @@ if parent_name: parent_name = "{0:s}".format(parent_name) ###change - #str += "\t<surface name=\"{0:s}\" size=\"{0:d}\" prim=\"Triangle\" parent={0:s}>\n".format((obj.name, len(fl)*3, parent_name[8:-1]) file.write("\t<surface name=\"{0:s}\" size=\"{1:d}\" prim=\"Triangle\" parent={2:s}>\n".format(obj.name, len(fl)*3, parent_name[8:-1])) else: ###change - #str += "\t<surface name=\"{0:s}\" size=\"{0:d}\" prim=\"Triangle\" parent=\"NULL\">\n".format((obj.name, len(fl)*3) file.write("\t<surface name=\"{0:s}\" size=\"{1:d}\" prim=\"Triangle\" parent=\"NULL\">\n".format(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]] @@ -233,17 +231,15 @@ ### get texture_image and change base64 data - #texture = mesh.faces[0].image texture = None - if mesh.uv_texture_stencil: + if mesh.uv_texture_stencil and mesh.uv_texture_stencil.data.values() != []: texture = mesh.uv_texture_stencil.data[0].image if texture: - file.write(loadTexture(texture.name)) + file.write(loadTexture(texture)) else: file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png")) file.write("\t\t</image>\n") - #return str vdata = [] vlist = [] @@ -258,13 +254,12 @@ else: normal = face.normal uvs = [] - if mesh.uv_texture_stencil: - uv_texture = mesh.uv_texture_stencil.data[face.index] - uvs = [uv_texture.uv1, uv_texture.uv2, uv_texture.uv3, uv_texture.uv4] + if mesh.uv_texture_stencil and mesh.uv_texture_stencil.data.values() != []: + print(mesh.uv_texture_stencil.data) + uv_tex = mesh.uv_texture_stencil.data[face.index] + uvs = [uv_tex.uv1, uv_tex.uv2, uv_tex.uv3, uv_tex.uv4] print(len(uvs)) - print(" ") print(len(face.vertices)) - print("\n") if len(uvs) == len(face.vertices): uv = uvs[vi] else: @@ -285,7 +280,7 @@ def make_material_chunk(material, image, file): if image: - file.write(loadTexture(image)) + file.write(loadTexture(image)) else: file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png")) global sample_whited @@ -352,9 +347,9 @@ if ob.type not in ('MESH', 'CURVE', 'SURFACE', 'TEXT', 'META'): continue - data = ob_derived.to_mesh(sce, True, 'PREVIEW') -# data = bpy.data.meshes[ob_derived.name] - data.uv_texture_stencil = bpy.data.meshes[ob_derived.name].uv_texture_stencil +# data = ob_derived.to_mesh(sce, True, 'PREVIEW') + data = bpy.data.meshes[ob_derived.name] +# data.uv_texture_stencil = bpy.data.meshes[ob_derived.name].uv_texture_stencil # data = getMeshFromObject(ob_derived, None, True, False, sce) if data: data.transform(mat) @@ -403,11 +398,10 @@ if free: free_derived_objects(ob) - # Make material chunks for all materials used in the meshes: - for mat_and_image in materialDict.values(): - print("make material chunk {0:s}\n".format(mat_and_image[1])) - make_material_chunk(mat_and_image[0], mat_and_image[1], file) + # for mat_and_image in materialDict.values(): + # print("make material chunk {0:s}\n".format(mat_and_image[1])) + # make_material_chunk(mat_and_image[0], mat_and_image[1], file) # Give all objects a unique ID and build a dictionary from object name to object id: """ @@ -427,11 +421,16 @@ file.write("\t</surface>\n") # if not blender_mesh.users: # bpy.data.remove_mesh(blender_mesh) - bpy.data.meshes.remove(blender_mesh) +# bpy.data.meshes.remove(blender_mesh) # blender_mesh.verts = None + file.write("</OBJECT-3D>\n") # Close the file: file.close() +# reinitialize + global images + images = {} + @@ -445,8 +444,8 @@ imageCount += 1 images[name] = imageCount image_path = texture.filepath - input = open(expandpath(image_path), 'r') - output = open('output.txt', 'w') + input = open(bpy.path.abspath(image_path), 'rb') + output = open('output.txt', 'wb') base64.encode(input,output) input.close() output.close() @@ -481,7 +480,7 @@ def menu_func(self, context): default_path = bpy.data.filepath.replace(".blend", ".xml") - self.layout.operator(ExportPS3.bl_idname, text="PS3 Cerium (.xml)").path = default_path + self.layout.operator(ExportPS3.bl_idname, text="PS3 Cerium (.xml)").filepath = default_path def register():