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
This commit is contained in:
Pablo Dobarro 2019-11-18 22:47:23 +01:00
parent 2ec9aa3b71
commit 15f82278d5
Notes: blender-bot 2023-02-14 07:31:34 +01:00
Referenced by commit 9cd9b35779, Fix T87816: Sculpt curve & line stroke hides dash settings
Referenced by commit aede740c8a, Fix T87816: Sculpt curve & line stroke hides dash settings
6 changed files with 67 additions and 10 deletions

View File

@ -972,10 +972,14 @@ class VIEW3D_PT_tools_brush_stroke(Panel, View3DPaintPanel):
row = col.row(align=True)
row.prop(brush, "spacing", text="Spacing")
row.prop(brush, "use_pressure_spacing", toggle=True, text="")
col.prop(brush, "dash_ratio")
col.prop(brush, "dash_samples")
if brush.use_line or brush.use_curve:
row = col.row(align=True)
row.prop(brush, "spacing", text="Spacing")
col.prop(brush, "dash_ratio")
col.prop(brush, "dash_samples")
if brush.use_curve:
col.template_ID(brush, "paint_curve", new="paintcurve.new")

View File

@ -3964,5 +3964,13 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
/* Dash Ratio and Dash Samples */
if (!DNA_struct_elem_find(fd->filesdna, "Brush", "float", "dash_ratio")) {
for (Brush *br = bmain->brushes.first; br; br = br->id.next) {
br->dash_ratio = 1.0f;
br->dash_samples = 20;
}
}
}
}

View File

@ -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);
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);
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");
/* 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 */

View File

@ -71,6 +71,10 @@
.rate = 0.1f, \
\
.jitter = 0.0f, \
\
/* Dash */ \
.dash_ratio = 1.0f, \
.dash_samples = 20, \
\
.texture_sample_bias = 0, /* value to added to texture samples */ \
.texture_overlay_alpha = 33, \

View File

@ -272,6 +272,10 @@ typedef struct Brush {
/** Background color. */
float secondary_rgb[3];
/** Rate */
float dash_ratio;
int dash_samples;
/** The direction of movement for sculpt vertices. */
int sculpt_plane;

View File

@ -1788,6 +1788,22 @@ static void rna_def_brush(BlenderRNA *brna)
prop, "Strength", "How powerful the effect of the brush is when applied");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop = RNA_def_property(srna, "dash_ratio", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "dash_ratio");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3);
RNA_def_property_ui_text(
prop, "Dash Ratio", "Ratio of samples in a cycle that the brush is enabled");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop = RNA_def_property(srna, "dash_samples", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "dash_samples");
RNA_def_property_range(prop, 1, 10000);
RNA_def_property_ui_range(prop, 1, 10000, 5, -1);
RNA_def_property_ui_text(
prop, "Dash Length", "Length of a dash cycle measured in stroke samples");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop = RNA_def_property(srna, "plane_offset", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, NULL, "plane_offset");
RNA_def_property_float_default(prop, 0);