[Bf-blender-cvs] [46477fc5d7a] soc-2020-greasepencil-curve: GPencil: Add operator to enter strokes into curve edit mdoe
Falk David
noreply at git.blender.org
Tue Jun 16 09:47:53 CEST 2020
Commit: 46477fc5d7a4badb68bdb3b4b27aa578f6274b7b
Author: Falk David
Date: Tue Jun 16 09:46:59 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB46477fc5d7a4badb68bdb3b4b27aa578f6274b7b
GPencil: Add operator to enter strokes into curve edit mdoe
This operator creates an editcurve for all selected strokes that
do not have an editcurve already.
===================================================================
M source/blender/editors/gpencil/gpencil_edit_curve.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_ops.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index 56a2ea4297d..098b3ba84f1 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -36,6 +36,7 @@
#include "BKE_context.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_curve.h"
+#include "BKE_gpencil_geom.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
@@ -78,7 +79,7 @@ static int gp_write_stroke_curve_data_exec(bContext *C, wmOperator *op)
if (gps->editcurve != NULL) {
BKE_gpencil_free_stroke_editcurve(gps);
}
- BKE_gpencil_stroke_editcurve_update(gps);
+ BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
if (gps->editcurve != NULL) {
gps->editcurve->resolution = gpd->editcurve_resolution;
}
@@ -114,4 +115,72 @@ void GPENCIL_OT_write_sample_stroke_curve_data(wmOperatorType *ot)
// ot->srna, "num_points", 2, 0, 100, "Curve points", "Number of test curve points", 0, 100);
}
+static int gp_stroke_enter_editcurve_mode(bContext *C, wmOperator *op)
+{
+ Object *ob = CTX_data_active_object(C);
+ bGPdata *gpd = ob->data;
+
+ float error_threshold = RNA_float_get(op->ptr, "error_threshold");
+ gpd->curve_edit_threshold = error_threshold;
+
+ if (ELEM(NULL, gpd)) {
+ return OPERATOR_CANCELLED;
+ }
+
+ const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ if (gpf == gpl->actframe) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ /* only allow selected and non-converted strokes to be transformed */
+ if (gps->flag & GP_STROKE_SELECT && gps->editcurve == NULL) {
+ BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+ if (gps->editcurve != NULL) {
+ gps->editcurve->resolution = gpd->editcurve_resolution;
+ gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+ }
+ BKE_gpencil_stroke_geometry_update(gps);
+ }
+ }
+ }
+ }
+ }
+
+ /* 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_enter_editcurve_mode(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Enter curve edit mode";
+ ot->idname = "GPENCIL_OT_stroke_enter_editcurve_mode";
+ ot->description = "Called to transform a stroke into a curve";
+
+ /* api callbacks */
+ ot->exec = gp_stroke_enter_editcurve_mode;
+ ot->poll = gp_active_layer_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ prop = RNA_def_float(ot->srna,
+ "error_threshold",
+ 0.1f,
+ FLT_MIN,
+ 100.0f,
+ "Error Threshold",
+ "Threshold on the maximum deviation from the actual stroke",
+ FLT_MIN,
+ 10.f);
+ RNA_def_property_ui_range(prop, FLT_MIN, 10.0f, 0.1f, 5);
+}
+
/** \} */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 4e101031ed5..85f25b2311c 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -445,6 +445,7 @@ void GPENCIL_OT_reproject(struct wmOperatorType *ot);
void GPENCIL_OT_recalc_geometry(struct wmOperatorType *ot);
void GPENCIL_OT_write_sample_stroke_curve_data(struct wmOperatorType *ot);
+void GPENCIL_OT_stroke_enter_editcurve_mode(struct wmOperatorType *ot);
/* stroke sculpting -- */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 16d663e11cd..9b7c5db1407 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -570,6 +570,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_weight_paint);
WM_operatortype_append(GPENCIL_OT_write_sample_stroke_curve_data);
+ WM_operatortype_append(GPENCIL_OT_stroke_enter_editcurve_mode);
/* Editing (Buttons) ------------ */
More information about the Bf-blender-cvs
mailing list