diff options
Diffstat (limited to 'intern/cycles/blender/blender_python.cpp')
-rw-r--r-- | intern/cycles/blender/blender_python.cpp | 118 |
1 files changed, 61 insertions, 57 deletions
diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index 063b0ede92b..ccd783073a3 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -194,10 +194,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; @@ -208,18 +208,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), ®ionptr); BL::Region region(regionptr); @@ -240,27 +236,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); } @@ -271,13 +253,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); @@ -287,16 +278,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); @@ -309,7 +304,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); @@ -318,9 +313,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); @@ -338,9 +333,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); @@ -349,26 +344,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); @@ -672,12 +676,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; @@ -685,8 +689,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); @@ -695,16 +699,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; @@ -934,10 +938,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, ""}, @@ -977,7 +981,7 @@ static struct PyModuleDef module = { "Blender cycles render integration", -1, methods, - NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, }; CCL_NAMESPACE_END |