[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55741] branches/soc-2008-mxcurioni: Use of text datablocks for storing Python style modules.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Wed Apr 3 02:00:31 CEST 2013


Revision: 55741
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55741
Author:   kjym3
Date:     2013-04-03 00:00:29 +0000 (Wed, 03 Apr 2013)
Log Message:
-----------
Use of text datablocks for storing Python style modules.
Suggested by Brecht Van Lommel and Campbell Barton through code review comments.

Previously style modules were external Python script files whose absolute paths
were kept in .blend files.  Now style modules are stored in .blend files as text
datablocks.

Style modules are configured in three steps:
1. Open an external style module file (or create a new text datablock) in the
Text Editor in Blender.
2. Add a style module to the list of style modules (by pressing the "Add" button)
in the Render Layer properties window.
3. Click the name entry and select the style module from the drop-down menu.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_freestyle.py
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/freestyle.c
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/text.c
    branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Canvas.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h
    branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_scene.c

Modified: branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_freestyle.py
===================================================================
--- branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_freestyle.py	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/release/scripts/startup/bl_ui/properties_freestyle.py	2013-04-03 00:00:29 UTC (rev 55741)
@@ -159,7 +159,7 @@
                 box.context_pointer_set("freestyle_module", module)
                 row = box.row(align=True)
                 row.prop(module, "use", text="")
-                row.prop(module, "module_path", text="")
+                row.prop(module, "script", text="")
                 row.operator("scene.freestyle_module_remove", icon='X', text="")
                 row.operator("scene.freestyle_module_move", icon='TRIA_UP', text="").direction = 'UP'
                 row.operator("scene.freestyle_module_move", icon='TRIA_DOWN', text="").direction = 'DOWN'

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/freestyle.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/freestyle.c	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/freestyle.c	2013-04-03 00:00:29 UTC (rev 55741)
@@ -128,18 +128,14 @@
 void BKE_freestyle_module_add(FreestyleConfig *config)
 {
 	FreestyleModuleConfig *module_conf = alloc_module();
-	const size_t maxlen = sizeof(module_conf->module_path);
 	BLI_addtail(&config->modules, (void *)module_conf);
-
-	BLI_strncpy(module_conf->module_path, BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "freestyle"), maxlen);
-	BLI_join_dirfile(module_conf->module_path, maxlen, module_conf->module_path, "style_modules");
-	BLI_join_dirfile(module_conf->module_path, maxlen, module_conf->module_path, "contour.py");
+	module_conf->script = NULL;
 	module_conf->is_displayed = 1;
 }
 
 static void copy_module(FreestyleModuleConfig *new_module, FreestyleModuleConfig *module)
 {
-	strcpy(new_module->module_path, module->module_path);
+	new_module->script = module->script;
 	new_module->is_displayed = module->is_displayed;
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/text.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/text.c	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/text.c	2013-04-03 00:00:29 UTC (rev 55741)
@@ -519,6 +519,9 @@
 	bNodeTree *ntree;
 	bNode *node;
 	Material *mat;
+	Scene *sce;
+	SceneRenderLayer *srl;
+	FreestyleModuleConfig *module;
 	short update;
 
 	for (ob = bmain->object.first; ob; ob = ob->id.next) {
@@ -608,6 +611,16 @@
 		}
 	}
 
+	/* Freestyle */
+	for (sce = bmain->scene.first; sce; sce = sce->id.next) {
+		for (srl = sce->r.layers.first; srl; srl = srl->next) {
+			for (module = srl->freestyleConfig.modules.first; module; module= module->next) {
+				if (module->script == text)
+					module->script = NULL;
+			}
+		}
+	}
+
 	text->id.us = 0;
 }
 

Modified: branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c	2013-04-03 00:00:29 UTC (rev 55741)
@@ -5026,6 +5026,7 @@
 	Sequence *seq;
 	SceneRenderLayer *srl;
 	TimeMarker *marker;
+	FreestyleModuleConfig *fmc;
 	FreestyleLineSet *fls;
 	
 	for (sce = main->scene.first; sce; sce = sce->id.next) {
@@ -5141,6 +5142,9 @@
 			for (srl = sce->r.layers.first; srl; srl = srl->next) {
 				srl->mat_override = newlibadr_us(fd, sce->id.lib, srl->mat_override);
 				srl->light_override = newlibadr_us(fd, sce->id.lib, srl->light_override);
+				for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
+					fmc->script = newlibadr(fd, sce->id.lib, fmc->script);
+				}
 				for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
 					fls->linestyle = newlibadr_us(fd, sce->id.lib, fls->linestyle);
 					fls->group = newlibadr_us(fd, sce->id.lib, fls->group);
@@ -9331,6 +9335,9 @@
 	   For now it is kept for backward compatibility, giving branch users time
 	   to migrate to the new CustomData-based edge/face marks. */
 	{
+		Scene *sce;
+		SceneRenderLayer *srl;
+		FreestyleModuleConfig *fmc;
 		Mesh *me;
 		MEdge *medge;
 		MPoly *mpoly;
@@ -9384,6 +9391,20 @@
 				printf("Migrated to CustomData-based Freestyle face marks\n");
 			}
 		}
