[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41322] branches/soc-2011-onion-uv-tools/ source/blender/editors/uvedit/uvedit_ops.c: smart stitching

Antony Riakiotakis kalast at gmail.com
Fri Oct 28 00:06:03 CEST 2011


Revision: 41322
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41322
Author:   psy-fi
Date:     2011-10-27 22:06:02 +0000 (Thu, 27 Oct 2011)
Log Message:
-----------
smart stitching
================
static island functionality:
*Now uvs are stitched to the "static island". No longer to the middle point between two stitchable uvs
*User can toggle between static islands with the I button.
*If a uv is on an island that can't be stitched to the static island, it is tagged unstitchable.

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-27 20:57:14 UTC (rev 41321)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c	2011-10-27 22:06:02 UTC (rev 41322)
@@ -1263,6 +1263,8 @@
 	int numOfEdges;
 	/* Flag to remember if island has been added for preview */
 	char addedForPreview;
+	/* Flag an island to be considered for determining static island */
+	char stitchableCandidate;
 }IslandStitchData;
 
 /* just for averaging UVs */
@@ -1330,6 +1332,7 @@
 #define STITCH_STITCHABLE 2
 #define STITCH_PROCESSED 4
 #define STITCH_BOUNDARY 8
+#define STITCH_STITCHABLE_CANDIDATE 16
 #endif
 /* Previewer stuff (see uvedit_intern.h for more info) */
 static StitchPreviewer *_stitch_preview;
@@ -1394,7 +1397,7 @@
 /* This function updates the header of the UV editor when the stitch tool updates its settings */
 static void stitch_update_header(StitchState *stitch_state, bContext *C)
 {
-	static char str[] = "Select(V {+Ctrl deselect}) Mode(M): %c Vertex  %c Edge  %c Preview(P)  %c Limit(L)  %c Snap(S)  Ctrl+Wheel(limit adjust): %.2f  Static Island(I): %d";
+	static char str[] = "Select(V {+Ctrl deselect}) Mode(M): %c Vertex  %c Edge  %c Preview(P)  %c Limit(L)  %c Snap(S)  Ctrl+Wheel(limit adjust): %.2f";
 	char msg[256];
 	ScrArea *sa= CTX_wm_area(C);
 	char mode = (stitch_state->mode == VERT_STITCH);
@@ -1405,8 +1408,7 @@
 				uv_get_stitch_previewer()->enabled?'*':' ',
 				stitch_state->use_limit?'*':' ',
 				stitch_state->snapIslands?'*' :' ',
-				stitch_state->limitDist,
-				stitch_state->static_island + 1);
+				stitch_state->limitDist);
 		ED_area_headerprint(sa, msg);
 	}
 }
@@ -2137,7 +2139,7 @@
 
 
 /* Checks for remote uvs that may be stitched with a certain uv, flags them if stitchable. */
-static int determine_uv_stitchability(UvElement *element, StitchState *state){
+static void determine_uv_stitchability(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data){
 	int vert_index;
 	UvElement *element_iter;
 	float limit= state->limitDist;
@@ -2157,15 +2159,18 @@
 
 				if(fabs(mtface_orig->uv[element->tfindex][0] - mtface_iter->uv[element_iter->tfindex][0]) < limit
 						&& fabs(mtface_orig->uv[element->tfindex][1] - mtface_iter->uv[element_iter->tfindex][1]) < limit){
-					return 1;
+					island_stitch_data[element_iter->island].stitchableCandidate = 1;
+					island_stitch_data[element->island].stitchableCandidate = 1;
+					element->flag |= STITCH_STITCHABLE_CANDIDATE;
 				}
 			}else{
 				/* if no limit exists, then the mere existence of a separate uv means that the uv is stitchable */
-				return 1;
+				island_stitch_data[element_iter->island].stitchableCandidate = 1;
+				island_stitch_data[element->island].stitchableCandidate = 1;
+				element->flag |= STITCH_STITCHABLE_CANDIDATE;
 			}
 		}
 	}
-	return 0;
 }
 
 /* Set preview buffer position of UV face in editface->tmp.l */
@@ -2213,22 +2218,38 @@
 
 				if(fabs(mtface_orig->uv[element->tfindex][0] - mtface_iter->uv[element_iter->tfindex][0]) < state->limitDist
 						&& fabs(mtface_orig->uv[element->tfindex][1] - mtface_iter->uv[element_iter->tfindex][1]) < state->limitDist){
-
-					if(!(element_iter->flag & STITCH_STITCHABLE)){
+					if(((element_iter->island == state->static_island) || (element->island == state->static_island))
+							&& !(element_iter->flag & STITCH_STITCHABLE)){
 						element_iter->flag |= STITCH_STITCHABLE;
 						preview->numOfStitchable++;
 						stitch_setup_face_preview_for_uv_group(element_iter, state, island_stitch_data);
+						if(!(element->flag & STITCH_STITCHABLE)){
+							element->flag |= STITCH_STITCHABLE;
+							preview->numOfStitchable++;
+							stitch_setup_face_preview_for_uv_group(element, state, island_stitch_data);
+						}
 					}
 				}
 			}else{
-				if(!(element_iter->flag & STITCH_STITCHABLE)){
+				if(((element_iter->island == state->static_island) || (element->island == state->static_island))
+						&& !(element_iter->flag & STITCH_STITCHABLE)){
 					element_iter->flag |= STITCH_STITCHABLE;
 					preview->numOfStitchable++;
 					stitch_setup_face_preview_for_uv_group(element_iter, state, island_stitch_data);
+					if(!(element->flag & STITCH_STITCHABLE)){
+						element->flag |= STITCH_STITCHABLE;
+						preview->numOfStitchable++;
+						stitch_setup_face_preview_for_uv_group(element, state, island_stitch_data);
+					}
 				}
 			}
 		}
 	}
