diff options
Diffstat (limited to 'source/blender/editors/transform/transform_conversions.c')
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 105 |
1 files changed, 56 insertions, 49 deletions
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 4dd7f3c3fdf..949ee79a3dc 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -29,12 +29,6 @@ * \ingroup edtransform */ - -#ifndef WIN32 -#include <unistd.h> -#else -#include <io.h> -#endif #include <string.h> #include <math.h> @@ -63,7 +57,6 @@ #include "BLI_listbase.h" #include "BLI_linklist_stack.h" #include "BLI_string.h" -#include "BLI_rect.h" #include "BLI_bitmap.h" #include "BKE_DerivedMesh.h" @@ -71,6 +64,7 @@ #include "BKE_armature.h" #include "BKE_constraint.h" #include "BKE_context.h" +#include "BKE_crazyspace.h" #include "BKE_curve.h" #include "BKE_depsgraph.h" #include "BKE_fcurve.h" @@ -108,11 +102,9 @@ #include "ED_markers.h" #include "ED_mesh.h" #include "ED_node.h" -#include "ED_types.h" #include "ED_uvedit.h" #include "ED_clip.h" #include "ED_mask.h" -#include "ED_util.h" /* for crazyspace correction */ #include "WM_api.h" /* for WM_event_add_notifier to deal with stabilization nodes */ #include "WM_types.h" @@ -884,7 +876,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) } } - con = BKE_add_pose_constraint(NULL, pchan, "TempConstraint", CONSTRAINT_TYPE_KINEMATIC); + con = BKE_constraint_add_for_pose(NULL, pchan, "TempConstraint", CONSTRAINT_TYPE_KINEMATIC); pchan->constflag |= (PCHAN_HAS_IK | PCHAN_HAS_TARGET); /* for draw, but also for detecting while pose solving */ data = con->data; if (targetless) { @@ -1620,7 +1612,7 @@ static void createTransLatticeVerts(TransInfo *t) { Lattice *latt = ((Lattice *)t->obedit->data)->editlatt->latt; TransData *td = NULL; - BPoint *bp, *actbp = BKE_lattice_active_point_get(latt); + BPoint *bp; float mtx[3][3], smtx[3][3]; int a; int count = 0, countsel = 0; @@ -1657,7 +1649,6 @@ static void createTransLatticeVerts(TransInfo *t) copy_v3_v3(td->center, td->loc); if (bp->f1 & SELECT) { td->flag = TD_SELECTED; - if (actbp && bp == actbp) td->flag |= TD_ACTIVE; } else td->flag = 0; copy_m3_m3(td->smtx, smtx); @@ -2059,9 +2050,13 @@ static struct TransIslandData *editmesh_islands_info_calc(BMEditMesh *em, int *r /* pass */ } else { - normalize_v3(no); - axis_dominant_v3_to_m3(trans_islands[i].axismtx, no); - invert_m3(trans_islands[i].axismtx); + if (normalize_v3(no) != 0.0f) { + axis_dominant_v3_to_m3(trans_islands[i].axismtx, no); + invert_m3(trans_islands[i].axismtx); + } + else { + unit_m3(trans_islands[i].axismtx); + } } } @@ -2142,7 +2137,6 @@ static void createTransEditVerts(TransInfo *t) BMesh *bm = em->bm; BMVert *eve; BMIter iter; - BMVert *eve_act = NULL; float (*mappedcos)[3] = NULL, (*quats)[4] = NULL; float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL; float *dists = NULL; @@ -2182,10 +2176,6 @@ static void createTransEditVerts(TransInfo *t) BLI_assert(0); } - - /* check active */ - eve_act = BM_mesh_active_vert_get(bm); - if (t->mode == TFM_BWEIGHT) { BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_VERT_BWEIGHT); cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); @@ -2251,9 +2241,9 @@ static void createTransEditVerts(TransInfo *t) if (totleft > 0) #endif { - mappedcos = crazyspace_get_mapped_editverts(t->scene, t->obedit); + mappedcos = BKE_crazyspace_get_mapped_editverts(t->scene, t->obedit); quats = MEM_mallocN(em->bm->totvert * sizeof(*quats), "crazy quats"); - crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !propmode); + BKE_crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !propmode); if (mappedcos) MEM_freeN(mappedcos); } @@ -2291,9 +2281,6 @@ static void createTransEditVerts(TransInfo *t) if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) tob->flag |= TD_SELECTED; - /* active */ - if (eve == eve_act) tob->flag |= TD_ACTIVE; - if (propmode) { if (propmode & T_PROP_CONNECTED) { tob->dist = dists[a]; @@ -3573,7 +3560,7 @@ static void bezt_to_transdata(TransData *td, TransData2D *td2d, AnimData *adt, B float mtx[3][3], float smtx[3][3]) { float *loc = bezt->vec[bi]; - float *cent = bezt->vec[1]; + const float *cent = bezt->vec[1]; /* New location from td gets dumped onto the old-location of td2d, which then * gets copied to the actual data at td2d->loc2d (bezt->vec[n]) @@ -3773,7 +3760,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) float xscale, yscale; /* apply scale factors to x and y axes of space-conversion matrices */ - UI_view2d_getscale(v2d, &xscale, &yscale); + UI_view2d_scale_get(v2d, &xscale, &yscale); /* mtx is data to global (i.e. view) conversion */ mul_v3_fl(mtx[0], xscale); @@ -3862,13 +3849,13 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } /* special hack (must be done after initTransDataCurveHandles(), as that stores handle settings to restore...): - * - Check if we've got entire BezTriple selected and we're rotating that point, + * - Check if we've got entire BezTriple selected and we're scaling/rotating that point, * then check if we're using auto-handles. * - If so, change them auto-handles to aligned handles so that handles get affected too */ - if ((t->mode == TFM_ROTATION) && - ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) && - ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) + if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) && + ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM) && + ELEM(t->mode, TFM_ROTATION, TFM_RESIZE)) { if (hdata && (sel1) && (sel3)) { bezt->h1 = HD_ALIGN; @@ -4107,14 +4094,16 @@ void flushTransGraphData(TransInfo *t) /* handle snapping for time values * - we should still be in NLA-mapping timespace * - only apply to keyframes (but never to handles) + * - don't do this when cancelling, or else these changes won't go away */ - if ((td->flag & TD_NOTIMESNAP) == 0) { + if ((t->state != TRANS_CANCEL) && (td->flag & TD_NOTIMESNAP) == 0) { switch (sipo->autosnap) { - case SACTSNAP_FRAME: /* snap to nearest frame (or second if drawing seconds) */ - if (sipo->flag & SIPO_DRAWTIME) - td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf; - else - td2d->loc[0] = floor((double)td2d->loc[0] + 0.5); + case SACTSNAP_FRAME: /* snap to nearest frame */ + td2d->loc[0] = floor((double)td2d->loc[0] + 0.5); + break; + + case SACTSNAP_SECOND: /* snap to nearest second */ + td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf; break; case SACTSNAP_MARKER: /* snap to nearest marker */ @@ -4128,6 +4117,31 @@ void flushTransGraphData(TransInfo *t) td2d->loc2d[0] = BKE_nla_tweakedit_remap(adt, td2d->loc[0], NLATIME_CONVERT_UNMAP); else td2d->loc2d[0] = td2d->loc[0]; + + /* Time-stepping auto-snapping modes don't get applied for Graph Editor transforms, + * as these use the generic transform modes which don't account for this sort of thing. + * These ones aren't affected by NLA mapping, so we do this after the conversion... + * + * NOTE: We also have to apply to td->loc, as that's what the handle-adjustment step below looks + * to, otherwise we get "swimming handles" + * NOTE: We don't do this when cancelling transforms, or else these changes don't go away + */ + if ((t->state != TRANS_CANCEL) && (td->flag & TD_NOTIMESNAP) == 0 && + ELEM(sipo->autosnap, SACTSNAP_STEP, SACTSNAP_TSTEP)) + { + switch (sipo->autosnap) { + case SACTSNAP_STEP: /* frame step */ + td2d->loc2d[0] = floor((double)td2d->loc[0] + 0.5); + td->loc[0] = floor((double)td->loc[0] + 0.5); + break; + + case SACTSNAP_TSTEP: /* second step */ + /* XXX: the handle behaviour in this case is still not quite right... */ + td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf; + td->loc[0] = floor(((double)td->loc[0] / secf) + 0.5) * secf; + break; + } + } /* if int-values only, truncate to integers */ if (td->flag & TD_INTVALUES) @@ -4703,8 +4717,7 @@ static bool constraints_list_needinv(TransInfo *t, ListBase *list) } /* transcribe given object into TransData for Transforming */ -static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob, - const Object *ob_act) +static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob) { Scene *scene = t->scene; bool constinv; @@ -4828,11 +4841,6 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob, unit_m3(td->smtx); unit_m3(td->mtx); } - - /* set active flag */ - if (ob == ob_act) { - td->flag |= TD_ACTIVE; - } } @@ -5840,7 +5848,6 @@ int special_transform_moving(TransInfo *t) static void createTransObject(bContext *C, TransInfo *t) { Scene *scene = t->scene; - const Object *ob_act = OBACT; TransData *td = NULL; TransDataExtension *tx; @@ -5883,7 +5890,7 @@ static void createTransObject(bContext *C, TransInfo *t) td->flag |= TD_SKIP; } - ObjectToTransData(t, td, ob, ob_act); + ObjectToTransData(t, td, ob); td->val = NULL; td++; tx++; @@ -5905,7 +5912,7 @@ static void createTransObject(bContext *C, TransInfo *t) td->ext = tx; td->ext->rotOrder = ob->rotmode; - ObjectToTransData(t, td, ob, ob_act); + ObjectToTransData(t, td, ob); td->val = NULL; td++; tx++; @@ -6026,7 +6033,7 @@ typedef struct TransDataTracking { /* tracks transformation from main window */ int area; - float *relative, *loc; + const float *relative, *loc; float soffset[2], srelative[2]; float offset[2]; @@ -6596,7 +6603,7 @@ static void MaskHandleToTransData(MaskSplinePoint *point, eMaskWhichHandle which /*const*/ float parent_inverse_matrix[3][3]) { BezTriple *bezt = &point->bezt; - short is_sel_any = MASKPOINT_ISSEL_ANY(point); + const bool is_sel_any = MASKPOINT_ISSEL_ANY(point); tdm->point = point; copy_m3_m3(tdm->vec, bezt->vec); |