diff options
Diffstat (limited to 'source/blender/editors/transform/transform_mode_vert_slide.c')
-rw-r--r-- | source/blender/editors/transform/transform_mode_vert_slide.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/source/blender/editors/transform/transform_mode_vert_slide.c b/source/blender/editors/transform/transform_mode_vert_slide.c index 62415b1ddc6..4b75c362da9 100644 --- a/source/blender/editors/transform/transform_mode_vert_slide.c +++ b/source/blender/editors/transform/transform_mode_vert_slide.c @@ -47,6 +47,7 @@ #include "BLT_translation.h" #include "transform.h" +#include "transform_constraints.h" #include "transform_convert.h" #include "transform_mode.h" #include "transform_snap.h" @@ -491,7 +492,7 @@ void drawVertSlide(TransInfo *t) } } -void doVertSlide(TransInfo *t, float perc) +static void doVertSlide(TransInfo *t, float perc) { VertSlideParams *slp = t->custom.mode.data; @@ -538,6 +539,37 @@ void doVertSlide(TransInfo *t, float perc) } } +static void vert_slide_snap_apply(TransInfo *t, float *value) +{ + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_OK(t); + VertSlideData *sld = tc->custom.mode.data; + TransDataVertSlideVert *sv = &sld->sv[sld->curr_sv_index]; + + float snap_point[3], co_orig_3d[3], co_curr_3d[3], dvec[3]; + copy_v3_v3(co_orig_3d, sv->co_orig_3d); + copy_v3_v3(co_curr_3d, sv->co_link_orig_3d[sv->co_link_curr]); + if (tc->use_local_mat) { + mul_m4_v3(tc->mat, co_orig_3d); + mul_m4_v3(tc->mat, co_curr_3d); + } + + getSnapPoint(t, dvec); + sub_v3_v3(dvec, t->tsnap.snapTarget); + if (t->tsnap.snapElem & (SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE)) { + float co_dir_3d[3]; + sub_v3_v3v3(co_dir_3d, co_curr_3d, co_orig_3d); + if (t->tsnap.snapElem & SCE_SNAP_MODE_EDGE) { + transform_constraint_snap_axis_to_edge(t, co_dir_3d, dvec); + } + else { + transform_constraint_snap_axis_to_face(t, co_dir_3d, dvec); + } + } + + add_v3_v3v3(snap_point, co_orig_3d, dvec); + *value = line_point_factor_v3(snap_point, co_orig_3d, co_curr_3d); +} + static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2])) { char str[UI_MAX_DRAW_STR]; @@ -551,6 +583,7 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; + applySnapping(t, &final); snapGridIncrement(t, &final); /* only do this so out of range values are not displayed */ @@ -596,6 +629,8 @@ void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp) t->mode = TFM_VERT_SLIDE; t->transform = applyVertSlide; t->handleEvent = handleEventVertSlide; + t->tsnap.applySnap = vert_slide_snap_apply; + t->tsnap.distance = transform_snap_distance_len_squared_fn; { VertSlideParams *slp = MEM_callocN(sizeof(*slp), __func__); @@ -617,7 +652,6 @@ void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp) if (sld) { tc->custom.mode.data = sld; tc->custom.mode.free_cb = freeVertSlideVerts; - trans_mesh_customdata_correction_init(t, tc); ok = true; } } |