Merge branch 'blender2.7'
[blender.git] / intern / cycles / blender / addon / __init__.py
1 #
2 # Copyright 2011-2013 Blender Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 # <pep8 compliant>
18
19 bl_info = {
20     "name": "Cycles Render Engine",
21     "author": "",
22     "blender": (2, 80, 0),
23     "location": "Info header, render engine menu",
24     "description": "Cycles Render Engine integration",
25     "warning": "",
26     "wiki_url": "https://docs.blender.org/manual/en/dev/render/cycles/",
27     "tracker_url": "",
28     "support": 'OFFICIAL',
29     "category": "Render"}
30
31 # Support 'reload' case.
32 if "bpy" in locals():
33     import importlib
34     if "engine" in locals():
35         importlib.reload(engine)
36     if "version_update" in locals():
37         importlib.reload(version_update)
38     if "ui" in locals():
39         importlib.reload(ui)
40     if "operators" in locals():
41         importlib.reload(operators)
42     if "properties" in locals():
43         importlib.reload(properties)
44     if "presets" in locals():
45         importlib.reload(presets)
46
47 import bpy
48
49 from . import (
50     engine,
51     version_update,
52 )
53
54
55 class CyclesRender(bpy.types.RenderEngine):
56     bl_idname = 'CYCLES'
57     bl_label = "Cycles"
58     bl_use_shading_nodes = True
59     bl_use_preview = True
60     bl_use_exclude_layers = True
61     bl_use_save_buffers = True
62     bl_use_spherical_stereo = True
63
64     def __init__(self):
65         self.session = None
66
67     def __del__(self):
68         engine.free(self)
69
70     # final render
71     def update(self, data, depsgraph):
72         if not self.session:
73             if self.is_preview:
74                 cscene = bpy.context.scene.cycles
75                 use_osl = cscene.shading_system and cscene.device == 'CPU'
76
77                 engine.create(self, data, preview_osl=use_osl)
78             else:
79                 engine.create(self, data)
80
81         engine.reset(self, data, depsgraph)
82
83     def render(self, depsgraph):
84         engine.render(self, depsgraph)
85
86     def bake(self, depsgraph, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result):
87         engine.bake(self, depsgraph, obj, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result)
88
89     # viewport render
90     def view_update(self, context):
91         if not self.session:
92             engine.create(self, context.blend_data,
93                           context.region, context.space_data, context.region_data)
94
95         engine.reset(self, context.blend_data, context.depsgraph)
96         engine.sync(self, context.depsgraph, context.blend_data)
97
98     def view_draw(self, context):
99         engine.draw(self, context.depsgraph, context.region, context.space_data, context.region_data)
100
101     def update_script_node(self, node):
102         if engine.with_osl():
103             from . import osl
104             osl.update_script_node(node, self.report)
105         else:
106             self.report({'ERROR'}, "OSL support disabled in this build.")
107
108     def update_render_passes(self, scene, srl):
109         engine.register_passes(self, scene, srl)
110
111
112 def engine_exit():
113     engine.exit()
114
115
116 classes = (
117     CyclesRender,
118 )
119
120
121 def register():
122     from bpy.utils import register_class
123     from . import ui
124     from . import operators
125     from . import properties
126     from . import presets
127     import atexit
128
129     # Make sure we only registered the callback once.
130     atexit.unregister(engine_exit)
131     atexit.register(engine_exit)
132
133     engine.init()
134
135     properties.register()
136     ui.register()
137     operators.register()
138     presets.register()
139
140     for cls in classes:
141         register_class(cls)
142
143     bpy.app.handlers.version_update.append(version_update.do_versions)
144
145
146 def unregister():
147     from bpy.utils import unregister_class
148     from . import ui
149     from . import operators
150     from . import properties
151     from . import presets
152     import atexit
153
154     bpy.app.handlers.version_update.remove(version_update.do_versions)
155
156     ui.unregister()
157     operators.unregister()
158     properties.unregister()
159     presets.unregister()
160
161     for cls in classes:
162         unregister_class(cls)