From c38e80d6322b942fd2a893f4f294a919ed6e6b99 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sat, 19 Jul 2014 15:38:56 +0900 Subject: WIP commit just for a record of a working snapshot of code revisions for node-based textured strokes. --- .../freestyle/intern/application/Controller.cpp | 6 +-- .../freestyle/intern/application/Controller.h | 4 +- .../blender_interface/BlenderStrokeRenderer.cpp | 25 ++++++++++-- .../intern/blender_interface/BlenderStyleModule.h | 21 +++++----- .../intern/blender_interface/FRS_freestyle.cpp | 7 +++- source/blender/freestyle/intern/stroke/Stroke.cpp | 45 ++++++++-------------- source/blender/freestyle/intern/stroke/Stroke.h | 16 +++++--- .../freestyle/intern/stroke/StrokeLayer.cpp | 4 +- .../blender/freestyle/intern/stroke/StrokeLayer.h | 2 +- .../blender/freestyle/intern/stroke/StrokeRep.cpp | 9 ++++- source/blender/freestyle/intern/stroke/StrokeRep.h | 12 ++++++ 11 files changed, 92 insertions(+), 59 deletions(-) (limited to 'source/blender/freestyle/intern') diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index e4bfdb27381..4fd58ab7af2 100644 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -892,10 +892,10 @@ void Controller::InsertStyleModule(unsigned index, const char *iFileName) _Canvas->InsertStyleModule(index, sm); } -void Controller::InsertStyleModule(unsigned index, const char *iName, struct FreestyleLineStyle *iLineStyle, - struct Text *iText) +void Controller::InsertStyleModule(unsigned index, const char *iName, struct Text *iText, + struct FreestyleLineStyle *iLineStyle, bool iUseShadingNodes) { - StyleModule *sm = new BlenderStyleModule(iText, iLineStyle, iName, _inter); + StyleModule *sm = new BlenderStyleModule(iName, _inter, iText, iLineStyle, iUseShadingNodes); _Canvas->InsertStyleModule(index, sm); } diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index d2b865de42a..c4f2596d7a9 100644 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -89,8 +89,8 @@ public: Render *RenderStrokes(Render *re, bool render); void SwapStyleModules(unsigned i1, unsigned i2); void InsertStyleModule(unsigned index, const char *iFileName); - void InsertStyleModule(unsigned index, const char *iName, struct FreestyleLineStyle *iLineStyle, - struct Text *iText); + void InsertStyleModule(unsigned index, const char *iName, struct Text *iText, + struct FreestyleLineStyle *iLineStyle, bool iUseShadingNodes); void AddStyleModule(const char *iFileName); void RemoveStyleModule(unsigned index); void ReloadStyleModule(unsigned index, const char * iFileName); diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index b119b10b9cb..a9ab69c67d4 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -52,6 +52,7 @@ extern "C" { #include "BKE_object.h" #include "BKE_scene.h" +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "RE_pipeline.h" @@ -330,6 +331,22 @@ Material* BlenderStrokeRenderer::GetStrokeShader(bContext *C, Main *bmain, Frees outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 2); // Alpha outsock = (bNodeSocket *)BLI_findlink(&output_linestyle->inputs, 3); // Alpha Fac #endif + +#if 0 + for (bNode *node = (bNode *)ntree->nodes.first; node; node = node->next) { + if (node->type == SH_NODE_TEX_IMAGE) { + bNode *input_uvmap = nodeAddStaticNode(C, ntree, SH_NODE_UVMAP); + input_uvmap->locx = node->locx - 200.0f; + input_uvmap->locy = node->locy; + NodeShaderUVMap *storage = (NodeShaderUVMap *)input_uvmap->storage; + BLI_strncpy(storage->uv_map, "along_stroke_tips", sizeof(storage->uv_map)); + + fromsock = (bNodeSocket *)BLI_findlink(&input_uvmap->outputs, 0); // UV + tosock = (bNodeSocket *)BLI_findlink(&node->inputs, 0); // Vector + nodeAddLink(ntree, input_uvmap, fromsock, node, tosock); + } + } +#endif } nodeSetActive(ntree, shader_mix); @@ -340,7 +357,7 @@ Material* BlenderStrokeRenderer::GetStrokeShader(bContext *C, Main *bmain, Frees void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const { - if (BKE_scene_use_new_shading_nodes(freestyle_scene)) { + if (iStrokeRep->useShadingNodes()) { Material *ma = BlenderStrokeRenderer::GetStrokeShader(_context, freestyle_bmain, iStrokeRep->getLineStyle()); if (strcmp(freestyle_scene->r.engine, "CYCLES") == 0) { @@ -464,7 +481,7 @@ void BlenderStrokeRenderer::test_strip_visibility(Strip::vertex_container& strip void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const { vector& strips = iStrokeRep->getStrips(); - const bool hasTex = iStrokeRep->getMTex(0) != NULL; + const bool hasTex = iStrokeRep->hasTex(); Strip::vertex_container::iterator v[3]; StrokeVertexRep *svRep[3]; unsigned int vertex_index, edge_index, loop_index; @@ -535,7 +552,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke"); CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 0); CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 0); - BKE_mesh_update_customdata_pointers(mesh, true); + BKE_mesh_update_customdata_pointers(mesh, false); loopsuv[0] = mesh->mloopuv; @@ -544,7 +561,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, "along_stroke_tips"); CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 1); CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 1); - BKE_mesh_update_customdata_pointers(mesh, true); + BKE_mesh_update_customdata_pointers(mesh, false); loopsuv[1] = mesh->mloopuv; } diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h index ad656fdc3f7..cc92d2274d8 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderStyleModule.h @@ -29,12 +29,11 @@ #include "../system/PythonInterpreter.h" extern "C" { -#include "BKE_global.h" -#include "BKE_library.h" -#include "BKE_text.h" -#include "BLI_utildefines.h" +#include "BLI_utildefines.h" // BLI_assert() struct FreestyleLineStyle; +struct Scene; +struct Text; } namespace Freestyle { @@ -42,11 +41,13 @@ namespace Freestyle { class BlenderStyleModule : public StyleModule { public: - BlenderStyleModule(struct Text *text, struct FreestyleLineStyle *linestyle, const string &name, - Interpreter *inter) : StyleModule(name, inter) + BlenderStyleModule(const string &name, Interpreter *inter, struct Text *text, + struct FreestyleLineStyle *lineStyle, bool useShadingNodes) + : StyleModule(name, inter) { _text = text; - _linestyle = linestyle; + _lineStyle = lineStyle; + _useShadingNodes = useShadingNodes; } virtual ~BlenderStyleModule() @@ -55,9 +56,8 @@ public: virtual StrokeLayer *execute() { - StrokeLayer *sl = StyleModule::execute(); - sl->setLineStyle(_linestyle); + sl->setLineStyle(_lineStyle, _useShadingNodes); return sl; } @@ -71,7 +71,8 @@ protected: private: struct Text *_text; - struct FreestyleLineStyle *_linestyle; + struct FreestyleLineStyle *_lineStyle; + bool _useShadingNodes; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BlenderStyleModule") diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index e662be02b87..f6557445d48 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -50,6 +50,7 @@ extern "C" { #include "BKE_library.h" #include "BKE_linestyle.h" #include "BKE_main.h" +#include "BKE_scene.h" #include "BKE_text.h" #include "BKE_context.h" @@ -294,6 +295,8 @@ static bool test_edge_type_conditions(struct edge_type_condition *conditions, static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl) { + const bool use_shading_nodes = BKE_scene_use_new_shading_nodes(re->scene); + // load mesh re->i.infostr = "Freestyle: Mesh loading"; re->stats_draw(re->sdh, &re->i); @@ -328,7 +331,7 @@ static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl) cout << " (" << module_conf->script->name << ")"; cout << endl; } - controller->InsertStyleModule(layer_count, id_name, NULL, module_conf->script); + controller->InsertStyleModule(layer_count, id_name, module_conf->script, NULL, use_shading_nodes); controller->toggleLayer(layer_count, true); layer_count++; } @@ -369,7 +372,7 @@ static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl) (lineset->linestyle ? (lineset->linestyle->id.name + 2) : "") << endl; } Text *text = create_lineset_handler(bmain, srl->name, lineset->name); - controller->InsertStyleModule(layer_count, lineset->name, lineset->linestyle, text); + controller->InsertStyleModule(layer_count, lineset->name, text, lineset->linestyle, use_shading_nodes); controller->toggleLayer(layer_count, true); if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) { ++use_ridges_and_valleys; diff --git a/source/blender/freestyle/intern/stroke/Stroke.cpp b/source/blender/freestyle/intern/stroke/Stroke.cpp index c85295e72bf..8900d19a102 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.cpp +++ b/source/blender/freestyle/intern/stroke/Stroke.cpp @@ -30,7 +30,11 @@ #include "StrokeAdvancedIterators.h" #include "StrokeRenderer.h" +#include "DNA_linestyle_types.h" + #include "BKE_global.h" +#include "BKE_linestyle.h" +#include "BKE_node.h" namespace Freestyle { @@ -394,11 +398,12 @@ Stroke::Stroke() _mediumType = OPAQUE_MEDIUM; _textureId = 0; _textureStep = 1.0; + _lineStyle = NULL; + _useShadingNodes = false; for (int a = 0; a < MAX_MTEX; a++) { _mtex[a] = NULL; } _tips = false; - _rep = NULL; } Stroke::Stroke(const Stroke& iBrother) @@ -416,6 +421,8 @@ Stroke::Stroke(const Stroke& iBrother) _mediumType = iBrother._mediumType; _textureId = iBrother._textureId; _textureStep = iBrother._textureStep; + _lineStyle = iBrother._lineStyle; + _useShadingNodes = iBrother._useShadingNodes; for (int a = 0; a < MAX_MTEX; a++) { if (iBrother._mtex) { _mtex[a] = iBrother._mtex[a]; @@ -425,10 +432,6 @@ Stroke::Stroke(const Stroke& iBrother) } } _tips = iBrother._tips; - if (iBrother._rep) - _rep = new StrokeRep(*(iBrother._rep)); - else - _rep = NULL; } Stroke::~Stroke() @@ -441,10 +444,6 @@ Stroke::~Stroke() } _ViewEdges.clear(); - if (_rep) { - delete _rep; - _rep = NULL; - } } Stroke& Stroke::operator=(const Stroke& iBrother) @@ -462,10 +461,6 @@ Stroke& Stroke::operator=(const Stroke& iBrother) _id = iBrother._id; _ViewEdges = iBrother._ViewEdges; _sampling = iBrother._sampling; - if (_rep) - delete _rep; - if (iBrother._rep) - _rep = new StrokeRep(*(iBrother._rep)); return *this; } @@ -601,11 +596,6 @@ int Stroke::Resample(int iNPoints) _Vertices = newVertices; newVertices.clear(); - if (_rep) { - delete _rep; - _rep = new StrokeRep(this); - } - return 0; } @@ -660,10 +650,6 @@ int Stroke::Resample(float iSampling) _Vertices = newVertices; newVertices.clear(); - if (_rep) { - delete _rep; - _rep = new StrokeRep(this); - } return 0; } @@ -774,18 +760,21 @@ void Stroke::ScaleThickness(float iFactor) } } +bool Stroke::hasTex() const +{ + return BKE_linestyle_use_textures(_lineStyle, _useShadingNodes); +} + void Stroke::Render(const StrokeRenderer *iRenderer) { - if (!_rep) - _rep = new StrokeRep(this); - iRenderer->RenderStrokeRep(_rep); + StrokeRep rep(this); + iRenderer->RenderStrokeRep(&rep); } void Stroke::RenderBasic(const StrokeRenderer *iRenderer) { - if (!_rep) - _rep = new StrokeRep(this); - iRenderer->RenderStrokeRepBasic(_rep); + StrokeRep rep(this); + iRenderer->RenderStrokeRepBasic(&rep); } Stroke::vertex_iterator Stroke::vertices_begin(float sampling) diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index d68a5938e98..391fbc47e34 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -545,8 +545,8 @@ private: MTex *_mtex[MAX_MTEX]; bool _tips; Vec2r _extremityOrientations[2]; // the orientations of the first and last extermity - StrokeRep *_rep; FreestyleLineStyle *_lineStyle; + bool _useShadingNodes; public: /*! default constructor */ @@ -651,6 +651,12 @@ public: return _lineStyle; } + /*! Return true if the new shading nodes are used. */ + inline bool useShadingNodes() + { + return _useShadingNodes; + } + /*! Returns the id of the texture used to simulate th marks system for this Stroke */ inline unsigned int getTextureId() {return _textureId;} @@ -663,10 +669,7 @@ public: } /*! Returns true if this Stroke has textures assigned, false otherwise. */ - inline bool hasTex() const - { - return _mtex[0] != NULL; - } + bool hasTex() const; /*! Returns true if this Stroke uses a texture with tips, false otherwise. */ inline bool hasTips() const @@ -747,9 +750,10 @@ public: void setLength(float iLength); /*! sets the line style of the Stroke. */ - void setLineStyle(struct FreestyleLineStyle *iLineStyle) + void setLineStyle(struct FreestyleLineStyle *iLineStyle, bool iUseShadingNodes) { _lineStyle = iLineStyle; + _useShadingNodes = iUseShadingNodes; } /*! sets the medium type that must be used for this Stroke. */ diff --git a/source/blender/freestyle/intern/stroke/StrokeLayer.cpp b/source/blender/freestyle/intern/stroke/StrokeLayer.cpp index ae8425625f2..6765bf1b665 100644 --- a/source/blender/freestyle/intern/stroke/StrokeLayer.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeLayer.cpp @@ -36,10 +36,10 @@ StrokeLayer::~StrokeLayer() clear(); } -void StrokeLayer::setLineStyle(struct FreestyleLineStyle *iLineStyle) +void StrokeLayer::setLineStyle(struct FreestyleLineStyle *iLineStyle, bool iUseShadingNodes) { for (StrokeLayer::stroke_container::iterator s = _strokes.begin(), send = _strokes.end(); s != send; ++s) { - (*s)->setLineStyle(iLineStyle); + (*s)->setLineStyle(iLineStyle, iUseShadingNodes); } } diff --git a/source/blender/freestyle/intern/stroke/StrokeLayer.h b/source/blender/freestyle/intern/stroke/StrokeLayer.h index 31fe368d931..bef7a2aca43 100644 --- a/source/blender/freestyle/intern/stroke/StrokeLayer.h +++ b/source/blender/freestyle/intern/stroke/StrokeLayer.h @@ -105,7 +105,7 @@ public: _strokes.push_back(iStroke); } - void setLineStyle(struct FreestyleLineStyle *iLineStyle); + void setLineStyle(struct FreestyleLineStyle *iLineStyle, bool iUseShadingNodes); #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeLayer") diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp index 04087693e3b..bdc21913f14 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp @@ -516,6 +516,7 @@ void Strip::setVertexColor (const vector& iStrokeVertices) void Strip::computeTexCoord (const vector& iStrokeVertices, float texStep) { + cout << "Strip::computeTexCoord texStep " << texStep << endl; vector::const_iterator v, vend; StrokeVertex *sv; int i = 0; @@ -705,6 +706,8 @@ StrokeRep::StrokeRep() _stroke = 0; _strokeType = Stroke::OPAQUE_MEDIUM; _lineStyle = NULL; + _useShadingNodes = false; + _hasTex = false; _textureStep = 1.0; for (int a = 0; a < MAX_MTEX; a++) { _mtex[a] = NULL; @@ -726,6 +729,8 @@ StrokeRep::StrokeRep(Stroke *iStroke) _stroke = iStroke; _strokeType = iStroke->getMediumType(); _lineStyle = iStroke->getLineStyle(); + _useShadingNodes = iStroke->useShadingNodes(); + _hasTex = iStroke->hasTex(); _textureId = iStroke->getTextureId(); _textureStep = iStroke->getTextureStep(); for (int a = 0; a < MAX_MTEX; a++) { @@ -760,6 +765,8 @@ StrokeRep::StrokeRep(const StrokeRep& iBrother) _textureId = iBrother._textureId; _textureStep = iBrother._textureStep; _lineStyle = iBrother._lineStyle; + _useShadingNodes = iBrother._useShadingNodes; + _hasTex = iBrother._hasTex; for (int a = 0; a < MAX_MTEX; a++) { if (iBrother._mtex[a]) { _mtex[a] = iBrother._mtex[a]; @@ -811,7 +818,7 @@ void StrokeRep::create() end = true; } if ((!strip.empty()) && (strip.size() > 1)) { - _strips.push_back(new Strip(strip, _stroke->hasTex(), first, end, _textureStep)); + _strips.push_back(new Strip(strip, _hasTex, first, end, _textureStep)); strip.clear(); } first = false; diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.h b/source/blender/freestyle/intern/stroke/StrokeRep.h index cf07e7aa108..a62fa4bdb9e 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.h +++ b/source/blender/freestyle/intern/stroke/StrokeRep.h @@ -188,6 +188,8 @@ protected: MTex *_mtex[MAX_MTEX]; Material *_material; FreestyleLineStyle *_lineStyle; + bool _useShadingNodes; + bool _hasTex; // float _averageTextureAlpha; @@ -229,6 +231,16 @@ public: return _lineStyle; } + inline bool useShadingNodes() const + { + return _useShadingNodes; + } + + inline bool hasTex() const + { + return _hasTex; + } + inline vector& getStrips() { return _strips; -- cgit v1.2.3