[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30728] branches/soc-2008-mxcurioni/source /blender: * Implemented the basic stroke rendering functionality for the new

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Mon Jul 26 03:23:35 CEST 2010


Revision: 30728
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30728
Author:   kjym3
Date:     2010-07-26 03:23:27 +0200 (Mon, 26 Jul 2010)

Log Message:
-----------
* 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.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/pipeline.c

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	2010-07-26 00:11:14 UTC (rev 30727)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	2010-07-26 01:23:27 UTC (rev 30728)
@@ -52,6 +52,7 @@
 	int FRS_is_freestyle_enabled(struct SceneRenderLayer* srl);
 	void FRS_init_stroke_rendering(struct Render* re);
 	struct Render* FRS_do_stroke_rendering(struct Render* re, struct SceneRenderLayer* srl);
+	void FRS_finish_stroke_rendering(struct Render* re);
 	void FRS_composite_result(struct Render* re, struct SceneRenderLayer* srl, struct Render* freestyle_render);
 	void FRS_exit();
 	

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2010-07-26 00:11:14 UTC (rev 30727)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp	2010-07-26 01:23:27 UTC (rev 30728)
@@ -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 *iName, struct Text *iText)
+{
+	StyleModule* sm = new BlenderStyleModule(iText, iName, _inter);
+  _Canvas->InsertStyleModule(index, sm);
+}
+
 void Controller::AddStyleModule(const char *iFileName)
 {
   //_pStyleWindow->Add(iFileName);

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2010-07-26 00:11:14 UTC (rev 30727)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h	2010-07-26 01:23:27 UTC (rev 30728)
@@ -89,6 +89,7 @@
   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);

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-07-26 00:11:14 UTC (rev 30727)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2010-07-26 01:23:27 UTC (rev 30728)
@@ -15,12 +15,14 @@
 #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 @@
 		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 @@
 	//   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 @@
 			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 @@
 		//print_m4("proj", freestyle_proj);
 	}
 
-	
-	void prepare(Render* re, SceneRenderLayer* srl ) {
+	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 ) {
 				
-		// clear canvas
-		controller->Clear();
-
 		// load mesh
         re->i.infostr= "Freestyle: Mesh loading";
 		re->stats_draw(re->sdh, &re->i);
@@ -147,19 +157,34 @@
 		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 @@
 	    }
 	}
 	
-	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 @@
 		cout << "----------------------------------------------------------" << endl;
 		
 		// prepare Freestyle:
-		//   - clear canvas
 		//   - load mesh
 		//   - add style modules
 		//   - set parameters
@@ -305,6 +339,11 @@
 		return freestyle_render;
 	}
 
+	void FRS_finish_stroke_rendering(Render* re) {
+		// clear canvas
+		controller->Clear();
+	}
+
 	//=======================================================
 	//   Freestyle Panel Configuration
 	//=======================================================

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h	2010-07-26 00:11:14 UTC (rev 30727)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h	2010-07-26 01:23:27 UTC (rev 30728)
@@ -54,7 +54,7 @@
     _inter = inter;
   }
 
-  ~StyleModule() {}
+  virtual ~StyleModule() {}
 
   StrokeLayer* execute() {
     if (!_inter) {
@@ -69,7 +69,7 @@
 
     Operators::reset();
 
-    if( _inter->interpretFile(_file_name) ) {
+    if( interpret() ) {
       cerr << "Error: interpretation failed" << endl;
       return NULL;
 	}
@@ -89,6 +89,14 @@
    return sl;
   }
 
+protected:
+
+  virtual int interpret() {
+    return _inter->interpretFile(_file_name);
+  }
+
+public:
+
   // accessors
 
   const string getFileName() const {
@@ -151,6 +159,9 @@
   bool		_drawable;
   bool		_modified;
   bool		_displayed;
+
+protected:
+
   Interpreter*	_inter;
 };
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h	2010-07-26 00:11:14 UTC (rev 30727)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h	2010-07-26 01:23:27 UTC (rev 30728)
@@ -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 @@
 	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);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list