[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41070] branches/soc-2011-onion-uv-tools/ source/blender/editors/uvedit/uvedit_ops.c: correct behaviour for edge-vertex stitch switch

Antony Riakiotakis kalast at gmail.com
Mon Oct 17 00:01:03 CEST 2011


Revision: 41070
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41070
Author:   psy-fi
Date:     2011-10-16 22:01:00 +0000 (Sun, 16 Oct 2011)
Log Message:
-----------
correct behaviour for edge-vertex stitch switch

Modified Paths:
--------------
    branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c

Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c	2011-10-16 20:58:48 UTC (rev 41069)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c	2011-10-16 22:01:00 UTC (rev 41070)
@@ -2234,7 +2234,7 @@
 }
 
 /* Main processing function. It calculates preview and final positions. */
-static int stitch_process_data(StitchState *state, Scene *scene, int final, int doIndexInit)
+static int stitch_process_data(StitchState *state, Scene *scene, int final)
 {
 	int i;
 	StitchPreviewer *preview = uv_get_stitch_previewer();
@@ -2262,12 +2262,9 @@
 		}
 	}
 
-	/* Store Indices to editVerts. This is not always needed according to current code so using a flag.
-	 * This may be recipe for trouble later though, if something changes. */
-	if(doIndexInit){
-		for(ev = state->em->verts.first, i = 0; ev; ev = ev->next, i++){
-			ev->tmp.l = i;
-		}
+	/* Store Indices to editVerts. */
+	for(ev = state->em->verts.first, i = 0; ev; ev = ev->next, i++){
+		ev->tmp.l = i;
 	}
 
 	/*****************************************
@@ -2302,13 +2299,13 @@
 							if(element_iter2->separate){
 								int uniqueIndex1;
 								int uniqueIndex2;
-								UvEdge tmp_edge, *edge;
+								UvEdge tmp_edge, *edge_iter;
 
 								if((element_iter1 == element1) && (element_iter2 == element2))
 									continue;
 
-								uniqueIndex1 = element_iter1 - state->elementMap->buf;
-								uniqueIndex2 = element_iter2 - state->elementMap->buf;
+								uniqueIndex1 = state->map[element_iter1 - state->elementMap->buf];
+								uniqueIndex2 = state->map[element_iter2 - state->elementMap->buf];
 
 								if(uniqueIndex2 > uniqueIndex1){
 									tmp_edge.uv1 = uniqueIndex1;
@@ -2318,9 +2315,9 @@
 									tmp_edge.uv2 = uniqueIndex1;
 								}
 
-								edge = (UvEdge *)BLI_ghash_lookup(state->edgeHash, &tmp_edge);
+								edge_iter = (UvEdge *)BLI_ghash_lookup(state->edgeHash, &tmp_edge);
 
-								if(edge && (edge->flag & STITCH_BOUNDARY)){
+								if(edge_iter && (edge_iter->flag & STITCH_BOUNDARY)){
 									if(state->use_limit){
 										MTFace *mtface_orig1 = CustomData_em_get(&state->em->fdata, element1->face->data, CD_MTFACE);
 										MTFace *mtface_iter1 = CustomData_em_get(&state->em->fdata, element_iter1->face->data, CD_MTFACE);
@@ -2332,22 +2329,42 @@
 										&& fabs(mtface_orig1->uv[element1->tfindex][1] - mtface_iter1->uv[element_iter1->tfindex][1]) < state->limitDist
 										&& fabs(mtface_orig2->uv[element2->tfindex][0] - mtface_iter2->uv[element_iter2->tfindex][0]) < state->limitDist
 										&& fabs(mtface_orig2->uv[element2->tfindex][1] - mtface_iter2->uv[element_iter2->tfindex][1]) < state->limitDist){
-											//success
+											stitch_setup_face_preview_for_uv_group(element1, state, island_stitch_data);
+											stitch_setup_face_preview_for_uv_group(element2, state, island_stitch_data);
+											stitch_setup_face_preview_for_uv_group(element_iter1, state, island_stitch_data);
+											stitch_setup_face_preview_for_uv_group(element_iter2, state, island_stitch_data);
+											if(!(edge_iter->flag & STITCH_STITCHABLE)){
+												edge_iter->flag |= STITCH_STITCHABLE;
+												preview->numOfStitchable++;
+											}
+											if(!(edge->flag & STITCH_STITCHABLE)){
+												edge->flag |= STITCH_STITCHABLE;
+												preview->numOfStitchable++;
+											}
 										}
 									}else{
-										//success
+										stitch_setup_face_preview_for_uv_group(element1, state, island_stitch_data);
+										stitch_setup_face_preview_for_uv_group(element2, state, island_stitch_data);
+										stitch_setup_face_preview_for_uv_group(element_iter1, state, island_stitch_data);
+										stitch_setup_face_preview_for_uv_group(element_iter2, state, island_stitch_data);
+										if(!(edge_iter->flag & STITCH_STITCHABLE)){
+											edge_iter->flag |= STITCH_STITCHABLE;
+											preview->numOfStitchable++;
+										}
+										if(!(edge->flag & STITCH_STITCHABLE)){
+											edge->flag |= STITCH_STITCHABLE;
+											preview->numOfStitchable++;
+										}
 									}
 								}
 							}
 						}
 					}
 				}
-
-				stitch_setup_face_preview_for_uv_group(element1, state, island_stitch_data);
-				stitch_setup_face_preview_for_uv_group(element2, state, island_stitch_data);
-
-				edge->flag |= STITCH_STITCHABLE;
-				preview->numOfStitchable++;
+				if(!(edge->flag & STITCH_STITCHABLE)){
+					/* Add to preview */
+					preview->numOfUnstitchable++;
+				}
 			}else{
 				/* Add to preview */
 				preview->numOfUnstitchable++;
@@ -2786,7 +2803,7 @@
 		}
 	}
 
