diff options
Diffstat (limited to 'source/blender/editors/uvedit/uvedit_ops.c')
-rw-r--r-- | source/blender/editors/uvedit/uvedit_ops.c | 382 |
1 files changed, 179 insertions, 203 deletions
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; + } +} + +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); } } -int uvedit_face_select_enable(Scene *scene, BMEditMesh *em, BMFace *efa, const bool do_history) +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) != 0; + } +} - return luv->flag & MLOOPUV_VERTSEL; +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) +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); } } |