* Edited and consistent-ified the File->Import menu item labels and fileselect button...
[blender.git] / release / scripts / slp_import.py
1 #!BPY
2
3 """
4 Name: 'Pro Engineer (.slp)...'
5 Blender: 232
6 Group: 'Import'
7 Tooltip: 'Import Pro Engineer (.slp) File Format'
8 """
9
10 # $Id$
11 #
12 # +---------------------------------------------------------+
13 # | Copyright (c) 2004 Anthony D'Agostino                   |
14 # | http://www.redrival.com/scorpius                        |
15 # | scorpius@netzero.com                                    |
16 # | May 3, 2004                                             |
17 # | Released under the Blender Artistic Licence (BAL)       |
18 # | Import Export Suite v0.5                                |
19 # +---------------------------------------------------------+
20 # | Read and write SLP Triangle File Format (*.slp)         |
21 # +---------------------------------------------------------+
22
23 import Blender, mod_meshtools
24 #import time
25
26 # ================================
27 # === Read SLP Triangle Format ===
28 # ================================
29 def read(filename):
30         #start = time.clock()
31         file = open(filename, "rb")
32
33         raw = []
34         for line in file.readlines():
35                 data = line.split()
36                 if data[0] == "vertex":
37                         vert = map(float, data[1:])
38                         raw.append(vert)
39
40         tri = []
41         for i in range(0, len(raw), 3):
42                 tri.append(raw[i] + raw[i+1] + raw[i+2])
43
44         #$import pprint; pprint.pprint(tri)
45
46         # Collect data from RAW format
47         faces = []
48         for line in tri:
49                 f1, f2, f3, f4, f5, f6, f7, f8, f9 = line
50                 faces.append([(f1, f2, f3), (f4, f5, f6), (f7, f8, f9)])
51
52         # Generate verts and faces lists, without duplicates
53         verts = []
54         coords = {}
55         index = 0
56         for i in range(len(faces)):
57                 for j in range(len(faces[i])):
58                         vertex = faces[i][j]
59                         if not coords.has_key(vertex):
60                                 coords[vertex] = index
61                                 index += 1
62                                 verts.append(vertex)
63                         faces[i][j] = coords[vertex]
64
65         objname = Blender.sys.splitext(Blender.sys.basename(filename))[0]
66
67         mod_meshtools.create_mesh(verts, faces, objname)
68         Blender.Window.DrawProgressBar(1.0, '')  # clear progressbar
69         file.close()
70         #end = time.clock()
71         #seconds = " in %.2f %s" % (end-start, "seconds")
72         message = "Successfully imported " + Blender.sys.basename(filename)# + seconds
73         mod_meshtools.print_boxed(message)
74
75 def fs_callback(filename):
76         read(filename)
77
78 Blender.Window.FileSelector(fs_callback, "Import SLP")