-
Notifications
You must be signed in to change notification settings - Fork 25
/
asc_exporter.py
executable file
·62 lines (47 loc) · 1.52 KB
/
asc_exporter.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
61
62
#!BPY
"""
Name: 'ASC Exporter'
Blender: 249
Group: 'Export'
Tooltip: 'Export selected meshes to an ASC file'
"""
__author__ = 'Andor Salga'
import Blender
import BPyMessages
import bpy
def asc_export(path, meshObjects):
fileObject = open(path, 'w')
totalNumVertices = 0
for mesh in meshObjects:
currMesh = mesh.getData(mesh=True)
coords = [vertex.co for vertex in currMesh.verts]
normals = [vertex.no for vertex in currMesh.verts]
numCoords = len(coords)
totalNumVertices += numCoords
for i in xrange(numCoords):
str = "%f %f %f %f %f %f\n" % (coords[i].x, coords[i].y, coords[i].z, \
normals[i].x, normals[i].y, normals[i].z)
fileObject.write(str)
fileObject.close()
print 'Exported %d vertices' % totalNumVertices
def main():
def doExport(path):
selected_objects = Blender.Object.GetSelected()
mesh_objects = []
for selected_object in selected_objects:
if selected_object.getType() == 'Mesh':
mesh_objects.append(selected_object)
asc_export(path, mesh_objects)
def fileSelector(path):
if path and Blender.sys.exists(path):
choice = Blender.Draw.PupMenu("%s already exists. Replace it?%%t|Yes|No" % path)
if choice != 1:
return
doExport(path)
# Make sure the user has an object selected in the scene
if len(Blender.Object.GetSelected()) > 0:
Blender.Window.FileSelector(fileSelector, 'Ok', Blender.sys.makename(ext='.ASC'))
else:
BPyMessages.Error_NoActive()
if __name__ == "__main__":
main()