[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37801] branches/soc-2011-onion/source/ blender/editors: smart stitch - confirm now applies operator + remove some unneeded code.

Antony Riakiotakis kalast at gmail.com
Sat Jun 25 01:58:14 CEST 2011


Revision: 37801
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37801
Author:   psy-fi
Date:     2011-06-24 23:58:13 +0000 (Fri, 24 Jun 2011)
Log Message:
-----------
smart stitch - confirm now applies operator + remove some unneeded code. Old operation fully restored and even better, I think the new code handles some cases better. Still a few safety checks to add

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h
    branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c
    branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c

Modified: branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h	2011-06-24 23:27:41 UTC (rev 37800)
+++ branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h	2011-06-24 23:58:13 UTC (rev 37801)
@@ -154,7 +154,6 @@
 
 struct UvVertMap *EM_make_uv_vert_map(struct EditMesh *em, int selected, int do_face_idx_array, float *limit);
 struct UvMapVert *EM_get_uv_map_vert(struct UvVertMap *vmap, unsigned int v);
-void		EM_uv_vert_map_sort(struct UvVertMap *vmap,  struct EditMesh *em, float *limit);
 void		EM_free_uv_vert_map(struct UvVertMap *vmap);
 
 void		EM_add_data_layer(struct EditMesh *em, struct CustomData *data, int type, const char *name);

Modified: branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c	2011-06-24 23:27:41 UTC (rev 37800)
+++ branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c	2011-06-24 23:58:13 UTC (rev 37801)
@@ -2315,67 +2315,54 @@
 	
 	if(limit)
 	{
-		EM_uv_vert_map_sort(vmap, em, limit);
-	}
+		/* sort individual uvs for each vert */
+		for(a=0, ev=em->verts.first; ev; a++, ev= ev->next) {
+			UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
+			UvMapVert *iterv, *v, *lastv, *next;
+			float *uv, *uv2;
 
-	if (do_face_idx_array)
-		EM_free_index_arrays();
+			while(vlist) {
+				v= vlist;
+				vlist= vlist->next;
+				v->next= newvlist;
+				newvlist= v;
 
-	return vmap;
-}
-
-/* Sort UVs of vertmap according to limit */
-void EM_uv_vert_map_sort(UvVertMap *vmap,  EditMesh *em, float *limit)
-{
-	EditFace *efa;
-	MTFace *tf;
-	unsigned int a;
-	EditVert *ev;
-
-	/* sort individual uvs for each vert */
-	for(a=0, ev=em->verts.first; ev; a++, ev= ev->next) {
-		UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
-		UvMapVert *iterv, *v, *lastv, *next;
-		float *uv, *uv2, uvdiff[2];
-
-		while(vlist) {
-			v= vlist;
-			vlist= vlist->next;
-			v->next= newvlist;
-			newvlist= v;
-
-			efa = EM_get_face_for_index(v->f);
-			tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-			uv = tf->uv[v->tfindex];
+				efa = EM_get_face_for_index(v->f);
+				tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+				uv = tf->uv[v->tfindex];
 			
-			lastv= NULL;
-			iterv= vlist;
+				lastv= NULL;
+				iterv= vlist;
 
-			while(iterv) {
-				next= iterv->next;
-				efa = EM_get_face_for_index(iterv->f);
-				tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-				uv2 = tf->uv[iterv->tfindex];
+				while(iterv) {
+					next= iterv->next;
+					efa = EM_get_face_for_index(iterv->f);
+					tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+					uv2 = tf->uv[iterv->tfindex];
 				
-				sub_v2_v2v2(uvdiff, uv2, uv);
+					if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
+						if(lastv) lastv->next= next;
+						else vlist= next;
+						iterv->next= newvlist;
+						newvlist= iterv;
+					}
+					else
+						lastv=iterv;
 
-				if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
-					if(lastv) lastv->next= next;
-					else vlist= next;
-					iterv->next= newvlist;
-					newvlist= iterv;
+					iterv= next;
 				}
-				else
-					lastv=iterv;
 
-				iterv= next;
+				newvlist->separate = 1;
 			}
 
-			newvlist->separate = 1;
+			vmap->vert[a]= newvlist;
 		}
-
-		vmap->vert[a]= newvlist;
 	}
+
+	if (do_face_idx_array)
+		EM_free_index_arrays();
+
+	return vmap;
 }
 
 UvMapVert *EM_get_uv_map_vert(UvVertMap *vmap, unsigned int v)

Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c	2011-06-24 23:27:41 UTC (rev 37800)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c	2011-06-24 23:58:13 UTC (rev 37801)
@@ -1223,7 +1223,7 @@
 }
 
 /* This function prepares the data of the previewer for display */
