[Bf-blender-cvs] [c67be0b] soc-2016-uv_tools: Wip: Select Shortest Path: Tagging of found path edges for selection

Phil Gosch noreply at git.blender.org
Thu Jun 2 21:40:08 CEST 2016


Commit: c67be0b14fd2c2db260508b9b8d1b853aa5598ce
Author: Phil Gosch
Date:   Thu Jun 2 21:39:36 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rBc67be0b14fd2c2db260508b9b8d1b853aa5598ce

Wip: Select Shortest Path: Tagging of found path edges for selection

Selection flags of MLOOPUV should be set in p_flush_uvs(), needs a closer look

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

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/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 8d2a7d3..b76ea8d 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1590,7 +1590,7 @@ static int uv_shortest_path_exec(bContext *C, wmOperator *op)
 	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);
+		WM_event_add_notifier(C, NC_GEOM | ND_SELECT | ND_DATA, obedit->data);
 
 		return OPERATOR_FINISHED;
 	}
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index eb8f595..ef48ef5 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -131,6 +131,7 @@ typedef struct PEdge {
 	struct PEdge *next;
 	struct PFace *face;
 	float *orig_uv, old_uv[2];
+	int *orig_flag;
 	unsigned short flag;
 
 } PEdge;
@@ -679,12 +680,27 @@ static void p_vert_load_pin_select_uvs(PHandle *handle, PVert *v)
 static void p_flush_uvs(PHandle *handle, PChart *chart)
 {
 	PEdge *e;
+	int sel_flag = 0;
+	/* ToDo (SaphireS): Find sensible variable names*/
+	int MLOOPEDGE_SELECTED = (1 << 0); /* MLOOPUV_EDGESEL*/
+	int MLOOPVERT_SELECTED = (1 << 1); /* MLOOPUV_VERTSEL*/
 
 	for (e = chart->edges; e; e = e->nextlink) {
 		if (e->orig_uv) {
 			e->orig_uv[0] = e->vert->uv[0] / handle->aspx;
 			e->orig_uv[1] = e->vert->uv[1] / handle->aspy;
 		}
+
+		/* ToDo (SaphireS): Move to own p_flush_uvs_selection() function ?*/
+		if (e->flag & PEDGE_SELECT) {
+			//if (e->orig_flag) {
+				//printf("---param_flush_uvs: orig_flag found\n");
+				sel_flag = e->orig_flag;
+				sel_flag |= MLOOPEDGE_SELECTED;/* MLOOPUV_EDGESEL*/
+				sel_flag |= MLOOPVERT_SELECTED; /* MLOOPUV_VERTSEL*/
+				e->orig_flag = sel_flag; //sel_flag
+			//}
+		}
 	}
 }
 
