4
Name: 'Radiosity (.radio)...'
7
Tooltip: 'Export selected mesh (with vertex colors) to Radiosity File Format (.radio)'
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"
16
This script exports meshes to Radiosity file format.
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.
23
Select meshes to be exported and run this script from "File->Export" menu.
26
Before exporting to .radio format, the mesh must have vertex colors.
27
Here's how to assign them:
31
2. Set up lights and materials, select a mesh, switch the drawing mode
32
to "textured," press the VKEY.
34
3. Press the VKEY and paint manually.
36
4. Use a custom script to calculate and apply simple diffuse shading and
37
specular highlights to the vertex colors.
39
5. The Videoscape format also allows vertex colors to be specified.
42
# $Id: radiosity_export.py,v 1.13 2006/12/12 07:28:20 campbellbarton Exp $
44
# +---------------------------------------------------------+
45
# | Copyright (c) 2002 Anthony D'Agostino |
46
# | http://www.redrival.com/scorpius |
47
# | scorpius@netzero.com |
49
# | Read and write Radiosity File Format (*.radio) |
50
# +---------------------------------------------------------+
52
# ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
68
# ***** END GPL LICENCE BLOCK *****
76
NULL_COLOR= struct.pack('<BBBB', 255,255,255,255)
82
# ================================
83
# ====== Write Radio Format ======
84
# ================================
86
if not filename.lower().endswith('.radio'):
89
scn= Blender.Scene.GetCurrent()
90
ob= scn.objects.active
92
Blender.Draw.PupMenu('Error%t|Select 1 active object')
96
file = open(filename, 'wb')
97
mesh = BPyMesh.getMeshFromObject(ob, None, True, False, scn)
99
Blender.Draw.PupMenu('Error%t|Could not get mesh data from active object')
102
mesh.transform(ob.matrixWorld)
106
start = Blender.sys.time()
107
file = open(filename, "wb")
112
#message = 'Please assign vertex colors before exporting "%s"|object was not saved' % object.name
113
#Blender.Draw.PupMenu("ERROR%t|"+message)
116
# === Object Name ===
117
file.write(struct.pack("<h", len(objname)))
118
file.write(struct.pack("<"+`len(objname)`+"s", objname))
120
# === Vertex List ===
121
file.write(struct.pack("<l", len(mesh.verts)))
123
#if not i%100 and meshtools.show_progress:
124
# Blender.Window.DrawProgressBar(float(i)/len(mesh.verts), "Writing Verts")
126
file.write(struct.pack("<fff", x, y, z))
129
file.write(struct.pack('<l', len(mesh.faces)))
130
#for i in range(len(mesh.faces)):
132
#if not i%100 and meshtools.show_progress:
133
# Blender.Window.DrawProgressBar(float(i)/len(mesh.faces), "Writing Faces")
135
file.write(struct.pack('<b', len(f) ))
136
#for j in range(len(mesh.faces[i].v)):
138
file.write(struct.pack('<h', v.index))
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))
144
# Write the last values out again. always have 4 cols even for tris
146
file.write(NULL_COLOR)
148
Blender.Window.DrawProgressBar(1.0, '') # clear progressbar
150
end = Blender.sys.time()
151
print '\nSuccessfully exported "%s" in %.2f seconds\n' % (Blender.sys.basename(filename), end-start)
153
#meshtools.print_boxed(message)
158
Blender.Draw.PupMenu('ERROR%t|Error: you need a full Python install to run this script')
161
Blender.Window.FileSelector(write, 'Export Radio', Blender.sys.makename(ext='.radio'))
163
if __name__ == '__main__':