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
This commit is contained in:
@@ -286,6 +286,21 @@ static PyObject *Stroke_stroke_vertices_end(BPy_Stroke *self)
|
||||
return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, true);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(Stroke_reversed_doc,
|
||||
".. method:: __reversed__()\n"
|
||||
"\n"
|
||||
" Returns a StrokeVertexIterator iterating over the vertices of the Stroke\n"
|
||||
" in the reversed order (from the last to the first).\n"
|
||||
"\n"
|
||||
" :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n"
|
||||
" :rtype: :class:`StrokeVertexIterator`");
|
||||
|
||||
static PyObject *Stroke_reversed(BPy_Stroke *self)
|
||||
{
|
||||
StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesEnd());
|
||||
return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, true);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(Stroke_stroke_vertices_size_doc,
|
||||
".. method:: stroke_vertices_size()\n"
|
||||
"\n"
|
||||
@@ -310,6 +325,7 @@ static PyMethodDef BPy_Stroke_methods[] = {
|
||||
{"stroke_vertices_begin", (PyCFunction)Stroke_stroke_vertices_begin, METH_VARARGS | METH_KEYWORDS,
|
||||
Stroke_stroke_vertices_begin_doc},
|
||||
{"stroke_vertices_end", (PyCFunction)Stroke_stroke_vertices_end, METH_NOARGS, Stroke_stroke_vertices_end_doc},
|
||||
{"__reversed__", (PyCFunction)Stroke_reversed, METH_NOARGS, Stroke_reversed_doc},
|
||||
{"stroke_vertices_size", (PyCFunction)Stroke_stroke_vertices_size, METH_NOARGS, Stroke_stroke_vertices_size_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user