diff options
-rw-r--r-- | release/scripts/freestyle/style_modules/parameter_editor.py | 32 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/properties_render.py | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/linestyle.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_linestyle_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_linestyle.c | 22 |
5 files changed, 71 insertions, 5 deletions
diff --git a/release/scripts/freestyle/style_modules/parameter_editor.py b/release/scripts/freestyle/style_modules/parameter_editor.py index d8ac2a54c29..45c242fec8e 100644 --- a/release/scripts/freestyle/style_modules/parameter_editor.py +++ b/release/scripts/freestyle/style_modules/parameter_editor.py @@ -736,6 +736,23 @@ class AndBP1D(BinaryPredicate1D): def __call__(self, i1, i2): return self.__pred1(i1, i2) and self.__pred2(i1, i2) +# predicates for selection + +class LengthThresholdUP1D(UnaryPredicate1D): + def __init__(self, min_length=None, max_length=None): + UnaryPredicate1D.__init__(self) + self._min_length = min_length + self._max_length = max_length + def getName(self): + return "LengthThresholdUP1D" + def __call__(self, inter): + length = inter.getLength2D() + if self._min_length is not None and length < self._min_length: + return False + if self._max_length is not None and length > self._max_length: + return False + return True + # predicates for splitting class MaterialBoundaryUP0D(UnaryPredicate0D): @@ -858,16 +875,24 @@ def process(layer_name, lineset_name): ymin, ymax = 0.0, float(h) upred = WithinImageBorderUP1D(xmin, xmax, ymin, ymax) selection_criteria.append(upred) - # do feature edge selection + # select feature edges upred = join_unary_predicates(selection_criteria, AndUP1D) if upred is None: upred = TrueUP1D() Operators.select(upred) - # join feature edges + # join feature edges to form chains bpred = AngleLargerThanBP1D(1.0) # XXX temporary fix for occasional unexpected long lines if linestyle.same_object: bpred = AndBP1D(bpred, SameShapeIdBP1D()) Operators.bidirectionalChain(ChainPredicateIterator(upred, bpred), NotUP1D(upred)) + # split chains + if linestyle.material_boundary: + Operators.sequentialSplit(MaterialBoundaryUP0D()) + # 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 = [] @@ -886,9 +911,6 @@ def process(layer_name, lineset_name): Operators.sequentialSplit(DashedLineStartingUP0D(controller), DashedLineStoppingUP0D(controller), sampling) - # split chains of feature edges - if linestyle.material_boundary: - Operators.sequentialSplit(MaterialBoundaryUP0D()) # prepare a list of stroke shaders shaders_list = [] for m in linestyle.geometry_modifiers: diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py index b024a6588be..f471ffc65e5 100644 --- a/release/scripts/startup/bl_ui/properties_render.py +++ b/release/scripts/startup/bl_ui/properties_render.py @@ -511,13 +511,30 @@ class RENDER_PT_freestyle_linestyle(RenderButtonsPanel, Panel): row = layout.row(align=True) row.prop(linestyle, "panel", expand=True) if linestyle.panel == "STROKES": + # Chaining col = layout.column() col.label(text="Chaining:") col.prop(linestyle, "same_object") + # Splitting col = layout.column() col.label(text="Splitting:") row = col.row(align=True) row.prop(linestyle, "material_boundary") + # Selection + col = layout.column() + col.label(text="Selection:") + sub = col.row() + subcol = sub.column() + subcol.prop(linestyle, "use_min_length", text="Min Length") + subsub = subcol.split() + subsub.prop(linestyle, "min_length", text="") + subsub.enabled = linestyle.use_min_length + subcol = sub.column() + subcol.prop(linestyle, "use_max_length", text="Max Length") + subsub = subcol.split() + subsub.prop(linestyle, "max_length", text="") + subsub.enabled = linestyle.use_max_length + # Caps col = layout.column() col.label(text="Caps:") row = col.row(align=True) diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 88584633a49..86ea80cb89e 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -69,6 +69,8 @@ static void default_linestyle_settings(FreestyleLineStyle *linestyle) linestyle->r = linestyle->g = linestyle->b = 0.0; linestyle->alpha = 1.0; linestyle->thickness = 1.0; + linestyle->min_length = 0.0f; + linestyle->max_length = 10000.0f; linestyle->color_modifiers.first = linestyle->color_modifiers.last = NULL; linestyle->alpha_modifiers.first = linestyle->alpha_modifiers.last = NULL; diff --git a/source/blender/makesdna/DNA_linestyle_types.h b/source/blender/makesdna/DNA_linestyle_types.h index 8b3b5a60181..85468ce6657 100644 --- a/source/blender/makesdna/DNA_linestyle_types.h +++ b/source/blender/makesdna/DNA_linestyle_types.h @@ -319,6 +319,8 @@ typedef struct LineStyleThicknessModifier_Calligraphy { #define LS_SAME_OBJECT 2 #define LS_DASHED_LINE 4 #define LS_MATERIAL_BOUNDARY 8 +#define LS_MIN_2D_LENGTH 16 +#define LS_MAX_2D_LENGTH 32 /* FreestyleLineStyle::caps */ #define LS_CAPS_BUTT 1 @@ -332,6 +334,7 @@ typedef struct FreestyleLineStyle { float r, g, b, alpha; float thickness; int flag, caps; + float min_length, max_length; unsigned short dash1, gap1, dash2, gap2, dash3, gap3; int panel; /* for UI */ int pad1; diff --git a/source/blender/makesrna/intern/rna_linestyle.c b/source/blender/makesrna/intern/rna_linestyle.c index e5b5aee5541..389d3746671 100644 --- a/source/blender/makesrna/intern/rna_linestyle.c +++ b/source/blender/makesrna/intern/rna_linestyle.c @@ -733,6 +733,28 @@ static void rna_def_linestyle(BlenderRNA *brna) 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_min_length", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", LS_MIN_2D_LENGTH); + RNA_def_property_ui_text(prop, "Use Min 2D Length", "Enable the selection of chains by a minimum 2D length."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "min_length", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "min_length"); + RNA_def_property_range(prop, 0.0f, 10000.0f); + RNA_def_property_ui_text(prop, "Min 2D Length", "Minimum 2D length for the selection of chains."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "use_max_length", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", LS_MAX_2D_LENGTH); + RNA_def_property_ui_text(prop, "Use Max 2D Length", "Enable the selection of chains by a maximum 2D length."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "max_length", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "max_length"); + RNA_def_property_range(prop, 0.0f, 10000.0f); + RNA_def_property_ui_text(prop, "Max 2D Length", "Maximum 2D length for the selection of chains."); + RNA_def_property_update(prop, NC_SCENE, NULL); + prop= RNA_def_property(srna, "material_boundary", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", LS_MATERIAL_BOUNDARY); RNA_def_property_ui_text(prop, "Material Boundary", "If true, chains of feature edges are split at material boundaries."); |