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

« back to all changes in this revision

Viewing changes to release/scripts/radiosity_import.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!BPY
2
 
 
3
 
"""
4
 
Name: 'Radiosity (.radio)...'
5
 
Blender: 232
6
 
Group: 'Import'
7
 
Tooltip: 'Import Radiosity File Format (.radio) with vertex colors'
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 Radiosity files to Blender.
17
 
 
18
 
The Radiosity file format is my own personal format. I created it to
19
 
learn how meshes and vertex colors were stored. See IO-Examples.zip, the
20
 
example *.radio files on my web page.
21
 
 
22
 
Usage:<br>
23
 
        Execute this script from the "File->Import" menu and choose a Radiosity
24
 
file to open.
25
 
"""
26
 
 
27
 
# $Id: radiosity_import.py,v 1.13 2007/01/27 04:58:09 campbellbarton Exp $
28
 
#
29
 
# +---------------------------------------------------------+
30
 
# | Copyright (c) 2002 Anthony D'Agostino                   |
31
 
# | http://www.redrival.com/scorpius                        |
32
 
# | scorpius@netzero.com                                    |
33
 
# | April 11, 2002                                          |
34
 
# | Read and write Radiosity File Format (*.radio)          |
35
 
# +---------------------------------------------------------+
36
 
 
37
 
# ***** BEGIN GPL LICENSE BLOCK *****
38
 
#
39
 
# This program is free software; you can redistribute it and/or
40
 
# modify it under the terms of the GNU General Public License
41
 
# as published by the Free Software Foundation; either version 2
42
 
# of the License, or (at your option) any later version.
43
 
#
44
 
# This program is distributed in the hope that it will be useful,
45
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
46
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47
 
# GNU General Public License for more details.
48
 
#
49
 
# You should have received a copy of the GNU General Public License
50
 
# along with this program; if not, write to the Free Software Foundation,
51
 
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
52
 
#
53
 
# ***** END GPL LICENCE BLOCK *****
54
 
 
55
 
import Blender, meshtools
56
 
 
57
 
try:
58
 
        import struct
59
 
except:
60
 
        struct= None
61
 
 
62
 
# ===============================
63
 
# ====== Read Radio Format ======
64
 
# ===============================
65
 
def read(filename):
66
 
        start = Blender.sys.time()
67
 
        Blender.Window.WaitCursor(1)
68
 
        file = open(filename, "rb")
69
 
        mesh = Blender.NMesh.GetRaw()
70
 
        #mesh.addMaterial(Blender.Material.New())
71
 
        
72
 
        NULL_UV3= [ (0,0), (0,1), (1,1) ]
73
 
        NULL_UV4= [ (0,0), (0,1), (1,1), (1,0) ]
74
 
        
75
 
        
76
 
        # === Object Name ===
77
 
        namelen, = struct.unpack("<h",  file.read(2))
78
 
        objname, = struct.unpack("<"+`namelen`+"s", file.read(namelen))
79
 
 
80
 
        # === Vertex List ===
81
 
        Vert= Blender.NMesh.Vert
82
 
        numverts, = struct.unpack("<l", file.read(4))
83
 
        
84
 
        # Se we can run in a LC
85
 
        def _vert_():
86
 
                x,y,z= struct.unpack('<fff', file.read(12))
87
 
                return Vert(x, y, z)
88
 
        
89
 
        mesh.verts= [_vert_() for i in xrange(numverts)]
90
 
        del _vert_
91
 
        
92
 
        
93
 
        # === Face List ===
94
 
        Face= Blender.NMesh.Face
95
 
        Col= Blender.NMesh.Col
96
 
        numfaces, = struct.unpack("<l", file.read(4))
97
 
        for i in xrange(numfaces):
98
 
                #if not i%100 and meshtools.show_progress:
99
 
                #       Blender.Window.DrawProgressBar(float(i)/numfaces, "Reading Faces")
100
 
 
101
 
                
102
 
                numfaceverts, = struct.unpack("<b", file.read(1))
103
 
                
104
 
                
105
 
                face = Face(\
106
 
                 [\
107
 
                 mesh.verts[\
108
 
                  struct.unpack("<h", file.read(2))[0]] for j in xrange(numfaceverts)\
109
 
                 ]
110
 
                )
111
 
                
112
 
                face.col= [ Col(r, g, b, a) \
113
 
                for j in xrange(4)\
114
 
                for r,g,b,a in ( struct.unpack("<BBBB", file.read(4)), )]
115
 
                
116
 
                if len(face) == 3:
117
 
                        face.uv = NULL_UV3
118
 
                else:
119
 
                        face.uv = NULL_UV4
120
 
 
121
 
                
122
 
                face.mode = 0
123
 
                mesh.faces.append(face)
124
 
 
125
 
        scn= Blender.Scene.GetCurrent()
126
 
        scn.objects.selected = []
127
 
        
128
 
        mesh.name= objname
129
 
        scn.objects.new(mesh)
130
 
        
131
 
        Blender.Window.DrawProgressBar(1.0, '')  # clear progressbar
132
 
        file.close()
133
 
        end = Blender.sys.time()
134
 
        message = 'Successfully imported "%s" in %.2f seconds' % (Blender.sys.basename(filename), end-start)
135
 
        meshtools.print_boxed(message)
136
 
        Blender.Window.WaitCursor(0)
137
 
        Blender.Window.RedrawAll()
138
 
 
139
 
 
140
 
def main():
141
 
        if not struct:
142
 
                Blender.Draw.PupMenu('ERROR%t|Error: you need a full Python install to run this script')
143
 
                return
144
 
        
145
 
        Blender.Window.FileSelector(read, 'Import Radio', '*.radio')
146
 
 
147
 
if __name__ == '__main__':
148
 
        main()