Revision: 22041
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22041
Author:   campbellbarton
Date:     2009-07-30 10:10:10 +0200 (Thu, 30 Jul 2009)

Log Message:
-----------
Engine specific panel's
- All of this is in python and easy to change.
- each panel class has a set() of compatible engines.
- this set is checked for the poll function
- external engines can add themselves to this panels compatible engines
eg.
 buttons_world.WORLD_PT_mist.COMPAT_ENGINES.add('POVRAY_RENDER')

I tried doing this by subclassing each panel and replacing only the poll 
function to reference 'POVRAY_RENDER' but it became fairly complicated and 
meant registering many of the same panels under different names.

Added mist support to povray.

Modified Paths:
--------------
    branches/blender2.5/blender/release/io/engine_render_pov.py
    branches/blender2.5/blender/release/ui/buttons_material.py
    branches/blender2.5/blender/release/ui/buttons_scene.py
    branches/blender2.5/blender/release/ui/buttons_world.py
    branches/blender2.5/blender/release/ui/space_console.py

Modified: branches/blender2.5/blender/release/io/engine_render_pov.py
===================================================================
--- branches/blender2.5/blender/release/io/engine_render_pov.py 2009-07-30 
06:35:27 UTC (rev 22040)
+++ branches/blender2.5/blender/release/io/engine_render_pov.py 2009-07-30 
08:10:10 UTC (rev 22041)
@@ -64,7 +64,7 @@
                        
                        file.write('light_source {\n')
                        file.write('\t< 0,0,0 >\n')
-                       file.write('\tcolor red %.6f green %.6f blue %.6f\n' % 
color)
+                       file.write('\tcolor rgb<%.3g, %.3g, %.3g>\n' % color)
                        
                        if lamp.type == 'POINT': # Point Lamp 
                                pass
@@ -310,7 +310,7 @@
                                
                                float_col = col[0], col[1], col[2], 
1-material.alpha, materialString
                                #print material.apl
-                               file.write(',\n\t\ttexture { pigment 
{rgbf<%.6f, %.6f, %.6f, %.6f>}%s}' % float_col)
+                               file.write(',\n\t\ttexture { pigment 
{rgbf<%.3g, %.3g, %.3g, %.3g>}%s}' % float_col)
                                index[0] = idx
                                idx+=1
                        
@@ -412,6 +412,22 @@
                        
                        bpy.data.remove_mesh(me)
        
+       def exportWorld(world):
+               if not world:
+                       return
+               
+               mist = world.mist
+               
+               if mist.enabled:
+                       file.write('\tfog {\n')
+                       file.write('\t\tdistance %.6f\n' % mist.depth)
+                       file.write('\t\tcolor rgbt<%.3g, %.3g, %.3g, %.3g>\n' % 
(tuple(world.horizon_color) + (1-mist.intensity,)))
+                       #file.write('\t\tfog_offset %.6f\n' % mist.start)
+                       #file.write('\t\tfog_alt 5\n')
+                       #file.write('\t\tturbulence 0.2\n')
+                       #file.write('\t\tturb_depth 0.3\n')
+                       file.write('\t\tfog_type 1\n')
+                       file.write('\t}\n')
        
        exportCamera()
        #exportMaterials()
@@ -419,6 +435,7 @@
        lamps = [l for l in sel if l.type == 'LAMP']
        exportLamps(lamps)
        exportMeshs(sel)
+       exportWorld(scene.world)
        
        file.close()
 
@@ -462,7 +479,8 @@
        file.close()
 
 
-class PovrayRenderEngine(bpy.types.RenderEngine):
+class PovrayRender(bpy.types.RenderEngine):
+       __idname__ = 'POVRAY_RENDER'
        __label__ = "Povray"
        DELAY = 0.02
        def _export(self, scene):
@@ -471,6 +489,11 @@
                self.temp_file_in = tempfile.mktemp(suffix='.pov')
                self.temp_file_out = tempfile.mktemp(suffix='.tga')
                self.temp_file_ini = tempfile.mktemp(suffix='.ini')
+               '''
+               self.temp_file_in = '/test.pov'
+               self.temp_file_out = '/test.tga'
+               self.temp_file_ini = '/test.ini'
+               '''
                
                def info_callback(txt):
                        self.update_stats("", "POVRAY: " + txt)
