annotate SceneGraph/BlenderScript/export_xml3.py @ 1035:ff0e6d00c060

bledenr script
author tkaito
date Mon, 29 Nov 2010 18:27:06 +0900
parents e1856ef4fc74
children
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
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
24 global anim
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
25 anim = 0
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
26
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
27
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 global images, imageCount
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 images = {}
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 imageCount = 0
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
33 __author__ = ["Shinji KONO"]
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
34 __url__ = ("www.ie.u-ryukyu.ac.jp/~kono/")
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
35 __version__ = "0.01a"
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
36 __bpydoc__ = """\
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
37
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
38 Cerium XML converter
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
39
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
40 """
658
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 # Data Structures
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
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 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 # Functions
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
54
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
55 def create_derived_objects(ob):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
56 if ob.parent and ob.parent.dupli_type != 'NONE':
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
57 return False, None
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
58
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
59 if ob.dupli_type != 'NONE':
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
60 ob.create_dupli_list()
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
61 return True, [(dob.object, dob.matrix) for dob in ob.dupli_list]
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
62 else:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
63 return False, [(ob, ob.matrix)]
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
64
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
65 # also used by X3D exporter
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
66 def free_derived_objects(ob):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
67 ob.free_dupli_list()
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
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 #exporting an anime
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 #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
73 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
74 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
75 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
76 #str = ""
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 file.write("")
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 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
79 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
80 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
81 Blender.Redraw()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 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
83
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 ##### XML header ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 #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
86 activelayers = Window.ViewLayer()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 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
88 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
89 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
90 object_list = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 matnames= []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 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
93 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
94 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
95
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
96 if obj.type == 'Mesh':
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 materials_obj_list = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 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
99 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
100 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
101 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
102
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 ##### Process Meshes ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 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
105 matrix = obj.getMatrix()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 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
107 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
108
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 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
110 #return str
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
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 # exporting a mesh
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 ##change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 #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
117 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
118
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 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
120 vlist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 flist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 tri_first = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 tri_second = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 tri_third = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 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
127 index = -1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 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
129 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
130 v = vlist[ivindex]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 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
132 (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
133 (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
134 (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
135 (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
136 (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
137 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
138 ((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
139 (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
140 index = ivindex
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 if index < 0:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 index = len(vlist)
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 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
144 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
145 vdata.append([])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 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
147 return index
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 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
150 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
151 flist.append([])
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 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
153
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 def getFaces():
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 ##change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 #str = ""
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 file.write("")
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
159 # matrix = obj.matrix
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
160 # already calcurated?
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
161 matrix = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 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
164 fl = flist[mindex]
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 if fl != []:
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
166 parent_name = obj.parent
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 if parent_name:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 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
169 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 #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
171 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
172 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 #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
175 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
176 ###change
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 #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
178 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
179 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
180 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
181 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
182 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
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\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
185 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
186 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
187 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
188
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 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
190 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
191 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
192 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
193 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
194
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 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
196 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
197 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
198 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
199
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 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
201 ###parameter of translate
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 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
203 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
204
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 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
206 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
207 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
208 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
209 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
210 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
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\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
213 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
214 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
215 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
216 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 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
218
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 ### 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
221 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
222 if texture:
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
223 file.write(loadTexture(texture.name))
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 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
226 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
227
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 #return str
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 vdata = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 vlist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 flist = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 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
234 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
235 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
236 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
237 if face.smooth:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 normal = vert.no
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 normal = face.no
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 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
242 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
243 else:
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 uv = []
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 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
246 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
247 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
248 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
249
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 #str = ""
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 #str += getFaces()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 getFaces();
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 #return str
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
256 def make_material_chunk(material, image):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
257 if image:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
258 file.write(loadTexture(image))
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
259 else:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
260 file.write("\t\t<image name=\"{0:s}\">\n".format(("sample_white.png") ))
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
261 global sample_whited
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
262 if (sample_whited == 0):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
263
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
264 file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
265 file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
266 sample_whited=1
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
267
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
268 file.write("\t\t</image>\n")
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 ######################################################
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 # EXPORT
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 ######################################################
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
273
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
274
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
275 def save_xml(filename, context):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
276 '''Save the Blender scene to a Cerium xml file.'''
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
277 # Time the export
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
278 global MatSaved
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
279 global anim
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
280 MatSaved = 0
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
281
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
282 if not filename.lower().endswith('.xml'):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
283 filename += '.xml'
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 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
285 file = open(filename, 'w')
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
286
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
287 # XXX
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
288 # if not BPyMessages.Warning_SaveOver(filename):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
289 # return
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
290
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
291 # XXX
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
292 time1 = time.clock()
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
293 # time1= Blender.sys.time()
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
294 # Blender.Window.WaitCursor(1)
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 ##### XML header ######
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 file.write("<?xml version=\"1.0\"?>\n")
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
298 file.write("<OBJECT-3D>\n")
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
300 sce = context.scene
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
301
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
302 # Get all the supported objects selected in this scene:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
303 # ob_sel= list(sce.objects.context)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
304 # mesh_objects = [ (ob, me) for ob in ob_sel for me in (BPyMesh.getMeshFromObject(ob, None, True, False, sce),) if me ]
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
305 # empty_objects = [ ob for ob in ob_sel if ob.type == 'Empty' ]
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
306
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
307 # Make a list of all materials used in the selected meshes (use a dictionary,
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
308 # each material is added once):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
309 materialDict = {}
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
310 mesh_objects = []
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
311 for ob in [ob for ob in context.scene.objects if ob.is_visible()]:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
312 # for ob in sce.objects.context:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
313
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
314 # get derived objects
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
315 free, derived = create_derived_objects(ob)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
316
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
317 if derived == None: continue
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
318
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
319 for ob_derived, mat in derived:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
320 # for ob_derived, mat in getDerivedObjects(ob, False):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
321
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
322 if ob.type not in ('MESH', 'CURVE', 'SURFACE', 'TEXT', 'META'):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
323 continue
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
325 data = ob_derived.create_mesh(True, 'PREVIEW')
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
326 # data = getMeshFromObject(ob_derived, None, True, False, sce)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
327 if data:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
328 data.transform(mat)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
329 # data.transform(mat, recalc_normals=False)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
330 mesh_objects.append((ob_derived, data))
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
331 mat_ls = data.materials
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
332 mat_ls_len = len(mat_ls)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
333
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
334 # get material/image tuples.
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
335 if len(data.uv_textures):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
336 # if data.faceUV:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
337 if not mat_ls:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
338 mat = mat_name = None
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
340 for f, uf in zip(data.faces, data.active_uv_texture.data):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
341 if mat_ls:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
342 mat_index = f.material_index
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
343 # mat_index = f.mat
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
344 if mat_index >= mat_ls_len:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
345 mat_index = f.mat = 0
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
346 mat = mat_ls[mat_index]
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
347 if mat: mat_name = mat.name
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
348 else: mat_name = None
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
349 # else there alredy set to none
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
351 img = uf.image
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
352 # img = f.image
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
353 if img: img_name = img.name
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
354 else: img_name = None
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
356 materialDict.setdefault((mat_name, img_name), (mat, img) )
658
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
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
359 else:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
360 for mat in mat_ls:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
361 if mat: # material may be None so check its not.
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
362 materialDict.setdefault((mat.name, None), (mat, None) )
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
364 # Why 0 Why!
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
365 for f in data.faces:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
366 if f.material_index >= mat_ls_len:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
367 # if f.mat >= mat_ls_len:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
368 f.material_index = 0
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
369 # f.mat = 0
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
371 if free:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
372 free_derived_objects(ob)
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
375 # Make material chunks for all materials used in the meshes:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
376 for mat_and_image in materialDict.values():
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
377 print("make material chunk {0:s}\n".format(mat_and_image[1]))
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
378 make_material_chunk(mat_and_image[0], mat_and_image[1])
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
380 # Give all objects a unique ID and build a dictionary from object name to object id:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
381 """
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
382 name_to_id = {}
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
383 for ob, data in mesh_objects:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
384 name_to_id[ob.name]= len(name_to_id)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
385 #for ob in empty_objects:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
386 # name_to_id[ob.name]= len(name_to_id)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
387 """
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
389 # Create object chunks for all meshes:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
390 for ob, blender_mesh in mesh_objects:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
391 print("export mesh {0:s}\n".format(ob.name))
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
392 exportMesh(blender_mesh,ob,file)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
393 if (anim):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
394 export_anime(obj,file)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
395 file.write("\t</surface>\n")
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
396 # if not blender_mesh.users:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
397 bpy.data.remove_mesh(blender_mesh)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
398 # blender_mesh.verts = None
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
399
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
400 # Close the file:
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
401 file.close()
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
402
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
403
658
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
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 def loadTexture(texture):
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 global images, imageCount
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
408 name = texture.name
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 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
410 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
411 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
412 imageCount += 1
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 images[name] = imageCount
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 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
415 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
416 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
417 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
418 input.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 output.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 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
421 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
422 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
423 input.close()
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 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
425 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
426 return out
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
428
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
429 from bpy.props import *
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
430 class ExportPS3(bpy.types.Operator):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
431 '''Export to Cerium XML file format.'''
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
432 bl_idname = "export.ps3cerium"
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
433 bl_label = 'Export PS3 Cerium'
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
434
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
435 # List of operator properties, the attributes will be assigned
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
436 # to the class instance from the operator settings before calling.
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
437
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
438
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
439 path = StringProperty(name="File Path", description="File path used for exporting the Cerium XML file", maxlen= 1024, default= "")
658
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
30a72124c7fd export_xml3 for Blender 2.5 ( not yet worked )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441
660
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
442 def execute(self, context):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
443 save_xml(self.properties.path, context)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
444 return ('FINISHED',)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
445
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
446 def invoke(self, context, event):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
447 wm = context.manager
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
448 wm.add_fileselect(self)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
449 return ('RUNNING_MODAL',)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
450
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
451 def poll(self, context): # Poll isnt working yet
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
452 return context.active_object != None
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
453
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
454 bpy.ops.add(ExportPS3)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
455
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
456 # Add to a menu
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
457 import dynamic_menu
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
458
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
459 def menu_func(self, context):
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
460 default_path = bpy.data.filename.replace(".blend", ".xml")
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
461 self.layout.operator(ExportPS3.bl_idname, text="PS3 Cerium...").path = default_path
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
462
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
463 menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
464
e1856ef4fc74 export xml3 not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 658
diff changeset
465 # end