+
+	/* This can happen if the uvs to be stitched are not on a stitchable island */
+	if(!(element->flag & STITCH_STITCHABLE)){
+		preview->numOfUnstitchable++;
+	}
 }
 
 /* Main processing function. It calculates preview and final positions. */
@@ -2237,6 +2258,7 @@
 	int i;
 	StitchPreviewer *preview = uv_get_stitch_previewer();
 	IslandStitchData *island_stitch_data = NULL;
+	int previousIsland = state->static_island;
 	short preview_enabled = preview->enabled;
 	EditFace *efa;
 	EditVert *ev;
@@ -2253,11 +2275,9 @@
 		efa->tmp.l = -1;
 	}
 
-	if(state->snapIslands){
-		island_stitch_data = MEM_callocN(sizeof(*island_stitch_data)*state->elementMap->totalIslands, "stitch_island_data");
-		if(!island_stitch_data){
-			return 0;
-		}
+	island_stitch_data = MEM_callocN(sizeof(*island_stitch_data)*state->elementMap->totalIslands, "stitch_island_data");
+	if(!island_stitch_data){
+		return 0;
 	}
 
 	/* Store Indices to editVerts. */
@@ -2272,10 +2292,26 @@
 		/* Uv Vert case */
 		for(i = 0; i < state->selection_size; i++){
 			UvElement *element = (UvElement *)state->selection_stack[i];
-			if(determine_uv_stitchability(element, state)){
+			determine_uv_stitchability(element, state, island_stitch_data);
+		}
+
+		/* Set static island to one that is added for preview */
+		state->static_island %= state->elementMap->totalIslands;
+		while(!(island_stitch_data[state->static_island].stitchableCandidate)){
+			state->static_island++;
+			state->static_island %= state->elementMap->totalIslands;
+			/* This is entirely possible if for example limit stitching with no stitchable verts or no selection */
+			if(state->static_island == previousIsland)
+				break;
+		}
+
+		for(i = 0; i < state->selection_size; i++){
+			UvElement *element = (UvElement *)state->selection_stack[i];
+			if(element->flag & STITCH_STITCHABLE_CANDIDATE){
+				element->flag &= ~STITCH_STITCHABLE_CANDIDATE;
 				stitch_setup_preview_for_stitchable_uv(element, state, island_stitch_data);
 			}else{
-				/* Add to preview */
+				/* Add to preview for unstitchable */
 				preview->numOfUnstitchable++;
 			}
 		}
@@ -2371,7 +2407,7 @@
 		}
 	}
 
-	printf("st %d, ust %d\n",preview->numOfStitchable, preview->numOfUnstitchable);
+	//printf("st %d, ust %d\n",preview->numOfStitchable, preview->numOfUnstitchable);
 	/*****************************************
 	 *  Setup preview for stitchable islands *
 	 *****************************************/
@@ -2498,13 +2534,6 @@
 	/******************************************************
 	 * Here we calculate the final coordinates of the uvs *
 	 ******************************************************/
-	/* Set static island to one that is added for preview */
-	if(state->selection_size && state->snapIslands){
-		while(!island_stitch_data[state->static_island].addedForPreview){
-			state->static_island++;
-			state->static_island %= state->elementMap->totalIslands;
-		}
-	}
 
 	if(state->mode == VERT_STITCH){
 		UVVertAverage *averageUvPosition = MEM_callocN(state->selection_size*sizeof(*averageUvPosition), "stitch_uv_average");
@@ -2515,19 +2544,15 @@
 			if(element->flag & STITCH_STITCHABLE){
 				UvElement *element_iter = state->elementMap->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
 				for(;element_iter; element_iter = element_iter->next){
-					if(element_iter->flag & STITCH_STITCHABLE){
+					if((element_iter->flag & STITCH_STITCHABLE) && (element_iter->island == state->static_island)){
 						MTFace *mt;
 						efa = element_iter->face;
 						mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
 
-						averageUvPosition[i].uv[0] += mt->uv[element_iter->tfindex][0];
-						averageUvPosition[i].uv[1] += mt->uv[element_iter->tfindex][1];
-						averageUvPosition[i].count++;
+						averageUvPosition[i].uv[0] = mt->uv[element_iter->tfindex][0];
+						averageUvPosition[i].uv[1] = mt->uv[element_iter->tfindex][1];
 					}
 				}
-				/* median result */
-				averageUvPosition[i].uv[0] /= averageUvPosition[i].count;
-				averageUvPosition[i].uv[1] /= averageUvPosition[i].count;
 			}
 		}
 		/* Second pass, propagate changes to stitchable uvs */
@@ -2597,8 +2622,7 @@
 		}
 	}
 
-	if(island_stitch_data)
-		MEM_freeN(island_stitch_data);
+	MEM_freeN(island_stitch_data);
 
 	return 1;
 }




More information about the Bf-blender-cvs mailing list