diff options
Diffstat (limited to 'source/blender/editors/transform/transform_mode_skin_resize.c')
-rw-r--r-- | source/blender/editors/transform/transform_mode_skin_resize.c | 92 |
1 files changed, 70 insertions, 22 deletions
diff --git a/source/blender/editors/transform/transform_mode_skin_resize.c b/source/blender/editors/transform/transform_mode_skin_resize.c index 75ad83b0787..45336602c5a 100644 --- a/source/blender/editors/transform/transform_mode_skin_resize.c +++ b/source/blender/editors/transform/transform_mode_skin_resize.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include "BLI_math.h" +#include "BLI_task.h" #include "BKE_context.h" #include "BKE_unit.h" @@ -38,6 +39,58 @@ #include "transform_snap.h" /* -------------------------------------------------------------------- */ +/** \name Transform (Skin) Element + * \{ */ + +/** + * \note Small arrays / data-structures should be stored copied for faster memory access. + */ +struct TransDataArgs_SkinResize { + const TransInfo *t; + const TransDataContainer *tc; + float mat[3][3]; +}; + +static void transdata_elem_skin_resize(const TransInfo *t, + const TransDataContainer *UNUSED(tc), + TransData *td, + const float mat[3][3]) +{ + float tmat[3][3], smat[3][3]; + float fsize[3]; + + if (t->flag & T_EDIT) { + mul_m3_m3m3(smat, mat, td->mtx); + mul_m3_m3m3(tmat, td->smtx, smat); + } + else { + copy_m3_m3(tmat, mat); + } + + if (t->con.applySize) { + t->con.applySize(t, NULL, NULL, tmat); + } + + mat3_to_size(fsize, tmat); + td->loc[0] = td->iloc[0] * (1 + (fsize[0] - 1) * td->factor); + td->loc[1] = td->iloc[1] * (1 + (fsize[1] - 1) * td->factor); +} + +static void transdata_elem_skin_resize_fn(void *__restrict iter_data_v, + const int iter, + const TaskParallelTLS *__restrict UNUSED(tls)) +{ + struct TransDataArgs_SkinResize *data = iter_data_v; + TransData *td = &data->tc->data[iter]; + if (td->flag & TD_SKIP) { + return; + } + transdata_elem_skin_resize(data->t, data->tc, td, data->mat); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ /** \name Transform (Skin) * \{ */ @@ -67,29 +120,24 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) headerResize(t, t->values_final, str, sizeof(str)); FOREACH_TRANS_DATA_CONTAINER (t, tc) { - TransData *td = tc->data; - for (i = 0; i < tc->data_len; i++, td++) { - float tmat[3][3], smat[3][3]; - float fsize[3]; - if (td->flag & TD_SKIP) { - continue; + if (tc->data_len < TRANSDATA_THREAD_LIMIT) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_SKIP) { + continue; + } + transdata_elem_skin_resize(t, tc, td, mat); } - - if (t->flag & T_EDIT) { - mul_m3_m3m3(smat, mat, td->mtx); - mul_m3_m3m3(tmat, td->smtx, smat); - } - else { - copy_m3_m3(tmat, mat); - } - - if (t->con.applySize) { - t->con.applySize(t, NULL, NULL, tmat); - } - - mat3_to_size(fsize, tmat); - td->loc[0] = td->iloc[0] * (1 + (fsize[0] - 1) * td->factor); - td->loc[1] = td->iloc[1] * (1 + (fsize[1] - 1) * td->factor); + } + else { + struct TransDataArgs_SkinResize data = { + .t = t, + .tc = tc, + }; + copy_m3_m3(data.mat, mat); + TaskParallelSettings settings; + BLI_parallel_range_settings_defaults(&settings); + BLI_task_parallel_range(0, tc->data_len, &data, transdata_elem_skin_resize_fn, &settings); } } |