diff --git a/intern/cycles/blender/addon/engine.py b/intern/cycles/blender/addon/engine.py index 60b77b23f25..3d71c25d7ad 100644 --- a/intern/cycles/blender/addon/engine.py +++ b/intern/cycles/blender/addon/engine.py @@ -22,17 +22,17 @@ import bpy def init(): - import bcycles + import _cycles import os.path path = os.path.dirname(__file__) user_path = os.path.dirname(os.path.abspath(bpy.utils.user_resource('CONFIG', ''))) - bcycles.init(path, user_path) + _cycles.init(path, user_path) def create(engine, data, scene, region=0, v3d=0, rv3d=0): - import bcycles + import _cycles data = data.as_pointer() scene = scene.as_pointer() @@ -43,42 +43,42 @@ def create(engine, data, scene, region=0, v3d=0, rv3d=0): if rv3d: rv3d = rv3d.as_pointer() - engine.session = bcycles.create(engine.as_pointer(), data, scene, region, v3d, rv3d) + engine.session = _cycles.create(engine.as_pointer(), data, scene, region, v3d, rv3d) def free(engine): if hasattr(engine, "session"): if engine.session: - import bcycles - bcycles.free(engine.session) + import _cycles + _cycles.free(engine.session) del engine.session def render(engine): - import bcycles + import _cycles if hasattr(engine, "session"): - bcycles.render(engine.session) + _cycles.render(engine.session) def update(engine, data, scene): - import bcycles - bcycles.sync(engine.session) + import _cycles + _cycles.sync(engine.session) def draw(engine, region, v3d, rv3d): - import bcycles + import _cycles v3d = v3d.as_pointer() rv3d = rv3d.as_pointer() # draw render image - bcycles.draw(engine.session, v3d, rv3d) + _cycles.draw(engine.session, v3d, rv3d) def available_devices(): - import bcycles - return bcycles.available_devices() + import _cycles + return _cycles.available_devices() def with_osl(): - import bcycles - return bcycles.with_osl() + import _cycles + return _cycles.with_osl diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index 58049bb8cbe..90dab298dc3 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -35,8 +35,7 @@ static PyObject *init_func(PyObject *self, PyObject *args) path_init(path, user_path); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject *create_func(PyObject *self, PyObject *args) @@ -89,35 +88,23 @@ static PyObject *create_func(PyObject *self, PyObject *args) return PyLong_FromVoidPtr(session); } -static PyObject *free_func(PyObject *self, PyObject *args) +static PyObject *free_func(PyObject *self, PyObject *value) { - PyObject *pysession; + delete (BlenderSession*)PyLong_AsVoidPtr(value); - if(!PyArg_ParseTuple(args, "O", &pysession)) - return NULL; - - delete (BlenderSession*)PyLong_AsVoidPtr(pysession); - - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -static PyObject *render_func(PyObject *self, PyObject *args) +static PyObject *render_func(PyObject *self, PyObject *value) { - PyObject *pysession; - - if(!PyArg_ParseTuple(args, "O", &pysession)) - return NULL; - Py_BEGIN_ALLOW_THREADS - BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession); + BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value); session->render(); Py_END_ALLOW_THREADS - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject *draw_func(PyObject *self, PyObject *args) @@ -137,22 +124,15 @@ static PyObject *draw_func(PyObject *self, PyObject *args) session->draw(viewport[2], viewport[3]); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -static PyObject *sync_func(PyObject *self, PyObject *args) +static PyObject *sync_func(PyObject *self, PyObject *value) { - PyObject *pysession; - - if(!PyArg_ParseTuple(args, "O", &pysession)) - return NULL; - - BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession); + BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value); session->synchronize(); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject *available_devices_func(PyObject *self, PyObject *args) @@ -163,38 +143,26 @@ static PyObject *available_devices_func(PyObject *self, PyObject *args) for(size_t i = 0; i < types.size(); i++) { string name = Device::string_from_type(types[i]); - PyTuple_SetItem(ret, i, PyUnicode_FromString(name.c_str())); + PyTuple_SET_ITEM(ret, i, PyUnicode_FromString(name.c_str())); } return ret; } -static PyObject *with_osl_func(PyObject *self, PyObject *args) -{ -#ifdef WITH_OSL - PyObject *ret = Py_True; -#else - PyObject *ret = Py_False; -#endif - - return Py_INCREF(ret), ret; -} - static PyMethodDef methods[] = { {"init", init_func, METH_VARARGS, ""}, {"create", create_func, METH_VARARGS, ""}, - {"free", free_func, METH_VARARGS, ""}, - {"render", render_func, METH_VARARGS, ""}, + {"free", free_func, METH_O, ""}, + {"render", render_func, METH_O, ""}, {"draw", draw_func, METH_VARARGS, ""}, - {"sync", sync_func, METH_VARARGS, ""}, + {"sync", sync_func, METH_O, ""}, {"available_devices", available_devices_func, METH_NOARGS, ""}, - {"with_osl", with_osl_func, METH_NOARGS, ""}, {NULL, NULL, 0, NULL}, }; static struct PyModuleDef module = { PyModuleDef_HEAD_INIT, - "bcycles", + "_cycles", "Blender cycles render integration", -1, methods, @@ -207,6 +175,16 @@ extern "C" PyObject *CYCLES_initPython(); PyObject *CYCLES_initPython() { - return PyModule_Create(&ccl::module); + PyObject *mod= PyModule_Create(&ccl::module); + +#ifdef WITH_OSL + PyModule_AddObject(mod, "with_osl", Py_True); + Py_INCREF(Py_True); +#else + PyModule_AddObject(mod, "with_osl", Py_False); + Py_INCREF(Py_False); +#endif + + return mod; } diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 14d74bcf5d0..90d5cccc85a 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -189,7 +189,7 @@ static struct _inittab bpy_internal_modules[]= { {(char *)"aud", AUD_initPython}, #endif #ifdef WITH_CYCLES - {(char *)"bcycles", CYCLES_initPython}, + {(char *)"_cycles", CYCLES_initPython}, #endif {(char *)"gpu", GPU_initPython}, {NULL, NULL}