How can I make a preview panel for an external renderer (e.g. yafaray) ?
For example - for world settings I have added some extra variables in the rna that are the external renderer specific. I am working with blender 2.5 python API.
How can I see the effect of those in the preview panel ?
If anyone can show me a way, it will be of great help to me.
Thanks in advance.
I also do not understand what template_preview() and template_ID_preview() actually does. These functions are in the bpy.types.UILayout class.
You can use Blender’s preview panel by enabling “bl_preview” in your bpy.types.RenderEngine class. When enabled Blender will pass the preview scene to render(self, scene) instead of the active scene.
Here’s a simple example…
class PreviewRender(bpy.types.RenderEngine):
bl_preview = True
bl_idname = "PREVIEW_RENDER"
bl_label = "Preview render example"
def render(self, scene):
if scene.name == "preview":
print("Should be running preview code")
else:
print("Should be running render code")
import properties_render
for member in dir(properties_render):
subclass = getattr(properties_render, member)
try:
subclass.COMPAT_ENGINES.add('PREVIEW_RENDER')
except:
pass
del properties_render
import properties_material
for member in dir(properties_material):
subclass = getattr(properties_material, member)
try:
subclass.COMPAT_ENGINES.add('PREVIEW_RENDER')
except:
pass
del properties_material
bpy.types.register(PreviewRender)
Paste this in Blender’s text editor and run, then select “Preview render example” in the render engine menu, switch between rendering a scene and looking at the material preview and watch the output on the console.
For template_preview you pass the datablock you want to preview and the texture slot if on a texture datablock. The preview window will adjust according to what datablock its previewing. I haven’t used template_ID_preview so not as sure about it.
See the files in your installation ./.blender/scripts/ui/properties_material.py for an example of template_preview for materials and ./.blender/scripts/ui/space_3dview_toolbar.py for template_ID_preview You can usually find a working example of almost anything by looking at the scripts driving Blender UI (I on Linux so I grep for methods when I’m looking for an example).
Not sure, works fine here… maybe your running an older build of Blender (bl_preview was only added a little while ago)?
I’m running Blender 2.5 Alpha 2 2.525 r29741 built in Debian Linux.
Yes, now I am using the latest svn (r29784) and the code is working. Thanks.
Now, I have got the preview scene.
What should I do with this scene data to show it in the preview window of blender (e.g. texture, material and world)?
I am asking this because in my preview scene there are some extra variable that are not part of default blender scene.
The whole process is handled by the methods and attributes in bpy.types.RenderEngine class (that we are subclassing from).
I’m assuming the variables your referring to are properties you’ve added to the world data block to control something in your exporter. Your exporter needs to be called in your render classes render method to export the scene data and call the renderer. The scene is either the active scene or an internal preview scene. The preview scene will have the datablock from your current context already linked in so if your exporter reacts to properties on it your preview render will react accordingly.
Once you have a render image you call self.begin_result() and use the returned RenderResult object to load the image into a renderlayer with its load_from_file() method. If rendering this will show in Blender’s render view, if previewing this will show in the preview pane.
The best way to figure this out is follow the excellent example in “.blender/scripts/io/engine_render_pov.py” starting from around line 791