From 25ce805a58fa833cf9c4e818f34d9664de1f3636 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Mon, 26 Jul 2010 01:23:27 +0000 Subject: * Implemented the basic stroke rendering functionality for the new Parameter Editor mode. This is a WIP commit. Only the base line color, base alpha transparency, and base line thickness are respected. More additions are anticipated to account for other parameters. * Added FRS_finish_stroke_rendering() to clean Freestyle-related temporary resources after stroke rendering. * Some functions in FRS_freestyle.cpp are now declared as static functions, so as not to mess up the program-wide name space. * Made the StyleModule class inheritable, and defined new subclass BlenderStyleModule that takes a Text object instead of a file name. --- .../freestyle/intern/application/Controller.cpp | 7 ++ .../freestyle/intern/application/Controller.h | 1 + .../intern/blender_interface/BlenderStyleModule.h | 39 ++++++++++ .../intern/blender_interface/FRS_freestyle.cpp | 83 ++++++++++++++++------ .../blender/freestyle/intern/stroke/StyleModule.h | 15 +++- .../freestyle/intern/system/PythonInterpreter.h | 22 ++++++ 6 files changed, 143 insertions(+), 24 deletions(-) create mode 100644 source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h (limited to 'source/blender/freestyle/intern') diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index 5cf1b40a344..7835bb832b6 100755 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -58,6 +58,7 @@ #include "../blender_interface/BlenderFileLoader.h" #include "../blender_interface/BlenderStrokeRenderer.h" +#include "../blender_interface/BlenderStyleModule.h" #ifdef __cplusplus extern "C" { @@ -717,6 +718,12 @@ void Controller::InsertStyleModule(unsigned index, const char *iFileName) } +void Controller::InsertStyleModule(unsigned index, const char *iName, struct Text *iText) +{ + StyleModule* sm = new BlenderStyleModule(iText, iName, _inter); + _Canvas->InsertStyleModule(index, sm); +} + void Controller::AddStyleModule(const char *iFileName) { //_pStyleWindow->Add(iFileName); diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index 367b57bf6c3..dfff7d7079c 100755 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -89,6 +89,7 @@ public: Render* RenderStrokes(Render *re); void SwapStyleModules(unsigned i1, unsigned i2); void InsertStyleModule(unsigned index, const char *iFileName); + void InsertStyleModule(unsigned index, const char *iName, struct Text *iText); void AddStyleModule(const char *iFileName); void RemoveStyleModule(unsigned index); void ReloadStyleModule(unsigned index, const char * iFileName); diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h new file mode 100644 index 00000000000..27880721762 --- /dev/null +++ b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h @@ -0,0 +1,39 @@ +#ifndef BLENDERSTYLEMODULE_H +#define BLENDERSTYLEMODULE_H + +#include "../stroke/StyleModule.h" +#include "../system/PythonInterpreter.h" + +extern "C" { +#include "BKE_global.h" +#include "BKE_library.h" +#include "BKE_text.h" +} + +class BlenderStyleModule : public StyleModule +{ +public: + + BlenderStyleModule(struct Text *text, const string &name, + Interpreter *inter) : StyleModule(name, inter) { + _text = text; + } + + virtual ~BlenderStyleModule() { + unlink_text(G.main, _text); + free_libblock(&G.main->text, _text); + } + +protected: + + virtual int interpret() { + PythonInterpreter* py_inter = dynamic_cast(_inter); + assert(py_inter != 0); + return py_inter->interpretText(_text, getFileName()); + } + +private: + struct Text *_text; +}; + +#endif // BLENDERSTYLEMODULE_H diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index c3c5058ddfd..18ec12bb862 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -15,12 +15,14 @@ extern "C" { #include "MEM_guardedalloc.h" #include "DNA_camera_types.h" +#include "DNA_text_types.h" #include "DNA_freestyle_types.h" #include "BKE_global.h" #include "BKE_library.h" #include "BKE_linestyle.h" #include "BKE_main.h" +#include "BKE_text.h" #include "BLI_blenlib.h" #include "BLI_math.h" #include "BPY_extern.h" @@ -61,6 +63,7 @@ extern "C" { controller = new Controller(); view = new AppView; controller->setView(view); + controller->Clear(); freestyle_scene = NULL; default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py"; @@ -83,7 +86,7 @@ extern "C" { // Rendering //======================================================= - void init_view(Render* re){ + static void init_view(Render* re){ float ycor = ((float)re->r.yasp) / ((float)re->r.xasp); int width = re->r.xsch; int height = (int)(((float)re->r.ysch) * ycor); @@ -107,7 +110,7 @@ extern "C" { cout << "Border : (" << xmin << ", " << ymin << ") - (" << xmax << ", " << ymax << ")" << endl; } - void init_camera(Render* re){ + static void init_camera(Render* re){ // It is assumed that imported meshes are in the camera coordinate system. // Therefore, the view point (i.e., camera position) is at the origin, and // the the model-view matrix is simply the identity matrix. @@ -128,12 +131,19 @@ extern "C" { //print_m4("proj", freestyle_proj); } - - void prepare(Render* re, SceneRenderLayer* srl ) { - - // clear canvas - controller->Clear(); + static Text *create_lineset_handler(char *layer_name, char *lineset_name) + { + Text *text = add_empty_text(lineset_name); + write_text(text, "import parameter_editor; parameter_editor.process('"); + write_text(text, layer_name); + write_text(text, "', '"); + write_text(text, lineset_name); + write_text(text, "')\n"); + return text; + } + static void prepare(Render* re, SceneRenderLayer* srl ) { + // load mesh re->i.infostr= "Freestyle: Mesh loading"; re->stats_draw(re->sdh, &re->i); @@ -147,19 +157,34 @@ extern "C" { FreestyleConfig* config = &srl->freestyleConfig; cout << "\n=== Rendering options ===" << endl; - cout << "Modules :"<< endl; int layer_count = 0; - - for( FreestyleModuleConfig* module_conf = (FreestyleModuleConfig *)config->modules.first; module_conf; module_conf = module_conf->next ) { - if( module_conf->is_displayed ) { - cout << " " << layer_count+1 << ": " << module_conf->module_path << endl; - controller->InsertStyleModule( layer_count, module_conf->module_path ); - controller->toggleLayer(layer_count, true); - layer_count++; + switch (config->mode) { + case FREESTYLE_CONTROL_SCRIPT_MODE: + cout << "Modules :"<< endl; + for (FreestyleModuleConfig* module_conf = (FreestyleModuleConfig *)config->modules.first; module_conf; module_conf = module_conf->next) { + if( module_conf->is_displayed ) { + cout << " " << layer_count+1 << ": " << module_conf->module_path << endl; + controller->InsertStyleModule( layer_count, module_conf->module_path ); + controller->toggleLayer(layer_count, true); + layer_count++; + } } - } - cout << endl; + cout << endl; + break; + case FREESTYLE_CONTROL_EDITOR_MODE: + cout << "Linesets:"<< endl; + for (FreestyleLineSet *lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) { + if (lineset->flags & FREESTYLE_LINESET_ENABLED) { + cout << " " << layer_count+1 << ": " << lineset->name << " - " << lineset->linestyle->id.name+2 << endl; + Text *text = create_lineset_handler(srl->name, lineset->name); + controller->InsertStyleModule( layer_count, lineset->name, text ); + controller->toggleLayer(layer_count, true); + layer_count++; + } + } + break; + } // set parameters controller->setCreaseAngle( config->crease_angle ); @@ -234,12 +259,22 @@ extern "C" { } } - int displayed_layer_count( SceneRenderLayer* srl ) { + static int displayed_layer_count( SceneRenderLayer* srl ) { int count = 0; - for( FreestyleModuleConfig* module_conf = (FreestyleModuleConfig *)srl->freestyleConfig.modules.first; module_conf; module_conf = module_conf->next ) { - if( module_conf->is_displayed ) - count++; + switch (srl->freestyleConfig.mode) { + case FREESTYLE_CONTROL_SCRIPT_MODE: + for (FreestyleModuleConfig* module = (FreestyleModuleConfig *)srl->freestyleConfig.modules.first; module; module = module->next) { + if( module->is_displayed ) + count++; + } + break; + case FREESTYLE_CONTROL_EDITOR_MODE: + for (FreestyleLineSet *lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) { + if (lineset->flags & FREESTYLE_LINESET_ENABLED) + count++; + } + break; } return count; } @@ -271,7 +306,6 @@ extern "C" { cout << "----------------------------------------------------------" << endl; // prepare Freestyle: - // - clear canvas // - load mesh // - add style modules // - set parameters @@ -305,6 +339,11 @@ extern "C" { return freestyle_render; } + void FRS_finish_stroke_rendering(Render* re) { + // clear canvas + controller->Clear(); + } + //======================================================= // Freestyle Panel Configuration //======================================================= diff --git a/source/blender/freestyle/intern/stroke/StyleModule.h b/source/blender/freestyle/intern/stroke/StyleModule.h index c023ad7517b..5bdb54cf16c 100755 --- a/source/blender/freestyle/intern/stroke/StyleModule.h +++ b/source/blender/freestyle/intern/stroke/StyleModule.h @@ -54,7 +54,7 @@ public: _inter = inter; } - ~StyleModule() {} + virtual ~StyleModule() {} StrokeLayer* execute() { if (!_inter) { @@ -69,7 +69,7 @@ public: Operators::reset(); - if( _inter->interpretFile(_file_name) ) { + if( interpret() ) { cerr << "Error: interpretation failed" << endl; return NULL; } @@ -89,6 +89,14 @@ public: return sl; } +protected: + + virtual int interpret() { + return _inter->interpretFile(_file_name); + } + +public: + // accessors const string getFileName() const { @@ -151,6 +159,9 @@ private: bool _drawable; bool _modified; bool _displayed; + +protected: + Interpreter* _inter; }; diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h index 1178e18cdea..ee2f2085d12 100755 --- a/source/blender/freestyle/intern/system/PythonInterpreter.h +++ b/source/blender/freestyle/intern/system/PythonInterpreter.h @@ -38,6 +38,7 @@ //soc extern "C" { #include "MEM_guardedalloc.h" +#include "DNA_text_types.h" #include "BKE_main.h" #include "BKE_context.h" #include "BKE_global.h" @@ -101,6 +102,27 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter return 0; } + int interpretText(struct Text *text, const string& name) { + + initPath(); + + ReportList* reports = CTX_wm_reports(_context); + + BKE_reports_clear(reports); + + if (!BPY_run_python_script(_context, NULL, text, reports)) { + cout << "\nError executing Python script from PythonInterpreter::interpretText" << endl; + cout << "Name: " << name << endl; + cout << "Errors: " << endl; + BKE_reports_print(reports, RPT_ERROR); + return 1; + } + + BKE_reports_clear(reports); + + return 0; + } + struct Options { static void setPythonPath(const string& path) { -- cgit v1.2.3