Commit: 8650a733fc26e912bac6b0dba7e00210d9c0ba73
Author: Phil Gosch
Date:   Tue Jun 14 11:32:29 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rB8650a733fc26e912bac6b0dba7e00210d9c0ba73

Implemented "real" hiding of UV elements

Previously it wasn't possible to hide elements without altering the BMesh 
selection state

ToDo: Make UV operators ignore hidden elements

===================================================================

M       source/blender/editors/uvedit/uvedit_draw.c
M       source/blender/editors/uvedit/uvedit_intern.h
M       source/blender/editors/uvedit/uvedit_ops.c
M       source/blender/makesdna/DNA_meshdata_types.h

===================================================================

diff --git a/source/blender/editors/uvedit/uvedit_draw.c 
b/source/blender/editors/uvedit/uvedit_draw.c
index 94d69a0..507d514 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -222,7 +222,9 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene 
*scene, BMEditMesh *em, MTe
                                                glBegin(GL_POLYGON);
                                                BM_ITER_ELEM (l, &liter, efa, 
BM_LOOPS_OF_FACE) {
                                                        luv = 
BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-                                                       glVertex2fv(luv->uv);
+                                                       if (!(luv->flag & 
MLOOPUV_HIDDEN)) {
+                                                               
glVertex2fv(luv->uv);
+                                                       }
                                                }
                                                glEnd();
                                        }
@@ -260,7 +262,9 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene 
*scene, BMEditMesh *em, MTe
                                                glBegin(GL_POLYGON);
                                                BM_ITER_ELEM (l, &liter, efa, 
BM_LOOPS_OF_FACE) {
                                                        luv = 
BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-                                                       glVertex2fv(luv->uv);
+                                                       if (!(luv->flag & 
MLOOPUV_HIDDEN)) {
+                                                               
glVertex2fv(luv->uv);
+                                                       }
                                                }
                                                glEnd();
                                        }
@@ -323,10 +327,12 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene 
*scene, BMEditMesh *em, MTe
                                        glBegin(GL_POLYGON);
                                        BM_ITER_ELEM_INDEX (l, &liter, efa, 
BM_LOOPS_OF_FACE, i) {
                                                luv = BM_ELEM_CD_GET_VOID_P(l, 
cd_loop_uv_offset);
-                                               a = fabsf(uvang[i] - ang[i]) / 
(float)M_PI;
-                                               weight_to_rgb(col, 1.0f - 
pow2f(1.0f - a));
-                                               glColor3fv(col);
-                                               glVertex2fv(luv->uv);
+                                               if (!(luv->flag & 
MLOOPUV_HIDDEN)) {
+                                                       a = fabsf(uvang[i] - 
ang[i]) / (float)M_PI;
+                                                       weight_to_rgb(col, 1.0f 
- pow2f(1.0f - a));
+                                                       glColor3fv(col);
+                                                       glVertex2fv(luv->uv);
+                                               }
                                        }
                                        glEnd();
                                }
@@ -359,7 +365,9 @@ static void draw_uvs_lineloop_bmface(BMFace *efa, const int 
cd_loop_uv_offset)
        glBegin(GL_LINE_LOOP);
        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
                luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-               glVertex2fv(luv->uv);
+               if (!(luv->flag & MLOOPUV_HIDDEN)) {
+                       glVertex2fv(luv->uv);
+               }
        }
        glEnd();
 }
@@ -372,7 +380,7 @@ static void draw_uvs_lineloop_mpoly(Mesh *me, MPoly *mpoly)
        glBegin(GL_LINE_LOOP);
        mloopuv = &me->mloopuv[mpoly->loopstart];
        for (i = mpoly->totloop; i != 0; i--, mloopuv++) {
-               glVertex2fv(mloopuv->uv);
+               glVertex2fv(mloopuv->uv); /* We don't check MLOOPUV_HIDDEN here 
since we always want to see other UVs */
        }
        glEnd();
 }
