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

This commit is contained in:
2014-06-28 19:18:47 +09:00
parent 1741df1e36
commit d459d102b5
7 changed files with 105 additions and 57 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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)

View File

@@ -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

View File

@@ -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");

View File

@@ -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;

View File

@@ -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"