Commit: b7b04095c029ffc9d93872ead9c436850acfdd91
Author: Phil Gosch
Date:   Wed Jun 1 10:24:46 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rBb7b04095c029ffc9d93872ead9c436850acfdd91

WIP: Select shortest path - Validate selection

Validation of the current selection, makes sure 2 matching elements are 
selected for path computation

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

M       source/blender/editors/include/ED_uvedit.h
M       source/blender/editors/uvedit/uvedit_ops.c
M       source/blender/editors/uvedit/uvedit_parametrizer.c
M       source/blender/editors/uvedit/uvedit_parametrizer.h
M       source/blender/editors/uvedit/uvedit_unwrap_ops.c

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

diff --git a/source/blender/editors/include/ED_uvedit.h 
b/source/blender/editors/include/ED_uvedit.h
index 5356838..89ca709 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -106,6 +106,8 @@ void ED_uvedit_unwrap_cube_project(struct Object *ob, 
struct BMesh *bm, float cu
 /* single call up unwrap using scene settings, used for edge tag unwrapping */
 void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short 
sel);
 
+/* select shortest path */
+bool ED_uvedit_shortest_path_select(struct Scene *scene,struct Object 
*ob,struct BMesh *bm);
 
 /* uvedit_draw.c */
 void ED_image_draw_cursor(struct ARegion *ar, const float cursor[2]);
diff --git a/source/blender/editors/uvedit/uvedit_ops.c 
b/source/blender/editors/uvedit/uvedit_ops.c
index 6a6e746..8d2a7d3 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1477,16 +1477,128 @@ static int uv_shortest_path_exec(bContext *C, 
wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
        Object *obedit = CTX_data_edit_object(C);
+       Image *ima = CTX_data_edit_image(C);
+       SpaceImage *sima = CTX_wm_space_image(C);
        ToolSettings *ts = scene->toolsettings;
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);      
+       BMEditMesh *em = BKE_editmesh_from_object(obedit);
+       BMesh *bm = em->bm;
+       BMFace *efa;
+       BMEdge *e;
+       BMIter iter, liter;
+       BMLoop *l;
+       BMEditSelection *ese_src, *ese_dst;
+       BMElem *ele_src = NULL, *ele_dst = NULL, *ele;
+       MLoopUV *luv_src = NULL, *luv_dst = NULL;
+       int elem_sel = 0;
+       
 
        if (ts->uv_flag & UV_SYNC_SELECTION) {
                return EDBM_shortest_path_select(C, op);
        }
+
+       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);
                 
-       /* TODO(SaphireS): implementation of operator based on UV islands*/
+       /* -------- Check for 2 selected elements of same type on the same UV 
island ---------- */
+       
+       if (ts->uv_selectmode & UV_SELECT_FACE) {
+               /* clear tags */
+               BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+                       BM_elem_flag_disable(efa, BM_ELEM_TAG);
+               }
 
