[Bf-blender-cvs] [d459d10] master: Added new operator "Create Freestyle Stroke Material" for testing.

Tamito Kajiyama noreply at git.blender.org
Tue Aug 12 03:16:54 CEST 2014


Commit: d459d102b5fb5e1021abb33bb03324ba6f784db4
Author: Tamito Kajiyama
Date:   Sat Jun 28 19:18:47 2014 +0900
Branches: master
https://developer.blender.org/rBd459d102b5fb5e1021abb33bb03324ba6f784db4

Added new operator "Create Freestyle Stroke Material" for testing.

===================================================================

M	source/blender/editors/render/render_intern.h
M	source/blender/editors/render/render_ops.c
M	source/blender/editors/render/render_shading.c
M	source/blender/freestyle/FRS_freestyle.h
M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
M	source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp

===================================================================

diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h
index 8f8cc54..f9377d5 100644
--- a/source/blender/editors/render/render_intern.h
+++ b/source/blender/editors/render/render_intern.h
@@ -72,6 +72,7 @@ void SCENE_OT_freestyle_geometry_modifier_add(struct wmOperatorType *ot);
 void SCENE_OT_freestyle_modifier_remove(struct wmOperatorType *ot);
 void SCENE_OT_freestyle_modifier_move(struct wmOperatorType *ot);
 void SCENE_OT_freestyle_modifier_copy(struct wmOperatorType *ot);
+void SCENE_OT_freestyle_stroke_material_create(struct wmOperatorType *ot);
 #endif
 
 
diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c
index 3401577..0d33408 100644
--- a/source/blender/editors/render/render_ops.c
+++ b/source/blender/editors/render/render_ops.c
@@ -75,6 +75,7 @@ void ED_operatortypes_render(void)
 	WM_operatortype_append(SCENE_OT_freestyle_modifier_remove);
 	WM_operatortype_append(SCENE_OT_freestyle_modifier_move);
 	WM_operatortype_append(SCENE_OT_freestyle_modifier_copy);
+	WM_operatortype_append(SCENE_OT_freestyle_stroke_material_create);
 #endif
 
 	WM_operatortype_append(TEXTURE_OT_slot_copy);
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c
index f833a95..021e4aa 100644
--- a/source/blender/editors/render/render_shading.c
+++ b/source/blender/editors/render/render_shading.c
@@ -1250,6 +1250,30 @@ void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
 	RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN");
 }
 
