Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorPablo Dobarro <pablodp606@gmail.com>2019-11-19 00:47:23 +0300
committerPablo Dobarro <pablodp606@gmail.com>2019-11-21 19:55:36 +0300
commit15f82278d5d4ca2b282cb8e5e377965cf28aaa17 (patch)
tree3baf4f638dec52fde9802699a2bb1a2ea261efe1 /source
parent2ec9aa3b71f4ebd9676326b690aaf3049849adee (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')
-rw-r--r--source/blender/blenloader/intern/versioning_280.c8
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c45
-rw-r--r--source/blender/makesdna/DNA_brush_defaults.h4
-rw-r--r--source/blender/makesdna/DNA_brush_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_brush.c16
5 files changed, 65 insertions, 12 deletions
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 761424a5879..488cf6b0213 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -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;
+ }
+ }
}
}
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 */
diff --git a/source/blender/makesdna/DNA_brush_defaults.h b/source/blender/makesdna/DNA_brush_defaults.h
index b2d4124a348..ff1f8c9a1c0 100644
--- a/source/blender/makesdna/DNA_brush_defaults.h
+++ b/source/blender/makesdna/DNA_brush_defaults.h
@@ -72,6 +72,10 @@
\
.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, \
.mask_overlay_alpha = 33, \
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 63fbf576bba..67bca60e7e1 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -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;
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index a392e4c080f..3f269299461 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -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);