-       return OPERATOR_FINISHED;
+               BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+                       MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, 
cd_poly_tex_offset);
+
+                       if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+                               if (uvedit_face_select_test(scene, efa, 
cd_loop_uv_offset)) {
+                                       elem_sel++;
+
+                                       if (luv_src == NULL) {
+                                               luv_src = efa;
+                                       }
+                                       else if ((luv_dst == NULL)) {
+                                               luv_dst = efa;
+                                       }
+                               }
+                       }
+               }
+       }
+       else if (ts->uv_selectmode & UV_SELECT_EDGE) {
+               /* clear tags */
+               BM_ITER_MESH(e, &iter, bm, BM_EDGES_OF_MESH) {
+                       BM_elem_flag_disable(e, BM_ELEM_TAG);
+               }
+
+               BM_ITER_MESH(e, &iter, bm, BM_EDGES_OF_MESH) {
+                       if (uvedit_edge_select_test(scene, e->l, 
cd_loop_uv_offset)) {
+
+                               elem_sel++;
+
+                               if (luv_src == NULL) {
+                                       luv_src = e;
+                               }
+                               else if ((luv_dst == NULL)) {
+                                       luv_dst = e;
+                               }
+                       }
+               }
+       }
+
+       else if (ts->uv_selectmode & UV_SELECT_VERTEX) {
+               /* clear tags */
+               BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+                       BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+                               BM_elem_flag_disable(l, BM_ELEM_TAG);
+                       }
+               }
+
+               BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+                       MTexPoly *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) 
 {
+                                       
+                                       MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, 
cd_loop_uv_offset);
+
+                                       if ((luv->flag & MLOOPUV_VERTSEL) != 0) 
{
+                                               if (luv_src == NULL) {
+                                                       luv_src = luv;
+                                                       elem_sel++;
+                                               }
+                                               else if ((luv_dst == NULL) && 
(!compare_v2v2(luv->uv, luv_src->uv, 0.000003f))) {
+                                                       luv_dst = luv;
+                                                       elem_sel++;
+                                               }
+                                               else if 
((!compare_v2v2(luv->uv, luv_src->uv, 0.000003f)) && (!compare_v2v2(luv->uv, 
luv_dst->uv, 0.000003f))) {
+                                                       elem_sel++;
+                                               }       
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (elem_sel != 2) {
+               /* Not exactly 2 elements of same typ selected */
+               BKE_report(op->reports, RPT_WARNING, "Path selection requires 
exactly two matching elements of the same island to be selected");
+               return OPERATOR_CANCELLED;
+       }
+       
+       /* -------- Now select shortest path between the 2 found elements 
---------- */
+
+       if (ED_uvedit_shortest_path_select(scene, obedit, bm)) {
+
+               DAG_id_tag_update(obedit->data, 0);
+               WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+
+               return OPERATOR_FINISHED;
+       }
+       else {
+               /* No path found because the selected elements aren't part of 
the same uv island */
+               BKE_report(op->reports, RPT_WARNING, "Path selection requires 
exactly two matching elements of the same island to be selected");
+               return OPERATOR_CANCELLED;
+       }
 }
 
 static void UV_OT_shortest_path(wmOperatorType *ot)
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c 
b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 9b95865..81cbe56 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -153,7 +153,8 @@ enum PVertFlag {
        PVERT_SELECT = 2,
        PVERT_INTERIOR = 4,
        PVERT_COLLAPSE = 8,
-       PVERT_SPLIT = 16
+       PVERT_SPLIT = 16,
+       PVERT_MARKED = 32
 };
 
 enum PEdgeFlag {
@@ -165,7 +166,8 @@ enum PEdgeFlag {
        PEDGE_FILLED = 32,
        PEDGE_COLLAPSE = 64,
        PEDGE_COLLAPSE_EDGE = 128,
-       PEDGE_COLLAPSE_PAIR = 256
+       PEDGE_COLLAPSE_PAIR = 256,
+       PEDGE_MARKED = 512
 };
 
 /* for flipping faces */
@@ -4703,6 +4705,11 @@ void param_scale_bounds(ParamHandle *handle)
        }
 }
 
+void param_shortest_path(ParamHandle *handle)
+{
+       /* TODO (SaphireS): Shortest Path computation here */
+}
+
 void param_flush(ParamHandle *handle)
 {
        PHandle *phandle = (PHandle *)handle;
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h 
b/source/blender/editors/uvedit/uvedit_parametrizer.h
index efbaae7..7f0a77e 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -113,6 +113,10 @@ void param_scale(ParamHandle *handle, float x, float y);
 
 void param_scale_bounds(ParamHandle *handle);
 
+/* Select shortest Path */
+
+void param_shortest_path(ParamHandle *handle);
+
 /* Flushing */
 
 void param_flush(ParamHandle *handle);
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 1d16146..aff3136 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -712,6 +712,17 @@ void UV_OT_minimize_stretch(wmOperatorType *ot)
        RNA_def_int(ot->srna, "iterations", 0, 0, INT_MAX, "Iterations", 
"Number of iterations to run, 0 is unlimited when run interactively", 0, 100);
 }
 
+/* ******************** Select Shortest Path operator **************** */
+bool ED_uvedit_shortest_path_select(Scene *scene, Object *ob, BMesh *bm) 
+{
+       ParamHandle *handle;
+       handle = construct_param_handle(scene, ob, bm, false, false, false, 
true);
+       param_shortest_path(handle);
+       param_flush(handle);
+       param_delete(handle);
+       return true; /* TODO (SaphireS): WIP Code, return true only if a valid 
path was found*/
+}
+
 /* ******************** Pack Islands operator **************** */
 
 void ED_uvedit_pack_islands(Scene *scene, Object *ob, BMesh *bm, bool 
selected, bool correct_aspect, bool do_rotate)

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

Reply via email to