From 7a547e441b2a107148a9c0abb3b8badbb728abef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 10 May 2013 06:46:32 +0000 Subject: [PATCH] avoid customdata lookups for selection test/enable disable. also add uvedit_face_select_set, uvedit_edge_select_set, uvedit_uv_select_set - since quite a few areas where setting based on a boolean. --- .../blenkernel/intern/editderivedmesh.c | 55 +-- source/blender/editors/include/ED_uvedit.h | 39 +- source/blender/editors/mesh/meshtools.c | 2 +- .../editors/transform/transform_conversions.c | 10 +- .../blender/editors/uvedit/uvedit_buttons.c | 20 +- source/blender/editors/uvedit/uvedit_draw.c | 18 +- source/blender/editors/uvedit/uvedit_intern.h | 4 +- source/blender/editors/uvedit/uvedit_ops.c | 384 ++++++++---------- .../editors/uvedit/uvedit_smart_stitch.c | 94 +++-- .../editors/uvedit/uvedit_unwrap_ops.c | 32 +- 10 files changed, 340 insertions(+), 318 deletions(-) diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 75b31605105..13ee9328cf6 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -221,33 +221,28 @@ static void emDM_drawUVEdges(DerivedMesh *dm) BMFace *efa; BMIter iter; + const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); + + if (UNLIKELY(cd_loop_uv_offset == -1)) { + return; + } + glBegin(GL_LINES); BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { - BMIter liter; - BMLoop *l; - MLoopUV *lastluv = NULL, *firstluv = NULL; + BMLoop *l_iter, *l_first; + const float *uv, *uv_prev; if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) continue; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - MLoopUV *luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); - - if (luv) { - if (lastluv) - glVertex2fv(luv->uv); - glVertex2fv(luv->uv); - - lastluv = luv; - if (!firstluv) - firstluv = luv; - } - } - - if (lastluv) { - glVertex2fv(lastluv->uv); - glVertex2fv(firstluv->uv); - } + l_iter = l_first = BM_FACE_FIRST_LOOP(efa); + uv_prev = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter->prev, cd_loop_uv_offset))->uv; + do { + uv = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset))->uv; + glVertex2fv(uv); + glVertex2fv(uv_prev); + uv_prev = uv; + } while ((l_iter = l_iter->next) != l_first); } glEnd(); } @@ -1312,6 +1307,7 @@ static void *emDM_getTessFaceDataArray(DerivedMesh *dm, int type) if (index != -1) { /* offset = bm->pdata.layers[index].offset; */ /* UNUSED */ + BMLoop *(*looptris)[3] = bmdm->em->looptris; const int size = CustomData_sizeof(type); int i, j; @@ -1322,20 +1318,29 @@ static void *emDM_getTessFaceDataArray(DerivedMesh *dm, int type) data = datalayer = DM_get_tessface_data_layer(dm, type); if (type == CD_MTFACE) { + const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); + const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY); + for (i = 0; i < bmdm->em->tottri; i++, data += size) { - BMFace *efa = bmdm->em->looptris[i][0]->f; - bmdata = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); + BMFace *efa = looptris[i][0]->f; + + // bmdata = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); + bmdata = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); + ME_MTEXFACE_CPY(((MTFace *)data), ((MTexPoly *)bmdata)); for (j = 0; j < 3; j++) { - bmdata = CustomData_bmesh_get(&bm->ldata, bmdm->em->looptris[i][j]->head.data, CD_MLOOPUV); + // bmdata = CustomData_bmesh_get(&bm->ldata, looptris[i][j]->head.data, CD_MLOOPUV); + bmdata = BM_ELEM_CD_GET_VOID_P(looptris[i][j], cd_loop_uv_offset); copy_v2_v2(((MTFace *)data)->uv[j], ((MLoopUV *)bmdata)->uv); } } } else { + const int cd_loop_color_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPCOL); for (i = 0; i < bmdm->em->tottri; i++, data += size) { for (j = 0; j < 3; j++) { - bmdata = CustomData_bmesh_get(&bm->ldata, bmdm->em->looptris[i][j]->head.data, CD_MLOOPCOL); + // bmdata = CustomData_bmesh_get(&bm->ldata, looptris[i][j]->head.data, CD_MLOOPCOL); + bmdata = BM_ELEM_CD_GET_VOID_P(looptris[i][j], cd_loop_color_offset); MESH_MLOOPCOL_TO_MCOL(((MLoopCol *)bmdata), (((MCol *)data) + j)); } } diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h index 02692c58a99..2a913b3c031 100644 --- a/source/blender/editors/include/ED_uvedit.h +++ b/source/blender/editors/include/ED_uvedit.h @@ -59,17 +59,34 @@ void ED_object_assign_active_image(struct Main *bmain, struct Object *ob, int ma int ED_uvedit_test(struct Object *obedit); /* visibility and selection */ -int uvedit_face_visible_test(struct Scene *scene, struct Image *ima, struct BMFace *efa, struct MTexPoly *tf); -int uvedit_face_select_test(struct Scene *scene, struct BMEditMesh *em, struct BMFace *efa); -int uvedit_edge_select_test(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l); -int uvedit_uv_select_test(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l); - -int uvedit_face_select_enable(struct Scene *scene, struct BMEditMesh *em, struct BMFace *efa, const bool do_history); -int uvedit_face_select_disable(struct Scene *scene, struct BMEditMesh *em, struct BMFace *efa); -void uvedit_edge_select_enable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, const bool do_history); -void uvedit_edge_select_disable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l); -void uvedit_uv_select_enable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, const bool do_history); -void uvedit_uv_select_disable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l); +bool uvedit_face_visible_test(struct Scene *scene, struct Image *ima, struct BMFace *efa, struct MTexPoly *tf); +bool uvedit_face_select_test(struct Scene *scene, struct BMFace *efa, + const int cd_loop_uv_offset); +bool uvedit_edge_select_test(struct Scene *scene, struct BMLoop *l, + const int cd_loop_uv_offset); +bool uvedit_uv_select_test(struct Scene *scene, struct BMLoop *l, + const int cd_loop_uv_offset); +/* uv face */ +bool uvedit_face_select_set(struct Scene *scene, struct BMEditMesh *em, struct BMFace *efa, const bool select, + const bool do_history, const int cd_loop_uv_offset); +bool uvedit_face_select_enable(struct Scene *scene, struct BMEditMesh *em, struct BMFace *efa, + const bool do_history, const int cd_loop_uv_offset); +bool uvedit_face_select_disable(struct Scene *scene, struct BMEditMesh *em, struct BMFace *efa, + const int cd_loop_uv_offset); +/* uv edge */ +void uvedit_edge_select_set(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, const bool select, + const bool do_history, const int cd_loop_uv_offset); +void uvedit_edge_select_enable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, + const bool do_history, const int cd_loop_uv_offset); +void uvedit_edge_select_disable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, + const int cd_loop_uv_offset); +/* uv vert */ +void uvedit_uv_select_set(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, const bool select, + const bool do_history, const int cd_loop_uv_offset); +void uvedit_uv_select_enable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, + const bool do_history, const int cd_loop_uv_offset); +void uvedit_uv_select_disable(struct BMEditMesh *em, struct Scene *scene, struct BMLoop *l, + const int cd_loop_uv_offset); int ED_uvedit_nearest_uv(struct Scene *scene, struct Object *obedit, struct Image *ima, const float co[2], float r_uv[2]); diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index efc4acd7c4f..5f451a542e6 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -1047,7 +1047,7 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float BMFace *efa; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - uv_poly_center(em, efa, cent); + uv_poly_center(efa, cent, cd_loop_uv_offset); if ( (fabsf(cent[0] - cent_vec[0]) < 0.001f) && (fabsf(cent[1] - cent_vec[1]) < 0.001f) ) { BMIter liter; diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index e2249cd48d7..d6b12e05b44 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2418,6 +2418,8 @@ static void createTransUVs(bContext *C, TransInfo *t) int propmode = t->flag & T_PROP_EDIT; int propconnected = t->flag & T_PROP_CONNECTED; + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + if (!ED_space_image_show_uvedit(sima, t->obedit)) return; /* count */ @@ -2442,7 +2444,7 @@ static void createTransUVs(bContext *C, TransInfo *t) BM_elem_flag_enable(efa, BM_ELEM_TAG); BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { countsel++; if (propconnected) { @@ -2478,7 +2480,7 @@ static void createTransUVs(bContext *C, TransInfo *t) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (!propmode && !uvedit_uv_select_test(em, scene, l)) + if (!propmode && !uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) continue; if (propconnected) { @@ -2489,8 +2491,8 @@ static void createTransUVs(bContext *C, TransInfo *t) } } - luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - UVsToTransData(sima, td++, td2d++, luv->uv, uvedit_uv_select_test(em, scene, l)); + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + UVsToTransData(sima, td++, td2d++, luv->uv, uvedit_uv_select_test(scene, l, cd_loop_uv_offset)); } } diff --git a/source/blender/editors/uvedit/uvedit_buttons.c b/source/blender/editors/uvedit/uvedit_buttons.c index 064a51a639f..e648caf51d2 100644 --- a/source/blender/editors/uvedit/uvedit_buttons.c +++ b/source/blender/editors/uvedit/uvedit_buttons.c @@ -71,17 +71,20 @@ static int uvedit_center(Scene *scene, BMEditMesh *em, Image *ima, float center[ BMIter iter, liter; MTexPoly *tf; MLoopUV *luv; - int tot = 0.0; + int tot = 0; + + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY); zero_v2(center); BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - tf = CustomData_bmesh_get(&em->bm->pdata, f->head.data, CD_MTEXPOLY); + tf = BM_ELEM_CD_GET_VOID_P(f, cd_poly_tex_offset); if (!uvedit_face_visible_test(scene, ima, f, tf)) continue; BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); add_v2_v2(center, luv->uv); tot++; } @@ -103,15 +106,18 @@ static void uvedit_translate(Scene *scene, BMEditMesh *em, Image *ima, float del BMIter iter, liter; MLoopUV *luv; MTexPoly *tf; + + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY); BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - tf = CustomData_bmesh_get(&em->bm->pdata, f->head.data, CD_MTEXPOLY); + tf = BM_ELEM_CD_GET_VOID_P(f, cd_poly_tex_offset); if (!uvedit_face_visible_test(scene, ima, f, tf)) continue; BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); add_v2_v2(luv->uv, delta); } } diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index f6d279c5fac..62b02cff683 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -497,7 +497,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) BM_elem_flag_enable(efa, BM_ELEM_TAG); if (tf == activetf) continue; /* important the temp boolean is set above */ - if (uvedit_face_select_test(scene, em, efa)) + if (uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) glColor4ubv((GLubyte *)col2); else glColor4ubv((GLubyte *)col1); @@ -648,7 +648,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) glBegin(GL_LINE_LOOP); BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - sel = (uvedit_uv_select_test(em, scene, l) ? 1 : 0); + sel = uvedit_uv_select_test(scene, l, cd_loop_uv_offset); glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -666,7 +666,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) glBegin(GL_LINES); BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - sel = (uvedit_edge_select_test(em, scene, l) ? 1 : 0); + sel = uvedit_edge_select_test(scene, l, cd_loop_uv_offset); if (sel != lastsel) { glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2); lastsel = sel; @@ -719,8 +719,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) continue; - if (!uvedit_face_select_test(scene, em, efa)) { - uv_poly_center(em, efa, cent); + if (!uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) { + uv_poly_center(efa, cent, cd_loop_uv_offset); bglVertex2fv(cent); } } @@ -734,8 +734,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) continue; - if (uvedit_face_select_test(scene, em, efa)) { - uv_poly_center(em, efa, cent); + if (uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) { + uv_poly_center(efa, cent, cd_loop_uv_offset); bglVertex2fv(cent); } } @@ -757,7 +757,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (!uvedit_uv_select_test(em, scene, l)) + if (!uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) bglVertex2fv(luv->uv); } } @@ -794,7 +794,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit) BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (uvedit_uv_select_test(em, scene, l)) + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) bglVertex2fv(luv->uv); } } diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h index d1893d639bb..864789124a5 100644 --- a/source/blender/editors/uvedit/uvedit_intern.h +++ b/source/blender/editors/uvedit/uvedit_intern.h @@ -47,11 +47,11 @@ struct BMEdge; struct BMVert; /* visibility and selection */ -int uvedit_face_visible_nolocal(struct Scene *scene, struct BMFace *efa); +bool uvedit_face_visible_nolocal(struct Scene *scene, struct BMFace *efa); /* geometric utilities */ void uv_poly_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy, int len); -void uv_poly_center(struct BMEditMesh *em, struct BMFace *f, float r_cent[2]); +void uv_poly_center(struct BMFace *f, float r_cent[2], const int cd_loop_uv_offset); /* find nearest */ diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index a24669f61f5..b0e0dabd6a3 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -174,8 +174,8 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I BMEditMesh *em; BMIter iter; MTexPoly *tf; - int update = 0; - int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); + bool update = false; + const bool selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* skip assigning these procedural images... */ if (ima && (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)) @@ -196,6 +196,7 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I else { BMFace *efa; + int cd_loop_uv_offset; int cd_poly_tex_offset; /* old shading system, assign image to selected faces */ @@ -216,9 +217,10 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I BM_data_layer_add(em->bm, &em->bm->ldata, CD_MLOOPUV); /* make UVs all nice 0-1 */ ED_mesh_uv_loop_reset_ex(obedit->data, CustomData_get_active_layer_index(&em->bm->pdata, CD_MTEXPOLY)); - update = 1; + update = true; } + cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY); /* now assign to all visible faces */ @@ -226,7 +228,7 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); if (uvedit_face_visible_test(scene, previma, efa, tf) && - (selected == TRUE || uvedit_face_select_test(scene, em, efa))) + (selected == true || uvedit_face_select_test(scene, efa, cd_loop_uv_offset))) { if (ima) { tf->tpage = ima; @@ -256,13 +258,14 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I tf->tpage = NULL; } - update = 1; + update = true; } } /* and update depdency graph */ - if (update) + if (update) { DAG_id_tag_update(obedit->data, 0); + } } } @@ -324,7 +327,7 @@ static void uvedit_pixel_to_float(SpaceImage *sima, float *dist, float pixeldist /*************** visibility and selection utilities **************/ -int uvedit_face_visible_nolocal(Scene *scene, BMFace *efa) +bool uvedit_face_visible_nolocal(Scene *scene, BMFace *efa) { ToolSettings *ts = scene->toolsettings; @@ -334,20 +337,20 @@ int uvedit_face_visible_nolocal(Scene *scene, BMFace *efa) return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0 && BM_elem_flag_test(efa, BM_ELEM_SELECT)); } -int uvedit_face_visible_test(Scene *scene, Image *ima, BMFace *efa, MTexPoly *tf) +bool uvedit_face_visible_test(Scene *scene, Image *ima, BMFace *efa, MTexPoly *tf) { ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SHOW_SAME_IMAGE) - return (tf->tpage == ima) ? uvedit_face_visible_nolocal(scene, efa) : 0; + return (tf->tpage == ima) ? uvedit_face_visible_nolocal(scene, efa) : false; else return uvedit_face_visible_nolocal(scene, efa); } -int uvedit_face_select_test(Scene *scene, BMEditMesh *em, BMFace *efa) +bool uvedit_face_select_test(Scene *scene, BMFace *efa, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; - if (ts->uv_flag & UV_SYNC_SELECTION) { return (BM_elem_flag_test(efa, BM_ELEM_SELECT)); } @@ -356,19 +359,29 @@ int uvedit_face_select_test(Scene *scene, BMEditMesh *em, BMFace *efa) MLoopUV *luv; BMIter liter; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* TODO, pass this on */ - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (!(luv->flag & MLOOPUV_VERTSEL)) - return 0; + return false; } - return 1; + return true; } } -int uvedit_face_select_enable(Scene *scene, BMEditMesh *em, BMFace *efa, const bool do_history) +bool uvedit_face_select_set(struct Scene *scene, struct BMEditMesh *em, struct BMFace *efa, const bool select, + const bool do_history, const int cd_loop_uv_offset) +{ + if (select) { + return uvedit_face_select_enable(scene, em, efa, do_history, cd_loop_uv_offset); + } + else { + return uvedit_face_select_disable(scene, em, efa, cd_loop_uv_offset); + } +} + +bool uvedit_face_select_enable(Scene *scene, BMEditMesh *em, BMFace *efa, const bool do_history, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; @@ -383,20 +396,19 @@ int uvedit_face_select_enable(Scene *scene, BMEditMesh *em, BMFace *efa, const b MLoopUV *luv; BMIter liter; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* TODO, pass this on */ - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); luv->flag |= MLOOPUV_VERTSEL; } - return 1; + return true; } - return 0; + return false; } -int uvedit_face_select_disable(Scene *scene, BMEditMesh *em, BMFace *efa) +bool uvedit_face_select_disable(Scene *scene, BMEditMesh *em, BMFace *efa, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; @@ -408,20 +420,19 @@ int uvedit_face_select_disable(Scene *scene, BMEditMesh *em, BMFace *efa) MLoopUV *luv; BMIter liter; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* TODO, pass this on */ - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); luv->flag &= ~MLOOPUV_VERTSEL; } - return 1; + return true; } - return 0; + return false; } -int uvedit_edge_select_test(BMEditMesh *em, Scene *scene, BMLoop *l) +bool uvedit_edge_select_test(Scene *scene, BMLoop *l, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; @@ -440,14 +451,27 @@ int uvedit_edge_select_test(BMEditMesh *em, Scene *scene, BMLoop *l) else { MLoopUV *luv1, *luv2; - luv1 = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - luv2 = CustomData_bmesh_get(&em->bm->ldata, l->next->head.data, CD_MLOOPUV); + luv1 = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + luv2 = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset); return (luv1->flag & MLOOPUV_VERTSEL) && (luv2->flag & MLOOPUV_VERTSEL); } } -void uvedit_edge_select_enable(BMEditMesh *em, Scene *scene, BMLoop *l, const bool do_history) +void uvedit_edge_select_set(BMEditMesh *em, Scene *scene, BMLoop *l, const bool select, + const bool do_history, const int cd_loop_uv_offset) + +{ + if (select) { + uvedit_edge_select_enable(em, scene, l, do_history, cd_loop_uv_offset); + } + else { + uvedit_edge_select_disable(em, scene, l, cd_loop_uv_offset); + } +} + +void uvedit_edge_select_enable(BMEditMesh *em, Scene *scene, BMLoop *l, const bool do_history, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; @@ -469,15 +493,16 @@ void uvedit_edge_select_enable(BMEditMesh *em, Scene *scene, BMLoop *l, const bo else { MLoopUV *luv1, *luv2; - luv1 = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - luv2 = CustomData_bmesh_get(&em->bm->ldata, l->next->head.data, CD_MLOOPUV); + luv1 = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + luv2 = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset); luv1->flag |= MLOOPUV_VERTSEL; luv2->flag |= MLOOPUV_VERTSEL; } } -void uvedit_edge_select_disable(BMEditMesh *em, Scene *scene, BMLoop *l) +void uvedit_edge_select_disable(BMEditMesh *em, Scene *scene, BMLoop *l, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; @@ -495,34 +520,44 @@ void uvedit_edge_select_disable(BMEditMesh *em, Scene *scene, BMLoop *l) else { MLoopUV *luv1, *luv2; - luv1 = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - luv2 = CustomData_bmesh_get(&em->bm->ldata, l->next->head.data, CD_MLOOPUV); + luv1 = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + luv2 = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset); luv1->flag &= ~MLOOPUV_VERTSEL; luv2->flag &= ~MLOOPUV_VERTSEL; } } -int uvedit_uv_select_test(BMEditMesh *em, Scene *scene, BMLoop *l) +bool uvedit_uv_select_test(Scene *scene, BMLoop *l, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { if (ts->selectmode & SCE_SELECT_FACE) - return BM_elem_flag_test(l->f, BM_ELEM_SELECT); + return BM_elem_flag_test_bool(l->f, BM_ELEM_SELECT); else - return BM_elem_flag_test(l->v, BM_ELEM_SELECT); + return BM_elem_flag_test_bool(l->v, BM_ELEM_SELECT); } else { - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* TODO, pass this on */ - MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - - return luv->flag & MLOOPUV_VERTSEL; + return (luv->flag & MLOOPUV_VERTSEL) != 0; } } -void uvedit_uv_select_enable(BMEditMesh *em, Scene *scene, BMLoop *l, const bool do_history) +void uvedit_uv_select_set(BMEditMesh *em, Scene *scene, BMLoop *l, const bool select, + const bool do_history, const int cd_loop_uv_offset) +{ + if (select) { + uvedit_uv_select_enable(em, scene, l, do_history, cd_loop_uv_offset); + } + else { + uvedit_uv_select_disable(em, scene, l, cd_loop_uv_offset); + } +} + +void uvedit_uv_select_enable(BMEditMesh *em, Scene *scene, BMLoop *l, + const bool do_history, const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; @@ -537,14 +572,13 @@ void uvedit_uv_select_enable(BMEditMesh *em, Scene *scene, BMLoop *l, const bool } } else { - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* TODO, pass this on */ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - luv->flag |= MLOOPUV_VERTSEL; } } -void uvedit_uv_select_disable(BMEditMesh *em, Scene *scene, BMLoop *l) +void uvedit_uv_select_disable(BMEditMesh *em, Scene *scene, BMLoop *l, + const int cd_loop_uv_offset) { ToolSettings *ts = scene->toolsettings; @@ -555,9 +589,7 @@ void uvedit_uv_select_disable(BMEditMesh *em, Scene *scene, BMLoop *l) BM_vert_select_set(em->bm, l->v, FALSE); } else { - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* TODO, pass this on */ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - luv->flag &= ~MLOOPUV_VERTSEL; } } @@ -574,14 +606,12 @@ void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit) } /*********************** geometric utilities ***********************/ -void uv_poly_center(BMEditMesh *em, BMFace *f, float r_cent[2]) +void uv_poly_center(BMFace *f, float r_cent[2], const int cd_loop_uv_offset) { BMLoop *l; MLoopUV *luv; BMIter liter; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* TODO, pass this on */ - zero_v2(r_cent); BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { @@ -623,7 +653,7 @@ int ED_uvedit_minmax(Scene *scene, Image *ima, Object *obedit, float r_min[2], f continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); minmax_v2v2_v2(r_min, r_max, luv->uv); sel = 1; @@ -655,7 +685,7 @@ static int ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[2 BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { add_v2_v2(co, luv->uv); sel++; } @@ -746,6 +776,7 @@ static void uv_find_nearest_face(Scene *scene, Image *ima, BMEditMesh *em, const BMIter iter; float mindist, dist, cent[2]; + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY); mindist = 1e10f; @@ -761,7 +792,7 @@ static void uv_find_nearest_face(Scene *scene, Image *ima, BMEditMesh *em, const if (!uvedit_face_visible_test(scene, ima, efa, tf)) continue; - uv_poly_center(em, efa, cent); + uv_poly_center(efa, cent, cd_loop_uv_offset); dist = fabsf(co[0] - cent[0]) + fabsf(co[1] - cent[1]); @@ -854,7 +885,7 @@ void uv_find_nearest_vert(Scene *scene, Image *ima, BMEditMesh *em, BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (penalty && uvedit_uv_select_test(em, scene, l)) + if (penalty && uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) dist = fabsf(co[0] - luv->uv[0]) + penalty[0] + fabsf(co[1] - luv->uv[1]) + penalty[1]; else dist = fabsf(co[0] - luv->uv[0]) + fabsf(co[1] - luv->uv[1]); @@ -1020,6 +1051,7 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH UvMapVert *iterv1, *iterv2; int a, looking, nverts, starttotf, select; + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY); /* setup */ @@ -1091,7 +1123,7 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH iterv2->flag = 1; if (extend) { - if (uvedit_uv_select_test(em, scene, hit->l)) + if (uvedit_uv_select_test(scene, hit->l, cd_loop_uv_offset)) select = 0; else select = 1; @@ -1105,8 +1137,7 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH iterv1 = uv_select_edgeloop_vertex_map_get(vmap, efa, a); if (iterv1->flag) { - if (select) uvedit_uv_select_enable(em, scene, l, FALSE); - else uvedit_uv_select_disable(em, scene, l); + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); } a++; @@ -1314,7 +1345,7 @@ static float *uv_sel_co_from_eve(Scene *scene, Image *ima, BMEditMesh *em, BMVer if (!uvedit_face_visible_test(scene, ima, l->f, tf)) continue; - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); return luv->uv; } @@ -1498,7 +1529,7 @@ static void uv_weld_align(bContext *C, int tool) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); minmax_v2v2_v2(min, max, luv->uv); } @@ -1521,7 +1552,7 @@ static void uv_weld_align(bContext *C, int tool) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); luv->uv[0] = cent[0]; } @@ -1541,7 +1572,7 @@ static void uv_weld_align(bContext *C, int tool) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); luv->uv[1] = cent[1]; } @@ -1570,7 +1601,7 @@ static void uv_weld_align(bContext *C, int tool) if (!uvedit_face_visible_test(scene, ima, l->f, tf)) continue; - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { BM_elem_flag_enable(eve, BM_ELEM_TAG); break; } @@ -1660,7 +1691,7 @@ static void uv_weld_align(bContext *C, int tool) if (!uvedit_face_visible_test(scene, ima, l->f, tf)) continue; - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); /* Projection of point (x, y) over line (x1, y1, x2, y2) along X axis: * new_y = (y2 - y1) / (x2 - x1) * (x - x1) + y1 @@ -1773,7 +1804,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); UVvert vert; vert.uv_loop = luv; @@ -1837,7 +1868,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op) BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { BLI_array_append(loop_arr, luv); } else { @@ -2062,7 +2093,8 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo MTexPoly *tf; MLoopUV *luv; NearestHit hit; - int i, select = 1, selectmode, sticky, sync, *hitv = NULL; + int i, selectmode, sticky, sync, *hitv = NULL; + bool select = true; BLI_array_declare(hitv); int flush = 0, hitlen = 0; /* 0 == don't flush, 1 == sel, -1 == desel; only use when selection sync is enabled */ float limit[2], **hituv = NULL; @@ -2208,38 +2240,20 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo else if (extend) { if (selectmode == UV_SELECT_VERTEX) { /* (de)select uv vertex */ - if (uvedit_uv_select_test(em, scene, hit.l)) { - uvedit_uv_select_disable(em, scene, hit.l); - select = 0; - } - else { - uvedit_uv_select_enable(em, scene, hit.l, TRUE); - select = 1; - } + select = !uvedit_uv_select_test(scene, hit.l, cd_loop_uv_offset); + uvedit_uv_select_set(em, scene, hit.l, select, true, cd_loop_uv_offset); flush = 1; } else if (selectmode == UV_SELECT_EDGE) { /* (de)select edge */ - if (uvedit_edge_select_test(em, scene, hit.l)) { - uvedit_edge_select_disable(em, scene, hit.l); - select = 0; - } - else { - uvedit_edge_select_enable(em, scene, hit.l, TRUE); - select = 1; - } + select = !(uvedit_edge_select_test(scene, hit.l, cd_loop_uv_offset)); + uvedit_edge_select_set(em, scene, hit.l, select, true, cd_loop_uv_offset); flush = 1; } else if (selectmode == UV_SELECT_FACE) { /* (de)select face */ - if (uvedit_face_select_test(scene, em, hit.efa)) { - uvedit_face_select_disable(scene, em, hit.efa); - select = 0; - } - else { - uvedit_face_select_enable(scene, em, hit.efa, TRUE); - select = 1; - } + select = !(uvedit_face_select_test(scene, hit.efa, cd_loop_uv_offset)); + uvedit_face_select_set(scene, em, hit.efa, select, true, cd_loop_uv_offset); flush = -1; } @@ -2255,37 +2269,19 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo BM_mesh_elem_index_ensure(em->bm, BM_VERT); - /* deselect */ - if (select == 0) { - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); - if (!uvedit_face_visible_test(scene, ima, efa, tf)) - continue; + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); + if (!uvedit_face_visible_test(scene, ima, efa, tf)) + continue; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (uv_sticky_select(limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) - uvedit_uv_select_disable(em, scene, l); - } + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + if (uv_sticky_select(limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); } - flush = -1; } - /* select */ - else { - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); - if (!uvedit_face_visible_test(scene, ima, efa, tf)) - continue; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (uv_sticky_select(limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) - uvedit_uv_select_enable(em, scene, l, FALSE); - } - } - - flush = 1; - } + flush = select ? 1 : -1; } } else { @@ -2294,17 +2290,17 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo if (selectmode == UV_SELECT_VERTEX) { /* select vertex */ - uvedit_uv_select_enable(em, scene, hit.l, TRUE); + uvedit_uv_select_enable(em, scene, hit.l, true, cd_loop_uv_offset); flush = 1; } else if (selectmode == UV_SELECT_EDGE) { /* select edge */ - uvedit_edge_select_enable(em, scene, hit.l, TRUE); + uvedit_edge_select_enable(em, scene, hit.l, true, cd_loop_uv_offset); flush = 1; } else if (selectmode == UV_SELECT_FACE) { /* select face */ - uvedit_face_select_enable(scene, em, hit.efa, TRUE); + uvedit_face_select_enable(scene, em, hit.efa, true, cd_loop_uv_offset); } /* select sticky uvs */ @@ -2319,7 +2315,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (uv_sticky_select(limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) - uvedit_uv_select_enable(em, scene, l, FALSE); + uvedit_uv_select_enable(em, scene, l, false, cd_loop_uv_offset); flush = 1; } @@ -2735,15 +2731,13 @@ static void uv_select_sync_flush(ToolSettings *ts, BMEditMesh *em, const short s * helper function for #uv_select_flush_from_tag_loop and uv_select_flush_from_tag_face */ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, BMEditMesh *em, UvVertMap *vmap, - const unsigned int efa_index, BMLoop *l, const bool select) + const unsigned int efa_index, BMLoop *l, + const bool select, const int cd_loop_uv_offset) { UvMapVert *start_vlist = NULL, *vlist_iter; BMFace *efa_vlist; - if (select) - uvedit_uv_select_enable(em, scene, l, FALSE); - else - uvedit_uv_select_disable(em, scene, l); + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); vlist_iter = EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); @@ -2770,10 +2764,7 @@ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, BMEditMes l_other = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa_vlist, vlist_iter->tfindex); - if (select) - uvedit_uv_select_enable(em, scene, l_other, FALSE); - else - uvedit_uv_select_disable(em, scene, l_other); + uvedit_uv_select_set(em, scene, l_other, select, false, cd_loop_uv_offset); } vlist_iter = vlist_iter->next; } @@ -2787,7 +2778,7 @@ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, BMEditMes * * \note! This function is very similar to #uv_select_flush_from_tag_loop, be sure to update both upon changing. */ -static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object *obedit, bool select) +static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object *obedit, const bool select) { /* Selecting UV Faces with some modes requires us to change * the selection in other faces (depending on the sticky mode). @@ -2801,6 +2792,7 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object BMLoop *l; BMIter iter, liter; /* MTexPoly *tf; */ + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); if ((ts->uv_flag & UV_SYNC_SELECTION) == 0 && sima->sticky == SI_STICKY_VERTEX) { /* Tag all verts as untouched, then touch the ones that have a face center @@ -2825,10 +2817,7 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (BM_elem_flag_test(l->v, BM_ELEM_TAG)) { - if (select) - uvedit_uv_select_enable(em, scene, l, FALSE); - else - uvedit_uv_select_disable(em, scene, l); + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); } } } @@ -2851,7 +2840,8 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object /* tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); */ /* UNUSED */ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - uv_select_flush_from_tag_sticky_loc_internal(scene, em, vmap, efa_index, l, select); + uv_select_flush_from_tag_sticky_loc_internal(scene, em, vmap, efa_index, l, + select, cd_loop_uv_offset); } } } @@ -2861,12 +2851,7 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object else { /* SI_STICKY_DISABLE or ts->uv_flag & UV_SYNC_SELECTION */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { - if (select) { - uvedit_face_select_enable(scene, em, efa, FALSE); - } - else { - uvedit_face_select_disable(scene, em, efa); - } + uvedit_face_select_set(scene, em, efa, select, false, cd_loop_uv_offset); } } } @@ -2897,6 +2882,9 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object BMIter iter, liter; /* MTexPoly *tf; */ + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + + if ((ts->uv_flag & UV_SYNC_SELECTION) == 0 && sima->sticky == SI_STICKY_VERTEX) { /* Tag all verts as untouched, then touch the ones that have a face center * in the loop and select all MLoopUV's that use a touched vert. */ @@ -2920,10 +2908,7 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (BM_elem_flag_test(l->v, BM_ELEM_TAG)) { - if (select) - uvedit_uv_select_enable(em, scene, l, FALSE); - else - uvedit_uv_select_disable(em, scene, l); + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); } } } @@ -2946,7 +2931,8 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (BM_elem_flag_test(l, BM_ELEM_TAG)) { - uv_select_flush_from_tag_sticky_loc_internal(scene, em, vmap, efa_index, l, select); + uv_select_flush_from_tag_sticky_loc_internal(scene, em, vmap, efa_index, l, + select, cd_loop_uv_offset); } } } @@ -2957,12 +2943,7 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (BM_elem_flag_test(l, BM_ELEM_TAG)) { - if (select) { - uvedit_uv_select_enable(em, scene, l, false); - } - else { - uvedit_uv_select_disable(em, scene, l); - } + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); } } } @@ -2987,8 +2968,8 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) MLoopUV *luv; rcti rect; rctf rectf; - int change, pinned, select, extend; - const int use_face_center = (ts->uv_flag & UV_SYNC_SELECTION) ? + bool change, pinned, select, extend; + const bool use_face_center = (ts->uv_flag & UV_SYNC_SELECTION) ? (ts->selectmode == SCE_SELECT_FACE) : (ts->uv_selectmode == UV_SELECT_FACE); @@ -3014,7 +2995,7 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) /* handle face selection mode */ float cent[2]; - change = 0; + change = false; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { /* assume not touched */ @@ -3022,10 +3003,10 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); if (uvedit_face_visible_test(scene, ima, efa, tf)) { - uv_poly_center(em, efa, cent); + uv_poly_center(efa, cent, cd_loop_uv_offset); if (BLI_rctf_isect_pt_v(&rectf, cent)) { BM_elem_flag_enable(efa, BM_ELEM_TAG); - change = 1; + change = true; } } } @@ -3037,7 +3018,7 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) } else { /* other selection modes */ - change = 1; + change = true; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); @@ -3050,14 +3031,12 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) /* UV_SYNC_SELECTION - can't do pinned selection */ if (BLI_rctf_isect_pt_v(&rectf, luv->uv)) { - if (select) uvedit_uv_select_enable(em, scene, l, FALSE); - else uvedit_uv_select_disable(em, scene, l); + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); } } else if (pinned) { if ((luv->flag & MLOOPUV_PINNED) && BLI_rctf_isect_pt_v(&rectf, luv->uv)) { - if (select) uvedit_uv_select_enable(em, scene, l, FALSE); - else uvedit_uv_select_disable(em, scene, l); + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); } } } @@ -3111,16 +3090,16 @@ static int uv_inside_circle(const float uv[2], const float offset[2], const floa return ((x * x + y * y) < 1.0f); } -static int uv_select_inside_ellipse(BMEditMesh *em, Scene *scene, const int select, - const float offset[2], const float ellipse[2], BMLoop *l, MLoopUV *luv) +static bool uv_select_inside_ellipse(BMEditMesh *em, Scene *scene, const bool select, + const float offset[2], const float ellipse[2], BMLoop *l, MLoopUV *luv, + const int cd_loop_uv_offset) { if (uv_inside_circle(luv->uv, offset, ellipse)) { - if (select) uvedit_uv_select_enable(em, scene, l, FALSE); - else uvedit_uv_select_disable(em, scene, l); - return TRUE; + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); + return true; } else { - return FALSE; + return false; } } @@ -3136,18 +3115,18 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op) BMLoop *l; BMIter iter, liter; MLoopUV *luv; - int x, y, radius, width, height, select; + int x, y, radius, width, height; float zoomx, zoomy, offset[2], ellipse[2]; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); - int change = FALSE; - const int use_face_center = (ts->uv_flag & UV_SYNC_SELECTION) ? - (ts->selectmode == SCE_SELECT_FACE) : - (ts->uv_selectmode == UV_SELECT_FACE); + const bool select = (gesture_mode == GESTURE_MODAL_SELECT); + bool change = false; + const bool use_face_center = (ts->uv_flag & UV_SYNC_SELECTION) ? + (ts->selectmode == SCE_SELECT_FACE) : + (ts->uv_selectmode == UV_SELECT_FACE); const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* get operator properties */ - select = (gesture_mode == GESTURE_MODAL_SELECT); x = RNA_int_get(op->ptr, "x"); y = RNA_int_get(op->ptr, "y"); radius = RNA_int_get(op->ptr, "radius"); @@ -3168,9 +3147,9 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op) BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { BM_elem_flag_disable(efa, BM_ELEM_TAG); /* assume not touched */ - if ((select) != (uvedit_face_select_test(scene, em, efa))) { + if (select != uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) { float cent[2]; - uv_poly_center(em, efa, cent); + uv_poly_center(efa, cent, cd_loop_uv_offset); if (uv_inside_circle(cent, offset, ellipse)) { BM_elem_flag_enable(efa, BM_ELEM_TAG); change = TRUE; @@ -3187,7 +3166,7 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op) BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - change |= uv_select_inside_ellipse(em, scene, select, offset, ellipse, l, luv); + change |= uv_select_inside_ellipse(em, scene, select, offset, ellipse, l, luv, cd_loop_uv_offset); } } } @@ -3228,7 +3207,7 @@ static void UV_OT_circle_select(wmOperatorType *ot) /* ******************** lasso select operator **************** */ -static int do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short moves, short select) +static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short moves, const bool select) { SpaceImage *sima = CTX_wm_space_image(C); Image *ima = CTX_data_edit_image(C); @@ -3249,25 +3228,25 @@ static int do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short mov BMFace *efa; BMLoop *l; MTexPoly *tf; - int screen_uv[2], change = TRUE; + int screen_uv[2]; + bool change = false; rcti rect; BLI_lasso_boundbox(&rect, mcords, moves); if (use_face_center) { /* Face Center Sel */ - change = FALSE; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { BM_elem_flag_disable(efa, BM_ELEM_TAG); /* assume not touched */ - if ((select) != (uvedit_face_select_test(scene, em, efa))) { + if (select != uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) { float cent[2]; - uv_poly_center(em, efa, cent); + uv_poly_center(efa, cent, cd_loop_uv_offset); UI_view2d_view_to_region(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]); if (BLI_rcti_isect_pt_v(&rect, screen_uv) && BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) { BM_elem_flag_enable(efa, BM_ELEM_TAG); - change = TRUE; + change = true; } } } @@ -3282,18 +3261,14 @@ static int do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short mov tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset); if (uvedit_face_visible_test(scene, ima, efa, tf)) { BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if ((select) != (uvedit_uv_select_test(em, scene, l))) { + if ((select) != (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); UI_view2d_view_to_region(&ar->v2d, luv->uv[0], luv->uv[1], &screen_uv[0], &screen_uv[1]); if (BLI_rcti_isect_pt_v(&rect, screen_uv) && BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) { - if (select) { - uvedit_uv_select_enable(em, scene, l, FALSE); - } - else { - uvedit_uv_select_disable(em, scene, l); - } + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); + change = true; } } } @@ -3318,8 +3293,8 @@ static int uv_lasso_select_exec(bContext *C, wmOperator *op) const int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot); if (mcords) { - short select; - short change; + bool select; + bool change; select = !RNA_boolean_get(op->ptr, "deselect"); change = do_lasso_select_mesh_uv(C, mcords, mcords_tot, select); @@ -3443,7 +3418,7 @@ static int uv_snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, Space continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); copy_v2_v2(luv->uv, sima->cursor); change = 1; @@ -3474,7 +3449,7 @@ static int uv_snap_uvs_to_adjacent_unselected(Scene *scene, Image *ima, Object * if (uvedit_face_visible_test(scene, ima, f, tface)) { BM_elem_flag_enable(f, BM_ELEM_TAG); BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - BM_elem_flag_set(l, BM_ELEM_TAG, uvedit_uv_select_test(em, scene, l)); + BM_elem_flag_set(l, BM_ELEM_TAG, uvedit_uv_select_test(scene, l, cd_loop_uv_offset)); } } else { @@ -3538,7 +3513,7 @@ static int uv_snap_uvs_to_pixels(SpaceImage *sima, Scene *scene, Object *obedit) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); uv_snap_to_pixel(luv->uv, w, h); } @@ -3629,11 +3604,11 @@ static int uv_pin_exec(bContext *C, wmOperator *op) luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (!clear) { - if (uvedit_uv_select_test(em, scene, l)) + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) luv->flag |= MLOOPUV_PINNED; } else { - if (uvedit_uv_select_test(em, scene, l)) + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) luv->flag &= ~MLOOPUV_PINNED; } } @@ -3686,7 +3661,7 @@ static int uv_select_pinned_exec(bContext *C, wmOperator *UNUSED(op)) luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (luv->flag & MLOOPUV_PINNED) - uvedit_uv_select_enable(em, scene, l, FALSE); + uvedit_uv_select_enable(em, scene, l, false, cd_loop_uv_offset); } } @@ -3786,7 +3761,7 @@ static int uv_hide_exec(bContext *C, wmOperator *op) if (bm_face_is_all_uv_sel(efa, true, cd_loop_uv_offset) == !swap) { BM_face_select_set(em->bm, efa, FALSE); } - uvedit_face_select_disable(scene, em, efa); + uvedit_face_select_disable(scene, em, efa, cd_loop_uv_offset); } else { if (bm_face_is_all_uv_sel(efa, true, cd_loop_uv_offset) == !swap) { @@ -3797,14 +3772,14 @@ static int uv_hide_exec(bContext *C, wmOperator *op) } } } - if (!swap) uvedit_face_select_disable(scene, em, efa); + if (!swap) uvedit_face_select_disable(scene, em, efa, cd_loop_uv_offset); } } else if (em->selectmode == SCE_SELECT_FACE) { /* check if a UV is de-selected */ if (bm_face_is_all_uv_sel(efa, false, cd_loop_uv_offset) != !swap) { BM_face_select_set(em->bm, efa, FALSE); - uvedit_face_select_disable(scene, em, efa); + uvedit_face_select_disable(scene, em, efa, cd_loop_uv_offset); } } else { @@ -4229,12 +4204,13 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *UNUSED(op)) BMesh *bm = em->bm; BMFace *efa; BMLoop *loop; - BMIter iter, liter; + const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); + BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (loop, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_edge_select_test(em, scene, loop)) { + if (uvedit_edge_select_test(scene, loop, cd_loop_uv_offset)) { BM_elem_flag_enable(loop->e, BM_ELEM_SEAM); } } diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 119f71ac941..e82d54286c8 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -305,6 +305,7 @@ static void stitch_uv_rotate(float mat[2][2], float medianPoint[2], float uv[2], /* check if two uvelements are stitchable. This should only operate on -different- separate UvElements */ static int stitch_check_uvs_stitchable(UvElement *element, UvElement *element_iter, StitchState *state) { + BMesh *bm = state->em->bm; float limit; if (element_iter == element) { @@ -319,9 +320,9 @@ static int stitch_check_uvs_stitchable(UvElement *element, UvElement *element_it l = element->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); l = element_iter->l; - luv_iter = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv_iter = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); if (fabsf(luv->uv[0] - luv_iter->uv[0]) < limit && fabsf(luv->uv[1] - luv_iter->uv[1]) < limit) @@ -339,6 +340,7 @@ static int stitch_check_uvs_stitchable(UvElement *element, UvElement *element_it static int stitch_check_edges_stitchable(UvEdge *edge, UvEdge *edge_iter, StitchState *state) { + BMesh *bm = state->em->bm; float limit; if (edge_iter == edge) { @@ -353,14 +355,14 @@ static int stitch_check_edges_stitchable(UvEdge *edge, UvEdge *edge_iter, Stitch MLoopUV *luv_orig2, *luv_iter2; l = state->uvs[edge->uv1]->l; - luv_orig1 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv_orig1 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); l = state->uvs[edge_iter->uv1]->l; - luv_iter1 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv_iter1 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); l = state->uvs[edge->uv2]->l; - luv_orig2 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv_orig2 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); l = state->uvs[edge_iter->uv2]->l; - luv_iter2 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv_iter2 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); if (fabsf(luv_orig1->uv[0] - luv_iter1->uv[0]) < limit && fabsf(luv_orig1->uv[1] - luv_iter1->uv[1]) < limit && @@ -404,6 +406,7 @@ static int stitch_check_edges_state_stitchable(UvEdge *edge, UvEdge *edge_iter, /* calculate snapping for islands */ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition *preview_position, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final) { + BMesh *bm = state->em->bm; int i; UvElement *element; @@ -453,7 +456,7 @@ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition BMLoop *l; l = element->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); if (final) { @@ -484,6 +487,7 @@ static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *state, UVVertAverage *uv_average, unsigned int *uvfinal_map, IslandStitchData *island_stitch_data) { + BMesh *bm = state->em->bm; UvElement *element1, *element2; float uv1[2], uv2[2]; float edgecos, edgesin; @@ -494,8 +498,8 @@ static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *sta element1 = state->uvs[edge->uv1]; element2 = state->uvs[edge->uv2]; - luv1 = CustomData_bmesh_get(&state->em->bm->ldata, element1->l->head.data, CD_MLOOPUV); - luv2 = CustomData_bmesh_get(&state->em->bm->ldata, element2->l->head.data, CD_MLOOPUV); + luv1 = CustomData_bmesh_get(&bm->ldata, element1->l->head.data, CD_MLOOPUV); + luv2 = CustomData_bmesh_get(&bm->ldata, element2->l->head.data, CD_MLOOPUV); if (state->mode == STITCH_VERT) { index1 = uvfinal_map[element1 - state->element_map->buf]; @@ -837,10 +841,16 @@ static void stitch_validate_edge_stichability(UvEdge *edge, StitchState *state, } -static void stitch_propagate_uv_final_position(UvElement *element, int index, PreviewPosition *preview_position, UVVertAverage *final_position, StitchState *state, char final, Scene *scene) +static void stitch_propagate_uv_final_position(Scene *scene, + UvElement *element, int index, PreviewPosition *preview_position, + UVVertAverage *final_position, StitchState *state, + const bool final) { + BMesh *bm = state->em->bm; StitchPreviewer *preview = state->stitch_preview; + const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); + if (element->flag & STITCH_STITCHABLE) { UvElement *element_iter = element; /* propagate to coincident uvs */ @@ -849,14 +859,14 @@ static void stitch_propagate_uv_final_position(UvElement *element, int index, Pr MLoopUV *luv; l = element_iter->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); element_iter->flag |= STITCH_PROCESSED; /* either flush to preview or to the MTFace, if final */ if (final) { copy_v2_v2(luv->uv, final_position[index].uv); - uvedit_uv_select_enable(state->em, scene, l, FALSE); + uvedit_uv_select_enable(state->em, scene, l, false, cd_loop_uv_offset); } else { int face_preview_pos = preview_position[BM_elem_index_get(element_iter->l->f)].data_position; @@ -883,6 +893,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) StitchPreviewer *preview; IslandStitchData *island_stitch_data = NULL; int previous_island = state->static_island; + BMesh *bm = state->em->bm; BMFace *efa; BMIter iter; UVVertAverage *final_position = NULL; @@ -899,9 +910,9 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) if (preview == NULL) return 0; - preview_position = MEM_mallocN(state->em->bm->totface * sizeof(*preview_position), "stitch_face_preview_position"); + preview_position = MEM_mallocN(bm->totface * sizeof(*preview_position), "stitch_face_preview_position"); /* each face holds its position in the preview buffer in tmp. -1 is uninitialized */ - for (i = 0; i < state->em->bm->totface; i++) { + for (i = 0; i < bm->totface; i++) { preview_position[i].data_position = STITCH_NO_PREVIEW; } @@ -911,7 +922,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) } /* store indices to editVerts and Faces. May be unneeded but ensuring anyway */ - BM_mesh_elem_index_ensure(state->em->bm, BM_VERT | BM_FACE); + BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE); /***************************************** * First determine stitchability of uvs * @@ -1004,7 +1015,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) } /* copy data from MLoopUVs to the preview display buffers */ - BM_ITER_MESH (efa, &iter, state->em->bm, BM_FACES_OF_MESH) { + BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { /* just to test if face was added for processing. uvs of inselected vertices will return NULL */ UvElement *element = ED_uv_element_get(state->element_map, efa, BM_FACE_FIRST_LOOP(efa)); @@ -1015,21 +1026,21 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) if (face_preview_pos != STITCH_NO_PREVIEW) { preview->uvs_per_polygon[preview_position[index].polycount_position] = efa->len; BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(preview->preview_polys + face_preview_pos + i * 2, luv->uv); } } if (element->island == state->static_island) { BMLoop *fl = BM_FACE_FIRST_LOOP(efa); - MLoopUV *fuv = CustomData_bmesh_get(&state->em->bm->ldata, fl->head.data, CD_MLOOPUV); + MLoopUV *fuv = CustomData_bmesh_get(&bm->ldata, fl->head.data, CD_MLOOPUV); BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { if (i < numoftris) { /* using next since the first uv is already accounted for */ BMLoop *lnext = l->next; - MLoopUV *luvnext = CustomData_bmesh_get(&state->em->bm->ldata, lnext->next->head.data, CD_MLOOPUV); - luv = CustomData_bmesh_get(&state->em->bm->ldata, lnext->head.data, CD_MLOOPUV); + MLoopUV *luvnext = CustomData_bmesh_get(&bm->ldata, lnext->next->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, lnext->head.data, CD_MLOOPUV); memcpy(preview->static_tris + buffer_index, fuv->uv, 2 * sizeof(float)); memcpy(preview->static_tris + buffer_index + 2, luv->uv, 2 * sizeof(float)); @@ -1050,7 +1061,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) UvElement *element = (UvElement *)state->uvs[i]; if (element->flag & STITCH_STITCHABLE) { l = element->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex * 2], luv->uv); @@ -1058,7 +1069,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) } else if (element->flag & STITCH_SELECTED) { l = element->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex * 2], luv->uv); unstitchBufferIndex++; @@ -1073,11 +1084,11 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) if (edge->flag & STITCH_STITCHABLE) { l = element1->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex * 4], luv->uv); l = element2->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(&preview->preview_stitchable[stitchBufferIndex * 4 + 2], luv->uv); stitchBufferIndex++; @@ -1085,11 +1096,11 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) } else if (edge->flag & STITCH_SELECTED) { l = element1->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex * 4], luv->uv); l = element2->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(&preview->preview_unstitchable[unstitchBufferIndex * 4 + 2], luv->uv); unstitchBufferIndex++; @@ -1122,7 +1133,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) UvElement *element_iter; l = element->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); uvfinal_map[element - state->element_map->buf] = i; @@ -1138,7 +1149,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) if (element_iter->separate) { if (stitch_check_uvs_state_stitchable(element, element_iter, state)) { l = element_iter->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); if (stitch_midpoints) { add_v2_v2(final_position[i].uv, luv->uv); final_position[i].count++; @@ -1167,9 +1178,9 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) UvEdge *edge_iter; l = state->uvs[edge->uv1]->l; - luv1 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv1 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); l = state->uvs[edge->uv2]->l; - luv2 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv2 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(final_position[edge->uv1].uv, luv1->uv); copy_v2_v2(final_position[edge->uv2].uv, luv2->uv); @@ -1185,9 +1196,9 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) for (edge_iter = edge->first; edge_iter; edge_iter = edge_iter->next) { if (stitch_check_edges_state_stitchable (edge, edge_iter, state)) { l = state->uvs[edge_iter->uv1]->l; - luv1 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv1 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); l = state->uvs[edge_iter->uv2]->l; - luv2 = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv2 = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); if (stitch_midpoints) { add_v2_v2(final_position[edge->uv1].uv, luv1->uv); @@ -1224,7 +1235,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) MLoopUV *luv; l = element->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); /* accumulate each islands' translation from stitchable elements. it is important to do here * because in final pass MTFaces get modified and result is zero. */ @@ -1272,7 +1283,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) MLoopUV *luv; l = element->l; - luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV); + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); /* accumulate each islands' translation from stitchable elements. it is important to do here * because in final pass MTFaces get modified and result is zero. */ @@ -1310,13 +1321,13 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) if (state->mode == STITCH_VERT) { UvElement *element = state->selection_stack[i]; - stitch_propagate_uv_final_position(element, i, preview_position, final_position, state, final, scene); + stitch_propagate_uv_final_position(scene, element, i, preview_position, final_position, state, final); } else { UvEdge *edge = state->selection_stack[i]; - stitch_propagate_uv_final_position(state->uvs[edge->uv1], edge->uv1, preview_position, final_position, state, final, scene); - stitch_propagate_uv_final_position(state->uvs[edge->uv2], edge->uv2, preview_position, final_position, state, final, scene); + stitch_propagate_uv_final_position(scene, state->uvs[edge->uv1], edge->uv1, preview_position, final_position, state, final); + stitch_propagate_uv_final_position(scene, state->uvs[edge->uv2], edge->uv2, preview_position, final_position, state, final); edge->flag &= (STITCH_SELECTED | STITCH_BOUNDARY); } @@ -1588,7 +1599,6 @@ static int stitch_init(bContext *C, wmOperator *op) BMFace *efa; BMLoop *l; BMIter iter, liter; - BMEditMesh *em; GHashIterator *ghi; UvEdge *all_edges; StitchState *state; @@ -1597,6 +1607,8 @@ static int stitch_init(bContext *C, wmOperator *op) ARegion *ar = CTX_wm_region(C); float aspx, aspy; Object *obedit = CTX_data_edit_object(C); + BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); if (!ar) return 0; @@ -1611,7 +1623,7 @@ static int stitch_init(bContext *C, wmOperator *op) /* initialize state */ state->use_limit = RNA_boolean_get(op->ptr, "use_limit"); state->limit_dist = RNA_float_get(op->ptr, "limit"); - state->em = em = BKE_editmesh_from_object(obedit); + state->em = em; state->snap_islands = RNA_boolean_get(op->ptr, "snap_islands"); state->static_island = RNA_int_get(op->ptr, "static_island"); state->midpoints = RNA_boolean_get(op->ptr, "midpoint_snap"); @@ -1863,7 +1875,7 @@ static int stitch_init(bContext *C, wmOperator *op) BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { UvElement *element = ED_uv_element_get(state->element_map, efa, l); if (element) { stitch_select_uv(element, state, 1); @@ -1877,7 +1889,7 @@ static int stitch_init(bContext *C, wmOperator *op) BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { - if (uvedit_edge_select_test(em, scene, l)) { + if (uvedit_edge_select_test(scene, l, cd_loop_uv_offset)) { UvEdge *edge = uv_edge_get(l, state); if (edge) { stitch_select_edge(edge, state, TRUE); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index c7bc59295f8..1a32d9007c9 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -104,7 +104,7 @@ static void modifier_unwrap_state(Object *obedit, Scene *scene, short *use_subsu *use_subsurf = subsurf; } -static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit) +static bool ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit) { Main *bmain = CTX_data_main(C); BMEditMesh *em = BKE_editmesh_from_object(obedit); @@ -115,6 +115,7 @@ static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit) ScrArea *sa; SpaceLink *slink; SpaceImage *sima; + int cd_loop_uv_offset; if (ED_uvedit_test(obedit)) return 1; @@ -125,6 +126,8 @@ static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit) if (!ED_uvedit_test(obedit)) return 0; + cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + ima = CTX_data_edit_image(C); if (!ima) { @@ -152,7 +155,7 @@ static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit) /* select new UV's */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - uvedit_face_select_enable(scene, em, efa, FALSE); + uvedit_face_select_enable(scene, em, efa, false, cd_loop_uv_offset); } return 1; @@ -165,8 +168,9 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, bool implicit) BMFace *efa; BMLoop *l; BMIter iter, liter; + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - if (!CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) { + if (cd_loop_uv_offset == -1) { return (em->bm->totfacesel != 0); } @@ -181,7 +185,7 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, bool implicit) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) break; } @@ -220,7 +224,7 @@ void uvedit_get_aspect(Scene *scene, Object *ob, BMEditMesh *em, float *aspx, fl } } -static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene, BMEditMesh *em, +static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene, BMFace *efa, const int cd_loop_uv_offset) { ParamKey key; @@ -245,7 +249,7 @@ static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene, B co[i] = l->v->co; uv[i] = luv->uv; pin[i] = (luv->flag & MLOOPUV_PINNED) != 0; - select[i] = uvedit_uv_select_test(em, scene, l) != 0; + select[i] = uvedit_uv_select_test(scene, l, cd_loop_uv_offset); } param_face_add(handle, key, i, vkeys, co, uv, pin, select, efa->no); @@ -289,7 +293,7 @@ static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMEditMesh bool is_loopsel = false; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(em, scene, l)) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { is_loopsel = true; break; } @@ -299,7 +303,7 @@ static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMEditMesh } } - construct_param_handle_face_add(handle, scene, em, efa, cd_loop_uv_offset); + construct_param_handle_face_add(handle, scene, efa, cd_loop_uv_offset); } if (!implicit) { @@ -320,7 +324,7 @@ static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMEditMesh static void texface_from_original_index(BMFace *efa, int index, float **uv, ParamBool *pin, ParamBool *select, - Scene *scene, BMEditMesh *em, const int cd_loop_uv_offset) + Scene *scene, const int cd_loop_uv_offset) { BMLoop *l; BMIter liter; @@ -338,7 +342,7 @@ static void texface_from_original_index(BMFace *efa, int index, float **uv, Para luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); *uv = luv->uv; *pin = (luv->flag & MLOOPUV_PINNED) ? 1 : 0; - *select = (uvedit_uv_select_test(em, scene, l) != 0); + *select = uvedit_uv_select_test(scene, l, cd_loop_uv_offset); break; } } @@ -465,10 +469,10 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B /* This is where all the magic is done. If the vertex exists in the, we pass the original uv pointer to the solver, thus * flushing the solution to the edit mesh. */ - texface_from_original_index(origFace, origVertIndices[face->v1], &uv[0], &pin[0], &select[0], scene, em, cd_loop_uv_offset); - texface_from_original_index(origFace, origVertIndices[face->v2], &uv[1], &pin[1], &select[1], scene, em, cd_loop_uv_offset); - texface_from_original_index(origFace, origVertIndices[face->v3], &uv[2], &pin[2], &select[2], scene, em, cd_loop_uv_offset); - texface_from_original_index(origFace, origVertIndices[face->v4], &uv[3], &pin[3], &select[3], scene, em, cd_loop_uv_offset); + texface_from_original_index(origFace, origVertIndices[face->v1], &uv[0], &pin[0], &select[0], scene, cd_loop_uv_offset); + texface_from_original_index(origFace, origVertIndices[face->v2], &uv[1], &pin[1], &select[1], scene, cd_loop_uv_offset); + texface_from_original_index(origFace, origVertIndices[face->v3], &uv[2], &pin[2], &select[2], scene, cd_loop_uv_offset); + texface_from_original_index(origFace, origVertIndices[face->v4], &uv[3], &pin[3], &select[3], scene, cd_loop_uv_offset); param_face_add(handle, key, 4, vkeys, co, uv, pin, select, NULL); }