Cycles Bake
[blender-staging.git] / intern / cycles / blender / addon / engine.py
index 6879efcb24eb2016137454128f24bcdc0e6a8c06..25a9e97a99b19b238bfb17a5cabb4a3bebc2a2de 100644 (file)
 #
-# Copyright 2011, Blender Foundation.
+# Copyright 2011-2013 Blender Foundation
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
 #
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License
 #
 
-import bpy
+# <pep8 compliant>
+
 
 def init():
-       import libcycles_blender as lib
-       import os.path
-       lib.init(os.path.dirname(__file__))
+    import bpy
+    import _cycles
+    import os.path
 
-def create(engine, data, scene, region = 0, v3d = 0, rv3d = 0):
-       import libcycles_blender as lib
+    path = os.path.dirname(__file__)
+    user_path = os.path.dirname(os.path.abspath(bpy.utils.user_resource('CONFIG', '')))
 
-       data = data.as_pointer()
-       scene = scene.as_pointer()
-       if region:
-               region = region.as_pointer()
-       if v3d:
-               v3d = v3d.as_pointer()
-       if rv3d:
-               rv3d = rv3d.as_pointer()
+    _cycles.init(path, user_path)
 
-       engine.session = lib.create(engine.as_pointer(), data, scene, region, v3d, rv3d)
 
-def free(engine):
-       if "session" in dir(engine):
-               if engine.session:
-                       import libcycles_blender as lib
-                       lib.free(engine.session)
-               del engine.session
+def create(engine, data, scene, region=0, v3d=0, rv3d=0, preview_osl=False):
+    import bpy
+    import _cycles
 
-def render(engine):
-       import libcycles_blender as lib
-       lib.render(engine.session)
+    data = data.as_pointer()
+    userpref = bpy.context.user_preferences.as_pointer()
+    scene = scene.as_pointer()
+    if region:
+        region = region.as_pointer()
+    if v3d:
+        v3d = v3d.as_pointer()
+    if rv3d:
+        rv3d = rv3d.as_pointer()
 
-def update(engine, data, scene):
-       import libcycles_blender as lib
-       lib.sync(engine.session)
+    engine.session = _cycles.create(engine.as_pointer(), userpref, data, scene, region, v3d, rv3d, preview_osl)
 
-def draw(engine, region, v3d, rv3d):
-       import libcycles_blender as lib
-       v3d = v3d.as_pointer()
-       rv3d = rv3d.as_pointer()
 
-       # draw render image
-       status, substatus = lib.draw(engine.session, v3d, rv3d)
+def free(engine):
+    if hasattr(engine, "session"):
+        if engine.session:
+            import _cycles
+            _cycles.free(engine.session)
+        del engine.session
 
-       # draw text over image
-       if status != "":
-               import blf
-               import bgl
 
-               fontid = 0 # todo, find out how to set this
-               dim = blf.dimensions(fontid, status)
-               dim_sub = blf.dimensions(fontid, substatus)
+def render(engine):
+    import _cycles
+    if hasattr(engine, "session"):
+        _cycles.render(engine.session)
 
-               padding = 5
 
-               x = (region.width - max(dim[0], dim_sub[0]))*0.5 - padding
-               y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 - padding
+def bake(engine, obj, pass_type, pixel_array, num_pixels, depth, result):
+    import _cycles
+    session = getattr(engine, "session", None)
+    if session is not None:
+        _cycles.bake(engine.session, obj.as_pointer(), pass_type, pixel_array.as_pointer(), num_pixels, depth, result.as_pointer())
 
-               bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
-               bgl.glEnable(bgl.GL_BLEND)
-               bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
-               bgl.glRectf(x, y, x+max(dim[0], dim_sub[0])+padding+padding, y+dim[1]+dim_sub[1]+padding+padding+2)
-               bgl.glDisable(bgl.GL_BLEND)
+def reset(engine, data, scene):
+    import _cycles
+    data = data.as_pointer()
+    scene = scene.as_pointer()
+    _cycles.reset(engine.session, data, scene)
 
-               x = (region.width - dim[0])*0.5
-               y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 + dim_sub[1] + padding
 
-               bgl.glColor3f(0.8, 0.8, 0.8)
-               blf.position(fontid, x, y, 0)
-               blf.draw(fontid, status)
+def update(engine, data, scene):
+    import _cycles
+    _cycles.sync(engine.session)
+
+
+def draw(engine, region, v3d, rv3d):
+    import _cycles
+    v3d = v3d.as_pointer()
+    rv3d = rv3d.as_pointer()
 
-               x = (region.width - dim_sub[0])*0.5
-               y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5
+    # draw render image
+    _cycles.draw(engine.session, v3d, rv3d)
 
-               bgl.glColor3f(0.6, 0.6, 0.6)
-               blf.position(fontid, x, y, 0)
-               blf.draw(fontid, substatus)
 
 def available_devices():
-       import libcycles_blender as lib
-       return lib.available_devices()
+    import _cycles
+    return _cycles.available_devices()
+
 
 def with_osl():
-       import libcycles_blender as lib
-       return lib.with_osl()
+    import _cycles
+    return _cycles.with_osl
+
 
+def with_network():
+    import _cycles
+    return _cycles.with_network