diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-18 16:40:13 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-18 16:40:13 +0300 |
commit | 5531f3093a62bffe4a0220180e740fa8ea3d76ef (patch) | |
tree | e2589e1fd2b05bb3febb99d8e6880a0eb9ac41a1 | |
parent | 22638e22ea24d1b2b005fd9260ecd9aa95175875 (diff) |
render engine example thanks to dougal2.
-rw-r--r-- | doc/python_api/examples/bpy.types.RenderEngine.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/doc/python_api/examples/bpy.types.RenderEngine.py b/doc/python_api/examples/bpy.types.RenderEngine.py new file mode 100644 index 00000000000..48d642f7602 --- /dev/null +++ b/doc/python_api/examples/bpy.types.RenderEngine.py @@ -0,0 +1,70 @@ +""" +Simple Render Engine +++++++++++++++++++++ +""" + +import bpy + + +class CustomRenderEngine(bpy.types.RenderEngine): + # These three members are used by blender to set up the + # RenderEngine; define its internal name, visible name and capabilities. + bl_idname = 'custom_renderer' + bl_label = 'Flat Color Renderer' + bl_use_preview = True + + # This is the only method called by blender, in this example + # we use it to detect preview rendering and call the implementation + # in another method. + def render(self, scene): + scale = scene.render.resolution_percentage / 100.0 + self.size_x = int(scene.render.resolution_x * scale) + self.size_y = int(scene.render.resolution_y * scale) + + if scene.name == 'preview': + self.render_preview(scene) + else: + self.render_scene(scene) + + # In this example, we fill the preview renders with a flat green color. + def render_preview(self, scene): + pixel_count = self.size_x * self.size_y + + # The framebuffer is defined as a list of pixels, each pixel + # itself being a list of R,G,B,A values + green_rect = [[0.0, 1.0, 0.0, 1.0]] * pixel_count + + # Here we write the pixel values to the RenderResult + result = self.begin_result(0, 0, self.size_x, self.size_y) + layer = result.layers[0] + layer.rect = green_rect + self.end_result(result) + + # In this example, we fill the full renders with a flat blue color. + def render_scene(self, scene): + pixel_count = self.size_x * self.size_y + + # The framebuffer is defined as a list of pixels, each pixel + # itself being a list of R,G,B,A values + blue_rect = [[0.0, 0.0, 1.0, 1.0]] * pixel_count + + # Here we write the pixel values to the RenderResult + result = self.begin_result(0, 0, self.size_x, self.size_y) + layer = result.layers[0] + layer.rect = blue_rect + self.end_result(result) + +# Register the RenderEngine +bpy.utils.register_class(CustomRenderEngine) + +# RenderEngines also need to tell UI Panels that they are compatible +# Otherwise most of the UI will be empty when the engine is selected. +# In this example, we need to see the main render image button and +# the material preview panel. +import properties_render +properties_render.RENDER_PT_render.COMPAT_ENGINES.add('custom_renderer') +del properties_render + +import properties_material +properties_material.MATERIAL_PT_preview.COMPAT_ENGINES.add('custom_renderer') +del properties_material |