Fix RenderEngine API docs
authorCampbell Barton <ideasman42@gmail.com>
Mon, 8 Feb 2016 09:08:21 +0000 (20:08 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 8 Feb 2016 09:35:32 +0000 (20:35 +1100)
Correct access to passes, D1779 by @levon.

Also use is_preview attr and use register/unregister functions.

doc/python_api/examples/bpy.types.RenderEngine.py

index 7af7de1068c33c8c52766026c3610dff7703d965..efb7640bcc786e0da5787789b19b51f58fd48593 100644 (file)
@@ -9,8 +9,8 @@ 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_idname = "custom_renderer"
+    bl_label = "Flat Color Renderer"
     bl_use_preview = True
 
     # This is the only method called by blender, in this example
@@ -21,7 +21,7 @@ class CustomRenderEngine(bpy.types.RenderEngine):
         self.size_x = int(scene.render.resolution_x * scale)
         self.size_y = int(scene.render.resolution_y * scale)
 
-        if scene.name == 'preview':
+        if self.is_preview:
             self.render_preview(scene)
         else:
             self.render_scene(scene)
@@ -36,7 +36,7 @@ class CustomRenderEngine(bpy.types.RenderEngine):
 
         # 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 = result.layers[0].passes["Combined"]
         layer.rect = green_rect
         self.end_result(result)
 
@@ -50,21 +50,37 @@ class CustomRenderEngine(bpy.types.RenderEngine):
 
         # 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 = result.layers[0].passes["Combined"]
         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.
-from bl_ui import properties_render
-properties_render.RENDER_PT_render.COMPAT_ENGINES.add('custom_renderer')
-del properties_render
+def register():
+    # Register the RenderEngine
+    bpy.utils.register_class(CustomRenderEngine)
 
-from bl_ui import properties_material
-properties_material.MATERIAL_PT_preview.COMPAT_ENGINES.add('custom_renderer')
-del properties_material
+    # 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.
+    from bl_ui import (
+            properties_render,
+            properties_material,
+            )
+    properties_render.RENDER_PT_render.COMPAT_ENGINES.add(CustomRenderEngine.bl_idname)
+    properties_material.MATERIAL_PT_preview.COMPAT_ENGINES.add(CustomRenderEngine.bl_idname)
+
+
+def unregister():
+    bpy.utils.unregister_class(CustomRenderEngine)
+
+    from bl_ui import (
+            properties_render,
+            properties_material,
+            )
+    properties_render.RENDER_PT_render.COMPAT_ENGINES.remove(CustomRenderEngine.bl_idname)
+    properties_material.MATERIAL_PT_preview.COMPAT_ENGINES.remove(CustomRenderEngine.bl_idname)
+
+
+if __name__ == "__main__":
+    register()