diff options
author | Antonioya <blendergit@gmail.com> | 2019-08-08 11:23:05 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2019-08-08 15:13:01 +0300 |
commit | b9d0f33530f095fb318890dca4f8933a9afd1904 (patch) | |
tree | 3506e4f5a951d591f871474caa5292b0868ab2d0 /source/blender/editors/gpencil | |
parent | 9d4a8cbd887f03bf1acfaae5e8e3342f3c7ed040 (diff) |
Fix T67545: GPencil - New Merge by Distance operator
Merge points when the distance is less than a predefined value.
The method to interpolate the position created a wrong merge. Now, always the secondary point is merged with the first one (merge at first), except the last point.
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 70 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_ops.c | 1 |
3 files changed, 72 insertions, 0 deletions
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 277628f4363..a7b9bb24bf8 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -4522,3 +4522,73 @@ bool ED_object_gpencil_exit(struct Main *bmain, Object *ob) } return ok; } + +/* ** merge by distance *** */ +bool gp_merge_by_distance_poll(bContext *C) +{ + Object *ob = CTX_data_active_object(C); + if (ob == NULL) { + return false; + } + bGPdata *gpd = (bGPdata *)ob->data; + if (gpd == NULL) { + return false; + } + + bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); + + return ((gpl != NULL) && (ob->mode == OB_MODE_EDIT_GPENCIL)); +} + +static int gp_merge_by_distance_exec(bContext *C, wmOperator *op) +{ + Object *ob = CTX_data_active_object(C); + bGPdata *gpd = (bGPdata *)ob->data; + const float threshold = RNA_float_get(op->ptr, "threshold"); + const bool unselected = RNA_boolean_get(op->ptr, "use_unselected"); + + /* 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) { + BKE_gpencil_merge_distance_stroke(gpf_, gps, threshold, unselected); + } + } + 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_merge_by_distance(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Merge by Distance"; + ot->idname = "GPENCIL_OT_stroke_merge_by_distance"; + ot->description = "Merge points by distance"; + + /* api callbacks */ + ot->exec = gp_merge_by_distance_exec; + ot->poll = gp_merge_by_distance_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + prop = RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, 100.0f, "Threshold", "", 0.0f, 100.0f); + /* avoid re-using last var */ + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean( + ot->srna, "use_unselected", 0, "Unselected", "Use whole stroke, not only selected points"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); +} diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h index 1c20da4bed3..3776dd09eb5 100644 --- a/source/blender/editors/gpencil/gpencil_intern.h +++ b/source/blender/editors/gpencil/gpencil_intern.h @@ -489,6 +489,7 @@ void GPENCIL_OT_stroke_smooth(struct wmOperatorType *ot); void GPENCIL_OT_stroke_merge(struct wmOperatorType *ot); void GPENCIL_OT_stroke_cutter(struct wmOperatorType *ot); void GPENCIL_OT_stroke_trim(struct wmOperatorType *ot); +void GPENCIL_OT_stroke_merge_by_distance(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 a1645a5c67d..54e99802c54 100644 --- a/source/blender/editors/gpencil/gpencil_ops.c +++ b/source/blender/editors/gpencil/gpencil_ops.c @@ -317,6 +317,7 @@ void ED_operatortypes_gpencil(void) WM_operatortype_append(GPENCIL_OT_stroke_merge); WM_operatortype_append(GPENCIL_OT_stroke_cutter); WM_operatortype_append(GPENCIL_OT_stroke_trim); + WM_operatortype_append(GPENCIL_OT_stroke_merge_by_distance); WM_operatortype_append(GPENCIL_OT_brush_presets_create); |