@@ -1101,7 +1117,7 @@ static PFace *p_face_add(PHandle *handle)
 
 static PFace *p_face_add_construct(PHandle *handle, ParamKey key, ParamKey *vkeys,
                                    float *co[4], float *uv[4], int i1, int i2, int i3,
-                                   ParamBool *pin, ParamBool *select)
+                                   ParamBool *pin, ParamBool *select, int flag[4])
 {
 	PFace *f = p_face_add(handle);
 	PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next;
@@ -1114,6 +1130,10 @@ static PFace *p_face_add_construct(PHandle *handle, ParamKey key, ParamKey *vkey
 	e2->orig_uv = uv[i2];
 	e3->orig_uv = uv[i3];
 
+	e1->orig_flag = flag[i1];
+	e2->orig_flag = flag[i2];
+	e3->orig_flag = flag[i3];
+
 	if (pin) {
 		if (pin[i1]) e1->flag |= PEDGE_PIN;
 		if (pin[i2]) e2->flag |= PEDGE_PIN;
@@ -4158,7 +4178,7 @@ void param_delete(ParamHandle *handle)
 
 static void p_add_ngon(ParamHandle *handle, ParamKey key, int nverts,
                        ParamKey *vkeys, float **co, float **uv,
-                       ParamBool *pin, ParamBool *select, const float normal[3])
+					   ParamBool *pin, ParamBool *select, const float normal[3], int *flag)
 {
 	int *boundary = BLI_array_alloca(boundary, nverts);
 
@@ -4212,10 +4232,11 @@ static void p_add_ngon(ParamHandle *handle, ParamKey key, int nverts,
 			ParamKey tri_vkeys[3] = {vkeys[v0], vkeys[v1], vkeys[v2]};
 			float *tri_co[3] = {co[v0], co[v1], co[v2]};
 			float *tri_uv[3] = {uv[v0], uv[v1], uv[v2]};
+			int tri_flag[3] = {flag[v0], flag[v1], flag[v2]};
 			ParamBool tri_pin[3] = {pin[v0], pin[v1], pin[v2]};
 			ParamBool tri_select[3] = {select[v0], select[v1], select[v2]};
 
-			param_face_add(handle, key, 3, tri_vkeys, tri_co, tri_uv, tri_pin, tri_select, NULL);
+			param_face_add(handle, key, 3, tri_vkeys, tri_co, tri_uv, tri_pin, tri_select, NULL, tri_flag);
 		}
 
 		/* remove corner */
@@ -4228,7 +4249,7 @@ static void p_add_ngon(ParamHandle *handle, ParamKey key, int nverts,
 
 void param_face_add(ParamHandle *handle, ParamKey key, int nverts,
                     ParamKey *vkeys, float *co[4], float *uv[4],
-                    ParamBool *pin, ParamBool *select, float normal[3])
+                    ParamBool *pin, ParamBool *select, float normal[3], int flag[4])
 {
 	PHandle *phandle = (PHandle *)handle;
 
@@ -4238,22 +4259,22 @@ void param_face_add(ParamHandle *handle, ParamKey key, int nverts,
 
 	if (nverts > 4) {
 		/* ngon */
-		p_add_ngon(handle, key, nverts, vkeys, co, uv, pin, select, normal);
+		p_add_ngon(handle, key, nverts, vkeys, co, uv, pin, select, normal, flag);
 	}
 	else if (nverts == 4) {
 		/* quad */
 		if (p_quad_split_direction(phandle, co, vkeys)) {
-			p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select);
-			p_face_add_construct(phandle, key, vkeys, co, uv, 0, 2, 3, pin, select);
+			p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select, flag);
+			p_face_add_construct(phandle, key, vkeys, co, uv, 0, 2, 3, pin, select, flag);
 		}
 		else {
-			p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 3, pin, select);
-			p_face_add_construct(phandle, key, vkeys, co, uv, 1, 2, 3, pin, select);
+			p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 3, pin, select, flag);
+			p_face_add_construct(phandle, key, vkeys, co, uv, 1, 2, 3, pin, select, flag);
 		}
 	}
 	else if (!p_face_exists(phandle, vkeys, 0, 1, 2)) {
 		/* triangle */
-		p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select);
+		p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select, flag);
 	}
 }
 
@@ -4747,11 +4768,6 @@ LinkNode* p_calc_path_vert(PChart *chart, PVert *src, PVert *dst)
 		vert->u.id = index; /* Abuse lscm id field */
 	}
 
-	//src->flag &= ~PVERT_MARKED;
-	//printf(" src unmarked, index: %i \n", src->u.id);
-	//dst->flag &= ~PVERT_MARKED;
-	//printf(" src unmarked, index: %i \n", dst->u.id);
-
 	/* alloc */
 	totvert = chart->nverts;
 	verts_prev = MEM_callocN(sizeof(*verts_prev) * totvert, __func__);
@@ -4798,8 +4814,10 @@ void param_shortest_path(ParamHandle *handle, bool *p_found)
 	int i, j;
 	bool success = false;
 