@@ -580,4 +603,28 @@
                self._cleanup()
 
 
-bpy.types.register(PovrayRenderEngine)
+bpy.types.register(PovrayRender)
+
+# Use some of the existing buttons.
+import buttons_scene
+buttons_scene.SCENE_PT_render.COMPAT_ENGINES.add('POVRAY_RENDER')
+buttons_scene.SCENE_PT_dimensions.COMPAT_ENGINES.add('POVRAY_RENDER')
+buttons_scene.SCENE_PT_antialiasing.COMPAT_ENGINES.add('POVRAY_RENDER')
+buttons_scene.SCENE_PT_output.COMPAT_ENGINES.add('POVRAY_RENDER')
+del buttons_scene
+
+# Use only a subset of the world panels
+import buttons_world
+buttons_world.WORLD_PT_preview.COMPAT_ENGINES.add('POVRAY_RENDER')
+buttons_world.WORLD_PT_context_world.COMPAT_ENGINES.add('POVRAY_RENDER')
+buttons_world.WORLD_PT_world.COMPAT_ENGINES.add('POVRAY_RENDER')
+buttons_world.WORLD_PT_mist.COMPAT_ENGINES.add('POVRAY_RENDER')
+del buttons_world
+
+# Example of wrapping every class 'as is'
+import buttons_material
+for member in dir(buttons_material):
+       subclass = getattr(buttons_material, member)
+       try:            subclass.COMPAT_ENGINES.add('POVRAY_RENDER')
+       except: pass
+del buttons_material

Modified: branches/blender2.5/blender/release/ui/buttons_material.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_material.py  2009-07-30 
06:35:27 UTC (rev 22040)
+++ branches/blender2.5/blender/release/ui/buttons_material.py  2009-07-30 
08:10:10 UTC (rev 22041)
@@ -5,13 +5,15 @@
        __space_type__ = "BUTTONS_WINDOW"
        __region_type__ = "WINDOW"
        __context__ = "material"
+       # COMPAT_ENGINES must be defined in each subclass, external engines can 
add themselves here
 
        def poll(self, context):
