annotate SceneGraph/BlenderScript/export_xml3.py @ 1479:163220e54cc0 draft

remove hard code for TaskLog
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Tue, 24 Jul 2012 17:15:15 +0900
parents 759798f134e3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
1 #!BPY
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
2 """Registration info for Blender menus:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
3 Name: 'Libps3 (.xml)'
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
4 Blender: 240
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
5 Group: 'Export'
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
6 Tooltip: 'Export to (.xml) for libps3'
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
7 """
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
8
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
9 bl_info = {
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
10 "name": "PS3 Cerium (.xml)",
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
11 "author": "Shinji KONO",
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
12 "version": (2, 0, 0),
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
13 "blender": (2, 5, 8),
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
14 "api": 37702,
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
15 "location": "File > Import-Export",
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
16 "description": "Export PS3 Cerium (.xml)",
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
17 "warning": "",
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
18 # "wiki_url": "",
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
19 # "tracker_url": "",
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
20 "category": "Import-Export"}
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
21
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
22
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
23
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
24 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
25 # Importing modules
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
26 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
27
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
28 import math
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
29 import os
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
30 import struct
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
31 import base64
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
32 import bpy
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
33
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
34 global anim
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
35 anim = 0
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
36
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
37
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
38 global images, imageCount
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
39 images = {}
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
40 imageCount = 0
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
41
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
42
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
43 __author__ = ["Shinji KONO"]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
44 __url__ = ("www.ie.u-ryukyu.ac.jp/~kono/")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
45 __version__ = "0.01a"
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
46 __bpydoc__ = """\
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
47
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
48 Cerium XML converter
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
49
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
50 """
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
51
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
52
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
53 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
54 # Data Structures
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
55 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
56
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
57
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
58
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
59
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
60 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
61 # Functions
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
62 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
63
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
64
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
65 def create_derived_objects(ob):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
66 if ob.parent and ob.parent.dupli_type != 'NONE':
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
67 return False, None
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
68
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
69 if ob.dupli_type != 'NONE':
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
70 ob.create_dupli_list()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
71 return True, [(dob.object, dob.matrix_basis) for dob in ob.dupli_list]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
72 else:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
73 return False, [(ob, ob.matrix_basis)] # Which do we use basis, local or world for matrix?
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
74
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
75 # also used by X3D exporter
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
76 def free_derived_objects(ob):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
77 ob.free_dupli_list()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
78
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
79
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
80 #exporting an anime
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
81 ###change
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
82 def export_anime(object_name,file):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
83 startF = Blender.Get('staframe')
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
84 endF = Blender.Get('endframe')
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
85 #str = ""
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
86 file.write("")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
87 file.write("\t\t<anim frame=\"{0:d}\">\n".format(endF))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
88 for i in range (startF, endF+1):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
89 Blender.Set('curframe', i)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
90 Blender.Redraw()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
91 # time1 = Blender.sys.time()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
92
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
93 ##### XML header ######
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
94 #get all the objects in this scene
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
95 activelayers = Window.ViewLayer()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
96 for i in range(len(activelayers)):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
97 activelayers[i] = 2**(activelayers[i]-1)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
98 object_list1 = Blender.Scene.GetCurrent().getChildren()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
99 object_list = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
100 matnames= []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
101 for obj in object_list1:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
102 if obj.Layer in activelayers:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
103 object_list.append(obj)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
104
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
105 if obj.type == 'Mesh':
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
106 materials_obj_list = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
107 materials_obj_list = obj.getData().materials
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
108 for mat in materials_obj_list:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
109 if mat.name not in matnames:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
110 matnames.append(mat.name)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
111
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
112 ##### Process Meshes ######
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
113 for obj in object_list:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
114 matrix = obj.getMatrix()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
115 if obj == object_name:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
116 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format(matrix[3][0], matrix[3][1], matrix[3][2]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
117
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
118 file.write("\t\t</anim>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
119 #return str
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
120
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
121
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
122
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
123 # exporting a mesh
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
124 ##change
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
125 def exportMesh(mesh, obj, file):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
126
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
127 vdata = [] # list of [ii0, ii1, ii2, ...] lists indexed by Blender-Vertex-index
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
128 vlist = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
129 flist = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
130 tri_first = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
131 tri_second = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
132 tri_third = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
133
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
134 def addVertex(bvindex, coord, normal, uv):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
135 index = -1
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
136 if bvindex < len(vdata):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
137 for ivindex in vdata[bvindex]:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
138 v = vlist[ivindex]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
139 if (abs(v[0][0]-coord[0])<0.0001) and \
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
140 (abs(v[0][1]-coord[1])<0.0001) and \
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
141 (abs(v[0][2]-coord[2])<0.0001) and \
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
142 (abs(v[1][0]-normal[0])<0.0001) and \
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
143 (abs(v[1][1]-normal[1])<0.0001) and \
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
144 (abs(v[1][2]-normal[2])<0.0001):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
145 if ((v[2]==[]) and (uv==[])) or \
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
146 ((abs(v[2][0]-uv[0])<0.0001) and \
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
147 (abs(v[2][1]-uv[1])<0.0001)):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
148 index = ivindex
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
149 if index < 0:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
150 index = len(vlist)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
151 vlist.append([coord, normal, uv])
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
152 while bvindex >= len(vdata):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
153 vdata.append([])
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
154 vdata[bvindex].append(index)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
155 return index
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
156
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
157 def addFace(mindex, index0, index1, index2):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
158 while mindex >= len(flist):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
159 flist.append([])
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
160 flist[mindex].append([index0, index1, index2])
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
161
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
162 ###change
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
163 def getFaces():
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
164 ##change
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
165 file.write("")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
166 # already calcurated?
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
167 matrix = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
168
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
169 for mindex in range(len(flist)):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
170 fl = flist[mindex]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
171 if fl != []:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
172 parent_name = obj.parent
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
173 if parent_name:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
174 parent_name = "{0:s}".format(parent_name)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
175 ###change
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
176 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]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
177 else:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
178 ###change
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
179 file.write("\t<surface name=\"{0:s}\" size=\"{1:d}\" prim=\"Triangle\" parent=\"NULL\">\n".format(obj.name, len(fl)*3))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
180 ###change
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
181 file.write("\t\t<coordinate>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
182 for f in fl:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
183 tri_first = vlist[f[0]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
184 tri_second = vlist[f[1]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
185 tri_third = vlist[f[2]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
186
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
187 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] ))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
188 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] ))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
189 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]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
190 file.write("\t\t</coordinate>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
191
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
192 file.write("\t\t<normal>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
193 for f in fl:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
194 tri_first = vlist[f[0]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
195 tri_second = vlist[f[1]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
196 tri_third = vlist[f[2]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
197
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
198 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]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
199 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]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
200 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]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
201 file.write("\t\t</normal>\n" )
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
202
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
203 file.write("\t\t<model>\n" )
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
204 ###parameter of translate
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
205 file.write("\t\t\t{0:f} {1:f} {2:f}\n".format(matrix[3][0], matrix[3][1], matrix[3][2]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
206 file.write("\t\t</model>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
207
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
208 if tri_first[2] != []:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
209 file.write("\t\t<texture>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
210 for f in fl:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
211 tri_first = vlist[f[0]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
212 tri_second = vlist[f[1]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
213 tri_third = vlist[f[2]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
214
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
215 file.write("\t\t\t{0:f} {1:f}\n".format(tri_first[2][0], tri_first[2][1]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
216 file.write("\t\t\t{0:f} {1:f}\n".format(tri_second[2][0], tri_second[2][1]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
217 file.write("\t\t\t{0:f} {0:f}\n".format(tri_third[2][0], tri_third[2][1]))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
218 file.write("\t\t</texture>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
219 else:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
220 file.write("\t\t<texture/>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
221
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
222
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
223 ### get texture_image and change base64 data
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
224 texture = None
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
225 if mesh.uv_texture_stencil and mesh.uv_texture_stencil.data.values() != []:
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
226 texture = mesh.uv_texture_stencil.data[0].image
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
227 if texture:
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
228 file.write(loadTexture(texture))
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
229 else:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
230 file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png"))
1239
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
231 #sample_whited = 0
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
232 #if (sample_whited == 0):
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
233 file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n")
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
234 file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n")
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
235 #sample_whited=1
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
236 file.write("\t\t</image>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
237
1239
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
238
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
239
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
240
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
241
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
242 vdata = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
243 vlist = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
244 flist = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
245 for face in mesh.faces:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
246 iis = [-1, -1, -1, -1]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
247 for vi in range(len(face.vertices)):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
248 # vert = face.vertices[vi]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
249 vert = mesh.vertices[face.vertices[vi]]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
250 if face.use_smooth:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
251 normal = vert.normal
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
252 else:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
253 normal = face.normal
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
254 uvs = []
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
255 if mesh.uv_texture_stencil and mesh.uv_texture_stencil.data.values() != []:
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
256 uv_tex = mesh.uv_texture_stencil.data[face.index]
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
257 uvs = [uv_tex.uv1, uv_tex.uv2, uv_tex.uv3, uv_tex.uv4]
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
258 if len(uvs) == len(face.vertices):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
259 uv = uvs[vi]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
260 else:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
261 uv = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
262 iis[vi] = addVertex(vert.index, vert.co, normal, uv)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
263 # MEMO: bpy.context.scene.objects['Cube'].data.uv_textures['UVTex'].data[0].uv1
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
264 addFace(face.material_index, iis[0], iis[1], iis[2])
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
265 if len(face.vertices) == 4:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
266 addFace(face.material_index, iis[2], iis[3], iis[0])
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
267
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
268 #str = ""
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
269 #str += getFaces()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
270 getFaces();
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
271
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
272 #return str
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
273
1239
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
274
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
275
1239
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
276 #sample_whited = 0
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
277 # don't call this method#
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
278 #def make_material_chunk(material, image, file):
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
279 # if image:
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
280 # file.write(loadTexture(image))
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
281 # else:
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
282 # file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png"))
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
283 # global sample_whited
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
284 # if (sample_whited == 0):
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
285 # file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
286 # file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
287 # sample_whited=1
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
288 #
759798f134e3 sample_white change by 095732B 095736E
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1238
diff changeset
289 # file.write("\t\t</image>\n")
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
290
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
291 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
292 # EXPORT
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
293 ######################################################
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
294
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
295
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
296 def save_xml(filename, context):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
297 '''Save the Blender scene to a Cerium xml file.'''
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
298 # Time the export
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
299 global MatSaved
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
300 global anim
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
301 MatSaved = 0
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
302
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
303 if not filename.lower().endswith('.xml'):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
304 filename += '.xml'
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
305 print("Saving to '" + filename + "'...\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
306 file = open(filename, 'w')
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
307
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
308 # XXX
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
309 # if not BPyMessages.Warning_SaveOver(filename):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
310 # return
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
311
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
312 # XXX
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
313 # time1 = time.clock()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
314 # time1= Blender.sys.time()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
315 # Blender.Window.WaitCursor(1)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
316
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
317 ##### XML header ######
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
318 file.write("<?xml version=\"1.0\"?>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
319 file.write("<OBJECT-3D>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
320
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
321 sce = context.scene
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
322
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
323 # Get all the supported objects selected in this scene:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
324 # ob_sel= list(sce.objects.context)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
325 # mesh_objects = [ (ob, me) for ob in ob_sel for me in (BPyMesh.getMeshFromObject(ob, None, True, False, sce),) if me ]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
326 # empty_objects = [ ob for ob in ob_sel if ob.type == 'Empty' ]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
327
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
328 # Make a list of all materials used in the selected meshes (use a dictionary,
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
329 # each material is added once):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
330 materialDict = {}
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
331 mesh_objects = []
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
332 for ob in [ob for ob in context.scene.objects if ob.is_visible(bpy.context.scene)]:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
333 # for ob in sce.objects.context:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
334
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
335 # get derived objects
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
336 free, derived = create_derived_objects(ob)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
337
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
338 if derived == None: continue
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
339
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
340 for ob_derived, mat in derived:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
341 if ob.type not in ('MESH', 'CURVE', 'SURFACE', 'TEXT', 'META'):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
342 continue
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
343
1238
8c2711796060 fix blender script
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1237
diff changeset
344 data = ob_derived.data
1237
3c7e09953326 delete codes for debuged
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1236
diff changeset
345
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
346 if data:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
347 data.transform(mat)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
348 mesh_objects.append((ob_derived, data))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
349 mat_ls = data.materials
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
350 mat_ls_len = len(mat_ls)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
351
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
352 # get material/image tuples.
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
353 if len(data.uv_textures):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
354 if not mat_ls:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
355 mat = mat_name = None
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
356
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
357 for f, uf in zip(data.faces, data.uv_texture_stencil.data):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
358 if mat_ls:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
359 mat_index = f.material_index
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
360 if mat_index >= mat_ls_len:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
361 mat_index = f.mat = 0
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
362 mat = mat_ls[mat_index]
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
363 if mat: mat_name = mat.name
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
364 else: mat_name = None
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
365 # else there alredy set to none
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
366
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
367 img = uf.image
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
368 if img: img_name = img.name
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
369 else: img_name = None
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
370
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
371 materialDict.setdefault((mat_name, img_name), (mat, img) )
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
372
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
373
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
374 else:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
375 for mat in mat_ls:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
376 if mat: # material may be None so check its not.
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
377 materialDict.setdefault((mat.name, None), (mat, None) )
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
378
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
379 # Why 0 Why!
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
380 for f in data.faces:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
381 if f.material_index >= mat_ls_len:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
382 f.material_index = 0
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
383 # f.mat = 0
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
384
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
385 if free:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
386 free_derived_objects(ob)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
387
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
388 # Make material chunks for all materials used in the meshes:
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
389 # for mat_and_image in materialDict.values():
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
390 # print("make material chunk {0:s}\n".format(mat_and_image[1]))
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
391 # make_material_chunk(mat_and_image[0], mat_and_image[1], file)
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
392
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
393 # Give all objects a unique ID and build a dictionary from object name to object id:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
394 """
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
395 name_to_id = {}
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
396 for ob, data in mesh_objects:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
397 name_to_id[ob.name]= len(name_to_id)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
398 #for ob in empty_objects:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
399 # name_to_id[ob.name]= len(name_to_id)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
400 """
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
401
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
402 # Create object chunks for all meshes:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
403 for ob, blender_mesh in mesh_objects:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
404 print("export mesh {0:s}\n".format(ob.name))
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
405 exportMesh(blender_mesh,ob,file)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
406 if (anim):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
407 export_anime(obj,file)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
408 file.write("\t</surface>\n")
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
409 # if not blender_mesh.users:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
410 # bpy.data.remove_mesh(blender_mesh)
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
411 # bpy.data.meshes.remove(blender_mesh)
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
412 # blender_mesh.verts = None
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
413
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
414 file.write("</OBJECT-3D>\n")
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
415 # Close the file:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
416 file.close()
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
417 # reinitialize
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
418 global images
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
419 images = {}
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
420
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
421
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
422
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
423
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
424
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
425 def loadTexture(texture):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
426 global images, imageCount
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
427 name = texture.name
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
428 if name in images:
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
429 return "\t\t<image name=\"" + name + "\"/>\n"
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
430 out = "\t\t<image name=\"" + name + "\">\n"
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
431 imageCount += 1
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
432 images[name] = imageCount
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
433 image_path = texture.filepath
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
434 input = open(bpy.path.abspath(image_path), 'rb')
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
435 output = open('output.txt', 'wb')
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
436 base64.encode(input,output)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
437 input.close()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
438 output.close()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
439 input = open('output.txt', 'r')
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
440 for b64 in input.readlines():
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
441 out += "\t\t\t{0:s}".format(b64)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
442 input.close()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
443 os.remove('output.txt')
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
444 out += "\t\t</image>\n"
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
445 return out
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
446
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
447 from bpy.props import *
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
448 class ExportPS3(bpy.types.Operator):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
449 '''Export to Cerium XML file format.'''
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
450 bl_idname = "export.ps3cerium"
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
451 bl_label = 'Export PS3 Cerium'
1235
1bb43068289b update blender script
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1234
diff changeset
452 filepath = StringProperty(subtype='FILE_PATH')
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
453
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
454 # List of operator properties, the attributes will be assigned
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
455 # to the class instance from the operator settings before calling.
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
456
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
457 def execute(self, context):
1235
1bb43068289b update blender script
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1234
diff changeset
458 save_xml(bpy.path.ensure_ext(self.filepath, ".xml"), context)
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
459 return {'FINISHED'}
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
460 def invoke(self, context, event):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
461 wm = context.window_manager
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
462 wm.fileselect_add(self)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
463 return {'RUNNING_MODAL'}
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
464
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
465
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
466 # Add to a menu
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
467
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
468 def menu_func(self, context):
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
469 default_path = bpy.data.filepath.replace(".blend", ".xml")
1236
bf913abaed15 fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 1235
diff changeset
470 self.layout.operator(ExportPS3.bl_idname, text="PS3 Cerium (.xml)").filepath = default_path
1234
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
471
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
472
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
473 def register():
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
474 bpy.utils.register_module(__name__)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
475
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
476 bpy.types.INFO_MT_file_export.append(menu_func)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
477
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
478
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
479 def unregister():
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
480 bpy.utils.unregister_module(__name__)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
481
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
482 bpy.types.INFO_MT_file_export.remove(menu_func)
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
483
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
484
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
485 if __name__ == "__main__":
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
486 register()
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
487
be0eb46dd20a update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 657
diff changeset
488 # end