-static void stitch_prepare_preview_data(StitchState *state)
+static int stitch_process_data(StitchState *state, int final)
 {
 	StitchPreviewer *preview = uv_get_stitch_previewer();
 	UVVertAverage *uv_average;
@@ -1242,7 +1242,8 @@
 	/* cleanup previous preview */
 	stitch_preview_delete();
 	preview = stitch_preview_init();
-	/*todo better store this in state */
+	if(preview == NULL)
+		return OPERATOR_CANCELLED;
 	preview->enabled = preview_enabled;
 
 	/* UV average is stored for every UV since potentially every UV can be stitched with another. Highly unlikely, I know but possible
@@ -1318,7 +1319,7 @@
 
 							if(fabs((mt->uv[i][0] - tmptface->uv[mv_iter->tfindex][0]) < STD_UV_CONNECT_LIMIT) &&
 								(fabs(mt->uv[i][1] - tmptface->uv[mv_iter->tfindex][1]) < STD_UV_CONNECT_LIMIT)){
-								/* if the uv being iterated is coincident with the original, add it to be updated later if
+								/* if the uv being iterated is coincident with the original, just add it to be updated later if
 								 * original uv is stitchable */
 								commonVertMaps[iter++] = mv_iter;
 							} else {
@@ -1335,20 +1336,6 @@
 									uv_average[averageIndex].count++;
 									uv_average[averageIndex].uv[0] += tmptface->uv[mv_iter->tfindex][0];
 									uv_average[averageIndex].uv[1] += tmptface->uv[mv_iter->tfindex][1];
-
-									/* store position of face in the preview buffer */
-									if(efa->tmp.l == -1)
-									{
-										if(efa->v4)
-										{
-											efa->tmp.l = preview->numOfQuads*8;
-											preview->numOfQuads++;
-										}
-										else {
-											efa->tmp.l = preview->numOfTris*6;
-											preview->numOfTris++;
-										}
-									}
 								}
 							}
 						}
@@ -1401,31 +1388,28 @@
 	}
 
 	MEM_freeN(commonVertMaps);
