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