* Sun lamp type export (known as parallel lights in povray)
* Native support for blenders metaballs, currently exports
 - ball and ellipsoid types
 - radius, stiffness
 - ellipsoid xyz scale
 - negative elements
 - single material (like blender)

Renamed rna props.
 elem.sizex -> size_x
 mball.last_selected_element ->  mball.active_element

minor changes to UI scripts.
This commit is contained in:
Campbell Barton 2009-08-07 01:05:33 +00:00
parent 0ac90cabe1
commit 917fce65a6
5 changed files with 129 additions and 61 deletions

@ -19,8 +19,9 @@ def write_pov(filename, scene=None, info_callback = None):
# Only for testing # Only for testing
if not scene: if not scene:
scene = bpy.data.scenes[0] scene = bpy.data.scenes[0]
render = scene.render_data render = scene.render_data
world = scene.world
materialTable = {} materialTable = {}
def saneName(name): def saneName(name):
@ -33,6 +34,39 @@ def write_pov(filename, scene=None, info_callback = None):
file.write('\tmatrix <%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f>\n' %\ file.write('\tmatrix <%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f>\n' %\
(matrix[0][0], matrix[0][1], matrix[0][2], matrix[1][0], matrix[1][1], matrix[1][2], matrix[2][0], matrix[2][1], matrix[2][2], matrix[3][0], matrix[3][1], matrix[3][2]) ) (matrix[0][0], matrix[0][1], matrix[0][2], matrix[1][0], matrix[1][1], matrix[1][2], matrix[2][0], matrix[2][1], matrix[2][2], matrix[3][0], matrix[3][1], matrix[3][2]) )
def blenderMaterialToPovString(material):
povstring = 'finish {'
if world != None:
povstring += 'ambient <%.6f, %.6f, %.6f> ' % tuple([c*material.ambient for c in world.ambient_color])
povstring += 'diffuse %.6f ' % material.diffuse_reflection
povstring += 'specular %.6f ' % material.specular_reflection
if material.raytrace_mirror.enabled:
#povstring += 'interior { ior %.6f } ' % material.IOR
raytrace_mirror= material.raytrace_mirror
if raytrace_mirror.reflect:
povstring += 'reflection {'
povstring += '<%.6f, %.6f, %.6f>' % tuple(material.mirror_color) # Should ask for ray mirror flag
povstring += 'fresnel 1 falloff %.6f exponent %.6f metallic %.6f} ' % (raytrace_mirror.fresnel, raytrace_mirror.fresnel_fac, raytrace_mirror.reflect)
if material.raytrace_transparency.enabled:
#povstring += 'interior { ior %.6f } ' % material.IOR
pass
#file.write('\t\troughness %.6f\n' % (material.hard*0.5))
#file.write('\t\t\tcrand 0.0\n') # Sand granyness
#file.write('\t\t\tmetallic %.6f\n' % material.spec)
#file.write('\t\t\tphong %.6f\n' % material.spec)
#file.write('\t\t\tphong_size %.6f\n' % material.spec)
povstring += 'brilliance %.6f ' % (material.specular_hardness/256.0) # Like hardness
povstring += '}'
#file.write('\t}\n')
return povstring
def exportCamera(): def exportCamera():
camera = scene.camera camera = scene.camera
matrix = camera.matrix matrix = camera.matrix
@ -79,6 +113,10 @@ def write_pov(filename, scene=None, info_callback = None):
file.write('\ttightness 0\n') # 0:10f file.write('\ttightness 0\n') # 0:10f
file.write('\tpoint_at <0, 0, -1>\n') file.write('\tpoint_at <0, 0, -1>\n')
elif lamp.type == 'SUN':
file.write('\tparallel\n')
file.write('\tpoint_at <0, 0, -1>\n') # *must* be after 'parallel'
elif lamp.type == 'AREA': elif lamp.type == 'AREA':
size_x = lamp.size size_x = lamp.size
@ -109,47 +147,68 @@ def write_pov(filename, scene=None, info_callback = None):
file.write('}\n') file.write('}\n')
def exportMeshs(sel): def exportMeta(metas):
def bMat2PovString(material):
povstring = 'finish {' # TODO - blenders 'motherball' naming is not supported.
if world != None:
povstring += 'ambient <%.6f, %.6f, %.6f> ' % tuple([c*material.ambient for c in world.ambient_color]) for ob in metas:
meta = ob.data
povstring += 'diffuse %.6f ' % material.diffuse_reflection file.write('blob {\n')
povstring += 'specular %.6f ' % material.specular_reflection file.write('\t\tthreshold %.4g\n' % meta.threshold)
try:
material= meta.materials[0] # lame! - blender cant do enything else.
except:
material= None
if material.raytrace_mirror.enabled: for elem in meta.elements:
#povstring += 'interior { ior %.6f } ' % material.IOR
raytrace_mirror= material.raytrace_mirror
if raytrace_mirror.reflect:
povstring += 'reflection {'
povstring += '<%.6f, %.6f, %.6f>' % tuple(material.mirror_color) # Should ask for ray mirror flag
povstring += 'fresnel 1 falloff %.6f exponent %.6f metallic %.6f} ' % (raytrace_mirror.fresnel, raytrace_mirror.fresnel_fac, raytrace_mirror.reflect)
if elem.type not in ('BALL', 'ELLIPSOID'):
continue # Not supported
loc = elem.location
stiffness= elem.stiffness
if elem.negative:
stiffness = -stiffness
if elem.type == 'BALL':
if material.raytrace_transparency.enabled: file.write('\tsphere { <%.6g, %.6g, %.6g>, %.4g, %.4g ' % (loc.x, loc.y, loc.z, elem.radius, stiffness))
#povstring += 'interior { ior %.6f } ' % material.IOR
pass # After this wecould do something simple like...
# "pigment {Blue} }"
# except we'll write the color
elif elem.type == 'ELLIPSOID':
# location is modified by scale
file.write('\tsphere { <%.6g, %.6g, %.6g>, %.4g, %.4g ' % (loc.x/elem.size_x, loc.y/elem.size_y, loc.z/elem.size_z, elem.radius, stiffness))
file.write( 'scale <%.6g, %.6g, %.6g> ' % (elem.size_x, elem.size_y, elem.size_z))
if material:
# materialString = materialTable[material.name]
diffuse_color = material.diffuse_color
file.write(
'pigment {rgbf<%.3g, %.3g, %.3g, %.3g>} }\n' % \
(diffuse_color[0], diffuse_color[1], diffuse_color[2], 1-material.alpha)
)
else:
file.write('}\n')
#file.write('\t\troughness %.6f\n' % (material.hard*0.5)) # Write the finish last.
#file.write('\t\t\tcrand 0.0\n') # Sand granyness if material:
#file.write('\t\t\tmetallic %.6f\n' % material.spec) file.write('\t%s\n' % materialTable[material.name])
#file.write('\t\t\tphong %.6f\n' % material.spec)
#file.write('\t\t\tphong_size %.6f\n' % material.spec) writeMatrix(ob.matrix)
povstring += 'brilliance %.6f ' % (material.specular_hardness/256.0) # Like hardness
povstring += '}'
#file.write('\t}\n')
return povstring
file.write('}\n')
world = scene.world
# Convert all materials to strings we can access directly per vertex.
for material in bpy.data.materials:
materialTable[material.name] = bMat2PovString(material)
def exportMeshs(sel):
ob_num = 0 ob_num = 0
@ -452,11 +511,15 @@ def write_pov(filename, scene=None, info_callback = None):
file.write('}\n') file.write('}\n')
# Convert all materials to strings we can access directly per vertex.
for material in bpy.data.materials:
materialTable[material.name] = blenderMaterialToPovString(material)
exportCamera() exportCamera()
#exportMaterials() #exportMaterials()
sel = scene.objects sel = scene.objects
lamps = [l for l in sel if l.type == 'LAMP'] exportLamps([l for l in sel if l.type == 'LAMP'])
exportLamps(lamps) exportMeta([l for l in sel if l.type == 'META'])
exportMeshs(sel) exportMeshs(sel)
exportWorld(scene.world) exportWorld(scene.world)
exportGlobalSettings(scene) exportGlobalSettings(scene)

