diff 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
line wrap: on
line diff
--- a/SceneGraph/BlenderScript/export_xml.py	Fri Jul 03 19:52:52 2009 +0900
+++ b/SceneGraph/BlenderScript/export_xml.py	Wed Jul 08 14:04:34 2009 +0900
@@ -21,6 +21,9 @@
 from Blender import sys as bsys, Mathutils, Draw, BGL
 from Blender.sys import *
 
+global images, imageCount
+images = {}
+imageCount = 0
 
 def info(object, spacing=10, collapse=1):
 	"""Print methods and doc strings.
@@ -45,7 +48,7 @@
 # Functions
 ######################################################
 
-
+# Image Get ?
 # New name based on old with a different extension
 def newFName(ext):
 	return Blender.Get('filename')[: -len(Blender.Get('filename').split('.', -1)[-1]) ] + ext
@@ -202,20 +205,15 @@
 				### get texture_image and change base64 data
 				texture = mesh.faces[0].image
 				if texture:
-					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')
-					base64.encode(input,output)
-					input.close()
-					output.close()
-					input = open('output.txt', 'r')
-					for b64 in input.readlines():
-						file.write("\t\t\t%s" %b64)
-					input.close()
+					file.write(loadTexture(texture))	
+					
+				else:
+					file.write("\t\t<image name=\"%s\">\n" %("sample_white.png") )
+
+					file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
+					file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
+
 					file.write("\t\t</image>\n")
-				else:
-					file.write("\t\t<image/>\n")
 
 		#return str
 
@@ -445,6 +443,29 @@
     if evt:
         Draw.Redraw()
 
+
+def loadTexture(texture):
+	global images, imageCount
+	name = texture.getName()
+	if name in images:
+		return "\t\t<image name=\"" + name + "\"/>\n"	
+	out = "\t\t<image name=\"" + name + "\">\n"
+	imageCount += 1
+	images[name] = imageCount
+	image_path = texture.getFilename()
+	input = open(expandpath(image_path), 'r')	
+	output = open('output.txt', 'w')
+	base64.encode(input,output)
+	input.close()
+	output.close()
+	input = open('output.txt', 'r')
+	for b64 in input.readlines():
+		out += "\t\t\t%s" %b64		
+	input.close()
+	os.remove('output.txt')
+	out += "\t\t</image>\n"
+	return out
+
 Draw.Register(gui, event, buttonEvt)