[Bf-blender-cvs] [7d3b1cdd7dd] blender2.8: GP: New Smooth operator

Antonioya noreply at git.blender.org
Thu Dec 13 19:49:28 CET 2018


Commit: 7d3b1cdd7dd3f2709e15965f4fa205ff39b7a296
Author: Antonioya
Date:   Thu Dec 13 19:49:13 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB7d3b1cdd7dd3f2709e15965f4fa205ff39b7a296

GP: New Smooth operator

Smooth a stroke, in edit mode, similar how mesh operator works with meshes.

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 4fc247cc8f5..470af8dc45f 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3740,6 +3740,7 @@ class VIEW3D_MT_edit_gpencil(Menu):
         layout.separator()
 
         layout.operator("gpencil.duplicate_move", text="Duplicate")
+        layout.operator("gpencil.stroke_smooth", text="Smooth")
         layout.operator("gpencil.stroke_subdivide", text="Subdivide")
         layout.menu("VIEW3D_MT_gpencil_simplify")
 
@@ -5347,6 +5348,7 @@ class VIEW3D_MT_gpencil_edit_specials(Menu):
         layout.menu("VIEW3D_MT_assign_material")
         layout.separator()
 
+        layout.operator("gpencil.stroke_smooth", text="Smooth")
         layout.operator("gpencil.stroke_subdivide", text="Subdivide")
         layout.operator("gpencil.stroke_simplify_fixed", text="Simplify")
         layout.operator("gpencil.stroke_simplify", text="Simplify Adaptative")
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 57fac1d27dc..ce5ebaf4b8f 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3591,3 +3591,90 @@ void GPENCIL_OT_stroke_split(wmOperatorType *ot)
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
+
+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);
+
+	/* 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);
+
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_stroke_smooth(wmOperatorType *ot)
+{
+	PropertyRNA *prop;
+
+	/* identifiers */
+	ot->name = "Smooth Stroke";
+	ot->idname = "GPENCIL_OT_stroke_smooth";
+	ot->description = "Smooth selected strokes";
+
+	/* api callbacks */
+	ot->exec = gp_stroke_smooth_exec;
+	ot->poll = gp_active_layer_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	prop = RNA_def_int(ot->srna, "repeat", 1, 1, 10, "Repeat", "", 1, 5);
+	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+
+	RNA_def_float(ot->srna, "factor", 0.5f, 0.0f, 2.0f, "Factor", "", 0.0f, 2.0f);
+	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", "");
+
+}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index f9951c2561a..fa806999d25 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -388,6 +388,7 @@ void GPENCIL_OT_stroke_simplify(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_simplify_fixed(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_separate(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_split(struct wmOperatorType *ot);
+void GPENCIL_OT_stroke_smooth(struct wmOperatorType *ot);
 
 void GPENCIL_OT_brush_presets_create(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 01221f57f05..3eaf72121a8 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -308,6 +308,7 @@ void ED_operatortypes_gpencil(void)
 	WM_operatortype_append(GPENCIL_OT_stroke_simplify_fixed);
 	WM_operatortype_append(GPENCIL_OT_stroke_separate);
 	WM_operatortype_append(GPENCIL_OT_stroke_split);
+	WM_operatortype_append(GPENCIL_OT_stroke_smooth);
 
 	WM_operatortype_append(GPENCIL_OT_brush_presets_create);



More information about the Bf-blender-cvs mailing list