FWIW I've done a workable faces_export def for the
povrayexport mod.
The only limitation I am aware of is in the handling of colors.
Faces allow per vertex coloring, triangles in Povray do not - so that
limitation
is inherent.
My implementation also limits mesh objects to one color. That can be
imrpoved
by creating texture objects for the individual triangles comprising the
mesh.
As implemented it adds 2 new export keywords"
"face_meshes" - to use the povray mesh primitive - see povray docs for
advantages over
seperate triangles
"face_normals" - whether to use triangle (without normals) or
smooth_triangels
So my exports def now has:
def export(display=None, filename=None, include_list=None, xy_ratio=4./3.,
custom_text='', shadowless=0, face_normals=1,face_mesh=0):
And, in iterating over the scene objects the amended code is:
if function:
if obj_name == "faces":
object_code = function(obj,face_normals,face_mesh)
else:
object_code = function(obj)
Then:
def export_faces(a,normals,mesh):
if normals:
ttype="smooth_triangle"
else:
ttype="triangle"
if mesh:
object_template = """
mesh { %(triangles)s
%(pigment)s }
"""
triangle_template = """
%(ttype)s {
<%(posx)f, %(posy)f, %(posz)f> %(n1)s,
<%(pos2x)f, %(pos2y)f, %(pos2z)f> %(n2)s,
<%(pos3x)f, %(pos3y)f, %(pos3z)f> %(n3)s
%(pigment)s
}
"""
triangles = []
i=0
if mesh :
pigment = ""
while i < len(a.pos):
if normals:
n1="<%f,%f,%f>" % (a.normal[i][0],a.normal[i][1],a.normal[i][2])
n2="<%f,%f,%f>" %
(a.normal[i+1][0],a.normal[i+1][1],a.normal[i+1][2])
n3="<%f,%f,%f>" %
(a.normal[i+2][0],a.normal[i+2][1],a.normal[i+2][2])
else:
n1=""
n2=""
n3=""
if not mesh:
pigment = "pigment { color rgb <%f, %f, %f> }" %tuple(a.color[i])
triangles.append(triangle_template % {'ttype':ttype,
'posx':a.pos[i][0], 'posy':a.pos[i][1], 'posz':a.pos[i][2],
'n1':n1,
'pos2x':a.pos[i+1][0],
'pos2y':a.pos[i+1][1], 'pos2z':a.pos[i+1][2],
'n2':n2,
'pos3x':a.pos[i+2][0],
'pos3y':a.pos[i+2][1], 'pos3z':a.pos[i+2][2],
'n3':n3,
'pigment':pigment})
i += 3
triangles_in=""
for j in triangles:
triangles_in = triangles_in + j + '\n'
if mesh:
pigment = "pigment { color rgb <%f, %f, %f> }" %tuple(a.color[0])
object_code = object_template % { 'triangles':triangles_in,
'pigment':pigment}
object_code = add_texture(a, object_code)
else:
object_code = triangles_in
return object_code
Art
|