Cycles: shuffle addon import statements a bit to try to fix a strange import
[blender-staging.git] / intern / cycles / blender / addon / engine.py
1 #
2 # Copyright 2011, Blender Foundation.
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18
19 # <pep8 compliant>
20
21 def init():
22     import bpy
23     import _cycles
24     import os.path
25
26     path = os.path.dirname(__file__)
27     user_path = os.path.dirname(os.path.abspath(bpy.utils.user_resource('CONFIG', '')))
28
29     _cycles.init(path, user_path)
30
31
32 def create(engine, data, scene, region=0, v3d=0, rv3d=0):
33     import bpy
34     import _cycles
35
36     data = data.as_pointer()
37     userpref = bpy.context.user_preferences.as_pointer()
38     scene = scene.as_pointer()
39     if region:
40         region = region.as_pointer()
41     if v3d:
42         v3d = v3d.as_pointer()
43     if rv3d:
44         rv3d = rv3d.as_pointer()
45
46     engine.session = _cycles.create(engine.as_pointer(), userpref, data, scene, region, v3d, rv3d)
47
48
49 def free(engine):
50     if hasattr(engine, "session"):
51         if engine.session:
52             import _cycles
53             _cycles.free(engine.session)
54         del engine.session
55
56
57 def render(engine):
58     import _cycles
59     if hasattr(engine, "session"):
60         _cycles.render(engine.session)
61
62
63 def reset(engine, data, scene):
64     import _cycles
65     data = data.as_pointer()
66     scene = scene.as_pointer()
67     _cycles.reset(engine.session, data, scene)
68
69
70 def update(engine, data, scene):
71     import _cycles
72     _cycles.sync(engine.session)
73
74
75 def draw(engine, region, v3d, rv3d):
76     import _cycles
77     v3d = v3d.as_pointer()
78     rv3d = rv3d.as_pointer()
79
80     # draw render image
81     _cycles.draw(engine.session, v3d, rv3d)
82
83
84 def available_devices():
85     import _cycles
86     return _cycles.available_devices()
87
88
89 def with_osl():
90     import _cycles
91     return _cycles.with_osl
92