Added support for dashed line in the Parameter Editor mode.
This commit is contained in:
@@ -392,6 +392,52 @@ class SquareCapShader(StrokeShader):
|
|||||||
stroke[-1].setPoint(p + d / d.length * caplen_beg)
|
stroke[-1].setPoint(p + d / d.length * caplen_beg)
|
||||||
stroke[-1].setAttribute(attr)
|
stroke[-1].setAttribute(attr)
|
||||||
|
|
||||||
|
# dashed line
|
||||||
|
|
||||||
|
class DashedLineStartingUP0D(UnaryPredicate0D):
|
||||||
|
def __init__(self, controller):
|
||||||
|
UnaryPredicate0D.__init__(self)
|
||||||
|
self._controller = controller
|
||||||
|
def __call__(self, inter):
|
||||||
|
return self._controller.start()
|
||||||
|
|
||||||
|
class DashedLineStoppingUP0D(UnaryPredicate0D):
|
||||||
|
def __init__(self, controller):
|
||||||
|
UnaryPredicate0D.__init__(self)
|
||||||
|
self._controller = controller
|
||||||
|
def __call__(self, inter):
|
||||||
|
return self._controller.stop()
|
||||||
|
|
||||||
|
class DashedLineController:
|
||||||
|
def __init__(self, pattern, sampling):
|
||||||
|
self.sampling = float(sampling)
|
||||||
|
k = len(pattern) // 2
|
||||||
|
n = k * 2
|
||||||
|
self.start_pos = [pattern[i] + pattern[i+1] for i in range(0, n, 2)]
|
||||||
|
self.stop_pos = [pattern[i] for i in range(0, n, 2)]
|
||||||
|
self.init()
|
||||||
|
def init(self):
|
||||||
|
self.start_len = 0.0
|
||||||
|
self.start_idx = 0
|
||||||
|
self.stop_len = self.sampling
|
||||||
|
self.stop_idx = 0
|
||||||
|
def start(self):
|
||||||
|
self.start_len += self.sampling
|
||||||
|
if abs(self.start_len - self.start_pos[self.start_idx]) < self.sampling / 2.0:
|
||||||
|
self.start_len = 0.0
|
||||||
|
self.start_idx = (self.start_idx + 1) % len(self.start_pos)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
def stop(self):
|
||||||
|
if self.start_len > 0.0:
|
||||||
|
self.init()
|
||||||
|
self.stop_len += self.sampling
|
||||||
|
if abs(self.stop_len - self.stop_pos[self.stop_idx]) < self.sampling / 2.0:
|
||||||
|
self.stop_len = self.sampling
|
||||||
|
self.stop_idx = (self.stop_idx + 1) % len(self.stop_pos)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
# main function for parameter processing
|
# main function for parameter processing
|
||||||
|
|
||||||
def process(layer_name, lineset_name):
|
def process(layer_name, lineset_name):
|
||||||
@@ -472,6 +518,24 @@ def process(layer_name, lineset_name):
|
|||||||
else:
|
else:
|
||||||
chaining_iterator = ChainSilhouetteIterator()
|
chaining_iterator = ChainSilhouetteIterator()
|
||||||
Operators.bidirectionalChain(chaining_iterator, NotUP1D(upred))
|
Operators.bidirectionalChain(chaining_iterator, NotUP1D(upred))
|
||||||
|
# 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
|
# prepare a list of stroke shaders
|
||||||
color = linestyle.color
|
color = linestyle.color
|
||||||
shaders_list = [
|
shaders_list = [
|
||||||
|
|||||||
@@ -412,9 +412,32 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, bpy.types.Panel):
|
|||||||
elif linestyle.panel == "STROKES":
|
elif linestyle.panel == "STROKES":
|
||||||
col.label(text="Chaining:")
|
col.label(text="Chaining:")
|
||||||
col.prop(linestyle, "same_object")
|
col.prop(linestyle, "same_object")
|
||||||
|
col.separator()
|
||||||
col.label(text="Caps:")
|
col.label(text="Caps:")
|
||||||
sub = col.row(align=True)
|
sub = col.row(align=True)
|
||||||
sub.prop(linestyle, "caps", expand=True)
|
sub.prop(linestyle, "caps", expand=True)
|
||||||
|
col.separator()
|
||||||
|
col.prop(linestyle, "use_dashed_line")
|
||||||
|
sub = col.row()
|
||||||
|
sub.enabled = linestyle.use_dashed_line
|
||||||
|
subsub = sub.column()
|
||||||
|
subsub.label(text="Dash")
|
||||||
|
subsub.prop(linestyle, "dash1", text="")
|
||||||
|
subsub = sub.column()
|
||||||
|
subsub.label(text="Gap")
|
||||||
|
subsub.prop(linestyle, "gap1", text="")
|
||||||
|
subsub = sub.column()
|
||||||
|
subsub.label(text="Dash")
|
||||||
|
subsub.prop(linestyle, "dash2", text="")
|
||||||
|
subsub = sub.column()
|
||||||
|
subsub.label(text="Gap")
|
||||||
|
subsub.prop(linestyle, "gap2", text="")
|
||||||
|
subsub = sub.column()
|
||||||
|
subsub.label(text="Dash")
|
||||||
|
subsub.prop(linestyle, "dash3", text="")
|
||||||
|
subsub = sub.column()
|
||||||
|
subsub.label(text="Gap")
|
||||||
|
subsub.prop(linestyle, "gap3", text="")
|
||||||
elif linestyle.panel == "DISTORT":
|
elif linestyle.panel == "DISTORT":
|
||||||
pass
|
pass
|
||||||
elif linestyle.panel == "MISC":
|
elif linestyle.panel == "MISC":
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ typedef struct LineStyleThicknessModifier_DistanceFromObject {
|
|||||||
/* FreestyleLineStyle::flag */
|
/* FreestyleLineStyle::flag */
|
||||||
#define LS_DS_EXPAND 1 /* for animation editors */
|
#define LS_DS_EXPAND 1 /* for animation editors */
|
||||||
#define LS_SAME_OBJECT 2
|
#define LS_SAME_OBJECT 2
|
||||||
|
#define LS_DASHED_LINE 4
|
||||||
|
|
||||||
/* FreestyleLineStyle::caps */
|
/* FreestyleLineStyle::caps */
|
||||||
#define LS_CAPS_BUTT 1
|
#define LS_CAPS_BUTT 1
|
||||||
@@ -194,7 +195,9 @@ typedef struct FreestyleLineStyle {
|
|||||||
float r, g, b, alpha;
|
float r, g, b, alpha;
|
||||||
float thickness;
|
float thickness;
|
||||||
int flag, caps;
|
int flag, caps;
|
||||||
|
unsigned short dash1, gap1, dash2, gap2, dash3, gap3;
|
||||||
int panel; /* for UI */
|
int panel; /* for UI */
|
||||||
|
int pad1;
|
||||||
|
|
||||||
ListBase color_modifiers;
|
ListBase color_modifiers;
|
||||||
ListBase alpha_modifiers;
|
ListBase alpha_modifiers;
|
||||||
|
|||||||
@@ -451,7 +451,12 @@ static void rna_def_linestyle(BlenderRNA *brna)
|
|||||||
|
|
||||||
prop= RNA_def_property(srna, "same_object", PROP_BOOLEAN, PROP_NONE);
|
prop= RNA_def_property(srna, "same_object", PROP_BOOLEAN, PROP_NONE);
|
||||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", LS_SAME_OBJECT);
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", LS_SAME_OBJECT);
|
||||||
RNA_def_property_ui_text(prop, "Same Object", "if true, only feature edges of the same object are joined.");
|
RNA_def_property_ui_text(prop, "Same Object", "If true, only feature edges of the same object are joined.");
|
||||||
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
|
prop= RNA_def_property(srna, "use_dashed_line", PROP_BOOLEAN, PROP_NONE);
|
||||||
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", LS_DASHED_LINE);
|
||||||
|
RNA_def_property_ui_text(prop, "Dashed Line", "Enable or disable dashed line.");
|
||||||
RNA_def_property_update(prop, NC_SCENE, NULL);
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
prop= RNA_def_property(srna, "caps", PROP_ENUM, PROP_NONE);
|
prop= RNA_def_property(srna, "caps", PROP_ENUM, PROP_NONE);
|
||||||
@@ -460,6 +465,42 @@ static void rna_def_linestyle(BlenderRNA *brna)
|
|||||||
RNA_def_property_ui_text(prop, "Cap", "Select the shape of both ends of strokes.");
|
RNA_def_property_ui_text(prop, "Cap", "Select the shape of both ends of strokes.");
|
||||||
RNA_def_property_update(prop, NC_SCENE, NULL);
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
|
prop= RNA_def_property(srna, "dash1", PROP_INT, PROP_UNSIGNED);
|
||||||
|
RNA_def_property_int_sdna(prop, NULL, "dash1");
|
||||||
|
RNA_def_property_range(prop, 0, USHRT_MAX);
|
||||||
|
RNA_def_property_ui_text(prop, "Dash #1", "Length of the 1st dash.");
|
||||||
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
|
prop= RNA_def_property(srna, "gap1", PROP_INT, PROP_UNSIGNED);
|
||||||
|
RNA_def_property_int_sdna(prop, NULL, "gap1");
|
||||||
|
RNA_def_property_range(prop, 0, USHRT_MAX);
|
||||||
|
RNA_def_property_ui_text(prop, "Gap #1", "Length of the 1st gap.");
|
||||||
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
|
prop= RNA_def_property(srna, "dash2", PROP_INT, PROP_UNSIGNED);
|
||||||
|
RNA_def_property_int_sdna(prop, NULL, "dash2");
|
||||||
|
RNA_def_property_range(prop, 0, USHRT_MAX);
|
||||||
|
RNA_def_property_ui_text(prop, "Dash #2", "Length of the 2nd dash.");
|
||||||
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
|
prop= RNA_def_property(srna, "gap2", PROP_INT, PROP_UNSIGNED);
|
||||||
|
RNA_def_property_int_sdna(prop, NULL, "gap2");
|
||||||
|
RNA_def_property_range(prop, 0, USHRT_MAX);
|
||||||
|
RNA_def_property_ui_text(prop, "Gap #2", "Length of the 2nd gap.");
|
||||||
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
|
prop= RNA_def_property(srna, "dash3", PROP_INT, PROP_UNSIGNED);
|
||||||
|
RNA_def_property_int_sdna(prop, NULL, "dash3");
|
||||||
|
RNA_def_property_range(prop, 0, USHRT_MAX);
|
||||||
|
RNA_def_property_ui_text(prop, "Dash #3", "Length of the 3rd dash.");
|
||||||
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
|
prop= RNA_def_property(srna, "gap3", PROP_INT, PROP_UNSIGNED);
|
||||||
|
RNA_def_property_int_sdna(prop, NULL, "gap3");
|
||||||
|
RNA_def_property_range(prop, 0, USHRT_MAX);
|
||||||
|
RNA_def_property_ui_text(prop, "Gap #3", "Length of the 3rd gap.");
|
||||||
|
RNA_def_property_update(prop, NC_SCENE, NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RNA_def_linestyle(BlenderRNA *brna)
|
void RNA_def_linestyle(BlenderRNA *brna)
|
||||||
|
|||||||
Reference in New Issue
Block a user