-	if (phandle->ncharts == 0)
+	if (phandle->ncharts == 0) {
+		*p_found = success;
 		return;
+	}
 
 	/* Get src and dst */
 	for (i = 0; i < phandle->ncharts; i++) {
@@ -4819,16 +4837,27 @@ void param_shortest_path(ParamHandle *handle, bool *p_found)
 					}
 				}
 			}
+
+			/* ToDo (SaphireS): Possible that more than one instance of src selected in different charts */
 		}
 	}
 
 	/* Connect src and dst */
-
 	LinkNode* path = NULL;
 	if (vert_src && vert_dst){
+		//printf("start path computation!\n");
 		path = p_calc_path_vert(current_chart, vert_src, vert_dst);
 		if (path) {
-			/* TODO (SaphireS): Set *_SELECT tag for verts/edges */
+			printf("--- DEBUG (SaphireS): path found\n");
+			LinkNode *node = NULL;
+			node = path;
+			do {
+				//printf("---tagging vert/edge for selection\n");
+				PVert *v = node->link;
+				v->flag |= PVERT_SELECT; /* ToDo: Necessary to set vert selection since only edge has orig_flag ?*/
+				PEdge *e = v->edge;
+				e->flag |= PEDGE_SELECT;
+			} while (node = node->next);
 			success = true;
 		}
 	}
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h b/source/blender/editors/uvedit/uvedit_parametrizer.h
index 2ce7fe1..8223e44 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -63,7 +63,8 @@ void param_face_add(ParamHandle *handle,
                     float *uv[4],
                     ParamBool *pin,
                     ParamBool *select,
-                    float face_normal[3]);
+                    float face_normal[3], 
+					int flag[4]);
 
 void param_edge_set_seam(ParamHandle *handle,
                          ParamKey *vkeys);
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 3aefb61..347cc6e 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -235,6 +235,7 @@ static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene,
 	ParamBool *select = BLI_array_alloca(select, efa->len);
 	float **co = BLI_array_alloca(co, efa->len);
 	float **uv = BLI_array_alloca(uv, efa->len);
+	int *flag = BLI_array_alloca(flag, efa->len);
 	int i;
 
 	BMIter liter;
@@ -251,10 +252,11 @@ static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene,
 		co[i] = l->v->co;
 		uv[i] = luv->uv;
 		pin[i] = (luv->flag & MLOOPUV_PINNED) != 0;
+		flag[i] = luv->flag;
 		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);
+	param_face_add(handle, key, i, vkeys, co, uv, pin, select, efa->no, flag);
 }
 
 static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMesh *bm,
@@ -325,7 +327,7 @@ static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMesh *bm,
 
 
 static void texface_from_original_index(BMFace *efa, int index, float **uv, ParamBool *pin, ParamBool *select,
-                                        Scene *scene, const int cd_loop_uv_offset)
+                                        int *flag, Scene *scene, const int cd_loop_uv_offset)
 {
 	BMLoop *l;
 	BMIter liter;
@@ -334,6 +336,7 @@ static void texface_from_original_index(BMFace *efa, int index, float **uv, Para
 	*uv = NULL;
 	*pin = 0;
 	*select = 1;
+	*flag = 0;
 
 	if (index == ORIGINDEX_NONE)
 		return;
@@ -344,6 +347,7 @@ static void texface_from_original_index(BMFace *efa, int index, float **uv, Para
 			*uv = luv->uv;
 			*pin = (luv->flag & MLOOPUV_PINNED) ? 1 : 0;
 			*select = uvedit_uv_select_test(scene, l, cd_loop_uv_offset);
+			*flag = luv->flag;
 			break;
 		}
 	}
@@ -445,6 +449,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
 		ParamBool pin[4], select[4];
 		float *co[4];
 		float *uv[4];
+		int flag[4];
 		BMFace *origFace = faceMap[i];
 
 		if (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) {
@@ -473,12 +478,12 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
 		
 		/* This is where all the magic is done. If the vertex exists

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list