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

« back to all changes in this revision

Viewing changes to release/scripts/radiosity_export.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: 'Export'
7
 
Tooltip: 'Export selected mesh (with vertex colors) to Radiosity File Format (.radio)'
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 exports meshes to Radiosity file format.
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
 
        Select meshes to be exported and run this script from "File->Export" menu.
24
 
 
25
 
Notes:<br>
26
 
        Before exporting to .radio format, the mesh must have vertex colors.
27
 
Here's how to assign them:
28
 
 
29
 
1. Use radiosity!
30
 
 
31
 
2. Set up lights and materials, select a mesh, switch the drawing mode
32
 
to "textured," press the VKEY.
33
 
 
34
 
3. Press the VKEY and paint manually.
35
 
 
36
 
4. Use a custom script to calculate and apply simple diffuse shading and
37
 
specular highlights to the vertex colors.
38
 
 
39
 
5. The Videoscape format also allows vertex colors to be specified.
40
 
"""
41
 
 
42
 
# $Id: radiosity_export.py,v 1.13 2006/12/12 07:28:20 campbellbarton Exp $
43
 
#
44
 
# +---------------------------------------------------------+
45
 
# | Copyright (c) 2002 Anthony D'Agostino                   |
46
 
# | http://www.redrival.com/scorpius                        |
47
 
# | scorpius@netzero.com                                    |
48
 
# | April 11, 2002                                          |
49
 
# | Read and write Radiosity File Format (*.radio)          |
50
 
# +---------------------------------------------------------+
51
 
 
52
 
# ***** BEGIN GPL LICENSE BLOCK *****
53
 
#
54
 
# This program is free software; you can redistribute it and/or
55
 
# modify it under the terms of the GNU General Public License
56
 
# as published by the Free Software Foundation; either version 2
57
 
# of the License, or (at your option) any later version.
58
 
#
59
 
# This program is distributed in the hope that it will be useful,
60
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
61
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
62
 
# GNU General Public License for more details.
63
 
#
64
 
# You should have received a copy of the GNU General Public License
65
 
# along with this program; if not, write to the Free Software Foundation,
66
 
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
67
 
#
68
 
# ***** END GPL LICENCE BLOCK *****
69
 
 
70
 
import Blender
71
 
#import time
72
 
import BPyMesh
73
 
 
74
 
try:
75
 
        import struct
76
 
        NULL_COLOR= struct.pack('<BBBB', 255,255,255,255)
77
 
except:
78
 
        struct= None
79
 
 
80
 
 
81
 
 
82
 
# ================================
83
 
# ====== Write Radio Format ======
84
 
# ================================
85
 
def write(filename):
86
 
        if not filename.lower().endswith('.radio'):
87
 
                filename += '.radio'
88
 
        
89
 
        scn= Blender.Scene.GetCurrent()
90
 
        ob= scn.objects.active
91
 
        if not ob:
92
 
                Blender.Draw.PupMenu('Error%t|Select 1 active object')
93
 
                return
94
 
        objname= ob.name
95
 
        
96
 
        file = open(filename, 'wb')
97
 
        mesh = BPyMesh.getMeshFromObject(ob, None, True, False, scn)
98
 
        if not mesh:
99
 
                Blender.Draw.PupMenu('Error%t|Could not get mesh data from active object')
100
 
                return
101
 
                
102
 
        mesh.transform(ob.matrixWorld)
103
 
        
104
 
        
105
 
        
106
 
        start = Blender.sys.time()
107
 
        file = open(filename, "wb")
108
 
 
109
 
        if not mesh.faceUV:
110
 
                mesh.vertexColors= 1
111
 
                
112
 
                #message = 'Please assign vertex colors before exporting "%s"|object was not saved' % object.name
113
 
                #Blender.Draw.PupMenu("ERROR%t|"+message)
114
 
                #return
115
 
 
116
 
        # === Object Name ===
117
 
        file.write(struct.pack("<h", len(objname)))
118
 
        file.write(struct.pack("<"+`len(objname)`+"s", objname))
119
 
 
120
 
        # === Vertex List ===
121
 
        file.write(struct.pack("<l", len(mesh.verts)))
122
 
        for v in mesh.verts:
123
 
                #if not i%100 and meshtools.show_progress:
124
 
                #       Blender.Window.DrawProgressBar(float(i)/len(mesh.verts), "Writing Verts")
125
 
                x, y, z = v.co
126
 
                file.write(struct.pack("<fff", x, y, z))
127
 
 
128
 
        # === Face List ===
129
 
        file.write(struct.pack('<l', len(mesh.faces)))
130
 
        #for i in range(len(mesh.faces)):
131
 
        for f in mesh.faces:
132
 
                #if not i%100 and meshtools.show_progress:
133
 
                #       Blender.Window.DrawProgressBar(float(i)/len(mesh.faces), "Writing Faces")
134
 
                
135
 
                file.write(struct.pack('<b', len(f) ))
136
 
                #for j in range(len(mesh.faces[i].v)):
137
 
                for v in f:
138
 
                        file.write(struct.pack('<h', v.index))
139
 
                
140
 
                f_col= f.col
141
 
                for c in f_col: # .col always has a length of 4
142
 
                        file.write(struct.pack('<BBBB', c.r, c.g, c.b, c.a))
143
 
                
144
 
                # Write the last values out again. always have 4 cols even for tris
145
 
                if len(f_col) == 3:
146
 
                        file.write(NULL_COLOR)
147
 
        
148
 
        Blender.Window.DrawProgressBar(1.0, '')  # clear progressbar
149
 
        file.close()
150
 
        end = Blender.sys.time()
151
 
        print '\nSuccessfully exported "%s" in %.2f seconds\n' % (Blender.sys.basename(filename), end-start)
152
 
        
153
 
        #meshtools.print_boxed(message)
154
 
 
155
 
 
156
 
def main():
157
 
        if not struct:
158
 
                Blender.Draw.PupMenu('ERROR%t|Error: you need a full Python install to run this script')
159
 
                return
160
 
        
161
 
        Blender.Window.FileSelector(write, 'Export Radio', Blender.sys.makename(ext='.radio'))
162
 
 
163
 
if __name__ == '__main__':
164
 
        main()