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
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-12-14 01:30:29 +0300
committerAntonioya <blendergit@gmail.com>2018-12-14 01:31:57 +0300
commitc7a31bad9fd5822e4de35209b7a9bd13731f726c (patch)
tree8b2c59713764d037f3faadb928ce2ba698460a1b /source/blender
parent26c8e09cffd50375c62d3ed11d4045deaf3abc6b (diff)
GP: Add Subdivide Smooth option
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c105
1 files changed, 63 insertions, 42 deletions
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index ce5ebaf4b8f..a09504c255c 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3013,6 +3013,54 @@ void GPENCIL_OT_reproject(wmOperatorType *ot)
}
/* ******************* Stroke subdivide ************************** */
+/* helper to smooth */
+static void gp_smooth_stroke(bContext *C, wmOperator *op)
+{
+ bGPdata *gpd = ED_gpencil_data_get_active(C);
+ const int repeat = RNA_int_get(op->ptr, "repeat");
+ float factor = RNA_float_get(op->ptr, "factor");
+ const bool only_selected = RNA_boolean_get(op->ptr, "only_selected");
+ const bool smooth_position = RNA_boolean_get(op->ptr, "smooth_position");
+ const bool smooth_thickness = RNA_boolean_get(op->ptr, "smooth_thickness");
+ const bool smooth_strength = RNA_boolean_get(op->ptr, "smooth_strength");
+ const bool smooth_uv = RNA_boolean_get(op->ptr, "smooth_uv");
+
+ if (factor == 0.0f) {
+ return;
+ }
+
+ GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps)
+ {
+ if (gps->flag & GP_STROKE_SELECT) {
+ for (int r = 0; r < repeat; r++) {
+ for (int i = 0; i < gps->totpoints; i++) {
+ bGPDspoint *pt = &gps->points[i];
+ if ((only_selected) && ((pt->flag & GP_SPOINT_SELECT) == 0)) {
+ continue;
+ }
+
+ /* perform smoothing */
+ if (smooth_position) {
+ BKE_gpencil_smooth_stroke(gps, i, factor);
+ }
+ if (smooth_strength) {
+ BKE_gpencil_smooth_stroke_strength(gps, i, factor);
+ }
+ if (smooth_thickness) {
+ /* thickness need to repeat process several times */
+ for (int r2 = 0; r2 < r * 10; r2++) {
+ BKE_gpencil_smooth_stroke_thickness(gps, i, factor);
+ }
+ }
+ if (smooth_uv) {
+ BKE_gpencil_smooth_stroke_uv(gps, i, factor);
+ }
+ }
+ }
+ }
+ }
+ GP_EDITABLE_STROKES_END(gpstroke_iter);
+}
/* helper: Count how many points need to be inserted */
static int gp_count_subdivision_cuts(bGPDstroke *gps)
@@ -3151,6 +3199,9 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
}
GP_EDITABLE_STROKES_END(gpstroke_iter);
+ /* smooth stroke */
+ gp_smooth_stroke(C, op);
+
/* notifiers */
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -3179,6 +3230,17 @@ void GPENCIL_OT_stroke_subdivide(wmOperatorType *ot)
/* avoid re-using last var because it can cause _very_ high value and annoy users */
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ /* Smooth parameters */
+ RNA_def_float(ot->srna, "factor", 0.0f, 0.0f, 2.0f, "Smooth", "", 0.0f, 2.0f);
+ prop = RNA_def_int(ot->srna, "repeat", 1, 1, 10, "Repeat", "", 1, 5);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ RNA_def_boolean(ot->srna, "only_selected", true, "Selected Points",
+ "Smooth only selected points in the stroke");
+ RNA_def_boolean(ot->srna, "smooth_position", true, "Position", "");
+ RNA_def_boolean(ot->srna, "smooth_thickness", true, "Thickness", "");
+ RNA_def_boolean(ot->srna, "smooth_strength", false, "Strength", "");
+ RNA_def_boolean(ot->srna, "smooth_uv", false, "UV", "");
+
}
/* ** simplify stroke *** */
@@ -3595,52 +3657,12 @@ void GPENCIL_OT_stroke_split(wmOperatorType *ot)
static int gp_stroke_smooth_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
- const int repeat = RNA_int_get(op->ptr, "repeat");
- float factor = RNA_float_get(op->ptr, "factor");
- const bool only_selected = RNA_boolean_get(op->ptr, "only_selected");
- const bool smooth_position = RNA_boolean_get(op->ptr, "smooth_position");
- const bool smooth_thickness = RNA_boolean_get(op->ptr, "smooth_thickness");
- const bool smooth_strength = RNA_boolean_get(op->ptr, "smooth_strength");
- const bool smooth_uv = RNA_boolean_get(op->ptr, "smooth_uv");
/* sanity checks */
if (ELEM(NULL, gpd))
return OPERATOR_CANCELLED;
- /* Go through each editable + selected stroke */
- GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps)
- {
- if (gps->flag & GP_STROKE_SELECT) {
- if (factor > 0.0f) {
- for (int r = 0; r < repeat; r++) {
- for (int i = 0; i < gps->totpoints; i++) {
- bGPDspoint *pt = &gps->points[i];
- if ((only_selected) && ((pt->flag & GP_SPOINT_SELECT) == 0)) {
- continue;
- }
-
- /* perform smoothing */
- if (smooth_position) {
- BKE_gpencil_smooth_stroke(gps, i, factor);
- }
- if (smooth_strength) {
- BKE_gpencil_smooth_stroke_strength(gps, i, factor);
- }
- if (smooth_thickness) {
- /* thickness need to repeat process several times */
- for (int r2 = 0; r2 < r * 10; r2++) {
- BKE_gpencil_smooth_stroke_thickness(gps, i, factor);
- }
- }
- if (smooth_uv) {
- BKE_gpencil_smooth_stroke_uv(gps, i, factor);
- }
- }
- }
- }
- }
- }
- GP_EDITABLE_STROKES_END(gpstroke_iter);
+ gp_smooth_stroke(C, op);
/* notifiers */
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
@@ -3676,5 +3698,4 @@ void GPENCIL_OT_stroke_smooth(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "smooth_thickness", true, "Thickness", "");
RNA_def_boolean(ot->srna, "smooth_strength", false, "Strength", "");
RNA_def_boolean(ot->srna, "smooth_uv", false, "UV", "");
-
}