+static int freestyle_stroke_material_create_exec(bContext *C, wmOperator *op)
+{
+	Main *bmain = CTX_data_main(C);
+	Scene *scene = CTX_data_scene(C);
+
+	FRS_create_stroke_material(C, bmain, scene);
+
+	return OPERATOR_FINISHED;
+}
+
+void SCENE_OT_freestyle_stroke_material_create(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Create Freestyle Stroke Material";
+	ot->idname = "freestyle_stroke_material_create_exec";
+	ot->description = "Create Freestyle stroke material for testing";
+
+	/* api callbacks */
+	ot->exec = freestyle_stroke_material_create_exec;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 #endif /* WITH_FREESTYLE */
 
 static int texture_slot_move_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h
index 7be51b3..c3bf854 100644
--- a/source/blender/freestyle/FRS_freestyle.h
+++ b/source/blender/freestyle/FRS_freestyle.h
@@ -30,6 +30,7 @@ extern "C" {
 #endif
 
 struct Render;
+struct Material;
 struct FreestyleConfig;
 struct bContext;
 
@@ -57,6 +58,9 @@ void FRS_delete_active_lineset(struct FreestyleConfig *config);
 void FRS_move_active_lineset_up(struct FreestyleConfig *config);
 void FRS_move_active_lineset_down(struct FreestyleConfig *config);
 
+/* Testing */
+struct Material *FRS_create_stroke_material(struct bContext *C, struct Main *bmain, struct Scene *scene);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
index 55b406c..b6ef58f 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
@@ -213,6 +213,68 @@ unsigned int BlenderStrokeRenderer::get_stroke_mesh_id(void) const
 	return mesh_id;
 }
 
+Material* BlenderStrokeRenderer::GetStrokeMaterial(bContext *C, Main *bmain, Scene *scene)
+{
+	Material *ma = BKE_material_add(bmain, "stroke_material");
+
+	ma->mode |= MA_VERTEXCOLP;
+	ma->mode |= MA_TRANSP;
+	ma->mode |= MA_SHLESS;
+	ma->vcol_alpha = 1;
+
+	if (BKE_scene_use_new_shading_nodes(scene)) {
+		bNodeTree *ntree;
+		bNodeSocket *fromsock, *tosock;
+
+		ntree = ntreeAddTree(NULL, "stroke_material", "ShaderNodeTree");
+		ma->nodetree = ntree;
+		ma->use_nodes = 1;
+
+		bNode *input_attribute = nodeAddStaticNode(C, ntree, SH_NODE_ATTRIBUTE);
+		input_attribute->locx = 0.0f;
+		input_attribute->locy = 0.0f;
+		NodeShaderAttribute *storage = (NodeShaderAttribute *)input_attribute->storage;
+		BLI_strncpy(storage->name, "Col", sizeof(storage->name));
+
+		bNode *shader_emission = nodeAddStaticNode(C, ntree, SH_NODE_EMISSION);
+		shader_emission->locx = 200.0f;
+		shader_emission->locy = 0.0f;
+
+		bNode *input_light_path = nodeAddStaticNode(C, ntree, SH_NODE_LIGHT_PATH);
+		input_light_path->locx = 200.0f;
+		input_light_path->locy = 300.0f;
+
+		bNode *shader_mix = nodeAddStaticNode(C, ntree, SH_NODE_MIX_SHADER);
+		shader_mix->locx = 400.0f;
+		shader_mix->locy = 100.0f;
+
+		bNode *output_material = nodeAddStaticNode(C, ntree, SH_NODE_OUTPUT_MATERIAL);
+		output_material->locx = 600.0f;
+		output_material->locy = 100.0f;
+
+		fromsock = (bNodeSocket *)BLI_findlink(&input_attribute->outputs, 0);
+		tosock = (bNodeSocket *)BLI_findlink(&shader_emission->inputs, 0);
+		nodeAddLink(ntree, input_attribute, fromsock, shader_emission, tosock);
+
+		fromsock = (bNodeSocket *)BLI_findlink(&shader_emission->outputs, 0);
+		tosock = (bNodeSocket *)BLI_findlink(&shader_mix->inputs, 2);
+		nodeAddLink(ntree, shader_emission, fromsock, shader_mix, tosock);
+
+		fromsock = (bNodeSocket *)BLI_findlink(&input_light_path->outputs, 0);
+		tosock = (bNodeSocket *)BLI_findlink(&shader_mix->inputs, 0);
+		nodeAddLink(ntree, input_light_path, fromsock, shader_mix, tosock);
+
+		fromsock = (bNodeSocket *)BLI_findlink(&shader_mix->outputs, 0);
+		tosock = (bNodeSocket *)BLI_findlink(&output_material->inputs, 0);
+		nodeAddLink(ntree, shader_mix, fromsock, output_material, tosock);
+
+		nodeSetActive(ntree, shader_mix);
+		ntreeUpdateTree(bmain, ntree);
+	}
+
+	return ma;
+}
+
 void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
 {
 	bool has_mat = false;
@@ -239,17 +301,12 @@ void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
 
 	// If still no material, create one
 	if (!has_mat) {
-		Material *ma = BKE_material_add(freestyle_bmain, "stroke_material");
-
-		ma->mode |= MA_VERTEXCOLP;
-		ma->mode |= MA_TRANSP;
-		ma->mode |= MA_SHLESS;
-		ma->vcol_alpha = 1;
+		Material *ma = BlenderStrokeRenderer::GetStrokeMaterial(_context, freestyle_bmain, freestyle_scene);
 
 		// Textures
 		//for (int a = 0; a < MAX_MTEX; a++) {
 		while (iStrokeRep->getMTex(a)) {
-			ma->mtex[a] = (MTex *) iStrokeRep->getMTex(a);
+			ma->mtex[a] = (MTex *)iStrokeRep->getMTex(a);
 
 			// We'll generate both with tips and without tips
 			// coordinates, on two different UV layers.
@@ -263,56 +320,6 @@ void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
 		}
 
 		if (strcmp(freestyle_scene->r.engine, "CYCLES") == 0) {
-			bNodeTree *ntree;
-			bNodeSocket *fromsock, *tosock;
-
-			BLI_assert(BKE_scene_use_new_shading_nodes(freestyle_scene));
-
-			ntree = ntreeAddTree(NULL, "stroke_material", "ShaderNodeTree");
-			ma->nodetree = ntree;
-			ma->use_nodes = 1;
-
-			bNode *input_attribute = nodeAddStaticNode(_context, ntree, SH_NODE_ATTRIBUTE);
-			input_attribute->locx = 0.0f;
-			input_attribute->locy = 0.0f;
-			NodeShaderAttribute *storage = (NodeShaderAttribute *)input_attribute->storage;
-			BLI_strncpy(storage->name, "Col", sizeof(storage->name));
-
-			bNode *shader_emission = nodeAddStaticNode(_context, ntree, SH_NODE_EMISSION);
-			shader_emission->locx = 200.0f;
-			shader_emission->locy = 0.0f;
-
-			bNode *input_light_path = nodeAddStaticNode(_context, ntree, SH_NODE_LIGHT_PATH);
-			input_light_path->locx = 200.0f;
-			input_light_path->locy = 300.0f;
-
-			bNode *shader_mix = nodeAddStaticNode(_context, ntree, SH_NODE_MIX_SHADER);
-			shader_mix->locx = 400.0f;
-			shader_mix->locy = 100.0f;
-
-			bNode *output_material = nodeAddStaticNode(_context, ntree, SH_NODE_OUTPUT_MATERIAL);
-			output_material->locx = 600.0f;
-			output_material->locy = 100.0f;
-
-			fromsock = (bNodeSocket *)BLI_findlink(&input_attribute->outputs, 0);
-			tosock = (bNodeSocket *)BLI_findlink(&shader_emission->inputs, 0);
-			nodeAddLink(ntree, input_attribute, fromsock, shader_emission, tosock);
-
-			fromsock = (bNodeSocket *)BLI_findlink(&shader_emission->outputs, 0);
-			tosock = (bNodeSocket *)BLI_findlink(&shader_mix->inputs, 2);
-			nodeAddLink(ntree, shader_emission, fromsock, shader_mix, tosock);
-
-			fromsock = (bNodeSocket *)BLI_findlink(&input_light_path->outputs, 0);
-			tosock = (bNodeSocket *)BLI_findlink(&shader_mix->inputs, 0);
-			nodeAddLink(ntree, input_light_path, fromsock, shader_mix, tosock);
-
-			fromsock = (bNodeSocket *)BLI_findlink(&shader_mix->outputs, 0);
-			tosock = (bNodeSocket *)BLI_findlink(&output_material->inputs, 0);
-			nodeAddLink(ntree, shader_mix, fromsock, output_material, tosock);
-
-			nodeSetActive(ntree, shader_mix);
-			ntreeUpdateTree(freestyle_bmain, ntree);
-
 			PointerRNA scene_ptr;
 			RNA_pointer_create(NULL, &RNA_Scene, freestyle_scene, &scene_ptr);
 			PointerRNA cycles_ptr = RNA_pointer_get(&scene_ptr, "cycles");
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
index 3ea5f4d..ab3297f 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
@@ -52,6 +52,8 @@ public:
 
 	Render *RenderScene(Render *re, bool render);
 
+	static Material* GetStrokeMaterial(bContext *C, Main *bmain, Scene *scene);
+
 protected:
 	Main *freestyle_bmain;
 	Scene *old_scene;
diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
index 9c2b5a4..00826c8 100644
--- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
+++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
@@ -31,6 +31,8 @@
 #include "../application/AppView.h"
 #include "../application/Controller.h"
 
+#include "BlenderStrokeRenderer.h"
+
 using namespace std;
 using namespace Freestyle

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list