diff options
author | Pablo Dobarro <pablodp606@gmail.com> | 2019-11-19 00:47:23 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2019-11-21 19:55:36 +0300 |
commit | 15f82278d5d4ca2b282cb8e5e377965cf28aaa17 (patch) | |
tree | 3baf4f638dec52fde9802699a2bb1a2ea261efe1 /source/blender/editors | |
parent | 2ec9aa3b71f4ebd9676326b690aaf3049849adee (diff) |
Sculpt/Paint: Dash Ratio and Dash Samples
Dash Ratio and Dash Samples are brush properties to modify the strength of the brush during a stroke. This is useful to create dashed lines in texture paint or stitches in sculpt mode.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D5949
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 36418045551..ee359def68c 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -91,6 +91,7 @@ typedef struct PaintStroke { PaintSample samples[PAINT_MAX_INPUT_SAMPLES]; int num_samples; int cur_sample; + int tot_samples; float last_mouse_position[2]; float last_world_space_position[3]; @@ -482,6 +483,12 @@ static bool paint_brush_update(bContext *C, return location_success && (is_dry_run == false); } +static bool paint_stroke_use_dash(Brush *brush) +{ + /* Only these stroke modes support dash lines */ + return brush->flag & BRUSH_SPACE || brush->flag & BRUSH_LINE || brush->flag & BRUSH_CURVE; +} + static bool paint_stroke_use_jitter(ePaintMode mode, Brush *brush, bool invert) { bool use_jitter = (brush->flag & BRUSH_ABSOLUTE_JITTER) ? (brush->jitter_absolute != 0) : @@ -582,19 +589,33 @@ static void paint_brush_stroke_add_step(bContext *C, return; } + /* Dash */ + bool add_step = true; + if (paint_stroke_use_dash(brush)) { + int dash_samples = stroke->tot_samples % brush->dash_samples; + float dash = (float)dash_samples / (float)brush->dash_samples; + if (dash > brush->dash_ratio) { + add_step = false; + } + } + /* Add to stroke */ - RNA_collection_add(op->ptr, "stroke", &itemptr); - RNA_float_set(&itemptr, "size", ups->pixel_radius); - RNA_float_set_array(&itemptr, "location", location); - RNA_float_set_array(&itemptr, "mouse", mouse_out); - RNA_boolean_set(&itemptr, "pen_flip", stroke->pen_flip); - RNA_float_set(&itemptr, "pressure", pressure); - - stroke->update_step(C, stroke, &itemptr); - - /* don't record this for now, it takes up a lot of memory when doing long - * strokes with small brush size, and operators have register disabled */ - RNA_collection_clear(op->ptr, "stroke"); + if (add_step) { + RNA_collection_add(op->ptr, "stroke", &itemptr); + RNA_float_set(&itemptr, "size", ups->pixel_radius); + RNA_float_set_array(&itemptr, "location", location); + RNA_float_set_array(&itemptr, "mouse", mouse_out); + RNA_boolean_set(&itemptr, "pen_flip", stroke->pen_flip); + RNA_float_set(&itemptr, "pressure", pressure); + + stroke->update_step(C, stroke, &itemptr); + + /* don't record this for now, it takes up a lot of memory when doing long + * strokes with small brush size, and operators have register disabled */ + RNA_collection_clear(op->ptr, "stroke"); + } + + stroke->tot_samples++; } /* Returns zero if no sculpt changes should be made, non-zero otherwise */ |