+	if(!final)
+	{
+		/* Initialize the preview buffers */
+		preview->previewQuads = (float *)MEM_mallocN(preview->numOfQuads*sizeof(float)*8, "quad_uv_stitch_prev");
+		preview->previewTris = (float *)MEM_mallocN(preview->numOfTris*sizeof(float)*6, "tri_uv_stitch_prev");
+		preview->previewPoints = (float *)MEM_mallocN(preview->numOfPoints*sizeof(float)*2, "stitch_preview_points");
+		preview->previewPointColors = (unsigned int *)MEM_mallocN(preview->numOfPoints*sizeof(unsigned int), "stitch_preview_point_colors");
 
-	/* Initialize the preview buffers */
-	preview->previewQuads = (float *)MEM_mallocN(preview->numOfQuads*sizeof(float)*8, "quad_uv_stitch_prev");
-	preview->previewTris = (float *)MEM_mallocN(preview->numOfTris*sizeof(float)*6, "tri_uv_stitch_prev");
-	preview->previewPoints = (float *)MEM_mallocN(preview->numOfPoints*sizeof(float)*2, "stitch_preview_points");
-	preview->previewPointColors = (unsigned int *)MEM_mallocN(preview->numOfPoints*sizeof(unsigned int), "stitch_preview_point_colors");
+		/* Copy data from MTFaces to the preview display buffers */
+		for(editFace = state->em->faces.first; editFace; editFace = editFace->next){
+			if(editFace->tmp.l != -1)
+			{
+				mt = CustomData_em_get(&state->em->fdata, editFace->data, CD_MTFACE);
 
-	/* Copy data from MTFaces to the preview display buffers */
-	for(editFace = state->em->faces.first; editFace; editFace = editFace->next){
-		if(editFace->tmp.l != -1)
-		{
-			mt = CustomData_em_get(&state->em->fdata, editFace->data, CD_MTFACE);
-
-			if(editFace->v4)
-			{
-				memcpy(preview->previewQuads+editFace->tmp.l, &mt->uv[0][0], 8*sizeof(float));
+				if(editFace->v4) {
+					memcpy(preview->previewQuads+editFace->tmp.l, &mt->uv[0][0], 8*sizeof(float));
+				} else {
+					memcpy(preview->previewTris+editFace->tmp.l, &mt->uv[0][0], 6*sizeof(float));
+				}
 			}
-			else {
-				memcpy(preview->previewTris+editFace->tmp.l, &mt->uv[0][0], 6*sizeof(float));
-			}
 		}
-	}
-	for(mapVert = vmap->buf, i = 0; i < state->vmap->numOfUVs; mapVert++, i++){
-		if(mapVert->flag){
-
+		for(mapVert = vmap->buf, i = 0; i < state->vmap->numOfUVs; mapVert++, i++){
 			if(mapVert->flag == STITCH_STITCHABLE){
 				float uv[2];
 				int averageBufIndex;
@@ -1465,9 +1449,29 @@
 			}
 		}
 	}
+	if(final)
+	{
+		for(mapVert = vmap->buf, i = 0; i < state->vmap->numOfUVs; mapVert++, i++){
+			if(mapVert->flag == STITCH_STITCHABLE){
+				float uv[2];
+				int averageBufIndex;
 
+				efa = faceArray[mapVert->f];
+				mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+				averageBufIndex = mapVert - vmap->buf;
+				uv[0] = uv_average[averageBufIndex].uv[0]/uv_average[averageBufIndex].count;
+				uv[1] = uv_average[averageBufIndex].uv[1]/uv_average[averageBufIndex].count;
+				mt->uv[mapVert->tfindex][0] = uv[0];
+				mt->uv[mapVert->tfindex][1] = uv[1];
+			}
+		}
+	}
+
 	MEM_freeN(uv_average);
 	MEM_freeN(faceArray);
+
+	return OPERATOR_FINISHED;
 }
 
 
@@ -1493,7 +1497,10 @@
 	stitch_state->vmap = EM_make_uv_vert_map(stitch_state->em, 1, 0, NULL);
 	EM_free_index_arrays();
 
-	stitch_prepare_preview_data(stitch_state);
+	if(!stitch_state->vmap){
+		return 0;
+	}
+	stitch_process_data(stitch_state, 0);
 
 	stitch_update_header(stitch_state, C);
 	return 1;
@@ -1550,12 +1557,12 @@
 
 static int stitch_exec(bContext *C, wmOperator *op)
 {
-//	int returnValue;
+	int returnValue;
 	if(!stitch_init(C, op))
 		return OPERATOR_CANCELLED;
-	//returnValue = stitch_uvs(C, op, 1);
+	returnValue = stitch_process_data((StitchState *)op->customdata, 1);
 	stitch_exit(C, op);
-	return OPERATOR_FINISHED;
+	return returnValue;
 }
 
 static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
@@ -1577,8 +1584,8 @@
 
 		case LEFTMOUSE:
 		case PADENTER:{
-			int returnValue = OPERATOR_FINISHED;
-			//returnValue = stitch_uvs(C, op, 1);
+			int returnValue;
+			returnValue = stitch_process_data(stitch_state, 1);
 			stitch_exit(C, op);
 			return returnValue;
 		}
@@ -1586,7 +1593,7 @@
 		case PADPLUSKEY:
 		case WHEELUPMOUSE:
 			stitch_state->limitDist += 0.01;
-			stitch_prepare_preview_data(stitch_state);
+			stitch_process_data(stitch_state, 0);
 			break;
 
 		/* Decrease limit */
@@ -1594,14 +1601,14 @@
 		case WHEELDOWNMOUSE:
 			stitch_state->limitDist -= 0.01;
 			stitch_state->limitDist = MAX2(0.01, stitch_state->limitDist);
-			stitch_prepare_preview_data(stitch_state);
+			stitch_process_data(stitch_state, 0);
 			break;
 
 		/* Use Limit (Default off)*/
 		case LKEY:
 			if(event->val == KM_PRESS){
 				stitch_state->use_limit = !stitch_state->use_limit;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list