Fix for dashed line options not working as expected in some applications

when combined with geometry modifiers.

The problem is that users were not able to choose the time when the
dashed line options are applied.  Instead, the dashed line options were
applied only before geometry modifiers were employed.  Since dashes were
separate strokes, the geometry modifiers were processed dash by dash.
Depending on users' artistic intention, this may or may not lead to
expected stylization results, as reported by octane98 in the
BlenderArtists Freestyle thread on January 3, 2012.
http://blenderartists.org/forum/showthread.php?89986-Freestyle-for-Blender&p=2018592&viewfull=1#post2018592

Now the Strokes tab of the Freestyle Line Style panel has two sets of
dashed line options.  One is in the Splitting section of the Strokes tab
and used for splitting strokes by dashed line patterns.  The other set
is called "Dashed Line" and used to generate dashed lines based on the
strokes after the geometry modifiers are applied.  The two sets of
dashed line options are independent of each other, so that users can
enable one of them as well as both at the same time.
This commit is contained in:
2012-11-04 23:52:26 +00:00
parent a9055460a9
commit dd633f1aff
4 changed files with 129 additions and 28 deletions

View File

@@ -762,6 +762,8 @@ class RoundCapShader(StrokeShader):
r = self.round_cap_thickness((nverts_end - i + 1) * n)
stroke[-i-1].setAttribute(attr)
stroke[-i-1].attribute().setThickness(R * r, L * r)
# update the curvilinear 2D length of each vertex
stroke.UpdateLength()
class SquareCapShader(StrokeShader):
def shade(self, stroke):
@@ -798,24 +800,26 @@ class SquareCapShader(StrokeShader):
d = p - q
stroke[-1].setPoint(p + d / d.length * caplen_beg)
stroke[-1].setAttribute(attr)
# update the curvilinear 2D length of each vertex
stroke.UpdateLength()
# dashed line
# Split by dashed line pattern
class DashedLineStartingUP0D(UnaryPredicate0D):
class SplitPatternStartingUP0D(UnaryPredicate0D):
def __init__(self, controller):
UnaryPredicate0D.__init__(self)
self._controller = controller
def __call__(self, inter):
return self._controller.start()
class DashedLineStoppingUP0D(UnaryPredicate0D):
class SplitPatternStoppingUP0D(UnaryPredicate0D):
def __init__(self, controller):
UnaryPredicate0D.__init__(self)
self._controller = controller
def __call__(self, inter):
return self._controller.stop()
class DashedLineController:
class SplitPatternController:
def __init__(self, pattern, sampling):
self.sampling = float(sampling)
k = len(pattern) // 2
@@ -845,6 +849,35 @@ class DashedLineController:
return True
return False
# Dashed line
class DashedLineShader(StrokeShader):
def __init__(self, pattern):
StrokeShader.__init__(self)
self._pattern = pattern
def getName(self):
return "DashedLineShader"
def shade(self, stroke):
index = 0 # pattern index
start = 0.0 # 2D curvilinear length
visible = True
sampling = 1.0
it = stroke.strokeVerticesBegin(sampling)
while not it.isEnd():
pos = it.t()
# The extra 'sampling' term is added below, because the
# visibility attribute of the i-th vertex refers to the
# visibility of the stroke segment between the i-th and
# (i+1)-th vertices.
if pos - start + sampling > self._pattern[index]:
start = pos
index += 1
if index == len(self._pattern):
index = 0
visible = not visible
it.getObject().attribute().setVisible(visible)
it.increment()
# predicates for chaining
class AngleLargerThanBP1D(BinaryPredicate1D):
@@ -1117,29 +1150,28 @@ def process(layer_name, lineset_name):
Operators.sequentialSplit(Curvature2DAngleThresholdUP0D(min_angle, max_angle))
if linestyle.use_split_length:
Operators.sequentialSplit(Length2DThresholdUP0D(linestyle.split_length), 1.0)
if linestyle.use_split_pattern:
pattern = []
if linestyle.split_dash1 > 0 and linestyle.split_gap1 > 0:
pattern.append(linestyle.split_dash1)
pattern.append(linestyle.split_gap1)
if linestyle.split_dash2 > 0 and linestyle.split_gap2 > 0:
pattern.append(linestyle.split_dash2)
pattern.append(linestyle.split_gap2)
if linestyle.split_dash3 > 0 and linestyle.split_gap3 > 0:
pattern.append(linestyle.split_dash3)
pattern.append(linestyle.split_gap3)
if len(pattern) > 0:
sampling = 1.0
controller = SplitPatternController(pattern, sampling)
Operators.sequentialSplit(SplitPatternStartingUP0D(controller),
SplitPatternStoppingUP0D(controller),
sampling)
# select chains
if linestyle.use_min_length or linestyle.use_max_length:
min_length = linestyle.min_length if linestyle.use_min_length else None
max_length = linestyle.max_length if linestyle.use_max_length else None
Operators.select(LengthThresholdUP1D(min_length, max_length))
# dashed line
if linestyle.use_dashed_line:
pattern = []
if linestyle.dash1 > 0 and linestyle.gap1 > 0:
pattern.append(linestyle.dash1)
pattern.append(linestyle.gap1)
if linestyle.dash2 > 0 and linestyle.gap2 > 0:
pattern.append(linestyle.dash2)
pattern.append(linestyle.gap2)
if linestyle.dash3 > 0 and linestyle.gap3 > 0:
pattern.append(linestyle.dash3)
pattern.append(linestyle.gap3)
if len(pattern) > 0:
sampling = 1.0
controller = DashedLineController(pattern, sampling)
Operators.sequentialSplit(DashedLineStartingUP0D(controller),
DashedLineStoppingUP0D(controller),
sampling)
# prepare a list of stroke shaders
shaders_list = []
for m in linestyle.geometry_modifiers:
@@ -1269,5 +1301,18 @@ def process(layer_name, lineset_name):
shaders_list.append(RoundCapShader())
elif linestyle.caps == "SQUARE":
shaders_list.append(SquareCapShader())
if linestyle.use_dashed_line:
pattern = []
if linestyle.dash1 > 0 and linestyle.gap1 > 0:
pattern.append(linestyle.dash1)
pattern.append(linestyle.gap1)
if linestyle.dash2 > 0 and linestyle.gap2 > 0:
pattern.append(linestyle.dash2)
pattern.append(linestyle.gap2)
if linestyle.dash3 > 0 and linestyle.gap3 > 0:
pattern.append(linestyle.dash3)
pattern.append(linestyle.gap3)
if len(pattern) > 0:
shaders_list.append(DashedLineShader(pattern))
# create strokes using the shaders list
Operators.create(TrueUP1D(), shaders_list)