-	if(!stitch_process_data(stitch_state, scene, 0, 1)){
+	if(!stitch_process_data(stitch_state, scene, 0)){
 		stitch_state_delete(stitch_state);
 		return 0;
 	}
@@ -2865,7 +2882,7 @@
 
 	if(!stitch_init(C, op))
 		return OPERATOR_CANCELLED;
-	if(stitch_process_data((StitchState *)op->customdata, scene, 1, 1)){
+	if(stitch_process_data((StitchState *)op->customdata, scene, 1)){
 		stitch_exit(C, op, 1);
 		return OPERATOR_FINISHED;
 	}else {
@@ -2873,6 +2890,45 @@
 	}
 }
 
+/* Make sure we are selectig only one of a vertex's common uv */
+static void stitch_select_uv(UvElement *element, StitchState *stitch_state, void **selection_stack, int *total_selected,int select)
+{
+	int uniqueIndex;
+	/* This works due to setting of tmp in find nearest uv vert */
+	UvElement *element_iter, *unique_element;
+	uniqueIndex = stitch_state->map[element - stitch_state->elementMap->buf];
+	unique_element = stitch_state->uvs[uniqueIndex];
+	element_iter = stitch_state->elementMap->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+	/* first deselect all common uvs */
+	for(; element_iter; element_iter = element_iter->next){
+		if(element_iter->separate){
+			/* only separators go to selection */
+			if(element_iter->flag & STITCH_SELECTED){
+				int i;
+				element_iter->flag &= ~STITCH_SELECTED;
+				for(i = 0; i < *total_selected; i++){
+					if(((UvElement *)selection_stack[i]) == element_iter){
+						(*total_selected)--;
+						selection_stack[i] = selection_stack[*total_selected];
+						break;
+					}
+				}
+			}
+		}
+	}
+
+	if(select && !(unique_element->flag & STITCH_SELECTED)){
+		unique_element->flag |= STITCH_SELECTED;
+		selection_stack[(*total_selected)++] = unique_element;
+	}
+}
+
+/* Make sure we are selectig only one of edges with common vertices */
+static void stitch_select_edge(UvEdge *edge, StitchState *stitch_state)
+{
+
+}
+
 static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
 	StitchState *stitch_state;
@@ -2897,7 +2953,7 @@
 		case LEFTMOUSE:
 		case PADENTER:
 		case RETKEY:
-			if(stitch_process_data(stitch_state, scene, 1, 1)){
+			if(stitch_process_data(stitch_state, scene, 1)){
 				stitch_exit(C, op, 1);
 				return OPERATOR_FINISHED;
 			}
@@ -2910,7 +2966,7 @@
 		case WHEELUPMOUSE:
 			if(event->ctrl){
 				stitch_state->limitDist += 0.01;
-				if(!stitch_process_data(stitch_state, scene, 0, 1)){
+				if(!stitch_process_data(stitch_state, scene, 0)){
 					return stitch_cancel(C, op);
 				}
 				break;
@@ -2924,7 +2980,7 @@
 			if(event->ctrl){
 				stitch_state->limitDist -= 0.01;
 				stitch_state->limitDist = MAX2(0.01, stitch_state->limitDist);
-				if(!stitch_process_data(stitch_state, scene, 0, 1)){
+				if(!stitch_process_data(stitch_state, scene, 0)){
 					return stitch_cancel(C, op);
 				}
 				break;
@@ -2936,7 +2992,7 @@
 		case LKEY:
 			if(event->val == KM_PRESS){
 				stitch_state->use_limit = !stitch_state->use_limit;
-				if(!stitch_process_data(stitch_state, scene, 0, 1)){
+				if(!stitch_process_data(stitch_state, scene, 0)){
 					return stitch_cancel(C, op);
 				}
 				break;
@@ -2949,7 +3005,7 @@
 				 * against the number of stitchable islands during processing */
 				stitch_state->static_island++;
 
-				if(!stitch_process_data(stitch_state, scene, 0, 1)){
+				if(!stitch_process_data(stitch_state, scene, 0)){
 					return stitch_cancel(C, op);
 				}
 				break;
@@ -2968,14 +3024,8 @@
 					for(i = 0; i < stitch_state->selection_size; i++){
 						UvEdge *edge = stitch_state->selection_stack[i];
 
-						if(!(stitch_state->uvs[edge->uv1]->flag & STITCH_SELECTED)){
-							stitch_state->uvs[edge->uv1]->flag |= STITCH_SELECTED;
-							new_selection[total_uvs_selected++] = stitch_state->uvs[edge->uv1];
-						}
-						if(!(stitch_state->uvs[edge->uv2]->flag & STITCH_SELECTED)){
-							stitch_state->uvs[edge->uv2]->flag |= STITCH_SELECTED;
-							new_selection[total_uvs_selected++] = stitch_state->uvs[edge->uv2];
-						}
+						stitch_select_uv(stitch_state->uvs[edge->uv1], stitch_state, new_selection, &total_uvs_selected, 1);
+						stitch_select_uv(stitch_state->uvs[edge->uv2], stitch_state, new_selection, &total_uvs_selected, 1);
 
 						edge->flag &= ~STITCH_SELECTED;
 					}
@@ -2987,23 +3037,42 @@
 				else{
 					int i;
 					int total_edges_selected = 0;
-					for(i = 0; i < stitch_state->total_edges; i++){
-						UvEdge *edge = stitch_state->edges + i;
+					for(i = 0; i < stitch_state->selection_size; i++){
+						UvElement *element = (UvElement *)stitch_state->selection_stack[i];
+						UvElement *element_iter = stitch_state->elementMap->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+						for(; element_iter; element_iter = element_iter->next){
+							if(element_iter->separate){
+								if(stitch_state->use_limit){
+									MTFace *mtface_orig = CustomData_em_get(&stitch_state->em->fdata, element->face->data, CD_MTFACE);
+									MTFace *mtface_iter = CustomData_em_get(&stitch_state->em->fdata, element_iter->face->data, CD_MTFACE);
 
-						for(i = 0; i < stitch_state->selection_size; i++){
-							if(determine_uv_stitchability((UvElement *)stitch_state->selection_stack[i], stitch_state)){
+									if(fabs(mtface_orig->uv[element->tfindex][0] - mtface_iter->uv[element_iter->tfindex][0]) < stitch_state->limitDist
+											&& fabs(mtface_orig->uv[element->tfindex][1] - mtface_iter->uv[element_iter->tfindex][1]) < stitch_state->limitDist){
 
+										if(!(element_iter->flag & STITCH_STITCHABLE)){
+											element_iter->flag |= STITCH_STITCHABLE;
+										}
+									}
+								}else{
+									if(!(element_iter->flag & STITCH_STITCHABLE)){
+										element_iter->flag |= STITCH_STITCHABLE;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list