diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-10 12:08:18 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-10 12:08:18 +0400 |
commit | 3104639a29fdd951b024b05596a3749eb999b08e (patch) | |
tree | 009a69e1faeee8206dd2cc91e6dddd1e261860e5 /source/blender/editors/mesh/mesh_data.c | |
parent | 2cf1f1f4d6a4ffebf404e7e00de42aee7a418b57 (diff) |
avoid using BLI_array_* macros for uv reset.
Diffstat (limited to 'source/blender/editors/mesh/mesh_data.c')
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 154 |
1 files changed, 76 insertions, 78 deletions
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 71db90e3ac4..ed652a7b812 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -219,108 +219,106 @@ static void delete_customdata_layer(Mesh *me, CustomDataLayer *layer) } } -/* without bContext, called in uvedit */ -void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum) +static void mesh_uv_reset_array(float **fuv, const int len) { - BMEditMesh *em = me->edit_btmesh; - MLoopUV *luv; - BLI_array_declare(polylengths); - int *polylengths = NULL; - BLI_array_declare(uvs); - float **uvs = NULL; - float **fuvs = NULL; - int i, j; + if (len == 3) { + fuv[0][0] = 0.0; + fuv[0][1] = 0.0; - if (em) { - /* Collect BMesh UVs */ + fuv[1][0] = 1.0; + fuv[1][1] = 0.0; - BMFace *efa; - BMLoop *l; - BMIter iter, liter; + fuv[2][0] = 1.0; + fuv[2][1] = 1.0; + } + else if (len == 4) { + fuv[0][0] = 0.0; + fuv[0][1] = 0.0; - BLI_assert(CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)); + fuv[1][0] = 1.0; + fuv[1][1] = 0.0; - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) - continue; + fuv[2][0] = 1.0; + fuv[2][1] = 1.0; - i = 0; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = CustomData_bmesh_get_n(&em->bm->ldata, l->head.data, CD_MLOOPUV, layernum); - BLI_array_append(uvs, luv->uv); - i++; - } + fuv[3][0] = 0.0; + fuv[3][1] = 1.0; + /*make sure we ignore 2-sided faces*/ + } + else if (len > 2) { + float fac = 0.0f, dfac = 1.0f / (float)len; + int i; - BLI_array_append(polylengths, efa->len); + dfac *= (float)M_PI * 2.0f; + + for (i = 0; i < len; i++) { + fuv[i][0] = 0.5f * sinf(fac) + 0.5f; + fuv[i][1] = 0.5f * cosf(fac) + 0.5f; + + fac += dfac; } } - else { - /* Collect Mesh UVs */ +} - MPoly *mp; - MLoopUV *mloouv; +static void mesh_uv_reset_bmface(BMFace *f, const int cd_loop_uv_offset) +{ + float **fuv = BLI_array_alloca(fuv, f->len); + BMIter liter; + BMLoop *l; + int i; - BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV)); - mloouv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum); + BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, i) { + fuv[i] = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset))->uv; + } - for (j = 0; j < me->totpoly; j++) { - mp = &me->mpoly[j]; + mesh_uv_reset_array(fuv, f->len); +} - for (i = 0; i < mp->totloop; i++) { - luv = &mloouv[mp->loopstart + i]; - BLI_array_append(uvs, luv->uv); - } +static void mesh_uv_reset_mface(MPoly *mp, MLoopUV *mloopuv) +{ + float **fuv = BLI_array_alloca(fuv, mp->totloop); + int i; - BLI_array_append(polylengths, mp->totloop); - } + for (i = 0; i < mp->totloop; i++) { + fuv[i] = mloopuv[mp->loopstart + i].uv; } - fuvs = uvs; - for (j = 0; j < BLI_array_count(polylengths); j++) { - int len = polylengths[j]; + mesh_uv_reset_array(fuv, mp->totloop); +} + +/* without bContext, called in uvedit */ +void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum) +{ + BMEditMesh *em = me->edit_btmesh; - if (len == 3) { - fuvs[0][0] = 0.0; - fuvs[0][1] = 0.0; - - fuvs[1][0] = 1.0; - fuvs[1][1] = 0.0; + if (em) { + /* Collect BMesh UVs */ + const int cd_loop_uv_offset = CustomData_get_n_offset(&em->bm->ldata, CD_MLOOPUV, layernum); - fuvs[2][0] = 1.0; - fuvs[2][1] = 1.0; - } - else if (len == 4) { - fuvs[0][0] = 0.0; - fuvs[0][1] = 0.0; - - fuvs[1][0] = 1.0; - fuvs[1][1] = 0.0; - - fuvs[2][0] = 1.0; - fuvs[2][1] = 1.0; - - fuvs[3][0] = 0.0; - fuvs[3][1] = 1.0; - /*make sure we ignore 2-sided faces*/ - } - else if (len > 2) { - float fac = 0.0f, dfac = 1.0f / (float)len; + BMFace *efa; + BMIter iter; - dfac *= (float)M_PI * 2.0f; + BLI_assert(cd_loop_uv_offset != -1); - for (i = 0; i < len; i++) { - fuvs[i][0] = 0.5f * sinf(fac) + 0.5f; - fuvs[i][1] = 0.5f * cosf(fac) + 0.5f; + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + continue; - fac += dfac; - } + mesh_uv_reset_bmface(efa, cd_loop_uv_offset); } - - fuvs += len; } + else { + /* Collect Mesh UVs */ + MLoopUV *mloopuv; + int i; + + BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV)); + mloopuv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum); - BLI_array_free(uvs); - BLI_array_free(polylengths); + for (i = 0; i < me->totpoly; i++) { + mesh_uv_reset_mface(&me->mpoly[i], mloopuv); + } + } DAG_id_tag_update(&me->id, 0); } |