From 128f9730f2c63b85d397e9c09a612e806665c863 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sun, 6 Dec 2009 22:01:04 +0000 Subject: Added Freestyle.getCurrentScene() to give access to the current scene from within style modules. Calling this function is only valid within style modules. Calling it from the Python Interactive Console results in an error as follows: >>> import Freestyle >>> Freestyle.getCurrentScene() Traceback (most recent call last): File "", line 1, in TypeError: current scene not available >>> --- source/blender/freestyle/CMakeLists.txt | 3 ++- source/blender/freestyle/FRS_freestyle.h | 1 + source/blender/freestyle/SConscript | 3 ++- .../freestyle/intern/blender_interface/FRS_freestyle.cpp | 6 ++++++ source/blender/freestyle/intern/python/BPy_Freestyle.cpp | 16 ++++++++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt index 298af7a4803..18f721ccfdc 100644 --- a/source/blender/freestyle/CMakeLists.txt +++ b/source/blender/freestyle/CMakeLists.txt @@ -27,7 +27,8 @@ FILE(GLOB_RECURSE SRC *.cpp) SET(INC - ../blenkernel ../blenloader ../blenlib ../imbuf ../makesdna ../makesrna ../python + ../blenkernel ../blenloader ../blenlib ../imbuf ../makesdna ../makesrna + ../python ../python/intern ../render/extern/include ../render/intern/include ../include ../src ../../../extern/glew/include ../../../intern/guardedalloc ../freestyle ${PYTHON_INC} diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h index 1add5f97b38..3d8e785ce99 100644 --- a/source/blender/freestyle/FRS_freestyle.h +++ b/source/blender/freestyle/FRS_freestyle.h @@ -10,6 +10,7 @@ extern "C" { #include "BKE_context.h" + extern Scene *freestyle_scene; extern float freestyle_viewpoint[3]; extern float freestyle_mv[4][4]; extern float freestyle_proj[4][4]; diff --git a/source/blender/freestyle/SConscript b/source/blender/freestyle/SConscript index 6fd6805bef9..b955365f44e 100644 --- a/source/blender/freestyle/SConscript +++ b/source/blender/freestyle/SConscript @@ -6,7 +6,8 @@ sources = [] defs = [] incs = '' -incs += '../blenkernel ../blenloader ../blenlib ../imbuf ../makesdna ../makesrna ../python ' +incs += '../blenkernel ../blenloader ../blenlib ../imbuf ../makesdna ../makesrna' +incs += '../python ../python/intern' incs += '../render/extern/include ../render/intern/include ../include ../src' incs += ' #/extern/glew/include #/intern/guardedalloc' incs += ' ' + env['BF_PYTHON_INC'] diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 0f2160d7bf6..393cd1b2dd9 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -39,6 +39,9 @@ extern "C" { float freestyle_proj[4][4]; int freestyle_viewport[4]; + // current scene + Scene *freestyle_scene; + string default_module_path; //======================================================= @@ -54,6 +57,7 @@ extern "C" { controller = new Controller(); view = new AppView; controller->setView(view); + freestyle_scene = NULL; default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py"; @@ -203,6 +207,7 @@ extern "C" { init_view(re); init_camera(re); + freestyle_scene = re->scene; for(srl= (SceneRenderLayer *)re->scene->r.layers.first; srl; srl= srl->next) { if( !(srl->layflag & SCE_LAY_DISABLE) && @@ -238,6 +243,7 @@ extern "C" { } } + freestyle_scene = NULL; } //======================================================= diff --git a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp index bd5a5c8b38a..3e8572d07ae 100644 --- a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp +++ b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp @@ -33,6 +33,7 @@ extern "C" { //static PyObject *Freestyle_testOutput( BPy_Freestyle * self ); +static PyObject *Freestyle_getCurrentScene( PyObject *self ); /*-----------------------Freestyle module doc strings--------------------------*/ @@ -42,6 +43,7 @@ static char module_docstring[] = "The Blender Freestyle module\n\n"; static PyMethodDef module_functions[] = { // {"testOutput", ( PyCFunction ) Freestyle_testOutput, METH_NOARGS, "() - Return Curve Data name"}, + {"getCurrentScene", ( PyCFunction ) Freestyle_getCurrentScene, METH_NOARGS, "() - Return the current scene."}, {NULL, NULL, 0, NULL} }; @@ -99,6 +101,20 @@ PyObject *Freestyle_Init( void ) /////////////////////////////////////////////////////////////////////////////////////////// +#include "FRS_freestyle.h" +#include "bpy_rna.h" /* pyrna_struct_CreatePyObject() */ + +static PyObject *Freestyle_getCurrentScene( PyObject *self ) +{ + if (!freestyle_scene) { + PyErr_SetString(PyExc_TypeError, "current scene not available"); + return NULL; + } + PointerRNA ptr_scene; + RNA_pointer_create(NULL, &RNA_Scene, freestyle_scene, &ptr_scene); + return pyrna_struct_CreatePyObject(&ptr_scene); +} + #ifdef __cplusplus } #endif -- cgit v1.2.3