diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-04-11 10:16:03 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-04-11 10:16:46 +0400 |
commit | 716803c0a0cc99cb30b4caee0364239889cf82e8 (patch) | |
tree | 7168ed8204abf91b2ddca5a92e2e8c6d62c41624 /release/scripts/freestyle/modules/parameter_editor.py | |
parent | 88298f1c40c2d3d504ee5d441628c0a42b74ec1a (diff) |
Fix for Sinus Displacement and 2D Offset stroke geometry modifiers.
These modifiers were not working properly when they were applied to strokes
whose backbone was already modified by other geometry shaders. This problem
was due to the use of Normal2DF0D that compute 2D vertex normals based on
the underlying FEdges up on which initial stroke geometry is defined. Now vertex
normals are computed on the basis of modified stroke vertices.
A helper function 'stroke_normal' for computing normals of stroke vertices was
added to the 'freestyle.utils' API module.
Diffstat (limited to 'release/scripts/freestyle/modules/parameter_editor.py')
-rw-r--r-- | release/scripts/freestyle/modules/parameter_editor.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/release/scripts/freestyle/modules/parameter_editor.py b/release/scripts/freestyle/modules/parameter_editor.py index f3dd66b78cc..ce15028d0d7 100644 --- a/release/scripts/freestyle/modules/parameter_editor.py +++ b/release/scripts/freestyle/modules/parameter_editor.py @@ -76,6 +76,7 @@ from freestyle.shaders import ( from freestyle.utils import ( ContextFunctions, getCurrentScene, + stroke_normal, ) from _freestyle import ( blendRamp, @@ -582,13 +583,15 @@ class SinusDisplacementShader(StrokeShader): self._wavelength = wavelength self._amplitude = amplitude self._phase = phase / wavelength * 2 * math.pi - self._getNormal = Normal2DF0D() def shade(self, stroke): + # separately iterate over stroke vertices to compute normals + buf = [] for it, distance in iter_distance_along_stroke(stroke): - v = it.object - n = self._getNormal(Interface0DIterator(it)) - n = n * self._amplitude * math.cos(distance / self._wavelength * 2 * math.pi + self._phase) + buf.append((it.object, distance, stroke_normal(it))) + # iterate over the vertices again to displace them + for v, distance, normal in buf: + n = normal * self._amplitude * math.cos(distance / self._wavelength * 2 * math.pi + self._phase) v.point = v.point + n stroke.update_length() @@ -639,18 +642,19 @@ class Offset2DShader(StrokeShader): self.__start = start self.__end = end self.__xy = mathutils.Vector((x, y)) - self.__getNormal = Normal2DF0D() def shade(self, stroke): + # first iterate over stroke vertices to compute normals + buf = [] it = stroke.stroke_vertices_begin() while not it.is_end: - v = it.object - u = v.u - a = self.__start + u * (self.__end - self.__start) - n = self.__getNormal(Interface0DIterator(it)) + buf.append((it.object, stroke_normal(it))) + it.increment() + # again iterate over the vertices to add displacement + for v, n in buf: + a = self.__start + v.u * (self.__end - self.__start) n = n * a v.point = v.point + n + self.__xy - it.increment() stroke.update_length() |