Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-06-28 14:18:47 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-08-12 05:10:11 +0400
commitd459d102b5fb5e1021abb33bb03324ba6f784db4 (patch)
tree954489a6fa28ff36400304ee507c80c4e466fdd6 /source/blender/freestyle
parent1741df1e36162c670082a64c66eed0975692c956 (diff)
Added new operator "Create Freestyle Stroke Material" for testing.
Diffstat (limited to 'source/blender/freestyle')
-rw-r--r--source/blender/freestyle/FRS_freestyle.h4
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp121
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h2
-rw-r--r--source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp9
4 files changed, 79 insertions, 57 deletions
diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h
index 7be51b37f7a..c3bf854447c 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 55b406c2bc2..b6ef58f0d60 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 3ea5f4de18d..ab3297f4944 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 9c2b5a4037f..00826c873bd 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;
@@ -730,4 +732,11 @@ void FRS_move_active_lineset_down(FreestyleConfig *config)
}
}
+// Testing
+
+Material *FRS_create_stroke_material(bContext *C, Main *bmain, Scene *scene)
+{
+ return BlenderStrokeRenderer::GetStrokeMaterial(C, bmain, scene);
+}
+
} // extern "C"