Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-21 06:57:44 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-21 06:57:44 +0400
commit39f8c6e189c89f4097f5d979612cb71bd8773030 (patch)
treed9a4ace57a1dc75f9e968ac0c1cae92ef995c145 /release/scripts/freestyle
parent92436c94d3adbbfc285bd7b3041db36e66dae5d5 (diff)
Freestyle Python API improvements - part 5.
Handling of keyword arguments in Python wrapper class constructors was revised. This revision is mainly focused on Interface0D, Interface1D, Iterator, and their subclasses, as well as a few additional view map component classes. Implementation notes: Because of the extensive use of constructor overloading in the underlying C++ classes, the corresponding Python wrappers try to parse arguments through multiple calls of PyArg_ParseTupleAndKeywords() if needed. The downside of this implementation is that most argument errors result in the same error message ("invalid argument(s)") without indicating what is wrong. For now this issue is left for future work. * Now the instantiation of ViewVertex is prohibited since the underlying C++ class is an abstract class. * Removed the .cast_to_interface0diterator() method from CurvePointIterator and StrokeVertexIterator. Instead the constructor of Interface0DIterator now accepts the instances of these two iterator classes to construct a nested Interface0DIterator instance that can be passed to Function0D functor objects. Specifically, an iterator 'it' is passed to a functor 'func' as follows: func(Interface0DIterator(it)) instead of: func(it.cast_to_interface0diterator()) * Boolean arguments of class constructors only accept values of boolean type. Input values of other types are considered as error. * Additional code clean-up was made.
Diffstat (limited to 'release/scripts/freestyle')
-rw-r--r--release/scripts/freestyle/style_modules/ChainingIterators.py30
-rw-r--r--release/scripts/freestyle/style_modules/parameter_editor.py10
-rw-r--r--release/scripts/freestyle/style_modules/shaders.py20
3 files changed, 29 insertions, 31 deletions
diff --git a/release/scripts/freestyle/style_modules/ChainingIterators.py b/release/scripts/freestyle/style_modules/ChainingIterators.py
index 5ef4b9c61dc..4c6343d5059 100644
--- a/release/scripts/freestyle/style_modules/ChainingIterators.py
+++ b/release/scripts/freestyle/style_modules/ChainingIterators.py
@@ -33,8 +33,8 @@ from freestyle_init import *
## then suggestive contours, then everything else. It doesn't chain the same ViewEdge twice
## You can specify whether to stay in the selection or not.
class pyChainSilhouetteIterator(ChainingIterator):
- def __init__(self, stayInSelection=1):
- ChainingIterator.__init__(self, stayInSelection, 1,None,1)
+ def __init__(self, stayInSelection=True):
+ ChainingIterator.__init__(self, stayInSelection, True, None, True)
def getExactTypeName(self):
return "pyChainSilhouetteIterator"
def init(self):
@@ -85,8 +85,8 @@ class pyChainSilhouetteIterator(ChainingIterator):
## You can specify whether to chain iterate over edges that were
## already visited or not.
class pyChainSilhouetteGenericIterator(ChainingIterator):
- def __init__(self, stayInSelection=1, stayInUnvisited=1):
- ChainingIterator.__init__(self, stayInSelection, stayInUnvisited,None,1)
+ def __init__(self, stayInSelection=True, stayInUnvisited=True):
+ ChainingIterator.__init__(self, stayInSelection, stayInUnvisited, None, True)
def getExactTypeName(self):
return "pyChainSilhouetteGenericIterator"
def init(self):
@@ -135,7 +135,7 @@ class pyChainSilhouetteGenericIterator(ChainingIterator):
class pyExternalContourChainingIterator(ChainingIterator):
def __init__(self):
- ChainingIterator.__init__(self, 0, 1,None,1)
+ ChainingIterator.__init__(self, False, True, None, True)
self._isExternalContour = ExternalContourUP1D()
def getExactTypeName(self):
return "pyExternalContourIterator"
@@ -182,8 +182,8 @@ class pyExternalContourChainingIterator(ChainingIterator):
## the natural chaining iterator
## with a sketchy multiple touch
class pySketchyChainSilhouetteIterator(ChainingIterator):
- def __init__(self, nRounds=3,stayInSelection=1):
- ChainingIterator.__init__(self, stayInSelection, 0,None,1)
+ def __init__(self, nRounds=3,stayInSelection=True):
+ ChainingIterator.__init__(self, stayInSelection, False, None, True)
self._timeStamp = GetTimeStampCF()+nRounds
self._nRounds = nRounds
def getExactTypeName(self):
@@ -241,8 +241,8 @@ class pySketchyChainSilhouetteIterator(ChainingIterator):
# can chain several times the same ViewEdge
# in order to produce multiple strokes per ViewEdge.
class pySketchyChainingIterator(ChainingIterator):
- def __init__(self, nRounds=3, stayInSelection=1):
- ChainingIterator.__init__(self, stayInSelection, 0,None,1)
+ def __init__(self, nRounds=3, stayInSelection=True):
+ ChainingIterator.__init__(self, stayInSelection, False, None, True)
self._timeStamp = GetTimeStampCF()+nRounds
self._nRounds = nRounds
def getExactTypeName(self):
@@ -272,7 +272,7 @@ class pySketchyChainingIterator(ChainingIterator):
## expressed in % of the total chain length
class pyFillOcclusionsRelativeChainingIterator(ChainingIterator):
def __init__(self, percent):
- ChainingIterator.__init__(self, 0, 1,None,1)
+ ChainingIterator.__init__(self, False, True, None, True)
self._length = 0
self._percent = float(percent)
def getExactTypeName(self):
@@ -375,7 +375,7 @@ class pyFillOcclusionsRelativeChainingIterator(ChainingIterator):
## expressed in pixels
class pyFillOcclusionsAbsoluteChainingIterator(ChainingIterator):
def __init__(self, length):
- ChainingIterator.__init__(self, 0, 1,None,1)
+ ChainingIterator.__init__(self, False, True, None, True)
self._length = float(length)
def getExactTypeName(self):
return "pySmallFillOcclusionsChainingIterator"
@@ -445,7 +445,7 @@ class pyFillOcclusionsAbsoluteChainingIterator(ChainingIterator):
## expressed in % of the total chain length
class pyFillOcclusionsAbsoluteAndRelativeChainingIterator(ChainingIterator):
def __init__(self, percent, l):
- ChainingIterator.__init__(self, 0, 1,None,1)
+ ChainingIterator.__init__(self, False, True, None, True)
self._length = 0
self._absLength = l
self._percent = float(percent)
@@ -550,7 +550,7 @@ class pyFillOcclusionsAbsoluteAndRelativeChainingIterator(ChainingIterator):
## expressed in % of the total chain length
class pyFillQi0AbsoluteAndRelativeChainingIterator(ChainingIterator):
def __init__(self, percent, l):
- ChainingIterator.__init__(self, 0, 1,None,1)
+ ChainingIterator.__init__(self, False, True, None, True)
self._length = 0
self._absLength = l
self._percent = float(percent)
@@ -655,8 +655,8 @@ class pyFillQi0AbsoluteAndRelativeChainingIterator(ChainingIterator):
## then suggestive contours, then everything else. It doesn't chain the same ViewEdge twice
## You can specify whether to stay in the selection or not.
class pyNoIdChainSilhouetteIterator(ChainingIterator):
- def __init__(self, stayInSelection=1):
- ChainingIterator.__init__(self, stayInSelection, 1,None,1)
+ def __init__(self, stayInSelection=True):
+ ChainingIterator.__init__(self, stayInSelection, True, None, True)
def getExactTypeName(self):
return "pyChainSilhouetteIterator"
def init(self):
diff --git a/release/scripts/freestyle/style_modules/parameter_editor.py b/release/scripts/freestyle/style_modules/parameter_editor.py
index 75a948b8623..ad710118688 100644
--- a/release/scripts/freestyle/style_modules/parameter_editor.py
+++ b/release/scripts/freestyle/style_modules/parameter_editor.py
@@ -363,7 +363,7 @@ def iter_material_color(stroke, material_attr):
func = CurveMaterialF0D()
it = stroke.stroke_vertices_begin()
while not it.is_end:
- material = func(it.cast_to_interface0diterator())
+ material = func(Interface0DIterator(it))
if material_attr == "DIFF":
color = (material.diffuse[0],
material.diffuse[1],
@@ -381,7 +381,7 @@ def iter_material_value(stroke, material_attr):
func = CurveMaterialF0D()
it = stroke.stroke_vertices_begin()
while not it.is_end:
- material = func(it.cast_to_interface0diterator())
+ material = func(Interface0DIterator(it))
if material_attr == "DIFF":
r = material.diffuse[0]
g = material.diffuse[1]
@@ -478,7 +478,7 @@ class CalligraphicThicknessShader(ThicknessBlenderMixIn, ScalarBlendModifier):
func = VertexOrientation2DF0D()
it = stroke.stroke_vertices_begin()
while not it.is_end:
- dir = func(it.cast_to_interface0diterator())
+ dir = func(Interface0DIterator(it))
orthDir = mathutils.Vector((-dir.y, dir.x))
orthDir.normalize()
fac = abs(orthDir * self.__orientation)
@@ -515,7 +515,7 @@ class SinusDisplacementShader(StrokeShader):
def shade(self, stroke):
for it, distance in iter_distance_along_stroke(stroke):
v = it.object
- n = self._getNormal(it.cast_to_interface0diterator())
+ n = self._getNormal(Interface0DIterator(it))
n = n * self._amplitude * math.cos(distance / self._wavelength * 2 * math.pi + self._phase)
v.point = v.point + n
stroke.update_length()
@@ -575,7 +575,7 @@ class Offset2DShader(StrokeShader):
v = it.object
u = v.u
a = self.__start + u * (self.__end - self.__start)
- n = self.__getNormal(it.cast_to_interface0diterator())
+ n = self.__getNormal(Interface0DIterator(it))
n = n * a
v.point = v.point + n + self.__xy
it.increment()
diff --git a/release/scripts/freestyle/style_modules/shaders.py b/release/scripts/freestyle/style_modules/shaders.py
index 7a363e3273f..31f22aad557 100644
--- a/release/scripts/freestyle/style_modules/shaders.py
+++ b/release/scripts/freestyle/style_modules/shaders.py
@@ -25,7 +25,7 @@ class pyDepthDiscontinuityThicknessShader(StrokeShader):
b = (self.__min*z_max-self.__max*z_min)/(z_max-z_min)
it = stroke.stroke_vertices_begin()
while not it.is_end:
- z = self.__func(it.cast_to_interface0diterator())
+ z = self.__func(Interface0DIterator(it))
thickness = a*z+b
it.object.attribute.thickness = (thickness, thickness)
it.increment()
@@ -72,8 +72,7 @@ class pyFXSVaryingThicknessWithDensityShader(StrokeShader):
it = stroke.stroke_vertices_begin()
func = DensityF0D(self.wsize)
while not it.is_end:
- toto = it.cast_to_interface0diterator()
- c= func(toto)
+ c = func(Interface0DIterator(it))
if c < self.threshold_min:
c = self.threshold_min
if c > self.threshold_max:
@@ -332,7 +331,7 @@ class pyZDependingThicknessShader(StrokeShader):
z_min = 1
z_max = 0
while not it.is_end:
- z = self.__func(it.cast_to_interface0diterator())
+ z = self.__func(Interface0DIterator(it))
if z < z_min:
z_min = z
if z > z_max:
@@ -341,7 +340,7 @@ class pyZDependingThicknessShader(StrokeShader):
z_diff = 1 / (z_max - z_min)
it = stroke.stroke_vertices_begin()
while not it.is_end:
- z = (self.__func(it.cast_to_interface0diterator()) - z_min) * z_diff
+ z = (self.__func(Interface0DIterator(it)) - z_min) * z_diff
thickness = (1 - z) * self.__max + z * self.__min
it.object.attribute.thickness = (thickness, thickness)
it.increment()
@@ -428,8 +427,7 @@ class pyMaterialColorShader(StrokeShader):
un = 4.* xn/ ( -2.*xn + 12.*yn + 3. )
vn= 9.* yn/ ( -2.*xn + 12.*yn +3. )
while not it.is_end:
- toto = it.cast_to_interface0diterator()
- mat = func(toto)
+ mat = func(Interface0DIterator(it))
r = mat.diffuse[0]
g = mat.diffuse[1]
@@ -499,7 +497,7 @@ class py2DCurvatureColorShader(StrokeShader):
it = stroke.stroke_vertices_begin()
func = Curvature2DAngleF0D()
while not it.is_end:
- c = func(it.cast_to_interface0diterator())
+ c = func(Interface0DIterator(it))
if c < 0:
print("negative 2D curvature")
color = 10.0 * c/3.1415
@@ -680,7 +678,7 @@ class pyDiffusion2Shader(StrokeShader):
while not it.is_end:
v = it.object
p1 = v.point
- p2 = self._normalInfo(it.cast_to_interface0diterator())*self._lambda*self._curvatureInfo(it.cast_to_interface0diterator())
+ p2 = self._normalInfo(Interface0DIterator(it))*self._lambda*self._curvatureInfo(Interface0DIterator(it))
v.point = p1+p2
it.increment()
stroke.update_length()
@@ -869,7 +867,7 @@ class pySinusDisplacementShader(StrokeShader):
while not it.is_end:
v = it.object
#print(self._getNormal.getName())
- n = self._getNormal(it.cast_to_interface0diterator())
+ n = self._getNormal(Interface0DIterator(it))
p = v.point
u = v.u
a = self._a*(1-2*(fabs(u-0.5)))
@@ -1265,7 +1263,7 @@ class pyDummyShader(StrokeShader):
def shade(self, stroke):
it = stroke.stroke_vertices_begin()
while not it.is_end:
- toto = it.cast_to_interface0diterator()
+ toto = Interface0DIterator(it)
att = it.object.attribute
att.color = (0.3, 0.4, 0.4)
att.thickness = (0, 5)