Povray
authorCampbell Barton <ideasman42@gmail.com>
Fri, 7 Aug 2009 01:05:33 +0000 (01:05 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 7 Aug 2009 01:05:33 +0000 (01:05 +0000)
* 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.

release/io/engine_render_pov.py
release/ui/buttons_data_metaball.py
release/ui/buttons_material.py
release/ui/buttons_object_constraint.py
source/blender/makesrna/intern/rna_meta.c

index 782d87fcdf3c1646b7dc0bded499594964ffb916..b1281e73c95eb5e6ae5358d786d6c57a13d4b791 100644 (file)
@@ -19,8 +19,9 @@ def write_pov(filename, scene=None, info_callback = None):
        # Only for testing
        if not scene:
                scene = bpy.data.scenes[0]
-               
+       
        render = scene.render_data
+       world = scene.world
        materialTable = {}
        
        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' %\
                (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():
                camera = scene.camera
                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('\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':
                                
                                size_x = lamp.size
@@ -109,47 +147,68 @@ def write_pov(filename, scene=None, info_callback = None):
                        
                        file.write('}\n')
        
-       def exportMeshs(sel):
-               def bMat2PovString(material):
-                       povstring = 'finish {'
-                       if world != None:
-                               povstring += 'ambient <%.6f, %.6f, %.6f> ' % tuple([c*material.ambient for c in world.ambient_color])
+       def exportMeta(metas):
+               
+               # TODO - blenders 'motherball' naming is not supported.
+               
+               for ob in metas:
+                       meta = ob.data
                        
-                       povstring += 'diffuse %.6f ' % material.diffuse_reflection
-                       povstring += 'specular %.6f ' % material.specular_reflection
+                       file.write('blob {\n')
+                       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:
-                               #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)
+                       for elem in meta.elements:
+                               
+                               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:
-                               #povstring += 'interior { ior %.6f } ' % material.IOR
-                               pass
+                                       file.write('\tsphere { <%.6g, %.6g, %.6g>, %.4g, %.4g ' % (loc.x, loc.y, loc.z, elem.radius, stiffness))
+                                       
+                                       # 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))
-                       #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
+                       # Write the finish last.
+                       if material:
+                               file.write('\t%s\n' % materialTable[material.name])
+
+                       writeMatrix(ob.matrix)
                        
+                       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
                
@@ -452,11 +511,15 @@ def write_pov(filename, scene=None, info_callback = None):
                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()
        #exportMaterials()
        sel = scene.objects
-       lamps = [l for l in sel if l.type == 'LAMP']
-       exportLamps(lamps)
+       exportLamps([l for l in sel if l.type == 'LAMP'])
+       exportMeta([l for l in sel if l.type == 'META'])
        exportMeshs(sel)
        exportWorld(scene.world)
        exportGlobalSettings(scene)
index 08959dab085415212419f9fc1624fc7e54ae728e..a3781705799f74a87a0b22faf7e1bcb1fcb9ad7c 100644 (file)
@@ -54,12 +54,12 @@ class DATA_PT_metaball_element(DataButtonsPanel):
        __label__ = "Active Element"
        
        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):
                layout = self.layout
                
-               metaelem = context.meta_ball.last_selected_element
+               metaelem = context.meta_ball.active_element
                
                split = layout.split(percentage=0.3)
                split.itemL(text="Type:")       
@@ -81,30 +81,30 @@ class DATA_PT_metaball_element(DataButtonsPanel):
                
                        col = split.column(align=True)
                        col.itemL(text="Size:") 
-                       col.itemR(metaelem, "sizex", text="X")
-                       col.itemR(metaelem, "sizey", text="Y")
-                       col.itemR(metaelem, "sizez", text="Z")
+                       col.itemR(metaelem, "size_x", text="X")
+                       col.itemR(metaelem, "size_y", text="Y")
+                       col.itemR(metaelem, "size_z", text="Z")
                        
                elif metaelem.type == 'TUBE':
                
                        col = split.column(align=True)
                        col.itemL(text="Size:") 
-                       col.itemR(metaelem, "sizex", text="X")
+                       col.itemR(metaelem, "size_x", text="X")
                        
                elif metaelem.type == 'PLANE':
                        
                        col = split.column(align=True)
                        col.itemL(text="Size:") 
-                       col.itemR(metaelem, "sizex", text="X")
-                       col.itemR(metaelem, "sizey", text="Y")
+                       col.itemR(metaelem, "size_x", text="X")
+                       col.itemR(metaelem, "size_y", text="Y")
                        
                elif metaelem.type == 'ELLIPSOID':
                        
                        col = split.column(align=True)
                        col.itemL(text="Size:") 
-                       col.itemR(metaelem, "sizex", text="X")
-                       col.itemR(metaelem, "sizey", text="Y")
-                       col.itemR(metaelem, "sizez", text="Z")
+                       col.itemR(metaelem, "size_x", text="X")
+                       col.itemR(metaelem, "size_y", text="Y")
+                       col.itemR(metaelem, "size_z", text="Z")
                
 
 bpy.types.register(DATA_PT_context_metaball)
index 4e03b2b4fd0ceff5924f62849445fea417067526..d401367008b508259bd865890db287a38174e89f 100644 (file)
@@ -207,7 +207,8 @@ class MATERIAL_PT_diffuse(MaterialButtonsPanel):
        COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        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):
                layout = self.layout
