Mercurial > hg > Members > kono > Cerium
comparison SceneGraph/BlenderScript/export_xml.py @ 345:fffbfbfc9e34
[BlenderScript/export_xml.py] deplicate image
author | aaa |
---|---|
date | Wed, 08 Jul 2009 14:04:34 +0900 |
parents | 5c194c71eca8 |
children | 30a72124c7fd |
comparison
equal
deleted
inserted
replaced
344:81da25cb3e02 | 345:fffbfbfc9e34 |
---|---|
19 import base64 | 19 import base64 |
20 from Blender import NMesh, Scene, Object, Material, Texture, Window | 20 from Blender import NMesh, Scene, Object, Material, Texture, Window |
21 from Blender import sys as bsys, Mathutils, Draw, BGL | 21 from Blender import sys as bsys, Mathutils, Draw, BGL |
22 from Blender.sys import * | 22 from Blender.sys import * |
23 | 23 |
24 global images, imageCount | |
25 images = {} | |
26 imageCount = 0 | |
24 | 27 |
25 def info(object, spacing=10, collapse=1): | 28 def info(object, spacing=10, collapse=1): |
26 """Print methods and doc strings. | 29 """Print methods and doc strings. |
27 | 30 |
28 Takes module, class, list, dictionary, or string.""" | 31 Takes module, class, list, dictionary, or string.""" |
43 | 46 |
44 ###################################################### | 47 ###################################################### |
45 # Functions | 48 # Functions |
46 ###################################################### | 49 ###################################################### |
47 | 50 |
48 | 51 # Image Get ? |
49 # New name based on old with a different extension | 52 # New name based on old with a different extension |
50 def newFName(ext): | 53 def newFName(ext): |
51 return Blender.Get('filename')[: -len(Blender.Get('filename').split('.', -1)[-1]) ] + ext | 54 return Blender.Get('filename')[: -len(Blender.Get('filename').split('.', -1)[-1]) ] + ext |
52 | 55 |
53 | 56 |
200 | 203 |
201 | 204 |
202 ### get texture_image and change base64 data | 205 ### get texture_image and change base64 data |
203 texture = mesh.faces[0].image | 206 texture = mesh.faces[0].image |
204 if texture: | 207 if texture: |
205 file.write("\t\t<image name=\"%s\">\n" %(texture.getName()) ) | 208 file.write(loadTexture(texture)) |
206 image_path = texture.getFilename() | 209 |
207 input = open(expandpath(image_path), 'r') | 210 else: |
208 output = open('output.txt', 'w') | 211 file.write("\t\t<image name=\"%s\">\n" %("sample_white.png") ) |
209 base64.encode(input,output) | 212 |
210 input.close() | 213 file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n"); |
211 output.close() | 214 file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n"); |
212 input = open('output.txt', 'r') | 215 |
213 for b64 in input.readlines(): | |
214 file.write("\t\t\t%s" %b64) | |
215 input.close() | |
216 file.write("\t\t</image>\n") | 216 file.write("\t\t</image>\n") |
217 else: | |
218 file.write("\t\t<image/>\n") | |
219 | 217 |
220 #return str | 218 #return str |
221 | 219 |
222 vdata = [] | 220 vdata = [] |
223 vlist = [] | 221 vlist = [] |
443 Blender.Window.FileSelector(save_anim, "Export Animation", newFName('xml')) | 441 Blender.Window.FileSelector(save_anim, "Export Animation", newFName('xml')) |
444 #if there was an event, redraw the window | 442 #if there was an event, redraw the window |
445 if evt: | 443 if evt: |
446 Draw.Redraw() | 444 Draw.Redraw() |
447 | 445 |
446 | |
447 def loadTexture(texture): | |
448 global images, imageCount | |
449 name = texture.getName() | |
450 if name in images: | |
451 return "\t\t<image name=\"" + name + "\"/>\n" | |
452 out = "\t\t<image name=\"" + name + "\">\n" | |
453 imageCount += 1 | |
454 images[name] = imageCount | |
455 image_path = texture.getFilename() | |
456 input = open(expandpath(image_path), 'r') | |
457 output = open('output.txt', 'w') | |
458 base64.encode(input,output) | |
459 input.close() | |
460 output.close() | |
461 input = open('output.txt', 'r') | |
462 for b64 in input.readlines(): | |
463 out += "\t\t\t%s" %b64 | |
464 input.close() | |
465 os.remove('output.txt') | |
466 out += "\t\t</image>\n" | |
467 return out | |
468 | |
448 Draw.Register(gui, event, buttonEvt) | 469 Draw.Register(gui, event, buttonEvt) |
449 | 470 |
450 | 471 |