annotate SceneGraph/BlenderScript/export_xml3.py @ 658:30a72124c7fd

export_xml3 for Blender 2.5 ( not yet worked )
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 27 Nov 2009 18:22:20 +0900
parents
children e1856ef4fc74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!BPY
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 """Registration info for Blender menus:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Name: 'Libps3 (.xml)'
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 Blender: 240
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 Group: 'Export'
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Tooltip: 'Export to (.xml) for libps3'
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 """
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 # Importing modules
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 import math
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #import subprocess
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 import os
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #import Blender
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 import struct
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 import base64
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #from Blender import NMesh, Scene, Object, Material, Texture, Window
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #from Blender import sys as bsys, Mathutils, Draw, BGL
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #from Blender.sys import *
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 global images, imageCount
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 images = {}
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 imageCount = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 def info(object, spacing=10, collapse=1):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 """Print methods and doc strings.
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 Takes module, class, list, dictionary, or string."""
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 methodList = [e for e in dir(object) if callable(getattr(object, e))]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 print("\n".join(["{0:s} {1:s}".format((method.ljust(spacing),
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 processFunc(str(getattr(object, method).__doc__))))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 for method in methodList]))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 # Data Structures
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 # Functions
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 # Image Get ?
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 # New name based on old with a different extension
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 def newFName(ext):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 return Blender.Get('filename')[: -len(Blender.Get('filename').split('.', -1)[-1]) ] + ext
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 #exporting an anime
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 #def export_anime(object_name):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 def export_anime(object_name,file):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 startF = Blender.Get('staframe')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 endF = Blender.Get('endframe')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 #str = ""
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 file.write("")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 file.write("\t\t<anim frame=\"{0:d}\">\n".format((endF) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 for i in range (startF, endF+1):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 Blender.Set('curframe', i)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 Blender.Redraw()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 time1 = Blender.sys.time()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 ##### XML header ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 #get all the objects in this scene
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 activelayers = Window.ViewLayer()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 for i in range(len(activelayers)):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 activelayers[i] = 2**(activelayers[i]-1)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 object_list1 = Blender.Scene.GetCurrent().getChildren()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 object_list = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 matnames= []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 for obj in object_list1:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 if obj.Layer in activelayers:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 object_list.append(obj)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 if obj.getType() == "Mesh":
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 materials_obj_list = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 materials_obj_list = obj.getData().materials
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 for mat in materials_obj_list:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 if mat.name not in matnames:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 matnames.append(mat.name)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 ##### Process Meshes ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 for obj in object_list:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 matrix = obj.getMatrix()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 if obj == object_name:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format((matrix[3][0], matrix[3][1], matrix[3][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 file.write("\t\t</anim>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 #return str
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 # exporting a mesh
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 ##change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 #def exportMesh(mesh, obj):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 def exportMesh(mesh, obj, file):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 vdata = [] # list of [ii0, ii1, ii2, ...] lists indexed by Blender-Vertex-index
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 vlist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 flist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 tri_first = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 tri_second = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 tri_third = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 def addVertex(bvindex, coord, normal, uv):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 index = -1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 if bvindex < len(vdata):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 for ivindex in vdata[bvindex]:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 v = vlist[ivindex]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 if (abs(v[0][0]-coord[0])<0.0001) and \
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 (abs(v[0][1]-coord[1])<0.0001) and \
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 (abs(v[0][2]-coord[2])<0.0001) and \
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 (abs(v[1][0]-normal[0])<0.0001) and \
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 (abs(v[1][1]-normal[1])<0.0001) and \
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 (abs(v[1][2]-normal[2])<0.0001):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 if ((v[2]==[]) and (uv==[])) or \
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 ((abs(v[2][0]-uv[0])<0.0001) and \
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 (abs(v[2][1]-uv[1])<0.0001)):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 index = ivindex
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 if index < 0:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 index = len(vlist)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 vlist.append([coord, normal, uv])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 while bvindex >= len(vdata):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 vdata.append([])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 vdata[bvindex].append(index)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 return index
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 def addFace(mindex, index0, index1, index2):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 while mindex >= len(flist):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 flist.append([])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 flist[mindex].append([index0, index1, index2])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 def getFaces():
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 ##change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 #str = ""
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 file.write("")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 matrix = obj.getMatrix()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 for mindex in range(len(flist)):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 fl = flist[mindex]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 if fl != []:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 parent_name = obj.getParent()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 if parent_name:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 parent_name = "{0:s}".format(parent_name)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 #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])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 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]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 #str += "\t<surface name=\"{0:s}\" size=\"{0:d}\" prim=\"Triangle\" parent=\"NULL\">\n".format((obj.name, len(fl)*3)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 file.write("\t<surface name=\"{0:s}\" size=\"{1:d}\" prim=\"Triangle\" parent=\"NULL\">\n".format((obj.name, len(fl)*3) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 #str += "\t\t<coordinate>\n"
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 file.write("\t\t<coordinate>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 for f in fl:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 tri_first = vlist[f[0]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 tri_second = vlist[f[1]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 tri_third = vlist[f[2]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format((tri_first[0][0] + matrix[3][0], tri_first[0][1] + matrix[3][1], tri_first[0][2] + matrix[3][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format((tri_second[0][0] + matrix[3][0], tri_second[0][1] + matrix[3][1], tri_second[0][2] + matrix[3][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format((tri_third[0][0] + matrix[3][0], tri_third[0][1] + matrix[3][1], tri_third[0][2] + matrix[3][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 file.write("\t\t</coordinate>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 file.write("\t\t<normal>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 for f in fl:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 tri_first = vlist[f[0]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 tri_second = vlist[f[1]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 tri_third = vlist[f[2]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format((tri_first[1][0], tri_first[1][1], tri_first[1][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format((tri_second[1][0], tri_second[1][1], tri_second[1][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format((tri_third[1][0], tri_third[1][1], tri_third[1][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 file.write("\t\t</normal>\n" )
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 file.write("\t\t<model>\n" )
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 ###parameter of translate
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format( (matrix[3][0], matrix[3][1], matrix[3][2]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 file.write("\t\t</model>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 if tri_first[2] != []:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 file.write("\t\t<texture>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 for f in fl:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 tri_first = vlist[f[0]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 tri_second = vlist[f[1]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 tri_third = vlist[f[2]]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 file.write("\t\t\t{0:f} {1:f}\n".format((tri_first[2][0], tri_first[2][1]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 file.write("\t\t\t{0:f} {1:f}\n".format((tri_second[2][0], tri_second[2][1]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 file.write("\t\t\t{0:f} {0:f}\n".format((tri_third[2][0], tri_third[2][1]) ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 file.write("\t\t</texture>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 file.write("\t\t<texture/>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 ### get texture_image and change base64 data
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 texture = mesh.faces[0].image
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 if texture:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 file.write(loadTexture(texture))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 file.write("\t\t<image name=\"{0:s}\">\n".format(("sample_white.png") ))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 file.write("\t\t</image>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 #return str
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 vdata = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 vlist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 flist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 for face in mesh.faces:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 iis = [-1, -1, -1, -1]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 for vi in range(len(face.v)):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 vert = face.v[vi]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 if face.smooth:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 normal = vert.no
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 normal = face.no
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 if len(face.uv) == len(face.v):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 uv = face.uv[vi]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 uv = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 iis[vi] = addVertex(vert.index, vert.co, normal, uv)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 addFace(face.materialIndex, iis[0], iis[1], iis[2])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 if len(face.v)==4:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 addFace(face.materialIndex, iis[2], iis[3], iis[0])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 #str = ""
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 #str += getFaces()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 getFaces();
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 #return str
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 # EXPORT
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 def save_xml(filename, unindexedname, anim):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 print("XML EXPORT\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 time1 = Blender.sys.time()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 print("Saving to '" + filename + "'...\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 file = open(filename, 'w')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 count_h = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 n = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 filename_h = filename[:-4] + ".h" #header file for cpp
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 file_h = open(filename_h, 'w')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 ##### XML header ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 file.write("<?xml version=\"1.0\"?>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 #get all the objects in this scene
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 activelayers = Window.ViewLayer()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 for i in range(len(activelayers)):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 activelayers[i] = 2**(activelayers[i]-1)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 object_list1 = Blender.Scene.GetCurrent().getChildren()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 object_list = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 matnames= []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 for obj in object_list1:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 if obj.Layer in activelayers:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 object_list.append(obj)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 if obj.getType() == "Mesh":
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 materials_obj_list = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 materials_obj_list = obj.getData().materials
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 for mat in materials_obj_list:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 if mat.name not in matnames:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 matnames.append(mat.name)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 ##### Process Meshes ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 meshlist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 file.write("<OBJECT-3D>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 for obj in object_list:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 if obj.getType() == "Mesh":
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 objectname = obj.getName()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 mesh = Blender.NMesh.GetRawFromObject(objectname)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 meshname = mesh.name
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 meshlight = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 if len(mesh.materials) > 0:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 mat0 = mesh.materials[0]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 if mat0.emit > 0:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 meshlight = 1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 if meshlight:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 print("processing Object \"{0:s}\" as Meshlight (Mesh \"{1:s}\")...".format((objectname, meshname)))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 print("processing Object \"{0:s}\" (Mesh \"{1:s}\")...".format((objectname, meshname)))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 try:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 meshlist.index(meshname)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 except ValueError:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 #file.write(exportMesh(mesh,obj))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 exportMesh(mesh,obj,file)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 meshlist.append(meshname)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 if anim == 1:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 #file.write("\t\t<anim>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 #file.write(export_anime(obj))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 export_anime(obj,file)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 #file.write("\t\t</anim>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 file.write("\t</surface>\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 file_h.write("#define {0:s} scene_graph".format((obj.name)))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 while n != count_h:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 file_h.write("->next")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 n = n + 1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 file_h.write("\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 count_h = count_h + 1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 n = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 ##### XML FOOTER ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 file.write("</OBJECT-3D>")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 file.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 file_h.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 print("Finished.\n")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 time2 = Blender.sys.time()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 print("Processing time: {0:f}\n".format((time2-time1)))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 Draw.Exit()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 ### SAVE ANIMATION ###
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 def save_anim(filename):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 global MatSaved
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 MatSaved = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 unindexedname = filename
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 save_xml(filename, unindexedname, 1)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 #### SAVE STILL (hackish...) ####
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 def save_still(filename):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 global MatSaved
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 MatSaved = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 unindexedname = filename
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 save_xml(filename, unindexedname, 0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 # Settings GUI
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 # Assign event numbers to buttons
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 evtNoEvt = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 evtExport = 1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 evtExportAnim = 2
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 # Set initial values of buttons
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 ## <size>800 600</size>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 sceneSizeX = Scene.GetCurrent().getRenderingContext().imageSizeX()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 sceneSizeY = Scene.GetCurrent().getRenderingContext().imageSizeY()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 SizeX = Draw.Create(sceneSizeX)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 SizeY = Draw.Create(sceneSizeY)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 TexExponent = Draw.Create(2.3)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 ## <metropolis>1</metropolis>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 MLT = Draw.Create(1)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 ## <large_mutation_prob>0.1</large_mutation_prob>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 LMP = Draw.Create(0.1)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 ## <max_change>0.02</max_change>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 MaxChange = Draw.Create(0.02)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 ## <russian_roulette_live_prob>0.7</russian_roulette_live_prob>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 RRLP = Draw.Create(0.7)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 ## <max_depth>100</max_depth>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 MaxDepth = Draw.Create(100)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 ## <bidirectional>false</bidirectional>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 Bidirectional = Draw.Create(0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 ## <strata_width>14</strata_width>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 StrataWidth = Draw.Create(14)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 ## <logging>0</logging>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 Logging = Draw.Create(0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 ## <save_untonemapped_exr>false</save_untonemapped_exr>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 SaveUTMExr = Draw.Create(0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 ## <save_tonemapped_exr>false</save_tonemapped_exr>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 SaveTMExr = Draw.Create(0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 ## <lens_radius>0.0</lens_radius>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 LensRadius = Draw.Create(0.0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 ## <focus_distance>2.0</focus_distance>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 FocusDistance = Draw.Create(2.0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 ## <turbidity>2.0</turbidity>
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 Turbidity = Draw.Create(2.0)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 GroundPlane = Draw.Create(1)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 ## Separate materials
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 MatFile = Draw.Create(1)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 # text color fix
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 textcol = [0, 0, 0]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 def gui():
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 global evtNoEvt, evtExport, evtExportAnim
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 global SizeX, SizeY, TexExponent, MLT, LMP, MaxChange, RRLP, MaxDepth, Bidirectional, StrataWidth, Logging, SaveUTMExr, SaveTMExr, LensRadius, FocusDistance,Turbidity, GroundPlane, MatFile
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 global textcol
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 Draw.Button("Export", evtExport, 10, 25, 100, 18, "Open file dialog and export")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 Draw.Button("Export Animation", evtExportAnim, 130, 25, 150, 18, "Open filedialog and export animation (careful: takes a lot of diskspace!!!)")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 BGL.glColor3f(textcol[0], textcol[1], textcol[2]) ; BGL.glRasterPos2i(10,10) ; Draw.Text("Press Q or ESC to quit.", "tiny")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 BGL.glRasterPos2i(10,60) ; Draw.Text("xml exporter for libps3")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 def event(evt, val): # function that handles keyboard and mouse events
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 if evt == Draw.ESCKEY or evt == Draw.QKEY:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 stop = Draw.PupMenu("OK?%t|Cancel export %x1")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 if stop == 1:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 Draw.Exit()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 return
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 def buttonEvt(evt): # function that handles button events
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 if evt == evtExport:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 Blender.Window.FileSelector(save_still, "Export", newFName('xml'))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 if evt == evtExportAnim:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 Blender.Window.FileSelector(save_anim, "Export Animation", newFName('xml'))
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 #if there was an event, redraw the window
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 if evt:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 Draw.Redraw()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 def loadTexture(texture):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 global images, imageCount
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 name = texture.getName()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 if name in images:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 return "\t\t<image name=\"" + name + "\"/>\n"
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 out = "\t\t<image name=\"" + name + "\">\n"
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 imageCount += 1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 images[name] = imageCount
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 image_path = texture.getFilename()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 input = open(expandpath(image_path), 'r')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 output = open('output.txt', 'w')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 base64.encode(input,output)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 input.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 output.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 input = open('output.txt', 'r')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 for b64 in input.readlines():
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 out += "\t\t\t{0:s}".format(b64)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 input.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 os.remove('output.txt')
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 out += "\t\t</image>\n"
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 return out
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 Draw.Register(gui, event, buttonEvt)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470