@ -54,12 +54,12 @@ class DATA_PT_metaball_element(DataButtonsPanel):
__label__ = "Active Element" __label__ = "Active Element"
def poll(self, context): def poll(self, context):
return (context.meta_ball and context.meta_ball.last_selected_element) return (context.meta_ball and context.meta_ball.active_element)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
metaelem = context.meta_ball.last_selected_element metaelem = context.meta_ball.active_element
split = layout.split(percentage=0.3) split = layout.split(percentage=0.3)
split.itemL(text="Type:") split.itemL(text="Type:")
@ -81,30 +81,30 @@ class DATA_PT_metaball_element(DataButtonsPanel):
col = split.column(align=True) col = split.column(align=True)
col.itemL(text="Size:") col.itemL(text="Size:")
col.itemR(metaelem, "sizex", text="X") col.itemR(metaelem, "size_x", text="X")
col.itemR(metaelem, "sizey", text="Y") col.itemR(metaelem, "size_y", text="Y")
col.itemR(metaelem, "sizez", text="Z") col.itemR(metaelem, "size_z", text="Z")
elif metaelem.type == 'TUBE': elif metaelem.type == 'TUBE':
col = split.column(align=True) col = split.column(align=True)
col.itemL(text="Size:") col.itemL(text="Size:")
col.itemR(metaelem, "sizex", text="X") col.itemR(metaelem, "size_x", text="X")
elif metaelem.type == 'PLANE': elif metaelem.type == 'PLANE':
col = split.column(align=True) col = split.column(align=True)
col.itemL(text="Size:") col.itemL(text="Size:")
col.itemR(metaelem, "sizex", text="X") col.itemR(metaelem, "size_x", text="X")
col.itemR(metaelem, "sizey", text="Y") col.itemR(metaelem, "size_y", text="Y")
elif metaelem.type == 'ELLIPSOID': elif metaelem.type == 'ELLIPSOID':
col = split.column(align=True) col = split.column(align=True)
col.itemL(text="Size:") col.itemL(text="Size:")
col.itemR(metaelem, "sizex", text="X") col.itemR(metaelem, "size_x", text="X")
col.itemR(metaelem, "sizey", text="Y") col.itemR(metaelem, "size_y", text="Y")
col.itemR(metaelem, "sizez", text="Z") col.itemR(metaelem, "size_z", text="Z")
bpy.types.register(DATA_PT_context_metaball) bpy.types.register(DATA_PT_context_metaball)

