44c5bf6ff05d184e900f111898edb1999f674cab
[blender.git] / release / scripts / off_import.py
1 #!BPY
2
3 """
4 Name: 'OFF...'
5 Blender: 232
6 Group: 'Import'
7 Tooltip: 'Import Object File Format (*.off)'
8 """
9
10 # +---------------------------------------------------------+
11 # | Copyright (c) 2002 Anthony D'Agostino                   |
12 # | http://www.redrival.com/scorpius                        |
13 # | scorpius@netzero.com                                    |
14 # | February 3, 2001                                        |
15 # | Released under the Blender Artistic Licence (BAL)       |
16 # | Import Export Suite v0.5                                |
17 # +---------------------------------------------------------+
18 # | Read and write Object File Format (*.off)               |
19 # +---------------------------------------------------------+
20
21 import Blender, mod_meshtools
22 #import time
23
24 # =============================
25 # ====== Read OFF Format ======
26 # =============================
27 def read(filename):
28         #start = time.clock()
29         file = open(filename, "rb")
30
31         verts = []
32         faces = []
33
34         # === OFF Header ===
35         offheader = file.readline()
36         numverts, numfaces, null = file.readline().split()
37         numverts = int(numverts)
38         numfaces = int(numfaces)
39
40         # === Vertex List ===
41         for i in range(numverts):
42                 if not i%100 and mod_meshtools.show_progress:
43                         Blender.Window.DrawProgressBar(float(i)/numverts, "Reading Verts")
44                 x, y, z = file.readline().split()
45                 x, y, z = float(x), float(y), float(z)
46                 verts.append((x, y, z))
47
48         # === Face List ===
49         for i in range(numfaces):
50                 if not i%100 and mod_meshtools.show_progress:
51                         Blender.Window.DrawProgressBar(float(i)/numfaces, "Reading Faces")
52                 line = file.readline().split()
53                 numfaceverts = len(line)-1
54                 facev = []
55                 for j in range(numfaceverts):
56                         index = int(line[j+1])
57                         facev.append(index)
58                 facev.reverse()
59                 faces.append(facev)
60
61         objname = Blender.sys.splitext(Blender.sys.basename(filename))[0]
62
63         mod_meshtools.create_mesh(verts, faces, objname)
64         Blender.Window.DrawProgressBar(1.0, '')  # clear progressbar
65         file.close()
66         #end = time.clock()
67         #seconds = " in %.2f %s" % (end-start, "seconds")
68         message = "Successfully imported " + Blender.sys.basename(filename)# + seconds
69         mod_meshtools.print_boxed(message)
70
71 def fs_callback(filename):
72         read(filename)
73
74 Blender.Window.FileSelector(fs_callback, "OFF Import")