Commit: 06305e5ca800c048c69f18a24951f4bc87305610 Author: Germano Cavalcante Date: Fri Feb 3 11:29:16 2023 -0300 Branches: master https://developer.blender.org/rB06305e5ca800c048c69f18a24951f4bc87305610
Cleanup/refactor: split Edge and Vert Slide code into more specific functions This makes the code more readable. In this commit also the `int curr_side_unclamp` member was moved to `EdgeSlideParams` as it is a common value for all "Containers". =================================================================== M source/blender/editors/transform/transform_mode_edge_slide.c M source/blender/editors/transform/transform_mode_vert_slide.c =================================================================== diff --git a/source/blender/editors/transform/transform_mode_edge_slide.c b/source/blender/editors/transform/transform_mode_edge_slide.c index f2ba8c4bd4d..df081180118 100644 --- a/source/blender/editors/transform/transform_mode_edge_slide.c +++ b/source/blender/editors/transform/transform_mode_edge_slide.c @@ -66,14 +66,14 @@ typedef struct EdgeSlideData { int mval_start[2], mval_end[2]; int curr_sv_index; - - /** when un-clamped - use this index: #TransDataEdgeSlideVert.dir_side */ - int curr_side_unclamp; } EdgeSlideData; typedef struct EdgeSlideParams { float perc; + /** when un-clamped - use this index: #TransDataEdgeSlideVert.dir_side */ + int curr_side_unclamp; + bool use_even; bool flipped; } EdgeSlideParams; @@ -1198,7 +1198,7 @@ void drawEdgeSlide(TransInfo *t) immEnd(); } else if (is_clamp == false) { - const int side_index = sld->curr_side_unclamp; + const int side_index = slp->curr_side_unclamp; TransDataEdgeSlideVert *sv; int i; const int alpha_shade = -160; @@ -1235,7 +1235,7 @@ void drawEdgeSlide(TransInfo *t) const int alpha_shade = -160; float co_dir[3]; - add_v3_v3v3(co_dir, curr_sv->v_co_orig, curr_sv->dir_side[sld->curr_side_unclamp]); + add_v3_v3v3(co_dir, curr_sv->v_co_orig, curr_sv->dir_side[slp->curr_side_unclamp]); GPU_line_width(line_size); immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade); @@ -1284,7 +1284,7 @@ static void edge_slide_snap_apply(TransInfo *t, float *value) side_index = perc < 0.0f; } else { - side_index = sld_active->curr_side_unclamp; + side_index = slp->curr_side_unclamp; } } else { @@ -1336,57 +1336,30 @@ static void edge_slide_snap_apply(TransInfo *t, float *value) *value = perc; } -static void doEdgeSlide(TransInfo *t, float perc) +static void edge_slide_apply_elem(const TransDataEdgeSlideVert *sv, + const float fac, + const float curr_length_fac, + const int curr_side_unclamp, + const bool use_clamp, + const bool use_even, + const bool use_flip, + float r_co[3]) { - EdgeSlideParams *slp = t->custom.mode.data; - EdgeSlideData *sld_active = edgeSlideFirstGet(t); - - slp->perc = perc; + copy_v3_v3(r_co, sv->v_co_orig); - if (slp->use_even == false) { - const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); - if (is_clamp) { - const int side_index = (perc < 0.0f); - const float perc_final = fabsf(perc); - FOREACH_TRANS_DATA_CONTAINER (t, tc) { - EdgeSlideData *sld = tc->custom.mode.data; - - if (sld == NULL) { - continue; - } - - TransDataEdgeSlideVert *sv = sld->sv; - for (int i = 0; i < sld->totsv; i++, sv++) { - madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, sv->dir_side[side_index], perc_final); - } - sld->curr_side_unclamp = side_index; - } + if (use_even == false) { + if (use_clamp) { + const int side_index = (fac < 0.0f); + const float fac_final = fabsf(fac); + madd_v3_v3fl(r_co, sv->dir_side[side_index], fac_final); } else { - const float perc_init = fabsf(perc) * - ((sld_active->curr_side_unclamp == (perc < 0.0f)) ? 1 : -1); - const int side_index = sld_active->curr_side_unclamp; - FOREACH_TRANS_DATA_CONTAINER (t, tc) { - EdgeSlideData *sld = tc->custom.mode.data; - - if (sld == NULL) { - continue; - } - - TransDataEdgeSlideVert *sv = sld->sv; - for (int i = 0; i < sld->totsv; i++, sv++) { - float dir_flip[3]; - float perc_final = perc_init; - if (!is_zero_v3(sv->dir_side[side_index])) { - copy_v3_v3(dir_flip, sv->dir_side[side_index]); - } - else { - copy_v3_v3(dir_flip, sv->dir_side[!side_index]); - perc_final *= -1; - } - madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, dir_flip, perc_final); - } + int side_index = curr_side_unclamp; + if (is_zero_v3(sv->dir_side[side_index])) { + side_index = !side_index; } + const float fac_final = (side_index == (fac < 0.0f) ? fabsf(fac) : -fabsf(fac)); + madd_v3_v3fl(r_co, sv->dir_side[side_index], fac_final); } } else { @@ -1400,36 +1373,55 @@ static void doEdgeSlide(TransInfo *t, float perc) * is the same as the distance between the original vert locations, * same goes for the lines below. */ - TransDataEdgeSlideVert *curr_sv = &sld_active->sv[sld_active->curr_sv_index]; - const float curr_length_perc = curr_sv->edge_len * - (((slp->flipped ? perc : -perc) + 1.0f) / 2.0f); - - float co_a[3]; - float co_b[3]; + if (sv->edge_len > FLT_EPSILON) { + float co_a[3], co_b[3]; + const float fac = min_ff(sv->edge_len, curr_length_fac) / sv->edge_len; - FOREACH_TRANS_DATA_CONTAINER (t, tc) { - EdgeSlideData *sld = tc->custom.mode.data; + add_v3_v3v3(co_a, sv->v_co_orig, sv->dir_side[0]); + add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_side[1]); - if (sld == NULL) { - continue; + if (use_flip) { + interp_line_v3_v3v3v3(r_co, co_b, sv->v_co_orig, co_a, fac); } + else { + interp_line_v3_v3v3v3(r_co, co_a, sv->v_co_orig, co_b, fac); + } + } + } +} - TransDataEdgeSlideVert *sv = sld->sv; - for (int i = 0; i < sld->totsv; i++, sv++) { - if (sv->edge_len > FLT_EPSILON) { - const float fac = min_ff(sv->edge_len, curr_length_perc) / sv->edge_len; +static void doEdgeSlide(TransInfo *t, float perc) +{ + EdgeSlideParams *slp = t->custom.mode.data; + EdgeSlideData *sld_active = edgeSlideFirstGet(t); - add_v3_v3v3(co_a, sv->v_co_orig, sv->dir_side[0]); - add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_side[1]); + slp->perc = perc; - if (slp->flipped) { - interp_line_v3_v3v3v3(sv->v->co, co_b, sv->v_co_orig, co_a, fac); - } - else { - interp_line_v3_v3v3v3(sv->v->co, co_a, sv->v_co_orig, co_b, fac); - } - } - } + const bool use_clamp = !(t->flag & T_ALT_TRANSFORM); + const bool use_even = slp->use_even; + const bool use_flip = slp->flipped; + + const int curr_side_unclamp = slp->curr_side_unclamp; + float curr_length_fac = 0.0f; + if (use_even) { + TransDataEdgeSlideVert *sv_active = &sld_active->sv[sld_active->curr_sv_index]; + curr_length_fac = sv_active->edge_len * (((use_flip ? perc : -perc) + 1.0f) / 2.0f); + } + else if (use_clamp) { + slp->curr_side_unclamp = (perc < 0.0f); + } + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + EdgeSlideData *sld = tc->custom.mode.data; + + if (sld == NULL) { + continue; + } + + TransDataEdgeSlideVert *sv = sld->sv; + for (int i = 0; i < sld->totsv; i++, sv++) { + edge_slide_apply_elem( + sv, perc, curr_length_fac, curr_side_unclamp, use_clamp, use_even, use_flip, sv->v->co); } } } diff --git a/source/blender/editors/transform/transform_mode_vert_slide.c b/source/blender/editors/transform/transform_mode_vert_slide.c index f6e8c64af8f..df96287af7c 100644 --- a/source/blender/editors/transform/transform_mode_vert_slide.c +++ b/source/blender/editors/transform/transform_mode_vert_slide.c @@ -466,53 +466,58 @@ void drawVertSlide(TransInfo *t) } } +static void vert_slide_apply_elem(const TransDataVertSlideVert *sv, + const float perc, + const bool use_even, + const bool use_flip, + float r_co[3]) +{ + if (use_even == false) { + interp_v3_v3v3(r_co, sv->co_orig_3d, sv->co_link_orig_3d[sv->co_link_curr], perc); + } + else { + float dir[3]; + sub_v3_v3v3(dir, sv->co_link_orig_3d[sv->co_link_curr], sv->co_orig_3d); + float edge_len = normalize_v3(dir); + if (edge_len > FLT_EPSILON) { + if (use_flip) { + madd_v3_v3v3fl(r_co, sv->co_link_orig_3d[sv->co_link_curr], dir, -perc); + } + else { + madd_v3_v3v3fl(r_co, sv->co_orig_3d, dir, perc); + } + } + else { + copy_v3_v3(r_co, sv->co_orig_3d); + } + } +} + static void doVertSlide(TransInfo *t, float perc) { VertSlideParams *slp = t->custom.mode.data; slp->perc = perc; + const bool use_even = slp->use_even; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { VertSlideData *sld = tc->custom.mode.data; if (sld == NULL) { continue; } - TransDataVertSlideVert *svlist = sld->sv, *sv; - int i; - - sv = svlist; - - if (slp->use_even == false) { - for (i = 0; i < sld->totsv; i++, sv++) { - interp_v3_v3v3(sv->v->co, sv->co_orig_3d, sv->co_link_orig_3d[sv->co_link_curr], perc); - } - } - else { + float tperc = perc; + if (use_even) { TransDataVertSlideVert *sv_curr = &sld->sv[sld->curr_sv_index]; const float edge_len_curr = len_v3v3(sv_curr->co_orig_3d, sv_curr->co_link_orig_3d[sv_curr->co_link_curr]); - const float tperc = perc * edge_len_curr; - - for (i = 0; i < sld->totsv; i++, sv++) { - float edge_len; - float dir[3]; - - sub_v3_v3v3(dir, sv->co_link_orig_3d[sv->co_link_curr], sv->co_orig_3d); - edge_len = normalize_v3(dir); + tperc *= edge_len_curr; + } - if (edge_len > FLT_EPSILON) { - if (slp->flipped) { - madd_v3_v3v3fl(sv->v->co, sv->co_link_orig_3d[sv->co_link_curr], dir, -tperc); - } - else { - madd_v3_v3v3fl(sv->v->co, sv->co_orig_3d, dir, tperc); - } - } - else { - copy_v3_v3(sv->v->co, sv->co_orig_3d); - } - } + TransDataVertSlideVert *sv = sld->sv; + for (int i = 0; i < sld->totsv; i++, sv++) { + vert_slide_apply_elem(sv, tperc, use_even, slp->flipped, sv->v->co); } } } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs