diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-10-31 17:21:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-10-31 17:27:03 +0300 |
commit | 941484ff81744ad2dca1741f3e9c4b4c18664a82 (patch) | |
tree | 3d80e516e39a7d55be8439c2ce3e06943de0a3f6 /source/blender/editors/curve | |
parent | 0dd98af2559b89149f2b6ae586969c0544c26369 (diff) | |
parent | 7fb393f9ba3866026c8fb2c5c5ef7e0906cfe8b4 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/editors/curve')
-rw-r--r-- | source/blender/editors/curve/curve_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/curve/curve_ops.c | 1 | ||||
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 80 |
3 files changed, 82 insertions, 0 deletions
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h index 02c76a840f1..bf1e22ae170 100644 --- a/source/blender/editors/curve/curve_intern.h +++ b/source/blender/editors/curve/curve_intern.h @@ -109,6 +109,7 @@ void CURVE_OT_radius_set(struct wmOperatorType *ot); void CURVE_OT_spline_weight_set(struct wmOperatorType *ot); void CURVE_OT_handle_type_set(struct wmOperatorType *ot); void CURVE_OT_normals_make_consistent(struct wmOperatorType *ot); +void CURVE_OT_decimate(struct wmOperatorType *ot); void CURVE_OT_shade_smooth(struct wmOperatorType *ot); void CURVE_OT_shade_flat(struct wmOperatorType *ot); void CURVE_OT_tilt_clear(struct wmOperatorType *ot); diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index 5d637b113d8..4dfd4a5c0f0 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -94,6 +94,7 @@ void ED_operatortypes_curve(void) WM_operatortype_append(CURVE_OT_spline_weight_set); WM_operatortype_append(CURVE_OT_handle_type_set); WM_operatortype_append(CURVE_OT_normals_make_consistent); + WM_operatortype_append(CURVE_OT_decimate); WM_operatortype_append(CURVE_OT_shade_smooth); WM_operatortype_append(CURVE_OT_shade_flat); WM_operatortype_append(CURVE_OT_tilt_clear); diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 4757c896650..565521ad111 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -5909,6 +5909,86 @@ void CURVE_OT_dissolve_verts(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +static bool nurb_bezt_flag_any(const Nurb *nu, const char flag_test) +{ + BezTriple *bezt = nu->bezt; + int i; + + for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) { + if (bezt->f2 & flag_test) { + return true; + } + } + + return false; +} + +static int curve_decimate_exec(bContext *C, wmOperator *op) +{ + Object *obedit = CTX_data_edit_object(C); + Curve *cu = (Curve *)obedit->data; + bool all_supported = true; + bool changed = false; + + { + const float error_sq_max = FLT_MAX; + float ratio = RNA_float_get(op->ptr, "ratio"); + + ListBase *editnurb = object_editcurve_get(obedit); + Nurb *nu; + + for (nu = editnurb->first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + if ((nu->pntsu > 2) && nurb_bezt_flag_any(nu, SELECT)) { + const int error_target_len = max_ii(2, nu->pntsu * ratio); + if (error_target_len != nu->pntsu) { + BKE_curve_decimate_nurb(nu, cu->resolu, error_sq_max, error_target_len); + changed = true; + } + } + } + else { + all_supported = false; + } + } + } + + if (all_supported == false) { + BKE_report(op->reports, RPT_WARNING, "Only bezier curves are supported"); + } + + if (changed) { + cu->actnu = cu->actvert = CU_ACT_NONE; + if (ED_curve_updateAnimPaths(obedit->data)) { + WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit); + } + + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + DEG_id_tag_update(obedit->data, 0); + } + + return OPERATOR_FINISHED; +} + +void CURVE_OT_decimate(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Decimate Curve"; + ot->description = "Simplify selected curves"; + ot->idname = "CURVE_OT_decimate"; + + /* api callbacks */ + ot->exec = curve_decimate_exec; + ot->poll = ED_operator_editcurve; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + RNA_def_float_factor(ot->srna, "ratio", 1.0f, 0.0f, 1.0f, "Ratio", "", 0.0f, 1.0f); +} + + /********************** shade smooth/flat operator *********************/ static int shade_smooth_exec(bContext *C, wmOperator *op) |