I am just going to post an export script of mine, it exports triangles and vertex colors
# export.py
# website (currently) http://www.geocities.com/z3r0_d/
# my e-mail is avaliable on my website
#
# description
# export .. into my! format
#
# to run:
# select object you wish to run this script on (it will only run
# on the active object), and in the script window containing this script
# press [alt] + [p]
#
# if the script window turns red, and errors are printed on the console
# the script was unable to find a proper order
#
# for more information (such as why it may not find a proper order)
# look at my website mentioned above
#
############# LEGAL STUFF #############
# This script is provided with NO WARRANTY for fitness towards any particular
# purpose. It MIGHT be helpful, but I am not responsible if it isn't,
# nor if it causes harm to your system
#
# If you distribute changes to this script do not remove my copyright notice
# and please note the chages you made
# ... it would also be nice if you told me, because I would like to know.
#
# one more thing:
# DO NOT port this script to another platform/program/language without my permission
# which can be obtained by e-mail
import Blender
from Blender.NMesh import *
from math import sqrt
def vec_dot(u, v):
return u[0]*v[0] + u[1]*v[1] + u[2]*v[2]
def vec_cross(u, v):
# | i j k |
# | u0 u1 u2 |
# | v0 v1 v2 |
# (u1*v2-u2*v1)i - (u0*v2-u2*v0)j + (u0*v1-u1*v0)k
# (u1*v2-u2*v1)i + (u2*v0-u0*v2)j + (u0*v1-u1*v0)k
return [u[1]*v[2]-u[2]*v[1], u[2]*v[0]-u[0]*v[2], u[0]*v[1]-u[1]*v[0]]
def vec_mag(u):
return sqrt(u[0]*u[0] + u[1]*u[1] + u[2]*u[2])
def vec_norm(u):
n = vec_mag(u)
return [u[0]/n, u[1]/n, u[2]/n]
def vec_between_points(u, v):
# returns the vector from point u to point v
return [v[0]-u[0], v[1]-u[1], v[2]-u[2]]
def colToList(col):
# return a list containing the rgb color of NMColType col
return [col.r, col.g, col.b]
def vecToList(vec):
# converts a VectorType to a list
return [vec[0], vec[1], vec[2]]
def textWinRed():
from Blender.BGL import *
Blender.Redraw()
glClearColor(1.0, 0.0, 0.0, 1.0)
glClear(GL_COLOR_BUFFER_BIT)
Blender.Redraw()
print "
--------------The Script has Begun--------------"
selectedObjs = Blender.Object.GetSelected()
if (len(selectedObjs)==0):
print "I NEED ONE SELECTED MESH!"
thisMesh = Blender.NMesh.GetRawFromObject(selectedObjs[0].name)
print "Object",selectedObjs[0].name
print "Mesh",thisMesh.name
print "Object Contains ",len(thisMesh.faces)," Faces"
print "opening file",thisMesh.name+".trx", "for writing"
f = open(Blender.Get('filename')+'/../objects/'+ thisMesh.name+".trx", 'w')
# the format is:
# name, value
# some things may have more than one value
f.write("numfaces "+str(len(thisMesh.faces))+"
")
# for each face
i = 0
numFaces = len(thisMesh.faces)
while i < numFaces:
#print "face number", i
print "*"*(79*i/numFaces)+"\r",
aFace = thisMesh.faces[i]
if len(aFace.v)==3:
#f.write("FLAGS" + aFace.
norm = vec_norm(vec_cross(vec_between_points(aFace.v[0], aFace.v[1]), vec_between_points(aFace.v[1], aFace.v[2])))
# are the faces oriented the same way as the vertex normal?
if (vec_dot(norm, aFace.v[0].no)<0.0):
# the normal is (likely) opposite the direction the
# orientation of the faces would suggest
print "BAADDD!", i
# flip the normal
#norm = [-norm[0],-norm[1], -norm[2]]
# ...? it works without it?
f.write("NORM " + str(norm) + "
" )
j = 0
while j < 3:
f.write("COLOR " + str(colToList(aFace.col[j])) + "
" )
f.write("COORD " + str(vecToList(aFace.v[j].co))+ "
" )
j+=1
pass
else:
print "A face has not 3 verticies
quitting..."
textWinRed()
break
i+=1
f.write("
")
f.close()
print "
--------------The Script has Finished--------------"
the important part is aFace.v[j].co which is the color of that vertex
aFace came from an NMesh, and v[j] is a vertex
radiosity stores it’s colors in vertex colors, so this script can export the radiosity result (once you convert to triangles, I was too lazy to make it flexible). I also am too lazy to give you just the code you need