WIP commit just for a record of a working snapshot of code revisions for node-based textured strokes.

This commit is contained in:
Tamito Kajiyama
2014-07-19 15:38:56 +09:00
parent a2a2d4679a
commit c38e80d632
13 changed files with 120 additions and 60 deletions

View File

@@ -408,17 +408,30 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
float3 *fdata = attr->data_float3();
size_t i = 0;
std::cout << "name " << name << std::endl;
for(l->data.begin(t); t != l->data.end(); ++t, ++i) {
fdata[0] = get_float3(t->uv1());
fdata[1] = get_float3(t->uv2());
fdata[2] = get_float3(t->uv3());
fdata += 3;
#if 0
std::cout << " 1st "
<< "( " << t->uv1()[0] << ", " << t->uv1()[1] << ") "
<< "( " << t->uv2()[0] << ", " << t->uv2()[1] << ") "
<< "( " << t->uv3()[0] << ", " << t->uv3()[1] << ") " << std::endl;
#endif
if(nverts[i] == 4) {
fdata[0] = get_float3(t->uv1());
fdata[1] = get_float3(t->uv3());
fdata[2] = get_float3(t->uv4());
fdata += 3;
#if 0
std::cout << " 2nd "
<< "( " << t->uv1()[0] << ", " << t->uv1()[1] << ") "
<< "( " << t->uv3()[0] << ", " << t->uv3()[1] << ") "
<< "( " << t->uv4()[0] << ", " << t->uv4()[1] << ") " << std::endl;
#endif
}
}
}

View File

@@ -1075,7 +1075,21 @@ def process(layer_name, lineset_name):
elif m.type == '2D_TRANSFORM':
shaders_list.append(Transform2DShader(
m.pivot, m.scale_x, m.scale_y, m.angle, m.pivot_u, m.pivot_x, m.pivot_y))
has_tex = False
if scene.render.use_shading_nodes:
if linestyle.use_nodes and linestyle.node_tree:
### TODO ###
#shaders_list.append(BlenderTextureShader(linestyle.nodetree))
has_tex = True
else:
if linestyle.use_texture:
for slot in linestyle.texture_slots:
if slot is not None:
shaders_list.append(BlenderTextureShader(slot))
has_tex = True
if has_tex:
shaders_list.append(StrokeTextureStepShader(linestyle.texture_spacing))
color = linestyle.color
if (not linestyle.use_chaining) or (linestyle.chaining == 'PLAIN' and linestyle.use_same_object):
thickness_position = linestyle.thickness_position
else:

View File

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

View File

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

View File

@@ -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<Strip*>& 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;
}

View File

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

View File

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

View File

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

View File

@@ -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. */

View File

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

View File

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

View File

@@ -516,6 +516,7 @@ void Strip::setVertexColor (const vector<StrokeVertex *>& iStrokeVertices)
void Strip::computeTexCoord (const vector<StrokeVertex *>& iStrokeVertices, float texStep)
{
cout << "Strip::computeTexCoord texStep " << texStep << endl;
vector<StrokeVertex *>::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;

View File

@@ -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<Strip*>& getStrips()
{
return _strips;