Merge branch 'blender2.7'
[blender.git] / intern / cycles / blender / blender_python.cpp
index bf7605e..de70233 100644 (file)
@@ -206,10 +206,10 @@ static PyObject *exit_func(PyObject * /*self*/, PyObject * /*args*/)
 
 static PyObject *create_func(PyObject * /*self*/, PyObject *args)
 {
-       PyObject *pyengine, *pyuserpref, *pydata, *pyscene, *pyregion, *pyv3d, *pyrv3d;
+       PyObject *pyengine, *pypreferences, *pydata, *pyregion, *pyv3d, *pyrv3d;
        int preview_osl;
 
-       if(!PyArg_ParseTuple(args, "OOOOOOOi", &pyengine, &pyuserpref, &pydata, &pyscene,
+       if(!PyArg_ParseTuple(args, "OOOOOOi", &pyengine, &pypreferences, &pydata,
                             &pyregion, &pyv3d, &pyrv3d, &preview_osl))
        {
                return NULL;
@@ -220,18 +220,14 @@ static PyObject *create_func(PyObject * /*self*/, PyObject *args)
        RNA_pointer_create(NULL, &RNA_RenderEngine, (void*)PyLong_AsVoidPtr(pyengine), &engineptr);
        BL::RenderEngine engine(engineptr);
 
-       PointerRNA userprefptr;
-       RNA_pointer_create(NULL, &RNA_UserPreferences, (void*)PyLong_AsVoidPtr(pyuserpref), &userprefptr);
-       BL::UserPreferences userpref(userprefptr);
+       PointerRNA preferencesptr;
+       RNA_pointer_create(NULL, &RNA_Preferences, (void*)PyLong_AsVoidPtr(pypreferences), &preferencesptr);
+       BL::Preferences preferences(preferencesptr);
 
        PointerRNA dataptr;
        RNA_main_pointer_create((Main*)PyLong_AsVoidPtr(pydata), &dataptr);
        BL::BlendData data(dataptr);
 
-       PointerRNA sceneptr;
-       RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pyscene), &sceneptr);
-       BL::Scene scene(sceneptr);
-
        PointerRNA regionptr;
        RNA_pointer_create(NULL, &RNA_Region, pylong_as_voidptr_typesafe(pyregion), &regionptr);
        BL::Region region(regionptr);
@@ -252,27 +248,13 @@ static PyObject *create_func(PyObject * /*self*/, PyObject *args)
                int width = region.width();
                int height = region.height();
 
-               session = new BlenderSession(engine, userpref, data, scene, v3d, rv3d, width, height);
+               session = new BlenderSession(engine, preferences, data, v3d, rv3d, width, height);
        }
        else {
-               /* override some settings for preview */
-               if(engine.is_preview()) {
-                       PointerRNA cscene = RNA_pointer_get(&sceneptr, "cycles");
-
-                       RNA_boolean_set(&cscene, "shading_system", preview_osl);
-                       RNA_boolean_set(&cscene, "use_progressive_refine", true);
-               }
-
                /* offline session or preview render */
-               session = new BlenderSession(engine, userpref, data, scene);
+               session = new BlenderSession(engine, preferences, data, preview_osl);
        }
 
-       python_thread_state_save(&session->python_thread_state);
-
-       session->create();
-
-       python_thread_state_restore(&session->python_thread_state);
-
        return PyLong_FromVoidPtr(session);
 }
 
@@ -283,13 +265,22 @@ static PyObject *free_func(PyObject * /*self*/, PyObject *value)
        Py_RETURN_NONE;
 }
 
