~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/off_import.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!BPY
2
2
 
3
3
"""
4
 
Name: 'OFF...'
 
4
Name: 'DEC Object File Format (.off)...'
5
5
Blender: 232
6
6
Group: 'Import'
7
 
Tooltip: 'Import Object File Format (*.off)'
8
 
"""
 
7
Tooltip: 'Import DEC Object File Format (*.off)'
 
8
"""
 
9
 
 
10
__author__ = "Anthony D'Agostino (Scorpius)"
 
11
__url__ = ("blender", "elysiun",
 
12
"Author's homepage, http://www.redrival.com/scorpius")
 
13
__version__ = "Part of IOSuite 0.5"
 
14
 
 
15
__bpydoc__ = """\
 
16
This script imports DEC Object File Format files to Blender.
 
17
 
 
18
The DEC (Digital Equipment Corporation) OFF format is very old and
 
19
almost identical to Wavefront's OBJ. I wrote this so I could get my huge
 
20
meshes into Moonlight Atelier. (DXF can also be used but the file size
 
21
is five times larger than OFF!) Blender/Moonlight users might find this
 
22
script to be very useful.
 
23
 
 
24
Usage:<br>
 
25
        Execute this script from the "File->Import" menu and choose an OFF file to
 
26
open.
 
27
 
 
28
Notes:<br>
 
29
        UV Coordinate support has been added.
 
30
"""
 
31
 
9
32
 
10
33
# +---------------------------------------------------------+
11
34
# | Copyright (c) 2002 Anthony D'Agostino                   |
12
 
# | http://ourworld.compuserve.com/homepages/scorpius       |
13
 
# | scorpius@compuserve.com                                 |
 
35
# | http://www.redrival.com/scorpius                        |
 
36
# | scorpius@netzero.com                                    |
14
37
# | February 3, 2001                                        |
15
38
# | Released under the Blender Artistic Licence (BAL)       |
16
39
# | Import Export Suite v0.5                                |
18
41
# | Read and write Object File Format (*.off)               |
19
42
# +---------------------------------------------------------+
20
43
 
21
 
import Blender
 
44
import Blender, meshtools
22
45
#import time
23
 
import mod_flags, mod_meshtools
24
46
 
25
47
# =============================
26
48
# ====== Read OFF Format ======
31
53
 
32
54
        verts = []
33
55
        faces = []
 
56
        uv = []
34
57
 
35
58
        # === OFF Header ===
36
59
        offheader = file.readline()
37
60
        numverts, numfaces, null = file.readline().split()
38
61
        numverts = int(numverts)
39
62
        numfaces = int(numfaces)
 
63
        if offheader.find('ST') >= 0:
 
64
                has_uv = True
 
65
        else:
 
66
                has_uv = False
40
67
 
41
68
        # === Vertex List ===
42
69
        for i in range(numverts):
43
 
                if not i%100 and mod_flags.show_progress:
 
70
                if not i%100 and meshtools.show_progress:
44
71
                        Blender.Window.DrawProgressBar(float(i)/numverts, "Reading Verts")
45
 
                x, y, z = file.readline().split()
46
 
                x, y, z = float(x), float(y), float(z)
 
72
                if has_uv:
 
73
                        x, y, z, u, v = map(float, file.readline().split())
 
74
                        uv.append((u, v))
 
75
                else:
 
76
                        x, y, z = map(float, file.readline().split())
47
77
                verts.append((x, y, z))
48
78
 
49
79
        # === Face List ===
50
80
        for i in range(numfaces):
51
 
                if not i%100 and mod_flags.show_progress:
 
81
                if not i%100 and meshtools.show_progress:
52
82
                        Blender.Window.DrawProgressBar(float(i)/numfaces, "Reading Faces")
53
83
                line = file.readline().split()
54
84
                numfaceverts = len(line)-1
61
91
 
62
92
        objname = Blender.sys.splitext(Blender.sys.basename(filename))[0]
63
93
 
64
 
        mod_meshtools.create_mesh(verts, faces, objname)
 
94
        meshtools.create_mesh(verts, faces, objname, faces, uv)
65
95
        Blender.Window.DrawProgressBar(1.0, '')  # clear progressbar
66
96
        file.close()
67
97
        #end = time.clock()
68
98
        #seconds = " in %.2f %s" % (end-start, "seconds")
69
99
        message = "Successfully imported " + Blender.sys.basename(filename)# + seconds
70
 
        mod_meshtools.print_boxed(message)
 
100
        meshtools.print_boxed(message)
71
101
 
72
102
def fs_callback(filename):
73
103
        read(filename)
74
104
 
75
 
Blender.Window.FileSelector(fs_callback, "OFF Import")
 
105
Blender.Window.FileSelector(fs_callback, "Import OFF")