+		for (sce = main->scene.first; sce; sce = sce->id.next) {
+			for (srl = sce->r.layers.first; srl; srl = srl->next) {
+				i = 1;
+				for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
+					if (fmc->module_path[0] != '\0' && !fmc->script) {
+						fprintf(stderr, "The external style module below needs to be reconfigured using text datablock:\n");
+						fprintf(stderr, "  %s\n", fmc->module_path);
+						fprintf(stderr, "  in scene \"%s\", render layer \"%s\", style module #%d (%s)\n",
+						        sce->id.name+2, srl->name, i, (fmc->is_displayed) ? "enabled" : "disabled");
+					}
+					i++;
+				}
+			}
+		}
 	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -10378,6 +10399,7 @@
 {
 	Base *base;
 	SceneRenderLayer *srl;
+	FreestyleModuleConfig *module;
 	FreestyleLineSet *lineset;
 	
 	for (base = sce->base.first; base; base = base->next) {
@@ -10399,6 +10421,10 @@
 	for (srl = sce->r.layers.first; srl; srl = srl->next) {
 		expand_doit(fd, mainvar, srl->mat_override);
 		expand_doit(fd, mainvar, srl->light_override);
+		for (module = srl->freestyleConfig.modules.first; module; module = module->next) {
+			if (module->script)
+				expand_doit(fd, mainvar, module->script);
+		}
 		for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
 			if (lineset->group)
 				expand_doit(fd, mainvar, lineset->group);

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h	2013-04-03 00:00:29 UTC (rev 55741)
@@ -46,12 +46,6 @@
 	{
 	}
 
-	virtual void close()
-	{
-		BKE_text_unlink(G.main, _text);
-		BKE_libblock_free(&G.main->text, _text);
-	}
-
 protected:
 	virtual int interpret()
 	{

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	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp	2013-04-03 00:00:29 UTC (rev 55741)
@@ -321,11 +321,15 @@
 		     module_conf;
 		     module_conf = module_conf->next)
 		{
-			if (module_conf->is_displayed) {
+			if (module_conf->script && module_conf->is_displayed) {
+				const char *id_name = module_conf->script->id.name + 2;
 				if (G.debug & G_DEBUG_FREESTYLE) {
-					cout << "  " << layer_count + 1 << ": " << module_conf->module_path << endl;
+					cout << "  " << layer_count + 1 << ": " << id_name;
+					if (module_conf->script->name)
+						cout << " (" << module_conf->script->name << ")";
+					cout << endl;
 				}
-				controller->InsertStyleModule(layer_count, module_conf->module_path);
+				controller->InsertStyleModule(layer_count, id_name, module_conf->script);
 				controller->toggleLayer(layer_count, true);
 				layer_count++;
 			}
@@ -537,7 +541,7 @@
 		     module;
 		     module = module->next)
 		{
-			if (module->is_displayed)
+			if (module->script && module->is_displayed)
 				count++;
 		}
 		break;

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Canvas.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Canvas.cpp	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Canvas.cpp	2013-04-03 00:00:29 UTC (rev 55741)
@@ -145,10 +145,8 @@
 
 	if (!_StyleModules.empty()) {
 		for (deque<StyleModule*>::iterator s = _StyleModules.begin(), send = _StyleModules.end(); s != send; ++s) {
-			if (*s) {
-				(*s)->close();
+			if (*s)
 				delete (*s);
-			}
 		}
 		_StyleModules.clear();
 	}

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/StyleModule.h	2013-04-03 00:00:29 UTC (rev 55741)
@@ -91,8 +91,6 @@
 		return sl;
 	}
 
-	virtual void close() {}
-
 protected:
 	virtual int interpret()
 	{

Modified: branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h	2013-04-02 19:18:38 UTC (rev 55740)
+++ branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_freestyle_types.h	2013-04-03 00:00:29 UTC (rev 55741)
@@ -28,9 +28,12 @@
 #ifndef __DNA_FREESTYLE_TYPES_H__
 #define __DNA_FREESTYLE_TYPES_H__
 
+#include "DNA_defs.h"
 #include "DNA_listBase.h"
 
 struct FreestyleLineStyle;
+struct Group;
+struct Text;
 
 /* FreestyleConfig::flags */
 #define FREESTYLE_SUGGESTIVE_CONTOURS_FLAG  (1 << 0)
@@ -107,7 +110,8 @@
 typedef struct FreestyleModuleConfig {
 	struct FreestyleModuleConfig *next, *prev;
 
-	char module_path[1024]; /* FILE_MAX */
+	struct Text *script;
+	char module_path[1024] DNA_DEPRECATED; /* FILE_MAX */
 	short is_displayed;
 	short pad[3];
 } FreestyleModuleConfig;

Modified: branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_scene.c
===================================================================

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list