############################################## # SIMPLE FULL-SCENE BLENDER TO YAFRAY EXPORT # ############################################## # GENERAL USAGE: # Specify the filename and layer bitmask below and use alt-p to export # Use '_ASxx' appended to objectnames to export autosmooth settings # set GZIPIT to 1 to export as .gz file, '.gz' will be appended to the filename automatically #-------------------------- # CURRENTLY EXPORTED: # All Blender lighttypes. # Hemi is exported as hemilight, might be changed to actual Blender Hemi emulation. # A spot light is exported as a softlight, when using Publisher the shadowmap parameters can be used to control # radius with the 'softness' parameter, bias with 'bias', res with 'BufSi' # In 2.23 these are set to defaults: res=100, bias=0.3, but radius can be controlled with the Quad1 slider. # When a World is used, the Horizon color will be used as the scene background color. (NOT IN PUBLISHER) # The hemicolor will not be exported in that case, so it will automatically use the background color # If a mesh has uv-coords they will be exported as well, all meshes are exported with their corresponding transforms. ####################################################################### # name and full path of the output .XML file filename = 'PATH_HERE/export_test.xml' # the layer bitmask of the layers that should be exported to the file layermask = 1 # Export as gzip file? 1=yes, 0=no GZIPIT = 0 ####################################################################### import Blender from math import * # Depending on the python compilation/installation, gzip might not be available on some systems. # The required zlib module is however also included with Publisher, so that will probably always work. try: import gzip GZIPOK = 1 except ImportError: print "Gzip module not supported!" GZIPOK = 0 BL_VERSION = Blender.Get('version') if BL_VERSION<=223: import Blender210 mesh_list = [] lamp_list = [] for ob in Blender.Object.Get(): if BL_VERSION<=223: dt = ob.data else: dt = ob.getData() if dt and (ob.Layer & layermask): if dt.block_type=='NMesh': mesh_list.append(ob) elif dt.block_type=='Lamp': lamp_list.append(ob) # if no meshes were found, stop, nothing to be done further if len(mesh_list)==0: raise "No meshes to export" # if no lamps found, print a warning if len(lamp_list)==0: print "WARNING: No lamps exported!" # test to see if a World is used, if so, background color will be set from it later # also used for the hemilight to see it it's color needs to be exported # Unfortunately the World module was removed in Publisher, so it only works in 223 or lower bworld = None if BL_VERSION<=223: bworld = Blender.World.Get() # only use first world in the list if len(bworld)!=0: bworld = bworld[0] else: bworld = None # the outputfile as a string st = "\n\n" # only write shaders once if used on more than one object shader_written = {} # name of the default grey blender material bdefname = 'blender_default' # export materials first, only (diffuse) color & specular color # only the first material in mesh material list is exported for ob in mesh_list: mt = None if BL_VERSION<=223: me = ob.data materials = me.mats if len(materials): mt = Blender.Material.Get(materials[0]) else: me = ob.getData() materials = me.getMaterials() if len(materials): mt = materials[0] if mt and not shader_written.has_key(mt.name): st += '\n' % mt.name st += '\t\n' st += '\t\t\n' % (mt.R, mt.G, mt.B) if BL_VERSION<=223: st += '\t\t\n' % (mt.SpecR, mt.SpecG, mt.SpecB) else: st += '\t\t\n' % (mt.specR, mt.specG, mt.specB) st += '\t\t\n' % mt.Hard st += '\t\n\n\n' shader_written[mt.name] = 1 elif not shader_written.has_key(bdefname): st += '' % bdefname st += '\t\n' st += '\t\t\n' st += '\t\t\n' st += '\t\t\n' st += '\t\n\n\n' shader_written[bdefname] = 1 # export the meshes, verts, faces & uv-coords (if used) for ob in mesh_list: mtx = ob.matrix mt = None if BL_VERSION<=223: me = ob.data materials = me.mats if len(materials): matname = materials[0] else: me = ob.getData() materials = me.getMaterials() if len(materials): matname = materials[0].name me = Blender.NMesh.GetRawFromObject(ob.name) # Write the object transform matrix st += '