@@ -525,7 +533,9 @@ static void draw_uvs_looptri(BMEditMesh *em, unsigned int 
*r_loop_index, const i
                unsigned int j;
                for (j = 0; j < 3; j++) {
                        MLoopUV *luv = 
BM_ELEM_CD_GET_VOID_P(em->looptris[i][j], cd_loop_uv_offset);
-                       glVertex2fv(luv->uv);
+                       if (!(luv->flag & MLOOPUV_HIDDEN)) {
+                               glVertex2fv(luv->uv);
+                       }
                }
                i++;
        } while (i != em->tottri && (f == em->looptris[i][0]->f));
@@ -801,7 +811,9 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object 
*obedit)
                                                        glColor4ubv(sel ? 
(GLubyte *)col1 : (GLubyte *)col2);
 
                                                        luv = 
BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-                                                       glVertex2fv(luv->uv);
+                                                       if (!(luv->flag & 
MLOOPUV_HIDDEN)) {
+                                                               
glVertex2fv(luv->uv);
+                                                       }
                                                }
                                                glEnd();
                                        }
@@ -819,9 +831,13 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, 
Object *obedit)
                                                                lastsel = sel;
                                                        }
                                                        luv = 
BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-                                                       glVertex2fv(luv->uv);
+                                                       if (!(luv->flag & 
MLOOPUV_HIDDEN)) {
+                                                               
glVertex2fv(luv->uv);
+                                                       }
                                                        luv = 
BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset);
-                                                       glVertex2fv(luv->uv);
+                                                       if (!(luv->flag & 
MLOOPUV_HIDDEN)) {
+                                                               
glVertex2fv(luv->uv);
+                                                       }
                                                }
                                                glEnd();
                                        }
@@ -862,9 +878,13 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, 
Object *obedit)
                        if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
                                continue;
 
+                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
+
                        if (!uvedit_face_select_test(scene, efa, 
cd_loop_uv_offset)) {
-                               uv_poly_center(efa, cent, cd_loop_uv_offset);
-                               glVertex2fv(cent);
+                               if (uv_poly_visible(efa, cd_loop_uv_offset)) {
+                                       uv_poly_center(efa, cent, 
cd_loop_uv_offset);
+                                       glVertex2fv(cent); 
+                               }
                        }
                }
 
@@ -875,9 +895,13 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, 
Object *obedit)
                        if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
                                continue;
 
+                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
+
                        if (uvedit_face_select_test(scene, efa, 
cd_loop_uv_offset)) {
-                               uv_poly_center(efa, cent, cd_loop_uv_offset);
-                               glVertex2fv(cent);
+                               if (uv_poly_visible(efa, cd_loop_uv_offset)) {
+                                       uv_poly_center(efa, cent, 
cd_loop_uv_offset);
+                                       glVertex2fv(cent); 
+                               }
                        }
                }
 
@@ -899,7 +923,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(scene, l, 
cd_loop_uv_offset))
+                               if (!uvedit_uv_select_test(scene, l, 
cd_loop_uv_offset) && !(luv->flag & MLOOPUV_HIDDEN))
                                        glVertex2fv(luv->uv);
                        }
                }
@@ -918,7 +942,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 (luv->flag & MLOOPUV_PINNED)
+                               if (luv->flag & MLOOPUV_PINNED && !(luv->flag & 
MLOOPUV_HIDDEN))
                                        glVertex2fv(luv->uv);
                        }
                }
@@ -936,7 +960,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(scene, l, 
cd_loop_uv_offset))
+                               if (uvedit_uv_select_test(scene, l, 
cd_loop_uv_offset) && !(luv->flag & MLOOPUV_HIDDEN))
                                        glVertex2fv(luv->uv);
                        }
                }
