diff options
Diffstat (limited to 'source/blender/editors/curve/editcurve.c')
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 93 |
1 files changed, 75 insertions, 18 deletions
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index f576440fe92..caa06eb15d0 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -47,6 +47,7 @@ #include "BKE_context.h" #include "BKE_curve.h" #include "BKE_depsgraph.h" +#include "BKE_displist.h" #include "BKE_fcurve.h" #include "BKE_global.h" #include "BKE_key.h" @@ -2307,11 +2308,12 @@ static int smooth_exec(bContext *C, wmOperator *UNUSED(op)) BezTriple *bezt, *beztOrig; BPoint *bp, *bpOrig; float val, newval, offset; - int a, i, change = 0; + int a, i; + bool changed = false; for (nu = editnurb->first; nu; nu = nu->next) { if (nu->bezt) { - change = 0; + changed = false; beztOrig = MEM_dupallocN(nu->bezt); for (bezt = &nu->bezt[1], a = 1; a < nu->pntsu - 1; a++, bezt++) { if (bezt->f2 & SELECT) { @@ -2324,12 +2326,13 @@ static int smooth_exec(bContext *C, wmOperator *UNUSED(op)) bezt->vec[0][i] += offset; bezt->vec[2][i] += offset; } - change = 1; + changed = true; } } MEM_freeN(beztOrig); - if (change) + if (changed) { BKE_nurb_handles_calc(nu); + } } else if (nu->bp) { bpOrig = MEM_dupallocN(nu->bp); @@ -3568,7 +3571,7 @@ static int set_spline_type_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); ListBase *editnurb = object_editcurve_get(obedit); Nurb *nu; - bool change = false; + bool changed = false; const bool use_handles = RNA_boolean_get(op->ptr, "use_handles"); const int type = RNA_enum_get(op->ptr, "type"); @@ -3582,11 +3585,11 @@ static int set_spline_type_exec(bContext *C, wmOperator *op) if (BKE_nurb_type_convert(nu, type, use_handles) == false) BKE_report(op->reports, RPT_ERROR, "No conversion possible"); else - change = true; + changed = true; } } - if (change) { + if (changed) { if (ED_curve_updateAnimPaths(obedit->data)) WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit); @@ -4364,7 +4367,7 @@ bool ed_editnurb_spin(float viewmat[4][4], Object *obedit, const float axis[3], Curve *cu = (Curve *)obedit->data; ListBase *editnurb = object_editcurve_get(obedit); Nurb *nu; - float si, phi, n[3], q[4], cmat[3][3], tmat[3][3], imat[3][3]; + float cmat[3][3], tmat[3][3], imat[3][3]; float bmat[3][3], rotmat[3][3], scalemat1[3][3], scalemat2[3][3]; float persmat[3][3], persinv[3][3]; bool ok, changed = false; @@ -4377,15 +4380,7 @@ bool ed_editnurb_spin(float viewmat[4][4], Object *obedit, const float axis[3], copy_m3_m4(bmat, obedit->obmat); invert_m3_m3(imat, bmat); - normalize_v3_v3(n, axis); - /* TODO - use math func */ - phi = M_PI / 8.0; - q[0] = cos(phi); - si = sin(phi); - q[1] = n[0] * si; - q[2] = n[1] * si; - q[3] = n[2] * si; - quat_to_mat3(cmat, q); + axis_angle_to_mat3(cmat, axis, M_PI / 4.0); mul_m3_m3m3(tmat, cmat, bmat); mul_m3_m3m3(rotmat, imat, tmat); @@ -6367,7 +6362,7 @@ static int curve_delete_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); Curve *cu = (Curve *)obedit->data; eCurveElem_Types type = RNA_enum_get(op->ptr, "type"); - int retval; + int retval = OPERATOR_CANCELLED; if (type == CURVE_VERTEX) retval = curve_delete_vertices(obedit); else if (type == CURVE_SEGMENT) retval = curve_delete_segments(obedit, false); @@ -6813,3 +6808,65 @@ int ED_curve_actSelection(Curve *cu, float center[3]) return 1; } + +/******************** Match texture space operator ***********************/ + +static int match_texture_space_poll(bContext *C) +{ + Object *object = CTX_data_active_object(C); + + return object && ELEM3(object->type, OB_CURVE, OB_SURF, OB_FONT); +} + +static int match_texture_space_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Scene *scene = CTX_data_scene(C); + Object *object = CTX_data_active_object(C); + Curve *curve = (Curve *) object->data; + float min[3], max[3], size[3], loc[3]; + int a; + + if (ELEM(NULL, object->curve_cache, object->curve_cache->disp.first)) { + BKE_displist_make_curveTypes(scene, object, FALSE); + } + + INIT_MINMAX(min, max); + BKE_displist_minmax(&object->curve_cache->disp, min, max); + + mid_v3_v3v3(loc, min, max); + + size[0] = (max[0] - min[0]) / 2.0f; + size[1] = (max[1] - min[1]) / 2.0f; + size[2] = (max[2] - min[2]) / 2.0f; + + for (a = 0; a < 3; a++) { + if (size[a] == 0.0f) size[a] = 1.0f; + else if (size[a] > 0.0f && size[a] < 0.00001f) size[a] = 0.00001f; + else if (size[a] < 0.0f && size[a] > -0.00001f) size[a] = -0.00001f; + } + + copy_v3_v3(curve->loc, loc); + copy_v3_v3(curve->size, size); + zero_v3(curve->rot); + + curve->texflag &= ~CU_AUTOSPACE; + + WM_event_add_notifier(C, NC_GEOM | ND_DATA, curve); + + return OPERATOR_FINISHED; +} + +void CURVE_OT_match_texture_space(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Match Texture Space"; + ot->idname = "CURVE_OT_match_texture_space"; + ot->description = "Match texture space to object's bounding box"; + + /* api callbacks */ + ot->exec = match_texture_space_exec; + ot->poll = match_texture_space_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} |