@ -207,7 +207,8 @@ class MATERIAL_PT_diffuse(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME']) COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
def poll(self, context): def poll(self, context):
return (context.material.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES) mat = context.material
return mat and (mat.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@ -260,7 +261,8 @@ class MATERIAL_PT_specular(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME']) COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
def poll(self, context): def poll(self, context):
return (context.material.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES) mat = context.material
return mat and (mat.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@ -311,7 +313,8 @@ class MATERIAL_PT_sss(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER']) COMPAT_ENGINES = set(['BLENDER_RENDER'])
def poll(self, context): def poll(self, context):
return (context.material.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES) mat = context.material
return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw_header(self, context): def draw_header(self, context):
layout = self.layout layout = self.layout
@ -352,7 +355,8 @@ class MATERIAL_PT_raymir(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER']) COMPAT_ENGINES = set(['BLENDER_RENDER'])
def poll(self, context): def poll(self, context):
return (context.material.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES) mat = context.material
return mat and (mat.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw_header(self, context): def draw_header(self, context):
layout = self.layout layout = self.layout
@ -403,7 +407,8 @@ class MATERIAL_PT_raytransp(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER']) COMPAT_ENGINES = set(['BLENDER_RENDER'])
def poll(self, context): def poll(self, context):
return (context.material.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES) mat = context.material
return mat and (mat.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw_header(self, context): def draw_header(self, context):
layout = self.layout layout = self.layout
@ -454,7 +459,8 @@ class MATERIAL_PT_halo(MaterialButtonsPanel):
COMPAT_ENGINES = set(['BLENDER_RENDER']) COMPAT_ENGINES = set(['BLENDER_RENDER'])
def poll(self, context): def poll(self, context):
return (context.material.type == 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES) mat = context.material
return mat and (mat.type == 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout

@ -10,7 +10,6 @@ class ConstraintButtonsPanel(bpy.types.Panel):
layout = self.layout layout = self.layout
box = layout.template_constraint(con) box = layout.template_constraint(con)
class_dict = self.__class__.__dict__
if box: if box:
# match enum type to our functions, avoids a lookup table. # match enum type to our functions, avoids a lookup table.
@ -18,7 +17,7 @@ class ConstraintButtonsPanel(bpy.types.Panel):
# show/key buttons here are most likely obsolete now, with # show/key buttons here are most likely obsolete now, with
# keyframing functionality being part of every button # keyframing functionality being part of every button
if con.type not in ("RIGID_BODY_JOINT", "NULL"): if con.type not in ('RIGID_BODY_JOINT', 'NULL'):
box.itemR(con, "influence") box.itemR(con, "influence")
def space_template(self, layout, con, target=True, owner=True): def space_template(self, layout, con, target=True, owner=True):
@ -31,7 +30,7 @@ class ConstraintButtonsPanel(bpy.types.Panel):
row.itemR(con, "target_space", text="") row.itemR(con, "target_space", text="")
if target and owner: if target and owner:
row.itemL(icon="ICON_ARROW_LEFTRIGHT") row.itemL(icon='ICON_ARROW_LEFTRIGHT')
if owner: if owner:
row.itemR(con, "owner_space", text="") row.itemR(con, "owner_space", text="")
@ -47,7 +46,7 @@ class ConstraintButtonsPanel(bpy.types.Panel):
row = layout.row() row = layout.row()
row.itemL(text="Head/Tail:") row.itemL(text="Head/Tail:")
row.itemR(con, "head_tail", text="") row.itemR(con, "head_tail", text="")
elif con.target.type in ("MESH", "LATTICE"): elif con.target.type in ('MESH', 'LATTICE'):
layout.item_pointerR(con, "subtarget", con.target, "vertex_groups", text="Vertex Group") layout.item_pointerR(con, "subtarget", con.target, "vertex_groups", text="Vertex Group")
def CHILD_OF(self, layout, con): def CHILD_OF(self, layout, con):
@ -95,7 +94,7 @@ class ConstraintButtonsPanel(bpy.types.Panel):
self.target_template(layout, con) self.target_template(layout, con)
layout.itemR(con, "pole_target") layout.itemR(con, "pole_target")
if con.pole_target and con.pole_target.type == "ARMATURE": if con.pole_target and con.pole_target.type == 'ARMATURE':
layout.item_pointerR(con, "pole_subtarget", con.pole_target.data, "bones", text="Bone") layout.item_pointerR(con, "pole_subtarget", con.pole_target.data, "bones", text="Bone")
flow = layout.column_flow() flow = layout.column_flow()
@ -499,7 +498,7 @@ class BONE_PT_constraints(ConstraintButtonsPanel):
def poll(self, context): def poll(self, context):
ob = context.object ob = context.object
return (ob and ob.type == "ARMATURE" and context.bone) return (ob and ob.type == 'ARMATURE' and context.bone)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout

@ -118,19 +118,19 @@ void rna_def_metaelement(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Radius", ""); RNA_def_property_ui_text(prop, "Radius", "");
RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); RNA_def_property_update(prop, 0, "rna_MetaElem_update_data");
prop= RNA_def_property(srna, "sizex", PROP_FLOAT, PROP_NONE); prop= RNA_def_property(srna, "size_x", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "expx"); RNA_def_property_float_sdna(prop, NULL, "expx");
RNA_def_property_range(prop, 0.0f, 20.0f); RNA_def_property_range(prop, 0.0f, 20.0f);
RNA_def_property_ui_text(prop, "Size X", "Size of element, use of components depends on element type."); RNA_def_property_ui_text(prop, "Size X", "Size of element, use of components depends on element type.");
RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); RNA_def_property_update(prop, 0, "rna_MetaElem_update_data");
prop= RNA_def_property(srna, "sizey", PROP_FLOAT, PROP_NONE); prop= RNA_def_property(srna, "size_y", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "expy"); RNA_def_property_float_sdna(prop, NULL, "expy");
RNA_def_property_range(prop, 0.0f, 20.0f); RNA_def_property_range(prop, 0.0f, 20.0f);
RNA_def_property_ui_text(prop, "Size Y", "Size of element, use of components depends on element type."); RNA_def_property_ui_text(prop, "Size Y", "Size of element, use of components depends on element type.");
RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); RNA_def_property_update(prop, 0, "rna_MetaElem_update_data");
prop= RNA_def_property(srna, "sizez", PROP_FLOAT, PROP_NONE); prop= RNA_def_property(srna, "size_z", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "expz"); RNA_def_property_float_sdna(prop, NULL, "expz");
RNA_def_property_range(prop, 0.0f, 20.0f); RNA_def_property_range(prop, 0.0f, 20.0f);
RNA_def_property_ui_text(prop, "Size Z", "Size of element, use of components depends on element type."); RNA_def_property_ui_text(prop, "Size Z", "Size of element, use of components depends on element type.");
@ -174,7 +174,7 @@ void rna_def_metaball(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "MetaElement"); RNA_def_property_struct_type(prop, "MetaElement");
RNA_def_property_ui_text(prop, "Elements", "Meta elements."); RNA_def_property_ui_text(prop, "Elements", "Meta elements.");
prop= RNA_def_property(srna, "last_selected_element", PROP_POINTER, PROP_NONE); prop= RNA_def_property(srna, "active_element", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "lastelem"); RNA_def_property_pointer_sdna(prop, NULL, "lastelem");
RNA_def_property_ui_text(prop, "Last selected element.", "Last selected element."); RNA_def_property_ui_text(prop, "Last selected element.", "Last selected element.");