@@ -260,7 +261,8 @@ class MATERIAL_PT_specular(MaterialButtonsPanel):
        COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        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):
                layout = self.layout
@@ -311,7 +313,8 @@ class MATERIAL_PT_sss(MaterialButtonsPanel):
        COMPAT_ENGINES = set(['BLENDER_RENDER'])
        
        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):
                layout = self.layout
@@ -352,7 +355,8 @@ class MATERIAL_PT_raymir(MaterialButtonsPanel):
        COMPAT_ENGINES = set(['BLENDER_RENDER'])
        
        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):
                layout = self.layout
@@ -403,7 +407,8 @@ class MATERIAL_PT_raytransp(MaterialButtonsPanel):
        COMPAT_ENGINES = set(['BLENDER_RENDER'])
                
        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):
                layout = self.layout
@@ -454,7 +459,8 @@ class MATERIAL_PT_halo(MaterialButtonsPanel):
        COMPAT_ENGINES = set(['BLENDER_RENDER'])
        
        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):
                layout = self.layout
index 7c352a7fb7568eb5e3400f8ef5befe7d080790d8..5606c6c258af11e3de0bf3188c2470b6bd22d724 100644 (file)
@@ -10,7 +10,6 @@ class ConstraintButtonsPanel(bpy.types.Panel):
                layout = self.layout
                
                box = layout.template_constraint(con)
-               class_dict = self.__class__.__dict__
 
                if box:
                        # 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
                        # 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")
        
        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="")
 
                        if target and owner:
-                               row.itemL(icon="ICON_ARROW_LEFTRIGHT")
+                               row.itemL(icon='ICON_ARROW_LEFTRIGHT')
 
                        if owner:
                                row.itemR(con, "owner_space", text="")
@@ -47,7 +46,7 @@ class ConstraintButtonsPanel(bpy.types.Panel):
                                        row = layout.row()
                                        row.itemL(text="Head/Tail:")
                                        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")
        
        def CHILD_OF(self, layout, con):
@@ -95,7 +94,7 @@ class ConstraintButtonsPanel(bpy.types.Panel):
                self.target_template(layout, con)
                
                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")
                
                flow = layout.column_flow()
@@ -499,7 +498,7 @@ class BONE_PT_constraints(ConstraintButtonsPanel):
 
        def poll(self, context):
                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):
                layout = self.layout
index e142bc4b2aa2d851a5799c0ce36c33514d5f6a7c..ad16c5a7c5c4d8a747a1a858012918380ca44ada 100644 (file)
@@ -118,19 +118,19 @@ void rna_def_metaelement(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Radius", "");
        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_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_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_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_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_range(prop, 0.0f, 20.0f);
        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_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_ui_text(prop, "Last selected element.", "Last selected element.");