-               return (context.material != None)
+               return (context.material) and (context.scene.render_data.engine 
in self.COMPAT_ENGINES)
 
 class MATERIAL_PT_preview(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_preview"
        __label__ = "Preview"
+       COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        def draw(self, context):
                layout = self.layout
@@ -22,9 +24,13 @@
 class MATERIAL_PT_context_material(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_context_material"
        __show_header__ = False
+       COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        def poll(self, context):
-               return (context.object)
+               # An exception, dont call the parent poll func because
+               # this manages materials for all engine types
+               
+               return (context.object) and (context.scene.render_data.engine 
in self.COMPAT_ENGINES)
 
        def draw(self, context):
                layout = self.layout
@@ -66,6 +72,7 @@
 class MATERIAL_PT_material(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_material"
        __label__ = "Shading"
+       COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        def draw(self, context):
                layout = self.layout
@@ -100,6 +107,7 @@
        __idname__= "MATERIAL_PT_strand"
        __label__ = "Strand"
        __default_closed__ = True
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
        
        def draw(self, context):
                layout = self.layout
@@ -132,6 +140,7 @@
 class MATERIAL_PT_options(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_options"
        __label__ = "Options"
+       COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        def draw(self, context):
                layout = self.layout
@@ -165,6 +174,7 @@
 class MATERIAL_PT_shadows(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_shadows"
        __label__ = "Shadows"
+       COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        def draw(self, context):
                layout = self.layout
@@ -190,10 +200,10 @@
 class MATERIAL_PT_diffuse(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_diffuse"
        __label__ = "Diffuse"
+       COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        def poll(self, context):
-               mat = context.material
-               return (mat and mat.type != 'HALO')
+               return (context.material.type != 'HALO') and 
(context.scene.render_data.engine in self.COMPAT_ENGINES)
 
        def draw(self, context):
                layout = self.layout
@@ -234,10 +244,10 @@
 class MATERIAL_PT_specular(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_specular"
        __label__ = "Specular"
+       COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
 
        def poll(self, context):
-               mat = context.material
-               return (mat and mat.type != 'HALO')
+               return (context.material.type != 'HALO') and 
(context.scene.render_data.engine in self.COMPAT_ENGINES)
 
        def draw(self, context):
                layout = self.layout
@@ -278,10 +288,10 @@
        __idname__= "MATERIAL_PT_sss"
        __label__ = "Subsurface Scattering"
        __default_closed__ = True
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
        
        def poll(self, context):
-               mat = context.material
-               return (mat and (mat.type == 'SURFACE' or mat.type == 'WIRE'))
+               return (context.material.type in ('SURFACE', 'WIRE')) and 
(context.scene.render_data.engine in self.COMPAT_ENGINES)
 
        def draw_header(self, context):
                layout = self.layout
@@ -317,10 +327,10 @@
        __idname__= "MATERIAL_PT_raymir"
        __label__ = "Ray Mirror"
        __default_closed__ = True
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
        
        def poll(self, context):
-               mat = context.material
-               return (mat and (mat.type == 'SURFACE' or mat.type == 'WIRE'))
+               return (context.material.type in 'SURFACE', 'WIRE') and 
(context.scene.render_data.engine in self.COMPAT_ENGINES)
        
        def draw_header(self, context):
                layout = self.layout
@@ -361,10 +371,10 @@
        __idname__= "MATERIAL_PT_raytransp"
        __label__= "Ray Transparency"
        __default_closed__ = True
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
                
        def poll(self, context):
-               mat = context.material
-               return (mat and (mat.type == 'SURFACE' or mat.type == 'WIRE'))
+               return (context.material.type in 'SURFACE', 'WIRE') and 
(context.scene.render_data.engine in self.COMPAT_ENGINES)
 
        def draw_header(self, context):
                layout = self.layout
@@ -405,10 +415,10 @@
 class MATERIAL_PT_halo(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_halo"
        __label__= "Halo"
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
        
        def poll(self, context):
-               mat = context.material
-               return (mat and mat.type == 'HALO')
+               return (context.material.type == 'HALO') and 
(context.scene.render_data.engine in self.COMPAT_ENGINES)
        
        def draw(self, context):
                layout = self.layout

Modified: branches/blender2.5/blender/release/ui/buttons_scene.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_scene.py     2009-07-30 
06:35:27 UTC (rev 22040)
+++ branches/blender2.5/blender/release/ui/buttons_scene.py     2009-07-30 
08:10:10 UTC (rev 22041)
@@ -5,14 +5,15 @@
        __space_type__ = "BUTTONS_WINDOW"
        __region_type__ = "WINDOW"
        __context__ = "scene"
-
+       # COMPAT_ENGINES must be defined in each subclass, external engines can 
add themselves here
+       
        def poll(self, context):
                rd = context.scene.render_data
-               return (not rd.use_game_engine)
+               return (rd.use_game_engine==False) and (rd.engine in 
self.COMPAT_ENGINES)
 
 class SCENE_PT_render(RenderButtonsPanel):
        __label__ = "Render"
-
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
        def draw(self, context):
                layout = self.layout
                rd = context.scene.render_data
@@ -26,7 +27,8 @@
 class SCENE_PT_layers(RenderButtonsPanel):
        __label__ = "Layers"
        __default_closed__ = True
-
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
+       
        def draw(self, context):
                layout = self.layout
                scene = context.scene
@@ -111,6 +113,7 @@
 
 class SCENE_PT_shading(RenderButtonsPanel):
        __label__ = "Shading"
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
 
        def draw(self, context):
                layout = self.layout
@@ -132,6 +135,7 @@
 class SCENE_PT_performance(RenderButtonsPanel):
        __label__ = "Performance"
        __default_closed__ = True
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
 
        def draw(self, context):
                layout = self.layout
@@ -174,6 +178,7 @@
 class SCENE_PT_post_processing(RenderButtonsPanel):
        __label__ = "Post Processing"
        __default_closed__ = True
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
 
        def draw(self, context):
                layout = self.layout
@@ -201,6 +206,7 @@
                
 class SCENE_PT_output(RenderButtonsPanel):
        __label__ = "Output"
+       COMPAT_ENGINES = set(['BLENDER_RENDER'])
 
        def draw(self, context):
                layout = self.layout
@@ -263,6 +269,7 @@
 class SCENE_PT_encoding(RenderButtonsPanel):
        __label__ = "Encoding"

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to