diff --git a/source/blender/editors/uvedit/uvedit_intern.h 
b/source/blender/editors/uvedit/uvedit_intern.h
index d5655e3..b16f94a 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -48,6 +48,7 @@ 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 BMFace *f, float r_cent[2], const int 
cd_loop_uv_offset);
+bool  uv_poly_visible(struct BMFace *f, 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 a8c052c..e510782 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -631,6 +631,24 @@ void uv_poly_center(BMFace *f, float r_cent[2], const int 
cd_loop_uv_offset)
        mul_v2_fl(r_cent, 1.0f / (float)f->len);
 }
 
+bool uv_poly_visible(BMFace *f, const int cd_loop_uv_offset)
+{
+       BMLoop *l;
+       MLoopUV *luv;
+       BMIter liter;
+       bool visible = false;
+
+       BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
+               luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+               if (!(luv->flag & MLOOPUV_HIDDEN)) {
+                       visible = true;
+                       break;
+               }
+       }
+
+       return visible;
+}
+
 void uv_poly_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float 
aspy, int len)
 {
        int i;
@@ -3922,61 +3940,14 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
 
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
                        luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-
-                       if (UV_SEL_TEST(luv, !swap)) {
-                               hide = 1;
-                               break;
-                       }
-               }
-
-               if (hide) {
-                       /* note, a special case for edges could be used,
-                        * for now edges act like verts and get flushed */
-                       if (use_face_center) {
-                               if (em->selectmode == SCE_SELECT_FACE) {
-                                       /* check that every UV is selected */
-                                       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, cd_loop_uv_offset);
-                               }
-                               else {
-                                       if (bm_face_is_all_uv_sel(efa, true, 
cd_loop_uv_offset) == !swap) {
-                                               BM_ITER_ELEM (l, &liter, efa, 
BM_LOOPS_OF_FACE) {
-                                                       luv = 
BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-                                                       if (UV_SEL_TEST(luv, 
!swap)) {
-                                                               
BM_vert_select_set(em->bm, l->v, false);
-                                                       }
-                                               }
-                                       }
-                                       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, cd_loop_uv_offset);
-                               }
-                       }
-                       else {
-                               BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) 
{
-                                       luv = BM_ELEM_CD_GET_VOID_P(l, 
cd_loop_uv_offset);
-                                       if (UV_SEL_TEST(luv, !swap)) {
-                                               BM_vert_select_set(em->bm, 
l->v, false);
-                                               if (!swap) luv->flag &= 
~MLOOPUV_VERTSEL;
-                                       }
-                               }
+                       if ((luv->flag & MLOOPUV_VERTSEL && !swap) || 
(!(luv->flag & MLOOPUV_VERTSEL) && swap)) {
+                               luv->flag |= MLOOPUV_HIDDEN;
                        }
                }
        }
-
-       /* flush vertex selection changes */
-       if (em->selectmode != SCE_SELECT_FACE)
-               EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX | 
SCE_SELECT_EDGE);
        
        BM_select_history_validate(em->bm);
-       WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+       WM_event_add_notifier(C, NC_GEOM | ND_SELECT | ND_DATA, obedit->data);
 
        return OPERATOR_FINISHED;
 }
@@ -4012,14 +3983,9 @@ static int uv_reveal_exec(bContext *C, wmOperator 
*UNUSED(op))
        BMLoop *l;
        BMIter iter, liter;
        MLoopUV *luv;
-       const int use_face_center = (ts->uv_selectmode == UV_SELECT_FACE);
-       const int stickymode = sima ? (sima->sticky != SI_STICKY_DISABLE) : 1;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, 
CD_MLOOPUV);
 
-       /* note on tagging, selecting faces needs to be delayed so it doesn't 
select the verts and
-        * confuse our checks on selected verts. */
-
        /* call the mesh function if we are in mesh sync sel */
        if (ts->uv_flag & UV_SYNC_SELECTION) {
                EDBM_mesh_reveal(em);
@@ -4027,92 +3993,19 @@ static int uv_reveal_exec(bContext *C, wmOperator 
*UNUSED(op))
 
                return OPERATOR_FINISHED;
        }
-       if (use_face_center) {
-               if (em->s

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to