diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-06-16 04:56:58 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-06-16 05:12:51 +0400 |
commit | 840891e22a12c7bbb7c3b8d086ef0c6ff11a24d9 (patch) | |
tree | 15160b0453f7cda7d5170e22680c8dda71da97be /source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp | |
parent | ea3bca75d91d140df4c46b501809e4c6e4e8f2d5 (diff) |
D545: Freestyle Python API: new methods for Stroke and StrokeVertexIterator.
This revision extends the Freestyle Python API to make for style module writing
easier.
- freestyle.types.Stroke: A proper support for reversed() is implemented. It
works the same with other Python sequence objects (returns an iterator starting
from the end). This is in effect equivalent to Stroke.stroke_vertices_end().
- freestyle.types.StrokeVertexIterator: An incremented, decremented and reversed
method are added. The first two methods return a new StrokeVertexIterator
object that has been incremented and decremented, respectively. The reversed
method returns a new StrokeVertexIterator object that will traverse stroke
vertices in the opposite direction.
- freestyle.types.Interface0DIterator: Its constructor now accepts a Stroke
object to create an Interface0DIterator that traverses stroke vertices. This is
in effect equivalent to Stroke.vertices_begin(). The new API makes stroke
shaders involving function calls much simpler as illustrated below:
# in the old API
it = stroke.stroke_vertices_begin()
for vert in it:
result = somefunc(Interface0DIterator(it))
# in the new API
it = Interface0DIterator(stroke)
for vert in it:
result = somefunc(it)
Differential Revision: https://developer.blender.org/D545
Reviewers: kjym3
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index a339e6653c6..faf99e90111 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -25,6 +25,7 @@ #include "BPy_Interface0DIterator.h" #include "../BPy_Convert.h" +#include "../BPy_Interface1D.h" #ifdef __cplusplus extern "C" { @@ -70,9 +71,10 @@ static int convert_nested_it(PyObject *obj, void *v) static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args, PyObject *kwds) { static const char *kwlist_1[] = {"it", NULL}; - static const char *kwlist_2[] = {"brother", NULL}; + static const char *kwlist_2[] = {"inter", NULL}; + static const char *kwlist_3[] = {"brother", NULL}; Interface0DIteratorNested *nested_it; - PyObject *brother; + PyObject *brother, *inter; if (PyArg_ParseTupleAndKeywords(args, kwds, "O&", (char **)kwlist_1, convert_nested_it, &nested_it)) { self->if0D_it = new Interface0DIterator(nested_it->copy()); @@ -80,7 +82,14 @@ static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *arg self->reversed = false; } else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Interface0DIterator_Type, &brother)) + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Interface1D_Type, &inter)) + { + self->if0D_it = new Interface0DIterator(((BPy_Interface1D *)inter)->if1D->verticesBegin()); + self->at_start = true; + self->reversed = false; + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_3, &Interface0DIterator_Type, &brother)) { self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)brother)->if0D_it)); self->at_start = ((BPy_Interface0DIterator *)brother)->at_start; |