-static PyObject *render_func(PyObject * /*self*/, PyObject *value)
+static PyObject *render_func(PyObject * /*self*/, PyObject *args)
 {
-       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value);
+       PyObject *pysession, *pydepsgraph;
+
+       if(!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
+               return NULL;
+
+       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
+
+       PointerRNA depsgraphptr;
+       RNA_pointer_create(NULL, &RNA_Depsgraph, (ID*)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
+       BL::Depsgraph b_depsgraph(depsgraphptr);
 
        python_thread_state_save(&session->python_thread_state);
 
-       session->render();
+       session->render(b_depsgraph);
 
        python_thread_state_restore(&session->python_thread_state);
 
@@ -299,16 +290,20 @@ static PyObject *render_func(PyObject * /*self*/, PyObject *value)
 /* pixel_array and result passed as pointers */
 static PyObject *bake_func(PyObject * /*self*/, PyObject *args)
 {
-       PyObject *pysession, *pyobject;
+       PyObject *pysession, *pydepsgraph, *pyobject;
        PyObject *pypixel_array, *pyresult;
        const char *pass_type;
        int num_pixels, depth, object_id, pass_filter;
 
-       if(!PyArg_ParseTuple(args, "OOsiiOiiO", &pysession, &pyobject, &pass_type, &pass_filter, &object_id, &pypixel_array, &num_pixels, &depth, &pyresult))
+       if(!PyArg_ParseTuple(args, "OOOsiiOiiO", &pysession, &pydepsgraph, &pyobject, &pass_type, &pass_filter, &object_id, &pypixel_array, &num_pixels, &depth, &pyresult))
                return NULL;
 
        BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
 
+       PointerRNA depsgraphptr;
+       RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
+       BL::Depsgraph b_depsgraph(depsgraphptr);
+
        PointerRNA objectptr;
        RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pyobject), &objectptr);
        BL::Object b_object(objectptr);
@@ -321,7 +316,7 @@ static PyObject *bake_func(PyObject * /*self*/, PyObject *args)
 
        python_thread_state_save(&session->python_thread_state);
 
-       session->bake(b_object, pass_type, pass_filter, object_id, b_bake_pixel, (size_t)num_pixels, depth, (float *)b_result);
+       session->bake(b_depsgraph, b_object, pass_type, pass_filter, object_id, b_bake_pixel, (size_t)num_pixels, depth, (float *)b_result);
 
        python_thread_state_restore(&session->python_thread_state);
 
@@ -330,9 +325,9 @@ static PyObject *bake_func(PyObject * /*self*/, PyObject *args)
 
 static PyObject *draw_func(PyObject * /*self*/, PyObject *args)
 {
-       PyObject *pysession, *pyv3d, *pyrv3d;
+       PyObject *pysession, *pygraph, *pyv3d, *pyrv3d;
 
-       if(!PyArg_ParseTuple(args, "OOO", &pysession, &pyv3d, &pyrv3d))
+       if(!PyArg_ParseTuple(args, "OOOO", &pysession, &pygraph, &pyv3d, &pyrv3d))
                return NULL;
 
        BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
@@ -350,9 +345,9 @@ static PyObject *draw_func(PyObject * /*self*/, PyObject *args)
 
 static PyObject *reset_func(PyObject * /*self*/, PyObject *args)
 {
-       PyObject *pysession, *pydata, *pyscene;
+       PyObject *pysession, *pydata, *pydepsgraph;
 
-       if(!PyArg_ParseTuple(args, "OOO", &pysession, &pydata, &pyscene))
+       if(!PyArg_ParseTuple(args, "OOO", &pysession, &pydata, &pydepsgraph))
                return NULL;
 
        BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
@@ -361,26 +356,35 @@ static PyObject *reset_func(PyObject * /*self*/, PyObject *args)
        RNA_main_pointer_create((Main*)PyLong_AsVoidPtr(pydata), &dataptr);
        BL::BlendData b_data(dataptr);
 
-       PointerRNA sceneptr;
-       RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pyscene), &sceneptr);
-       BL::Scene b_scene(sceneptr);
+       PointerRNA depsgraphptr;
+       RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
+       BL::Depsgraph b_depsgraph(depsgraphptr);
 
        python_thread_state_save(&session->python_thread_state);
 
-       session->reset_session(b_data, b_scene);
+       session->reset_session(b_data, b_depsgraph);
 
        python_thread_state_restore(&session->python_thread_state);
 
        Py_RETURN_NONE;
 }
 
