2004-01-28 19:16:50 +00:00
|
|
|
#!BPY
|
|
|
|
|
|
|
|
"""
|
2004-06-11 02:12:37 +00:00
|
|
|
Name: 'Radiosity (.radio)...'
|
2004-01-28 19:16:50 +00:00
|
|
|
Blender: 232
|
|
|
|
Group: 'Export'
|
2004-06-11 02:12:37 +00:00
|
|
|
Tooltip: 'Export selected mesh (with vertex colors) to Radiosity File Format (.radio)'
|
2004-01-28 19:16:50 +00:00
|
|
|
"""
|
|
|
|
|
2004-11-07 16:31:13 +00:00
|
|
|
__author__ = "Anthony D'Agostino (Scorpius)"
|
|
|
|
__url__ = ("blender", "elysiun",
|
|
|
|
"Author's homepage, http://www.redrival.com/scorpius")
|
|
|
|
__version__ = "Part of IOSuite 0.5"
|
|
|
|
|
|
|
|
__bpydoc__ = """\
|
|
|
|
This script exports meshes to Radiosity file format.
|
|
|
|
|
2004-11-30 02:27:46 +00:00
|
|
|
The Radiosity file format is my own personal format. I created it to
|
|
|
|
learn how meshes and vertex colors were stored. See IO-Examples.zip, the
|
|
|
|
example *.radio files on my web page.
|
2004-11-07 16:31:13 +00:00
|
|
|
|
2004-11-30 02:27:46 +00:00
|
|
|
Usage:<br>
|
|
|
|
Select meshes to be exported and run this script from "File->Export" menu.
|
|
|
|
|
|
|
|
Notes:<br>
|
|
|
|
Before exporting to .radio format, the mesh must have vertex colors.
|
|
|
|
Here's how to assign them:
|
|
|
|
|
|
|
|
1. Use radiosity!
|
|
|
|
|
|
|
|
2. Set up lights and materials, select a mesh, switch the drawing mode
|
|
|
|
to "textured," press the VKEY.
|
2004-11-07 16:31:13 +00:00
|
|
|
|
2004-11-30 02:27:46 +00:00
|
|
|
3. Press the VKEY and paint manually.
|
|
|
|
|
|
|
|
4. Use a custom script to calculate and apply simple diffuse shading and
|
|
|
|
specular highlights to the vertex colors.
|
|
|
|
|
|
|
|
5. The Videoscape format also allows vertex colors to be specified.
|
|
|
|
"""
|
2004-11-07 16:31:13 +00:00
|
|
|
|
2004-06-10 03:27:46 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
2004-01-28 19:16:50 +00:00
|
|
|
# +---------------------------------------------------------+
|
|
|
|
# | Copyright (c) 2002 Anthony D'Agostino |
|
2004-06-07 01:34:15 +00:00
|
|
|
# | http://www.redrival.com/scorpius |
|
|
|
|
# | scorpius@netzero.com |
|
2004-01-28 19:16:50 +00:00
|
|
|
# | April 11, 2002 |
|
|
|
|
# | Read and write Radiosity File Format (*.radio) |
|
|
|
|
# +---------------------------------------------------------+
|
|
|
|
|
2006-01-29 19:17:53 +00:00
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ***** END GPL LICENCE BLOCK *****
|
|
|
|
|
2006-12-12 07:28:20 +00:00
|
|
|
import Blender
|
2004-01-28 19:16:50 +00:00
|
|
|
#import time
|
2006-07-03 04:12:53 +00:00
|
|
|
import BPyMesh
|
2004-06-07 01:34:15 +00:00
|
|
|
|
2004-01-28 19:16:50 +00:00
|
|
|
try:
|
|
|
|
import struct
|
2006-07-03 04:12:53 +00:00
|
|
|
NULL_COLOR= struct.pack('<BBBB', 255,255,255,255)
|
2004-01-28 19:16:50 +00:00
|
|
|
except:
|
2006-07-03 04:12:53 +00:00
|
|
|
struct= None
|
|
|
|
|
|
|
|
|
2004-01-28 19:16:50 +00:00
|
|
|
|
|
|
|
# ================================
|
|
|
|
# ====== Write Radio Format ======
|
|
|
|
# ================================
|
|
|
|
def write(filename):
|
2006-07-03 04:12:53 +00:00
|
|
|
if not filename.lower().endswith('.radio'):
|
|
|
|
filename += '.radio'
|
|
|
|
|
|
|
|
scn= Blender.Scene.GetCurrent()
|
2006-12-12 07:28:20 +00:00
|
|
|
ob= scn.objects.active
|
|
|
|
if not ob:
|
2006-07-03 04:12:53 +00:00
|
|
|
Blender.Draw.PupMenu('Error%t|Select 1 active object')
|
|
|
|
return
|
2006-12-12 07:28:20 +00:00
|
|
|
objname= ob.name
|
2006-07-03 04:12:53 +00:00
|
|
|
|
|
|
|
file = open(filename, 'wb')
|
2006-12-12 07:28:20 +00:00
|
|
|
mesh = BPyMesh.getMeshFromObject(ob, None, True, False, scn)
|
2006-07-03 04:12:53 +00:00
|
|
|
if not mesh:
|
|
|
|
Blender.Draw.PupMenu('Error%t|Could not get mesh data from active object')
|
|
|
|
return
|
|
|
|
|
2006-12-12 07:28:20 +00:00
|
|
|
mesh.transform(ob.matrixWorld)
|
2006-07-03 04:12:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start = Blender.sys.time()
|
2004-01-28 19:16:50 +00:00
|
|
|
file = open(filename, "wb")
|
|
|
|
|
2006-07-03 04:12:53 +00:00
|
|
|
if not mesh.faceUV:
|
2006-12-12 07:28:20 +00:00
|
|
|
mesh.vertexColors= 1
|
|
|
|
|
2006-07-03 04:12:53 +00:00
|
|
|
#message = 'Please assign vertex colors before exporting "%s"|object was not saved' % object.name
|
|
|
|
#Blender.Draw.PupMenu("ERROR%t|"+message)
|
|
|
|
#return
|
2004-01-28 19:16:50 +00:00
|
|
|
|
|
|
|
# === Object Name ===
|
|
|
|
file.write(struct.pack("<h", len(objname)))
|
|
|
|
file.write(struct.pack("<"+`len(objname)`+"s", objname))
|
|
|
|
|
|
|
|
# === Vertex List ===
|
|
|
|
file.write(struct.pack("<l", len(mesh.verts)))
|
2006-07-03 04:12:53 +00:00
|
|
|
for v in mesh.verts:
|
|
|
|
#if not i%100 and meshtools.show_progress:
|
|
|
|
# Blender.Window.DrawProgressBar(float(i)/len(mesh.verts), "Writing Verts")
|
2006-07-26 00:30:31 +00:00
|
|
|
x, y, z = v.co
|
2004-01-28 19:16:50 +00:00
|
|
|
file.write(struct.pack("<fff", x, y, z))
|
|
|
|
|
|
|
|
# === Face List ===
|
2006-07-03 04:12:53 +00:00
|
|
|
file.write(struct.pack('<l', len(mesh.faces)))
|
|
|
|
#for i in range(len(mesh.faces)):
|
|
|
|
for f in mesh.faces:
|
|
|
|
#if not i%100 and meshtools.show_progress:
|
|
|
|
# Blender.Window.DrawProgressBar(float(i)/len(mesh.faces), "Writing Faces")
|
|
|
|
|
|
|
|
file.write(struct.pack('<b', len(f) ))
|
|
|
|
#for j in range(len(mesh.faces[i].v)):
|
2006-12-12 07:28:20 +00:00
|
|
|
for v in f:
|
2006-07-03 04:12:53 +00:00
|
|
|
file.write(struct.pack('<h', v.index))
|
|
|
|
|
|
|
|
f_col= f.col
|
|
|
|
for c in f_col: # .col always has a length of 4
|
|
|
|
file.write(struct.pack('<BBBB', c.r, c.g, c.b, c.a))
|
|
|
|
|
|
|
|
# Write the last values out again. always have 4 cols even for tris
|
|
|
|
if len(f_col) == 3:
|
|
|
|
file.write(NULL_COLOR)
|
|
|
|
|
2004-01-28 19:16:50 +00:00
|
|
|
Blender.Window.DrawProgressBar(1.0, '') # clear progressbar
|
|
|
|
file.close()
|
2006-07-03 04:12:53 +00:00
|
|
|
end = Blender.sys.time()
|
2006-12-12 07:28:20 +00:00
|
|
|
print '\nSuccessfully exported "%s" in %.2f seconds\n' % (Blender.sys.basename(filename), end-start)
|
|
|
|
|
|
|
|
#meshtools.print_boxed(message)
|
2004-01-28 19:16:50 +00:00
|
|
|
|
|
|
|
|
2006-07-03 04:12:53 +00:00
|
|
|
def main():
|
|
|
|
if not struct:
|
|
|
|
Blender.Draw.PupMenu('ERROR%t|Error: you need a full Python install to run this script')
|
|
|
|
return
|
|
|
|
|
|
|
|
Blender.Window.FileSelector(write, 'Export Radio', Blender.sys.makename(ext='.radio'))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|