diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-10-24 00:42:26 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-10-24 00:42:26 +0400 |
commit | 86e433728d8e45716537e1a6ac0719383bd10aa0 (patch) | |
tree | ed2f361408e5ab6d295a7d929b99c29f804859ff | |
parent | 7a1f092cac4b40e06742af52577c7f7c36cb4a28 (diff) |
Added support for dashed line in the Parameter Editor mode.
-rw-r--r-- | release/scripts/freestyle/style_modules/parameter_editor.py | 64 | ||||
-rw-r--r-- | release/scripts/ui/properties_render.py | 23 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_linestyle_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_linestyle.c | 43 |
4 files changed, 132 insertions, 1 deletions
diff --git a/release/scripts/freestyle/style_modules/parameter_editor.py b/release/scripts/freestyle/style_modules/parameter_editor.py index ea01228b81b..1e59648f8c9 100644 --- a/release/scripts/freestyle/style_modules/parameter_editor.py +++ b/release/scripts/freestyle/style_modules/parameter_editor.py @@ -392,6 +392,52 @@ class SquareCapShader(StrokeShader): stroke[-1].setPoint(p + d / d.length * caplen_beg) 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 def process(layer_name, lineset_name): @@ -472,6 +518,24 @@ def process(layer_name, lineset_name): else: chaining_iterator = ChainSilhouetteIterator() 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 color = linestyle.color shaders_list = [ diff --git a/release/scripts/ui/properties_render.py b/release/scripts/ui/properties_render.py index 7e5848d0aa0..81727de209b 100644 --- a/release/scripts/ui/properties_render.py +++ b/release/scripts/ui/properties_render.py @@ -412,9 +412,32 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, bpy.types.Panel): elif linestyle.panel == "STROKES": col.label(text="Chaining:") col.prop(linestyle, "same_object") + col.separator() col.label(text="Caps:") sub = col.row(align=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": pass elif linestyle.panel == "MISC": diff --git a/source/blender/makesdna/DNA_linestyle_types.h b/source/blender/makesdna/DNA_linestyle_types.h index 3deef684e3d..88e44294ed4 100644 --- a/source/blender/makesdna/DNA_linestyle_types.h +++ b/source/blender/makesdna/DNA_linestyle_types.h @@ -181,6 +181,7 @@ typedef struct LineStyleThicknessModifier_DistanceFromObject { /* FreestyleLineStyle::flag */ #define LS_DS_EXPAND 1 /* for animation editors */ #define LS_SAME_OBJECT 2 +#define LS_DASHED_LINE 4 /* FreestyleLineStyle::caps */ #define LS_CAPS_BUTT 1 @@ -194,7 +195,9 @@ typedef struct FreestyleLineStyle { float r, g, b, alpha; float thickness; int flag, caps; + unsigned short dash1, gap1, dash2, gap2, dash3, gap3; int panel; /* for UI */ + int pad1; ListBase color_modifiers; ListBase alpha_modifiers; diff --git a/source/blender/makesrna/intern/rna_linestyle.c b/source/blender/makesrna/intern/rna_linestyle.c index 4012acfde92..63968bd481c 100644 --- a/source/blender/makesrna/intern/rna_linestyle.c +++ b/source/blender/makesrna/intern/rna_linestyle.c @@ -451,7 +451,12 @@ static void rna_def_linestyle(BlenderRNA *brna) 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_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); 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_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) |