/
superexport.py
executable file
·60 lines (48 loc) · 1.74 KB
/
superexport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!BPY
"""
Name: 'SuperExport'
Blender: 249
Group: 'Export'
Tooltip: 'Supernova Mobile Exporter'
"""
import Blender
import bpy
def write_obj(filePath):
out = file(filePath, 'w')
sce = bpy.data.scenes.active
obj = sce.objects.active
mesh = obj.getData(mesh=1)
out.write('<model>\n')
#out.write('\t<verts>\n')
#out.write('\t</verts>\n')
out.write('\t<verts>\n')
i = 0
for face in mesh.faces:
for vert in face.v:
out.write('\t\t<i>%i</i>\n' % (i))
i = i + 1
out.write('\t\t<vx>%f</vx>\n' % (vert.co.x))
out.write('\t\t<vy>%f</vy>\n' % (vert.co.y))
out.write('\t\t<vz>%f</vz>\n' % (vert.co.z))
out.write('\t\t<vnx>%f</vnx>\n' % (vert.no.x))
out.write('\t\t<vny>%f</vny>\n' % (vert.no.y))
out.write('\t\t<vnz>%f</vnz>\n\n' % (vert.no.z))
out.write('\t</verts>\n')
if mesh.faceUV:
out.write('\t<uv>\n')
for face in mesh.faces:
for uv in face.uv:
u, v = uv
out.write('\t\t<u>%f</u>\n' % (u))
out.write('\t\t<v>%f</v>\n' % (v))
out.write('\t</uv>\n')
# Texture #
####################################################
mats = Blender.Material.get()
if (len(mats) > 0):
for m in mats:
if (type(m.textures[0]).__name__ != "NoneType" and type(m.textures[0].tex.getImage()).__name__ != "NoneType"):
out.write("\t<tex>" + m.textures[0].tex.getImage().getName() + "</tex>\n")
out.write('</model>')
out.close()
Blender.Window.FileSelector(write_obj, "Export")