Mercurial > hg > Game > Cerium
annotate SceneGraph/BlenderScript/export_xml3.py @ 1238:8c2711796060 draft
fix blender script
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 21 Oct 2011 18:20:49 +0900 |
parents | 3c7e09953326 |
children | 759798f134e3 |
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")) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
231 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
|
232 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
233 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
234 vdata = [] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
235 vlist = [] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
236 flist = [] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
237 for face in mesh.faces: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
238 iis = [-1, -1, -1, -1] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
239 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
|
240 # vert = face.vertices[vi] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
241 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
|
242 if face.use_smooth: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
243 normal = vert.normal |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
244 else: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
245 normal = face.normal |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
246 uvs = [] |
1236
bf913abaed15
fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1235
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 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
|
251 uv = uvs[vi] |
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 uv = [] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
254 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
|
255 # 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
|
256 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
|
257 if len(face.vertices) == 4: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
258 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
|
259 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
260 #str = "" |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
261 #str += getFaces() |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
262 getFaces(); |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
263 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
264 #return str |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
265 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
266 sample_whited = 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 def make_material_chunk(material, image, file): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
269 if image: |
1236
bf913abaed15
fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1235
diff
changeset
|
270 file.write(loadTexture(image)) |
1234
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
271 else: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
272 file.write("\t\t<image name=\"{0:s}\">\n".format("sample_white.png")) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
273 global sample_whited |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
274 if (sample_whited == 0): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
275 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
276 file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n"); |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
277 file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n"); |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
278 sample_whited=1 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
279 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
280 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
|
281 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
282 ###################################################### |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
283 # EXPORT |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
284 ###################################################### |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
285 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
286 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
287 def save_xml(filename, context): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
288 '''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
|
289 # Time the export |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
290 global MatSaved |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
291 global anim |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
292 MatSaved = 0 |
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 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
|
295 filename += '.xml' |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
296 print("Saving to '" + filename + "'...\n") |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
297 file = open(filename, 'w') |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
298 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
299 # XXX |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
300 # 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
|
301 # return |
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 # XXX |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
304 # time1 = time.clock() |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
305 # time1= Blender.sys.time() |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
306 # Blender.Window.WaitCursor(1) |
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 ##### XML header ###### |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
309 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
|
310 file.write("<OBJECT-3D>\n") |
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 sce = context.scene |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
313 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
314 # 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
|
315 # 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
|
316 # 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
|
317 # 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
|
318 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
319 # 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
|
320 # each material is added once): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
321 materialDict = {} |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
322 mesh_objects = [] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
323 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
|
324 # 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
|
325 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
326 # get derived objects |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
327 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
|
328 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
329 if derived == None: continue |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
330 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
331 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
|
332 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
|
333 continue |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
334 |
1238 | 335 data = ob_derived.data |
1237 | 336 |
1234
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
337 if data: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
338 data.transform(mat) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
339 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
|
340 mat_ls = data.materials |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
341 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
|
342 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
343 # get material/image tuples. |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
344 if len(data.uv_textures): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
345 if not mat_ls: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
346 mat = mat_name = None |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
347 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
348 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
|
349 if mat_ls: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
350 mat_index = f.material_index |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
351 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
|
352 mat_index = f.mat = 0 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
353 mat = mat_ls[mat_index] |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
354 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
|
355 else: mat_name = None |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
356 # 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
|
357 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
358 img = uf.image |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
359 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
|
360 else: img_name = None |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
361 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
362 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
|
363 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
364 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
365 else: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
366 for mat in mat_ls: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
367 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
|
368 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
|
369 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
370 # Why 0 Why! |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
371 for f in data.faces: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
372 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
|
373 f.material_index = 0 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
374 # f.mat = 0 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
375 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
376 if free: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
377 free_derived_objects(ob) |
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 # 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
|
380 # 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
|
381 # 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
|
382 # 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
|
383 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
384 # 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
|
385 """ |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
386 name_to_id = {} |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
387 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
|
388 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
|
389 #for ob in empty_objects: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
390 # 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
|
391 """ |
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 # 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
|
394 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
|
395 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
|
396 exportMesh(blender_mesh,ob,file) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
397 if (anim): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
398 export_anime(obj,file) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
399 file.write("\t</surface>\n") |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
400 # if not blender_mesh.users: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
401 # 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
|
402 # 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
|
403 # blender_mesh.verts = None |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
404 |
1236
bf913abaed15
fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1235
diff
changeset
|
405 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
|
406 # Close the file: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
407 file.close() |
1236
bf913abaed15
fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1235
diff
changeset
|
408 # reinitialize |
bf913abaed15
fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1235
diff
changeset
|
409 global images |
bf913abaed15
fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1235
diff
changeset
|
410 images = {} |
bf913abaed15
fix blender script for blender 2.59
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1235
diff
changeset
|
411 |
1234
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
412 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
413 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
414 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
415 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
416 def loadTexture(texture): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
417 global images, imageCount |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
418 name = texture.name |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
419 if name in images: |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
420 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
|
421 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
|
422 imageCount += 1 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
423 images[name] = imageCount |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 base64.encode(input,output) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
428 input.close() |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
429 output.close() |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
430 input = open('output.txt', 'r') |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
431 for b64 in input.readlines(): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
432 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
|
433 input.close() |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
434 os.remove('output.txt') |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
435 out += "\t\t</image>\n" |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
436 return out |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
437 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
438 from bpy.props import * |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
439 class ExportPS3(bpy.types.Operator): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
440 '''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
|
441 bl_idname = "export.ps3cerium" |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
442 bl_label = 'Export PS3 Cerium' |
1235 | 443 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
|
444 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
445 # 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
|
446 # 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
|
447 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
448 def execute(self, context): |
1235 | 449 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
|
450 return {'FINISHED'} |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
451 def invoke(self, context, event): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
452 wm = context.window_manager |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
453 wm.fileselect_add(self) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
454 return {'RUNNING_MODAL'} |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
455 |
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 # Add to a menu |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
458 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
459 def menu_func(self, context): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
460 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
|
461 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
|
462 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
463 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
464 def register(): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
465 bpy.utils.register_module(__name__) |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
466 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
467 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
|
468 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
469 |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
470 def unregister(): |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
471 bpy.utils.unregister_module(__name__) |
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 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
|
474 |
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 if __name__ == "__main__": |
be0eb46dd20a
update blender script for SceneGraph XML
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
657
diff
changeset
|
477 register() |
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 # end |