-static PyObject *sync_func(PyObject * /*self*/, PyObject *value)
+static PyObject *sync_func(PyObject * /*self*/, PyObject *args)
 {
-       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value);
+       PyObject *pysession, *pydepsgraph;
+
+       if(!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
+               return NULL;
+
+       BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(pysession);
+
+       PointerRNA depsgraphptr;
+       RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
+       BL::Depsgraph b_depsgraph(depsgraphptr);
 
        python_thread_state_save(&session->python_thread_state);
 
-       session->synchronize();
+       session->synchronize(b_depsgraph);
 
        python_thread_state_restore(&session->python_thread_state);
 
@@ -660,12 +664,12 @@ static PyObject *denoise_func(PyObject * /*self*/, PyObject *args, PyObject *key
        static const char *keyword_list[] = {"preferences", "scene", "view_layer",
                                             "input", "output",
                                             "tile_size", "samples", NULL};
-       PyObject *pypreferences, *pyscene, *pyrenderlayer;
+       PyObject *pypreferences, *pyscene, *pyviewlayer;
        PyObject *pyinput, *pyoutput = NULL;
        int tile_size = 0, samples = 0;
 
        if (!PyArg_ParseTupleAndKeywords(args, keywords, "OOOO|Oii", (char**)keyword_list,
-                                        &pypreferences, &pyscene, &pyrenderlayer,
+                                        &pypreferences, &pyscene, &pyviewlayer,
                                                                         &pyinput, &pyoutput,
                                         &tile_size, &samples)) {
                return NULL;
@@ -673,8 +677,8 @@ static PyObject *denoise_func(PyObject * /*self*/, PyObject *args, PyObject *key
 
        /* Get device specification from preferences and scene. */
        PointerRNA preferencesptr;
-       RNA_pointer_create(NULL, &RNA_UserPreferences, (void*)PyLong_AsVoidPtr(pypreferences), &preferencesptr);
-       BL::UserPreferences b_preferences(preferencesptr);
+       RNA_pointer_create(NULL, &RNA_Preferences, (void*)PyLong_AsVoidPtr(pypreferences), &preferencesptr);
+       BL::Preferences b_preferences(preferencesptr);
 
        PointerRNA sceneptr;
        RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pyscene), &sceneptr);
@@ -683,16 +687,16 @@ static PyObject *denoise_func(PyObject * /*self*/, PyObject *args, PyObject *key
        DeviceInfo device = blender_device_info(b_preferences, b_scene, true);
 
        /* Get denoising parameters from view layer. */
-       PointerRNA renderlayerptr;
-       RNA_pointer_create((ID*)PyLong_AsVoidPtr(pyscene), &RNA_SceneRenderLayer, PyLong_AsVoidPtr(pyrenderlayer), &renderlayerptr);
-       PointerRNA crenderlayer = RNA_pointer_get(&renderlayerptr, "cycles");
+       PointerRNA viewlayerptr;
+       RNA_pointer_create((ID*)PyLong_AsVoidPtr(pyscene), &RNA_ViewLayer, PyLong_AsVoidPtr(pyviewlayer), &viewlayerptr);
+       PointerRNA cviewlayer = RNA_pointer_get(&viewlayerptr, "cycles");
 
        DenoiseParams params;
-       params.radius = get_int(crenderlayer, "denoising_radius");
-       params.strength = get_float(crenderlayer, "denoising_strength");
-       params.feature_strength = get_float(crenderlayer, "denoising_feature_strength");
-       params.relative_pca = get_boolean(crenderlayer, "denoising_relative_pca");
-       params.neighbor_frames = get_int(crenderlayer, "denoising_neighbor_frames");
+       params.radius = get_int(cviewlayer, "denoising_radius");
+       params.strength = get_float(cviewlayer, "denoising_strength");
+       params.feature_strength = get_float(cviewlayer, "denoising_feature_strength");
+       params.relative_pca = get_boolean(cviewlayer, "denoising_relative_pca");
+       params.neighbor_frames = get_int(cviewlayer, "denoising_neighbor_frames");
 
        /* Parse file paths list. */
        vector<string> input, output;
@@ -886,10 +890,10 @@ static PyMethodDef methods[] = {
        {"exit", exit_func, METH_VARARGS, ""},
        {"create", create_func, METH_VARARGS, ""},
        {"free", free_func, METH_O, ""},
-       {"render", render_func, METH_O, ""},
+       {"render", render_func, METH_VARARGS, ""},
        {"bake", bake_func, METH_VARARGS, ""},
        {"draw", draw_func, METH_VARARGS, ""},
-       {"sync", sync_func, METH_O, ""},
+       {"sync", sync_func, METH_VARARGS, ""},
        {"reset", reset_func, METH_VARARGS, ""},
 #ifdef WITH_OSL
        {"osl_update_node", osl_update_node_func, METH_VARARGS, ""},
@@ -927,7 +931,7 @@ static struct PyModuleDef module = {
        "Blender cycles render integration",
        -1,
        methods,
-       NULL, NULL, NULL, NULL
+       NULL, NULL, NULL, NULL,
 };
 
 CCL_NAMESPACE_END