Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/operators/bmo_utils.c
| Show First 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | |||||
| void bmo_rotate_uvs_exec(BMesh *bm, BMOperator *op) | void bmo_rotate_uvs_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| BMOIter fs_iter; /* selected faces iterator */ | BMOIter fs_iter; /* selected faces iterator */ | ||||
| BMFace *fs; /* current face */ | BMFace *fs; /* current face */ | ||||
| BMIter l_iter; /* iteration loop */ | BMIter l_iter; /* iteration loop */ | ||||
| const bool use_ccw = BMO_slot_bool_get(op->slots_in, "use_ccw"); | const bool use_ccw = BMO_slot_bool_get(op->slots_in, "use_ccw"); | ||||
| const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); | const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2); | ||||
| if (cd_loop_uv_offset != -1) { | if (cd_loop_uv_offset != -1) { | ||||
| BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) { | BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) { | ||||
| if (use_ccw == false) { /* same loops direction */ | if (use_ccw == false) { /* same loops direction */ | ||||
| BMLoop *lf; /* current face loops */ | BMLoop *lf; /* current face loops */ | ||||
| MLoopUV *f_luv; /* first face loop uv */ | float *f_luv; /* first face loop uv */ | ||||
| float p_uv[2]; /* previous uvs */ | float p_uv[2]; /* previous uvs */ | ||||
| float t_uv[2]; /* temp uvs */ | float t_uv[2]; /* temp uvs */ | ||||
| int n = 0; | int n = 0; | ||||
| BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) { | ||||
| /* current loop uv is the previous loop uv */ | /* current loop uv is the previous loop uv */ | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(lf, cd_loop_uv_offset); | ||||
| if (n == 0) { | if (n == 0) { | ||||
| f_luv = luv; | f_luv = luv; | ||||
| copy_v2_v2(p_uv, luv->uv); | copy_v2_v2(p_uv, luv); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v2_v2(t_uv, luv->uv); | copy_v2_v2(t_uv, luv); | ||||
| copy_v2_v2(luv->uv, p_uv); | copy_v2_v2(luv, p_uv); | ||||
| copy_v2_v2(p_uv, t_uv); | copy_v2_v2(p_uv, t_uv); | ||||
| } | } | ||||
| n++; | n++; | ||||
| } | } | ||||
| copy_v2_v2(f_luv->uv, p_uv); | copy_v2_v2(f_luv, p_uv); | ||||
| } | } | ||||
| else { /* counter loop direction */ | else { /* counter loop direction */ | ||||
| BMLoop *lf; /* current face loops */ | BMLoop *lf; /* current face loops */ | ||||
| MLoopUV *p_luv; /* previous loop uv */ | float *p_luv; /* previous loop uv */ | ||||
| MLoopUV *luv; | float *luv; | ||||
| float t_uv[2]; /* current uvs */ | float t_uv[2]; /* current uvs */ | ||||
| int n = 0; | int n = 0; | ||||
| BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) { | ||||
| /* previous loop uv is the current loop uv */ | /* previous loop uv is the current loop uv */ | ||||
| luv = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_uv_offset); | luv = BM_ELEM_CD_GET_FLOAT_P(lf, cd_loop_uv_offset); | ||||
| if (n == 0) { | if (n == 0) { | ||||
| p_luv = luv; | p_luv = luv; | ||||
| copy_v2_v2(t_uv, luv->uv); | copy_v2_v2(t_uv, luv); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v2_v2(p_luv->uv, luv->uv); | copy_v2_v2(p_luv, luv); | ||||
| p_luv = luv; | p_luv = luv; | ||||
| } | } | ||||
| n++; | n++; | ||||
| } | } | ||||
| copy_v2_v2(luv->uv, t_uv); | copy_v2_v2(luv, t_uv); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /**************************************************************************** * | /**************************************************************************** * | ||||
| * Reverse UVs for a face | * Reverse UVs for a face | ||||
| **************************************************************************** */ | **************************************************************************** */ | ||||
| static void bm_face_reverse_uvs(BMFace *f, const int cd_loop_uv_offset) | static void bm_face_reverse_uvs(BMFace *f, const int cd_loop_uv_offset) | ||||
| { | { | ||||
| BMIter iter; | BMIter iter; | ||||
| BMLoop *l; | BMLoop *l; | ||||
| int i; | int i; | ||||
| float(*uvs)[2] = BLI_array_alloca(uvs, f->len); | float(*uvs)[2] = BLI_array_alloca(uvs, f->len); | ||||
| BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) { | BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| copy_v2_v2(uvs[i], luv->uv); | copy_v2_v2(uvs[i], luv); | ||||
| } | } | ||||
| /* now that we have the uvs in the array, reverse! */ | /* now that we have the uvs in the array, reverse! */ | ||||
| BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) { | BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) { | ||||
| /* current loop uv is the previous loop uv */ | /* current loop uv is the previous loop uv */ | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| copy_v2_v2(luv->uv, uvs[(f->len - i - 1)]); | copy_v2_v2(luv, uvs[(f->len - i - 1)]); | ||||
| } | } | ||||
| } | } | ||||
| void bmo_reverse_uvs_exec(BMesh *bm, BMOperator *op) | void bmo_reverse_uvs_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| BMOIter iter; | BMOIter iter; | ||||
| BMFace *f; | BMFace *f; | ||||
| const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); | const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_PROP_FLOAT2); | ||||
| if (cd_loop_uv_offset != -1) { | if (cd_loop_uv_offset != -1) { | ||||
| BMO_ITER (f, &iter, op->slots_in, "faces", BM_FACE) { | BMO_ITER (f, &iter, op->slots_in, "faces", BM_FACE) { | ||||
| bm_face_reverse_uvs(f, cd_loop_uv_offset); | bm_face_reverse_uvs(f, cd_loop_uv_offset); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines | |||||