diff options
author | Folkert de Vries <flokkievids@gmail.com> | 2015-07-10 15:57:23 +0300 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2015-07-10 17:15:56 +0300 |
commit | eeeb845d33e81afbc8ed127e6ab4ae7b18472a54 (patch) | |
tree | 78f8f3ecf9c4dd3bf4383ccc73520bcd2c6b2c7b /source/blender/freestyle | |
parent | 7837f0e8332f3726e0322b0c48b0da4d7c2d5813 (diff) |
Freestyle: new stroke modifiers
This patch introduces a couple new stroke modifiers. The ones currently implemented are based on prototypes by @kjym3 and myself.
The new modifiers:
- Tangent
- Thickness noise
- Crease Angle
- Simplification
- Curvature 3D
The documentation for these new modifier types can be found [[ http://www.blender.org/manual/render/freestyle/parameter_editor/index.html | in the manual ]]:
{F134441}
(left: AnisotropicThicknessShader, right: NoiseThicknessShader)
{F140499}
(left: Curvature 3D, right: Simplification)
Author: Folkert de Vries (flokkievids)
Reviewers: kjym3
Subscribers: #user_interface, plasmasolutions, kjym3
Projects: #bf_blender
Differential Revision: https://developer.blender.org/D963
Diffstat (limited to 'source/blender/freestyle')
3 files changed, 35 insertions, 1 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp index 39e4aed7cc0..21a5ceaa3b2 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp @@ -25,6 +25,8 @@ #include "BPy_FrsNoise.h" #include "BPy_Convert.h" +#include "../system/RandGen.h" + #include <sstream> #ifdef __cplusplus @@ -69,12 +71,14 @@ static int FrsNoise_init(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) if (!PyArg_ParseTupleAndKeywords(args, kwds, "|l", (char **)kwlist, &seed)) return -1; self->n = new Noise(seed); + self->pn = new PseudoNoise(); return 0; } static void FrsNoise_dealloc(BPy_FrsNoise *self) { delete self->n; + delete self->pn; Py_TYPE(self)->tp_free((PyObject *)self); } @@ -99,6 +103,32 @@ PyDoc_STRVAR(FrsNoise_turbulence1_doc, " :return: A noise value.\n" " :rtype: float"); +static PyObject *FrsNoise_drand(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist[] = {"seed", NULL}; + long seed = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|I", (char **)kwlist, &seed)) { + PyErr_SetString(PyExc_TypeError, "optional argument 1 must be of type int"); + return NULL; + } + if (seed){ + RandGen::srand48(seed); + } + return PyFloat_FromDouble(RandGen::drand48()); +} + +static PyObject *FrsNoise_turbulence_smooth(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist[] = {"v", "oct", NULL}; + + double x; // note: this has to be a double (not float) + unsigned nbOctaves = 8; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|I", (char **)kwlist, &x, &nbOctaves)) + return NULL; + return PyFloat_FromDouble(self->pn->turbulenceSmooth(x, nbOctaves)); +} + static PyObject *FrsNoise_turbulence1(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"v", "freq", "amp", "oct", NULL}; @@ -257,6 +287,8 @@ static PyMethodDef BPy_FrsNoise_methods[] = { {"smoothNoise1", (PyCFunction)FrsNoise_smoothNoise1, METH_VARARGS | METH_KEYWORDS, FrsNoise_smoothNoise1_doc}, {"smoothNoise2", (PyCFunction)FrsNoise_smoothNoise2, METH_VARARGS | METH_KEYWORDS, FrsNoise_smoothNoise2_doc}, {"smoothNoise3", (PyCFunction)FrsNoise_smoothNoise3, METH_VARARGS | METH_KEYWORDS, FrsNoise_smoothNoise3_doc}, + {"rand", (PyCFunction)FrsNoise_drand, METH_VARARGS | METH_KEYWORDS, NULL}, + {"turbulence_smooth", (PyCFunction)FrsNoise_turbulence_smooth, METH_VARARGS | METH_KEYWORDS, NULL}, {NULL, NULL, 0, NULL} }; diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.h b/source/blender/freestyle/intern/python/BPy_FrsNoise.h index 19788e30a43..a5a1064ea8d 100644 --- a/source/blender/freestyle/intern/python/BPy_FrsNoise.h +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.h @@ -30,6 +30,7 @@ extern "C" { } #include "../geometry/Noise.h" +#include "../system/PseudoNoise.h" using namespace Freestyle; @@ -47,6 +48,7 @@ extern PyTypeObject FrsNoise_Type; typedef struct { PyObject_HEAD Noise *n; + PseudoNoise *pn; } BPy_FrsNoise; /*---------------------------Python BPy_FrsNoise visible prototypes-----------*/ diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp index 11b7df7ecec..eed90a53d77 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp @@ -185,7 +185,7 @@ int ThicknessNoiseShader::shade(Stroke& stroke) const real bruit, bruit2; PseudoNoise mynoise, mynoise2; for (vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - bruit = mynoise.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU1, 2); // 2 : nbOctaves + bruit = mynoise.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU1, 2); // 2 : nbOctaves bruit2 = mynoise2.turbulenceSmooth(_scale * v->curvilinearAbscissa() + initU2, 2); // 2 : nbOctaves const float *originalThickness = v->attribute().getThickness(); float r = bruit * _amplitude + originalThickness[0]; |