Freestyle: minor revisions of Python API docstrings and comments.
This commit is contained in:
@@ -77,7 +77,7 @@ NATURES = (
|
|||||||
|
|
||||||
|
|
||||||
def nature_in_preceding(nature, index):
|
def nature_in_preceding(nature, index):
|
||||||
""" Returns True if given nature appears before index, else False """
|
"""Returns True if given nature appears before index, else False."""
|
||||||
return any(nature & nat for nat in NATURES[:index])
|
return any(nature & nat for nat in NATURES[:index])
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
"""
|
"""
|
||||||
Functions operating on vertices (0D elements) and polylines (1D
|
Functions operating on vertices (0D elements) and polylines (1D
|
||||||
elements). Also intended to be a collection of examples for predicate
|
elements). Also intended to be a collection of examples for predicate
|
||||||
definition in Python
|
definition in Python.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# module members
|
# module members
|
||||||
@@ -97,7 +97,7 @@ from mathutils import Vector
|
|||||||
class CurveMaterialF0D(UnaryFunction0DMaterial):
|
class CurveMaterialF0D(UnaryFunction0DMaterial):
|
||||||
"""
|
"""
|
||||||
A replacement of the built-in MaterialF0D for stroke creation.
|
A replacement of the built-in MaterialF0D for stroke creation.
|
||||||
MaterialF0D does not work with Curves and Strokes. Line color
|
MaterialF0D does not work with Curves and Strokes. Line color
|
||||||
priority is used to pick one of the two materials at material
|
priority is used to pick one of the two materials at material
|
||||||
boundaries.
|
boundaries.
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ class pyCurvilinearLengthF0D(UnaryFunction0DDouble):
|
|||||||
|
|
||||||
|
|
||||||
class pyDensityAnisotropyF0D(UnaryFunction0DDouble):
|
class pyDensityAnisotropyF0D(UnaryFunction0DDouble):
|
||||||
"""Estimates the anisotropy of density"""
|
"""Estimates the anisotropy of density."""
|
||||||
def __init__(self, level):
|
def __init__(self, level):
|
||||||
UnaryFunction0DDouble.__init__(self)
|
UnaryFunction0DDouble.__init__(self)
|
||||||
self.IsoDensity = ReadCompleteViewMapPixelF0D(level)
|
self.IsoDensity = ReadCompleteViewMapPixelF0D(level)
|
||||||
@@ -149,7 +149,7 @@ class pyDensityAnisotropyF0D(UnaryFunction0DDouble):
|
|||||||
|
|
||||||
|
|
||||||
class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f):
|
class pyViewMapGradientVectorF0D(UnaryFunction0DVec2f):
|
||||||
"""Returns the gradient vector for a pixel
|
"""Returns the gradient vector for a pixel.
|
||||||
|
|
||||||
:arg level: the level at which to compute the gradient
|
:arg level: the level at which to compute the gradient
|
||||||
:type level: int
|
:type level: int
|
||||||
|
@@ -112,9 +112,8 @@ class pyVertexNatureUP0D(UnaryPredicate0D):
|
|||||||
|
|
||||||
class pyBackTVertexUP0D(UnaryPredicate0D):
|
class pyBackTVertexUP0D(UnaryPredicate0D):
|
||||||
"""
|
"""
|
||||||
Check whether an Interface0DIterator
|
Check whether an Interface0DIterator references a TVertex and is
|
||||||
references a TVertex and is the one that is
|
the one that is hidden (inferred from the context).
|
||||||
hidden (inferred from the context)
|
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
UnaryPredicate0D.__init__(self)
|
UnaryPredicate0D.__init__(self)
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Stroke shaders used for creation of stylized strokes. Also intended
|
Stroke shaders used for creation of stylized strokes. Also intended
|
||||||
to be a collection of examples for shader definition in Python
|
to be a collection of examples for shader definition in Python.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# module members
|
# module members
|
||||||
@@ -100,7 +100,7 @@ from random import randint
|
|||||||
class pyDepthDiscontinuityThicknessShader(StrokeShader):
|
class pyDepthDiscontinuityThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns a thickness to the stroke based on the stroke's distance
|
Assigns a thickness to the stroke based on the stroke's distance
|
||||||
to the camera (Z-value)
|
to the camera (Z-value).
|
||||||
"""
|
"""
|
||||||
def __init__(self, min, max):
|
def __init__(self, min, max):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -118,7 +118,7 @@ class pyDepthDiscontinuityThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pyConstantThicknessShader(StrokeShader):
|
class pyConstantThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns a constant thickness along the stroke
|
Assigns a constant thickness along the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self, thickness):
|
def __init__(self, thickness):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -131,7 +131,7 @@ class pyConstantThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pyFXSVaryingThicknessWithDensityShader(StrokeShader):
|
class pyFXSVaryingThicknessWithDensityShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assings thickness to a stroke based on the density of the diffuse map
|
Assings thickness to a stroke based on the density of the diffuse map.
|
||||||
"""
|
"""
|
||||||
def __init__(self, wsize, threshold_min, threshold_max, thicknessMin, thicknessMax):
|
def __init__(self, wsize, threshold_min, threshold_max, thicknessMin, thicknessMax):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -155,7 +155,7 @@ class pyFXSVaryingThicknessWithDensityShader(StrokeShader):
|
|||||||
|
|
||||||
class pyIncreasingThicknessShader(StrokeShader):
|
class pyIncreasingThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Increasingly thickens the stroke
|
Increasingly thickens the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self, thicknessMin, thicknessMax):
|
def __init__(self, thicknessMin, thicknessMax):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -176,7 +176,7 @@ class pyIncreasingThicknessShader(StrokeShader):
|
|||||||
class pyConstrainedIncreasingThicknessShader(StrokeShader):
|
class pyConstrainedIncreasingThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Increasingly thickens the stroke, constrained by a ratio of the
|
Increasingly thickens the stroke, constrained by a ratio of the
|
||||||
stroke's length
|
stroke's length.
|
||||||
"""
|
"""
|
||||||
def __init__(self, thicknessMin, thicknessMax, ratio):
|
def __init__(self, thicknessMin, thicknessMax, ratio):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -203,7 +203,7 @@ class pyConstrainedIncreasingThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pyDecreasingThicknessShader(StrokeShader):
|
class pyDecreasingThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Inverse of pyIncreasingThicknessShader, decreasingly thickens the stroke
|
Inverse of pyIncreasingThicknessShader, decreasingly thickens the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self, thicknessMin, thicknessMax):
|
def __init__(self, thicknessMin, thicknessMax):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -224,7 +224,7 @@ class pyDecreasingThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pyNonLinearVaryingThicknessShader(StrokeShader):
|
class pyNonLinearVaryingThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns thickness to a stroke based on an exponential function
|
Assigns thickness to a stroke based on an exponential function.
|
||||||
"""
|
"""
|
||||||
def __init__(self, thicknessExtremity, thicknessMiddle, exponent):
|
def __init__(self, thicknessExtremity, thicknessMiddle, exponent):
|
||||||
self._thicknessMin = thicknessMiddle
|
self._thicknessMin = thicknessMiddle
|
||||||
@@ -243,7 +243,7 @@ class pyNonLinearVaryingThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pySLERPThicknessShader(StrokeShader):
|
class pySLERPThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns thickness to a stroke based on spherical linear interpolation
|
Assigns thickness to a stroke based on spherical linear interpolation.
|
||||||
"""
|
"""
|
||||||
def __init__(self, thicknessMin, thicknessMax, omega=1.2):
|
def __init__(self, thicknessMin, thicknessMax, omega=1.2):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -267,7 +267,7 @@ class pySLERPThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pyTVertexThickenerShader(StrokeShader):
|
class pyTVertexThickenerShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Thickens TVertices (visual intersections between two edges)
|
Thickens TVertices (visual intersections between two edges).
|
||||||
"""
|
"""
|
||||||
def __init__(self, a=1.5, n=3):
|
def __init__(self, a=1.5, n=3):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -297,7 +297,7 @@ class pyImportance2DThicknessShader(StrokeShader):
|
|||||||
"""
|
"""
|
||||||
Assigns thickness based on distance to a given point in 2D space.
|
Assigns thickness based on distance to a given point in 2D space.
|
||||||
the thickness is inverted, so the vertices closest to the
|
the thickness is inverted, so the vertices closest to the
|
||||||
specified point have the lowest thickness
|
specified point have the lowest thickness.
|
||||||
"""
|
"""
|
||||||
def __init__(self, x, y, w, kmin, kmax):
|
def __init__(self, x, y, w, kmin, kmax):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -317,7 +317,7 @@ class pyImportance2DThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pyImportance3DThicknessShader(StrokeShader):
|
class pyImportance3DThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns thickness based on distance to a given point in 3D space
|
Assigns thickness based on distance to a given point in 3D space.
|
||||||
"""
|
"""
|
||||||
def __init__(self, x, y, z, w, kmin, kmax):
|
def __init__(self, x, y, z, w, kmin, kmax):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -338,7 +338,7 @@ class pyImportance3DThicknessShader(StrokeShader):
|
|||||||
class pyZDependingThicknessShader(StrokeShader):
|
class pyZDependingThicknessShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns thickness based on an object's local Z depth (point
|
Assigns thickness based on an object's local Z depth (point
|
||||||
closest to camera is 1, point furthest from camera is zero)
|
closest to camera is 1, point furthest from camera is zero).
|
||||||
"""
|
"""
|
||||||
def __init__(self, min, max):
|
def __init__(self, min, max):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -363,7 +363,7 @@ class pyZDependingThicknessShader(StrokeShader):
|
|||||||
|
|
||||||
class pyConstantColorShader(StrokeShader):
|
class pyConstantColorShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns a constant color to the stroke
|
Assigns a constant color to the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self,r,g,b, a = 1):
|
def __init__(self,r,g,b, a = 1):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -377,7 +377,7 @@ class pyConstantColorShader(StrokeShader):
|
|||||||
|
|
||||||
class pyIncreasingColorShader(StrokeShader):
|
class pyIncreasingColorShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Fades from one color to another along the stroke
|
Fades from one color to another along the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self,r1,g1,b1,a1, r2,g2,b2,a2):
|
def __init__(self,r1,g1,b1,a1, r2,g2,b2,a2):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -397,7 +397,7 @@ class pyIncreasingColorShader(StrokeShader):
|
|||||||
|
|
||||||
class pyInterpolateColorShader(StrokeShader):
|
class pyInterpolateColorShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Fades from one color to another and back
|
Fades from one color to another and back.
|
||||||
"""
|
"""
|
||||||
def __init__(self,r1,g1,b1,a1, r2,g2,b2,a2):
|
def __init__(self,r1,g1,b1,a1, r2,g2,b2,a2):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -431,7 +431,7 @@ class pyModulateAlphaShader(StrokeShader):
|
|||||||
|
|
||||||
class pyMaterialColorShader(StrokeShader):
|
class pyMaterialColorShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns the color of the underlying material to the stroke
|
Assigns the color of the underlying material to the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self, threshold=50):
|
def __init__(self, threshold=50):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -493,7 +493,7 @@ class pyMaterialColorShader(StrokeShader):
|
|||||||
|
|
||||||
class pyRandomColorShader(StrokeShader):
|
class pyRandomColorShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns a color to the stroke based on given seed
|
Assigns a color to the stroke based on given seed.
|
||||||
"""
|
"""
|
||||||
def __init__(self, s=1):
|
def __init__(self, s=1):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -510,7 +510,7 @@ class pyRandomColorShader(StrokeShader):
|
|||||||
class py2DCurvatureColorShader(StrokeShader):
|
class py2DCurvatureColorShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns a color (greyscale) to the stroke based on the curvature.
|
Assigns a color (greyscale) to the stroke based on the curvature.
|
||||||
A higher curvature will yield a brighter color
|
A higher curvature will yield a brighter color.
|
||||||
"""
|
"""
|
||||||
def shade(self, stroke):
|
def shade(self, stroke):
|
||||||
func = Curvature2DAngleF0D()
|
func = Curvature2DAngleF0D()
|
||||||
@@ -526,7 +526,7 @@ class py2DCurvatureColorShader(StrokeShader):
|
|||||||
class pyTimeColorShader(StrokeShader):
|
class pyTimeColorShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Assigns a greyscale value that increases for every vertex.
|
Assigns a greyscale value that increases for every vertex.
|
||||||
The brightness will increase along the stroke
|
The brightness will increase along the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self, step=0.01):
|
def __init__(self, step=0.01):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -543,7 +543,7 @@ class pyTimeColorShader(StrokeShader):
|
|||||||
class pySamplingShader(StrokeShader):
|
class pySamplingShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Resamples the stroke, which gives the stroke the ammount of
|
Resamples the stroke, which gives the stroke the ammount of
|
||||||
vertices specified
|
vertices specified.
|
||||||
"""
|
"""
|
||||||
def __init__(self, sampling):
|
def __init__(self, sampling):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -556,7 +556,7 @@ class pySamplingShader(StrokeShader):
|
|||||||
|
|
||||||
class pyBackboneStretcherShader(StrokeShader):
|
class pyBackboneStretcherShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Stretches the stroke's backbone by a given length (in pixels)
|
Stretches the stroke's backbone by a given length (in pixels).
|
||||||
"""
|
"""
|
||||||
def __init__(self, l):
|
def __init__(self, l):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -617,7 +617,7 @@ class pyGuidingLineShader(StrokeShader):
|
|||||||
|
|
||||||
class pyBackboneStretcherNoCuspShader(StrokeShader):
|
class pyBackboneStretcherNoCuspShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Stretches the stroke's backbone, excluding cusp vertices (end junctions)
|
Stretches the stroke's backbone, excluding cusp vertices (end junctions).
|
||||||
"""
|
"""
|
||||||
def __init__(self, l):
|
def __init__(self, l):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -663,7 +663,7 @@ class pyDiffusion2Shader(StrokeShader):
|
|||||||
|
|
||||||
class pyTipRemoverShader(StrokeShader):
|
class pyTipRemoverShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Removes the tips of the stroke
|
Removes the tips of the stroke.
|
||||||
"""
|
"""
|
||||||
def __init__(self, l):
|
def __init__(self, l):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -704,7 +704,7 @@ class pyTipRemoverShader(StrokeShader):
|
|||||||
|
|
||||||
class pyTVertexRemoverShader(StrokeShader):
|
class pyTVertexRemoverShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Removes t-vertices from the stroke
|
Removes t-vertices from the stroke.
|
||||||
"""
|
"""
|
||||||
def shade(self, stroke):
|
def shade(self, stroke):
|
||||||
if len(stroke) < 4:
|
if len(stroke) < 4:
|
||||||
@@ -721,7 +721,7 @@ class pyTVertexRemoverShader(StrokeShader):
|
|||||||
class pyHLRShader(StrokeShader):
|
class pyHLRShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Controlls visibility based upon the quantative invisibility (QI)
|
Controlls visibility based upon the quantative invisibility (QI)
|
||||||
based on hidden line removal (HLR)
|
based on hidden line removal (HLR).
|
||||||
"""
|
"""
|
||||||
def shade(self, stroke):
|
def shade(self, stroke):
|
||||||
if len(stroke) < 4:
|
if len(stroke) < 4:
|
||||||
@@ -736,7 +736,7 @@ class pyHLRShader(StrokeShader):
|
|||||||
|
|
||||||
class pySinusDisplacementShader(StrokeShader):
|
class pySinusDisplacementShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Displaces the stroke in the shape of a sine wave
|
Displaces the stroke in the shape of a sine wave.
|
||||||
"""
|
"""
|
||||||
def __init__(self, f, a):
|
def __init__(self, f, a):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -758,7 +758,7 @@ class pyPerlinNoise1DShader(StrokeShader):
|
|||||||
"""
|
"""
|
||||||
Displaces the stroke using the curvilinear abscissa. This means
|
Displaces the stroke using the curvilinear abscissa. This means
|
||||||
that lines with the same length and sampling interval will be
|
that lines with the same length and sampling interval will be
|
||||||
identically distorded
|
identically distorded.
|
||||||
"""
|
"""
|
||||||
def __init__(self, freq=10, amp=10, oct=4, seed=-1):
|
def __init__(self, freq=10, amp=10, oct=4, seed=-1):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -778,9 +778,9 @@ class pyPerlinNoise1DShader(StrokeShader):
|
|||||||
class pyPerlinNoise2DShader(StrokeShader):
|
class pyPerlinNoise2DShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Displaces the stroke using the strokes coordinates. This means
|
Displaces the stroke using the strokes coordinates. This means
|
||||||
that in a scene no strokes will be distorded identically
|
that in a scene no strokes will be distorded identically.
|
||||||
|
|
||||||
More information on the noise shaders can be found at
|
More information on the noise shaders can be found at:
|
||||||
freestyleintegration.wordpress.com/2011/09/25/development-updates-on-september-25/
|
freestyleintegration.wordpress.com/2011/09/25/development-updates-on-september-25/
|
||||||
"""
|
"""
|
||||||
def __init__(self, freq=10, amp=10, oct=4, seed=-1):
|
def __init__(self, freq=10, amp=10, oct=4, seed=-1):
|
||||||
@@ -799,7 +799,7 @@ class pyPerlinNoise2DShader(StrokeShader):
|
|||||||
|
|
||||||
class pyBluePrintCirclesShader(StrokeShader):
|
class pyBluePrintCirclesShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Draws the silhouette of the object as a circle
|
Draws the silhouette of the object as a circle.
|
||||||
"""
|
"""
|
||||||
def __init__(self, turns=1, random_radius=3, random_center=5):
|
def __init__(self, turns=1, random_radius=3, random_center=5):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -983,7 +983,7 @@ class pyBluePrintSquaresShader(StrokeShader):
|
|||||||
|
|
||||||
class pyBluePrintDirectedSquaresShader(StrokeShader):
|
class pyBluePrintDirectedSquaresShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Replaces the stroke with a directed square
|
Replaces the stroke with a directed square.
|
||||||
"""
|
"""
|
||||||
def __init__(self, turns=1, bb_len=10, mult=1):
|
def __init__(self, turns=1, bb_len=10, mult=1):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
# ##### END GPL LICENSE BLOCK #####
|
# ##### END GPL LICENSE BLOCK #####
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Submodule containing all Freestyle types
|
Submodule containing all Freestyle types.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# module members
|
# module members
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
# ##### END GPL LICENSE BLOCK #####
|
# ##### END GPL LICENSE BLOCK #####
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Helper functions used for Freestyle style module writing
|
Helper functions used for Freestyle style module writing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# module members
|
# module members
|
||||||
@@ -43,12 +43,12 @@ from itertools import tee
|
|||||||
# -- real utility functions -- #
|
# -- real utility functions -- #
|
||||||
|
|
||||||
def rgb_to_bw(r, g, b):
|
def rgb_to_bw(r, g, b):
|
||||||
""" Method to convert rgb to a bw intensity value. """
|
"""Method to convert rgb to a bw intensity value."""
|
||||||
return 0.35 * r + 0.45 * g + 0.2 * b
|
return 0.35 * r + 0.45 * g + 0.2 * b
|
||||||
|
|
||||||
|
|
||||||
def bound(lower, x, higher):
|
def bound(lower, x, higher):
|
||||||
""" Returns x bounded by a maximum and minimum value. equivalent to:
|
"""Returns x bounded by a maximum and minimum value. Equivalent to:
|
||||||
return min(max(x, lower), higher)
|
return min(max(x, lower), higher)
|
||||||
"""
|
"""
|
||||||
# this is about 50% quicker than min(max(x, lower), higher)
|
# this is about 50% quicker than min(max(x, lower), higher)
|
||||||
@@ -78,14 +78,14 @@ def phase_to_direction(length):
|
|||||||
results.append((phase, Vector((cos(2 * pi * phase), sin(2 * pi * phase)))))
|
results.append((phase, Vector((cos(2 * pi * phase), sin(2 * pi * phase)))))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
# A named tuple primitive used for storing data that
|
# A named tuple primitive used for storing data that has an upper and
|
||||||
# has an upper and lower bound (eg. thickness, range and certain values)
|
# lower bound (e.g., thickness, range and certain values)
|
||||||
BoundedProperty = namedtuple("BoundedProperty", ["min", "max", "delta"])
|
BoundedProperty = namedtuple("BoundedProperty", ["min", "max", "delta"])
|
||||||
|
|
||||||
# -- helper functions for chaining -- #
|
# -- helper functions for chaining -- #
|
||||||
|
|
||||||
def get_chain_length(ve, orientation):
|
def get_chain_length(ve, orientation):
|
||||||
"""Returns the 2d length of a given ViewEdge """
|
"""Returns the 2d length of a given ViewEdge."""
|
||||||
from freestyle.chainingiterators import pyChainSilhouetteGenericIterator
|
from freestyle.chainingiterators import pyChainSilhouetteGenericIterator
|
||||||
length = 0.0
|
length = 0.0
|
||||||
# setup iterator
|
# setup iterator
|
||||||
@@ -120,7 +120,7 @@ def get_chain_length(ve, orientation):
|
|||||||
|
|
||||||
|
|
||||||
def find_matching_vertex(id, it):
|
def find_matching_vertex(id, it):
|
||||||
"""Finds the matching vertex, or returns None """
|
"""Finds the matching vertex, or returns None."""
|
||||||
return next((ve for ve in it if ve.id == id), None)
|
return next((ve for ve in it if ve.id == id), None)
|
||||||
|
|
||||||
# -- helper functions for iterating -- #
|
# -- helper functions for iterating -- #
|
||||||
@@ -146,7 +146,7 @@ def tripplewise(iterable):
|
|||||||
|
|
||||||
|
|
||||||
def iter_t2d_along_stroke(stroke):
|
def iter_t2d_along_stroke(stroke):
|
||||||
""" Yields the progress along the stroke """
|
"""Yields the progress along the stroke."""
|
||||||
total = stroke.length_2d
|
total = stroke.length_2d
|
||||||
distance = 0.0
|
distance = 0.0
|
||||||
# yield for the comparison from the first vertex to itself
|
# yield for the comparison from the first vertex to itself
|
||||||
@@ -186,7 +186,7 @@ def iter_distance_from_object(stroke, location, range_min, range_max, normfac):
|
|||||||
|
|
||||||
|
|
||||||
def iter_material_value(stroke, func, attribute):
|
def iter_material_value(stroke, func, attribute):
|
||||||
"Yields a specific material attribute from the vertex' underlying material. "
|
"Yields a specific material attribute from the vertex' underlying material."
|
||||||
it = Interface0DIterator(stroke)
|
it = Interface0DIterator(stroke)
|
||||||
for svert in it:
|
for svert in it:
|
||||||
material = func(it)
|
material = func(it)
|
||||||
|
@@ -109,7 +109,7 @@ from itertools import cycle, tee
|
|||||||
|
|
||||||
|
|
||||||
class ColorRampModifier(StrokeShader):
|
class ColorRampModifier(StrokeShader):
|
||||||
"""Primitive for the color modifiers """
|
"""Primitive for the color modifiers."""
|
||||||
def __init__(self, blend, influence, ramp):
|
def __init__(self, blend, influence, ramp):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
self.blend = blend
|
self.blend = blend
|
||||||
@@ -125,7 +125,7 @@ class ColorRampModifier(StrokeShader):
|
|||||||
|
|
||||||
|
|
||||||
class ScalarBlendModifier(StrokeShader):
|
class ScalarBlendModifier(StrokeShader):
|
||||||
"""Primitive for alpha and thickness modifiers """
|
"""Primitive for alpha and thickness modifiers."""
|
||||||
def __init__(self, blend_type, influence):
|
def __init__(self, blend_type, influence):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
self.blend_type = blend_type
|
self.blend_type = blend_type
|
||||||
@@ -201,7 +201,7 @@ class ThicknessBlenderMixIn(ThicknessModifierMixIn):
|
|||||||
self.ratio = ratio
|
self.ratio = ratio
|
||||||
|
|
||||||
def blend_thickness(self, svert, v):
|
def blend_thickness(self, svert, v):
|
||||||
""" Blends and sets the thickness."""
|
"""Blends and sets the thickness."""
|
||||||
outer, inner = svert.attribute.thickness
|
outer, inner = svert.attribute.thickness
|
||||||
fe = svert.fedge
|
fe = svert.fedge
|
||||||
v = self.blend(outer + inner, v)
|
v = self.blend(outer + inner, v)
|
||||||
@@ -262,7 +262,7 @@ class BaseThicknessShader(StrokeShader, ThicknessModifierMixIn):
|
|||||||
# Along Stroke modifiers
|
# Along Stroke modifiers
|
||||||
|
|
||||||
class ColorAlongStrokeShader(ColorRampModifier):
|
class ColorAlongStrokeShader(ColorRampModifier):
|
||||||
"""Maps a ramp to the color of the stroke, using the curvilinear abscissa (t) """
|
"""Maps a ramp to the color of the stroke, using the curvilinear abscissa (t)."""
|
||||||
def shade(self, stroke):
|
def shade(self, stroke):
|
||||||
for svert, t in zip(stroke, iter_t2d_along_stroke(stroke)):
|
for svert, t in zip(stroke, iter_t2d_along_stroke(stroke)):
|
||||||
a = svert.attribute.color
|
a = svert.attribute.color
|
||||||
@@ -271,7 +271,7 @@ class ColorAlongStrokeShader(ColorRampModifier):
|
|||||||
|
|
||||||
|
|
||||||
class AlphaAlongStrokeShader(CurveMappingModifier):
|
class AlphaAlongStrokeShader(CurveMappingModifier):
|
||||||
"""Maps a curve to the alpha/transparancy of the stroke, using the curvilinear abscissa (t) """
|
"""Maps a curve to the alpha/transparancy of the stroke, using the curvilinear abscissa (t)."""
|
||||||
def shade(self, stroke):
|
def shade(self, stroke):
|
||||||
for svert, t in zip(stroke, iter_t2d_along_stroke(stroke)):
|
for svert, t in zip(stroke, iter_t2d_along_stroke(stroke)):
|
||||||
a = svert.attribute.alpha
|
a = svert.attribute.alpha
|
||||||
@@ -280,7 +280,7 @@ class AlphaAlongStrokeShader(CurveMappingModifier):
|
|||||||
|
|
||||||
|
|
||||||
class ThicknessAlongStrokeShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
class ThicknessAlongStrokeShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
||||||
"""Maps a curve to the thickness of the stroke, using the curvilinear abscissa (t) """
|
"""Maps a curve to the thickness of the stroke, using the curvilinear abscissa (t)."""
|
||||||
def __init__(self, thickness_position, thickness_ratio,
|
def __init__(self, thickness_position, thickness_ratio,
|
||||||
blend, influence, mapping, invert, curve, value_min, value_max):
|
blend, influence, mapping, invert, curve, value_min, value_max):
|
||||||
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
||||||
@@ -296,7 +296,7 @@ class ThicknessAlongStrokeShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
|||||||
# -- Distance from Camera modifiers -- #
|
# -- Distance from Camera modifiers -- #
|
||||||
|
|
||||||
class ColorDistanceFromCameraShader(ColorRampModifier):
|
class ColorDistanceFromCameraShader(ColorRampModifier):
|
||||||
"""Picks a color value from a ramp based on the vertex' distance from the camera """
|
"""Picks a color value from a ramp based on the vertex' distance from the camera."""
|
||||||
def __init__(self, blend, influence, ramp, range_min, range_max):
|
def __init__(self, blend, influence, ramp, range_min, range_max):
|
||||||
ColorRampModifier.__init__(self, blend, influence, ramp)
|
ColorRampModifier.__init__(self, blend, influence, ramp)
|
||||||
self.range = BoundedProperty(range_min, range_max, range_max - range_min)
|
self.range = BoundedProperty(range_min, range_max, range_max - range_min)
|
||||||
@@ -310,7 +310,7 @@ class ColorDistanceFromCameraShader(ColorRampModifier):
|
|||||||
|
|
||||||
|
|
||||||
class AlphaDistanceFromCameraShader(CurveMappingModifier):
|
class AlphaDistanceFromCameraShader(CurveMappingModifier):
|
||||||
"""Picks an alpha value from a curve based on the vertex' distance from the camera """
|
"""Picks an alpha value from a curve based on the vertex' distance from the camera"""
|
||||||
def __init__(self, blend, influence, mapping, invert, curve, range_min, range_max):
|
def __init__(self, blend, influence, mapping, invert, curve, range_min, range_max):
|
||||||
CurveMappingModifier.__init__(self, blend, influence, mapping, invert, curve)
|
CurveMappingModifier.__init__(self, blend, influence, mapping, invert, curve)
|
||||||
self.range = BoundedProperty(range_min, range_max, range_max - range_min)
|
self.range = BoundedProperty(range_min, range_max, range_max - range_min)
|
||||||
@@ -324,7 +324,7 @@ class AlphaDistanceFromCameraShader(CurveMappingModifier):
|
|||||||
|
|
||||||
|
|
||||||
class ThicknessDistanceFromCameraShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
class ThicknessDistanceFromCameraShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
||||||
"""Picks a thickness value from a curve based on the vertex' distance from the camera """
|
"""Picks a thickness value from a curve based on the vertex' distance from the camera."""
|
||||||
def __init__(self, thickness_position, thickness_ratio,
|
def __init__(self, thickness_position, thickness_ratio,
|
||||||
blend, influence, mapping, invert, curve, range_min, range_max, value_min, value_max):
|
blend, influence, mapping, invert, curve, range_min, range_max, value_min, value_max):
|
||||||
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
||||||
@@ -341,7 +341,7 @@ class ThicknessDistanceFromCameraShader(ThicknessBlenderMixIn, CurveMappingModif
|
|||||||
# Distance from Object modifiers
|
# Distance from Object modifiers
|
||||||
|
|
||||||
class ColorDistanceFromObjectShader(ColorRampModifier):
|
class ColorDistanceFromObjectShader(ColorRampModifier):
|
||||||
"""Picks a color value from a ramp based on the vertex' distance from a given object """
|
"""Picks a color value from a ramp based on the vertex' distance from a given object."""
|
||||||
def __init__(self, blend, influence, ramp, target, range_min, range_max):
|
def __init__(self, blend, influence, ramp, target, range_min, range_max):
|
||||||
ColorRampModifier.__init__(self, blend, influence, ramp)
|
ColorRampModifier.__init__(self, blend, influence, ramp)
|
||||||
if target is None:
|
if target is None:
|
||||||
@@ -361,7 +361,7 @@ class ColorDistanceFromObjectShader(ColorRampModifier):
|
|||||||
|
|
||||||
|
|
||||||
class AlphaDistanceFromObjectShader(CurveMappingModifier):
|
class AlphaDistanceFromObjectShader(CurveMappingModifier):
|
||||||
"""Picks an alpha value from a curve based on the vertex' distance from a given object """
|
"""Picks an alpha value from a curve based on the vertex' distance from a given object."""
|
||||||
def __init__(self, blend, influence, mapping, invert, curve, target, range_min, range_max):
|
def __init__(self, blend, influence, mapping, invert, curve, target, range_min, range_max):
|
||||||
CurveMappingModifier.__init__(self, blend, influence, mapping, invert, curve)
|
CurveMappingModifier.__init__(self, blend, influence, mapping, invert, curve)
|
||||||
if target is None:
|
if target is None:
|
||||||
@@ -381,7 +381,7 @@ class AlphaDistanceFromObjectShader(CurveMappingModifier):
|
|||||||
|
|
||||||
|
|
||||||
class ThicknessDistanceFromObjectShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
class ThicknessDistanceFromObjectShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
||||||
"""Picks a thickness value from a curve based on the vertex' distance from a given object """
|
"""Picks a thickness value from a curve based on the vertex' distance from a given object."""
|
||||||
def __init__(self, thickness_position, thickness_ratio,
|
def __init__(self, thickness_position, thickness_ratio,
|
||||||
blend, influence, mapping, invert, curve, target, range_min, range_max, value_min, value_max):
|
blend, influence, mapping, invert, curve, target, range_min, range_max, value_min, value_max):
|
||||||
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
||||||
@@ -403,7 +403,7 @@ class ThicknessDistanceFromObjectShader(ThicknessBlenderMixIn, CurveMappingModif
|
|||||||
|
|
||||||
# Material modifiers
|
# Material modifiers
|
||||||
class ColorMaterialShader(ColorRampModifier):
|
class ColorMaterialShader(ColorRampModifier):
|
||||||
""" Assigns a color to the vertices based on their underlying material """
|
"""Assigns a color to the vertices based on their underlying material."""
|
||||||
def __init__(self, blend, influence, ramp, material_attribute, use_ramp):
|
def __init__(self, blend, influence, ramp, material_attribute, use_ramp):
|
||||||
ColorRampModifier.__init__(self, blend, influence, ramp)
|
ColorRampModifier.__init__(self, blend, influence, ramp)
|
||||||
self.attribute = material_attribute
|
self.attribute = material_attribute
|
||||||
@@ -430,7 +430,7 @@ class ColorMaterialShader(ColorRampModifier):
|
|||||||
svert.attribute.color = self.blend_ramp(a, b)
|
svert.attribute.color = self.blend_ramp(a, b)
|
||||||
|
|
||||||
class AlphaMaterialShader(CurveMappingModifier):
|
class AlphaMaterialShader(CurveMappingModifier):
|
||||||
""" Assigns an alpha value to the vertices based on their underlying material """
|
"""Assigns an alpha value to the vertices based on their underlying material."""
|
||||||
def __init__(self, blend, influence, mapping, invert, curve, material_attribute):
|
def __init__(self, blend, influence, mapping, invert, curve, material_attribute):
|
||||||
CurveMappingModifier.__init__(self, blend, influence, mapping, invert, curve)
|
CurveMappingModifier.__init__(self, blend, influence, mapping, invert, curve)
|
||||||
self.attribute = material_attribute
|
self.attribute = material_attribute
|
||||||
@@ -444,7 +444,7 @@ class AlphaMaterialShader(CurveMappingModifier):
|
|||||||
|
|
||||||
|
|
||||||
class ThicknessMaterialShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
class ThicknessMaterialShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
||||||
""" Assigns a thickness value to the vertices based on their underlying material """
|
"""Assigns a thickness value to the vertices based on their underlying material."""
|
||||||
def __init__(self, thickness_position, thickness_ratio,
|
def __init__(self, thickness_position, thickness_ratio,
|
||||||
blend, influence, mapping, invert, curve, material_attribute, value_min, value_max):
|
blend, influence, mapping, invert, curve, material_attribute, value_min, value_max):
|
||||||
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
||||||
@@ -463,7 +463,7 @@ class ThicknessMaterialShader(ThicknessBlenderMixIn, CurveMappingModifier):
|
|||||||
|
|
||||||
|
|
||||||
class CalligraphicThicknessShader(ThicknessBlenderMixIn, ScalarBlendModifier):
|
class CalligraphicThicknessShader(ThicknessBlenderMixIn, ScalarBlendModifier):
|
||||||
"""Thickness modifier for achieving a calligraphy-like effect """
|
"""Thickness modifier for achieving a calligraphy-like effect."""
|
||||||
def __init__(self, thickness_position, thickness_ratio,
|
def __init__(self, thickness_position, thickness_ratio,
|
||||||
blend_type, influence, orientation, thickness_min, thickness_max):
|
blend_type, influence, orientation, thickness_min, thickness_max):
|
||||||
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
ThicknessBlenderMixIn.__init__(self, thickness_position, thickness_ratio)
|
||||||
@@ -488,7 +488,7 @@ class CalligraphicThicknessShader(ThicknessBlenderMixIn, ScalarBlendModifier):
|
|||||||
# Geometry modifiers
|
# Geometry modifiers
|
||||||
|
|
||||||
class SinusDisplacementShader(StrokeShader):
|
class SinusDisplacementShader(StrokeShader):
|
||||||
"""Displaces the stroke in a sinewave-like shape """
|
"""Displaces the stroke in a sinewave-like shape."""
|
||||||
def __init__(self, wavelength, amplitude, phase):
|
def __init__(self, wavelength, amplitude, phase):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
self.wavelength = wavelength
|
self.wavelength = wavelength
|
||||||
@@ -510,7 +510,7 @@ class PerlinNoise1DShader(StrokeShader):
|
|||||||
"""
|
"""
|
||||||
Displaces the stroke using the curvilinear abscissa. This means
|
Displaces the stroke using the curvilinear abscissa. This means
|
||||||
that lines with the same length and sampling interval will be
|
that lines with the same length and sampling interval will be
|
||||||
identically distorded
|
identically distorded.
|
||||||
"""
|
"""
|
||||||
def __init__(self, freq=10, amp=10, oct=4, angle=radians(45), seed=-1):
|
def __init__(self, freq=10, amp=10, oct=4, angle=radians(45), seed=-1):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
@@ -531,9 +531,9 @@ class PerlinNoise1DShader(StrokeShader):
|
|||||||
class PerlinNoise2DShader(StrokeShader):
|
class PerlinNoise2DShader(StrokeShader):
|
||||||
"""
|
"""
|
||||||
Displaces the stroke using the strokes coordinates. This means
|
Displaces the stroke using the strokes coordinates. This means
|
||||||
that in a scene no strokes will be distorded identically
|
that in a scene no strokes will be distorded identically.
|
||||||
|
|
||||||
More information on the noise shaders can be found at
|
More information on the noise shaders can be found at:
|
||||||
freestyleintegration.wordpress.com/2011/09/25/development-updates-on-september-25/
|
freestyleintegration.wordpress.com/2011/09/25/development-updates-on-september-25/
|
||||||
"""
|
"""
|
||||||
def __init__(self, freq=10, amp=10, oct=4, angle=radians(45), seed=-1):
|
def __init__(self, freq=10, amp=10, oct=4, angle=radians(45), seed=-1):
|
||||||
@@ -553,7 +553,7 @@ class PerlinNoise2DShader(StrokeShader):
|
|||||||
|
|
||||||
|
|
||||||
class Offset2DShader(StrokeShader):
|
class Offset2DShader(StrokeShader):
|
||||||
"""Offsets the stroke by a given amount """
|
"""Offsets the stroke by a given amount."""
|
||||||
def __init__(self, start, end, x, y):
|
def __init__(self, start, end, x, y):
|
||||||
StrokeShader.__init__(self)
|
StrokeShader.__init__(self)
|
||||||
self.start = start
|
self.start = start
|
||||||
|
Reference in New Issue
Block a user