[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47484] branches/soc-2012-bratwurst/source /blender/editors/transform: UV transform correction tool

Antony Riakiotakis kalast at gmail.com
Wed Jun 6 00:38:34 CEST 2012


Revision: 47484
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47484
Author:   psy-fi
Date:     2012-06-05 22:38:22 +0000 (Tue, 05 Jun 2012)
Log Message:
-----------
UV transform correction tool
============================
* Fix for proportional editing. It seems that the reason that the tool
didn't work for proportional editing was that TransformData are sorted
making editvert indices invalid. I thought that BMVerts were sorted
instead, then I realized that they are not used during transform. I
wrestled with the idea of copying the indices during sort to avoid
storing the initial positions of BM_Verts again but I didn't want to
slow it down. Copying the coordinates of the vertices instead uses a bit
more memory (96 instead of 64 bits for 64 bit pointer) but does the
trick. 
* Also removed a lot of debug stuff.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h
    branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c
    branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c

Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h	2012-06-05 22:12:17 UTC (rev 47483)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h	2012-06-05 22:38:22 UTC (rev 47484)
@@ -230,13 +230,8 @@
 
 /* unwrap transform correction structure, will contain mesh elements that will be used for unwrapping */
 typedef struct UVTransCorrect {
-//	struct BMEdge **boundary_edges;
-//	struct BMFace **unwrapped_faces;
-//	struct BMVert **affected_verts;
 	UVTransCorrInfoUV **initial_uvs;
-	int *vert_indices;
-//	int total_boundary_edges;
-//	int total_unwrapped_faces;
+	float (*init_vec)[3]; /* initial vertex value */
 	int total_verts;
 	char init;
 } UVTransCorrect;
@@ -261,7 +256,6 @@
 	int  flag;           /* Various flags */
 	short  protectflag;	 /* If set, copy of Object or PoseChannel protection */
 	struct BMVert *eve;
-	int oldindex;
 } TransData;
 
 typedef struct MouseInput {

Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c	2012-06-05 22:12:17 UTC (rev 47483)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c	2012-06-05 22:38:22 UTC (rev 47484)
@@ -1942,7 +1942,7 @@
 	TransDataExtension *tx = NULL;
 	BMEditMesh *em = BMEdit_FromObject(t->obedit);
 	BMesh *bm = em->bm;
-	BMVert *eve, **affected_verts;
+	BMVert *eve;
 	UVTransCorrect *uvtc;
 	UVTransCorrInfoUV **initial_uvs;
 	BMIter iter;
@@ -2052,7 +2052,7 @@
 		uvtc = t->uvtc = MEM_callocN(sizeof(*t->uvtc), "UVTransformCorrect");
 //		uvtc->affected_verts = affected_verts = MEM_mallocN(t->total * sizeof(*t->uvtc->affected_verts), "uvtc_verts");
 		uvtc->initial_uvs = initial_uvs = MEM_mallocN(bm->totvert * sizeof(*t->uvtc->initial_uvs), "uvtc_inituvs");
-		uvtc->vert_indices = MEM_mallocN(bm->totvert * sizeof(*t->uvtc->vert_indices), "uvtc_indices");
+		uvtc->init_vec = MEM_mallocN(bm->totvert * sizeof(*t->uvtc->init_vec), "uvtc_initial_vertexes");
 		uvtc->total_verts = bm->totvert;
 		BM_mesh_elem_index_ensure(bm, BM_VERT);
 	}
@@ -2110,7 +2110,8 @@
 	eve = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL);
 	for (a=0, i=0; eve; eve=BM_iter_step(&iter), a++) {
 		if(t->flag & T_IMAGE_PRESERVE_CALC) {
-			uvtc->vert_indices[a] = -1;
+			/* will need to save initial position iteratable by vertex too */
+			copy_v3_v3(uvtc->init_vec[a], eve->co);
 			initial_uvs[a] = NULL;
 		}
 
@@ -2128,11 +2129,11 @@
 					UVTransCorrInfoUV *uvprev = NULL;
 
 					tob->eve = eve;
-					tob->oldindex = BM_elem_index_get(eve);
-					uvtc->vert_indices[a] = i;
+
 					if(propmode)
 						BLI_assert(i == a);
 					BLI_assert(BM_elem_index_get(eve) == a);
+
 					BM_ITER_ELEM(l, &iter2, eve, BM_LOOPS_OF_VERT) {
 						MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
 
@@ -2204,8 +2205,6 @@
 		}
 	}
 
-	if(propmode)
-		BLI_assert(i == a);
 	if (mirror != 0) {
 		tob = t->data;
 		for (a = 0; a < t->total; a++, tob++ ) {

Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c	2012-06-05 22:12:17 UTC (rev 47483)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c	2012-06-05 22:38:22 UTC (rev 47484)
@@ -1262,11 +1262,11 @@
 	if(uvtc->affected_verts) {
 		MEM_freeN(uvtc->affected_verts);
 		uvtc->affected_verts = NULL;
-	}
+	}	
 	*/
-	if(uvtc->vert_indices) {
-		MEM_freeN(uvtc->vert_indices);
-		uvtc->vert_indices = NULL;
+	if(uvtc->init_vec) {
+		MEM_freeN(uvtc->init_vec);
+		uvtc->init_vec = NULL;
 	}
 	if(uvtc->initial_uvs) {
 		int i;
@@ -1711,15 +1711,15 @@
 
 	/* iterate through loops of vert and calculate image space diff of uvs */
 	for (i = 0 ; i < t->total; i++) {
-		BMVert *v = td[i].eve;
-
 		if(not_prop_edit || td[i].factor > 0.0) {
+			int index;
 			float uv_tot[2];
 			int uv_counter = 0;
+			BMVert *v = td[i].eve;
+			index = BM_elem_index_get(v);
 
 			uv_tot[0] = uv_tot[1] = 0.0;
 
-			//printf("disc loops %d\n",  bmesh_disk_facevert_count(v));
 			BM_ITER_ELEM(l, &iter, v, BM_LOOPS_OF_VERT) {
 				float mul;
 				float edge_len_init, edge_len_init2;
@@ -1730,49 +1730,31 @@
 				float uvdiff[2], uvdiff2[2];
 				int index_next, index_prev;
 				BMLoop *l_next, *l_prev;
-				MLoopUV *luv_next, *luv_prev, *luv;
+				MLoopUV *luv;
 
 				l_next =l->next;
 				l_prev = l->prev;
 
-				luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
-				if(!not_prop_edit)
-					BLI_assert(BM_elem_index_get(v) == td[i].oldindex);
-				//print_v2("last =", luv->uv);
-				//print_v2("last =", uvtc->initial_uvs[BM_elem_index_get(v)]->init_uv);
-				luv_next = CustomData_bmesh_get(&em->bm->ldata, l_next->head.data, CD_MLOOPUV);
-				luv_prev = CustomData_bmesh_get(&em->bm->ldata, l_prev->head.data, CD_MLOOPUV);
+				index_next = BM_elem_index_get(l_next->v);
+				index_prev = BM_elem_index_get(l_prev->v);
 
-				index_next = uvtc->vert_indices[BM_elem_index_get(l_next->v)];
-				index_prev = uvtc->vert_indices[BM_elem_index_get(l_prev->v)];
-
-				if(!not_prop_edit) {
-					BLI_assert(index_next == BM_elem_index_get(l_next->v));
-					BLI_assert(index_prev == BM_elem_index_get(l_prev->v));
-					if(td[index_next].oldindex == BM_elem_index_get(l_next->v) &&
-					       td[index_next].oldindex != BM_elem_index_get(l_next->v))
-						BLI_assert(td[index_prev].oldindex == BM_elem_index_get(l_prev->v));
-				}
 				/* find initial and final edge lengths */
-				if(index_next == -1) {
-					/* get BMvert coords since the vertex hasn't changed */
-					sub_v3_v3v3(edge_vec_init, l_next->v->co, td[i].iloc);
-					sub_v3_v3v3(edge_vec_final, l_next->v->co, v->co);
-					sub_v2_v2v2(edge_uv_init, luv_next->uv, uvtc->initial_uvs[BM_elem_index_get(v)]->init_uv);
-				} else {
-					sub_v3_v3v3(edge_vec_init, td[index_next].iloc, td[i].iloc);
-					sub_v3_v3v3(edge_vec_final, td[index_next].iloc, v->co);
-					sub_v2_v2v2(edge_uv_init, uvtc->initial_uvs[BM_elem_index_get(l_next->v)]->init_uv, uvtc->initial_uvs[BM_elem_index_get(v)]->init_uv);
+				sub_v3_v3v3(edge_vec_init, uvtc->init_vec[index_next], td[i].iloc);
+				sub_v3_v3v3(edge_vec_final, uvtc->init_vec[index_next], v->co);
+				if(uvtc->initial_uvs[index_next])
+					sub_v2_v2v2(edge_uv_init, uvtc->initial_uvs[index_next]->init_uv, uvtc->initial_uvs[index]->init_uv);
+				else {
+					luv = CustomData_bmesh_get(&em->bm->ldata, l_next->head.data, CD_MLOOPUV);
+					sub_v2_v2v2(edge_uv_init, luv->uv, uvtc->initial_uvs[index]->init_uv);
 				}
-				if(index_prev == -1) {
-					/* get BMvert coords since the vertex hasn't changed */
-					sub_v3_v3v3(edge_vec_init2, l_prev->v->co, td[i].iloc);
-					sub_v3_v3v3(edge_vec_final2, l_prev->v->co, v->co);
-					sub_v2_v2v2(edge_uv_init2, luv_prev->uv, uvtc->initial_uvs[BM_elem_index_get(v)]->init_uv);
-				} else {
-					sub_v3_v3v3(edge_vec_init2, td[index_prev].iloc, td[i].iloc);
-					sub_v3_v3v3(edge_vec_final2, td[index_prev].iloc, v->co);
-					sub_v2_v2v2(edge_uv_init2, uvtc->initial_uvs[BM_elem_index_get(l_prev->v)]->init_uv, uvtc->initial_uvs[BM_elem_index_get(v)]->init_uv);
+
+				sub_v3_v3v3(edge_vec_init2, uvtc->init_vec[index_prev], td[i].iloc);
+				sub_v3_v3v3(edge_vec_final2, uvtc->init_vec[index_prev], v->co);
+				if(uvtc->initial_uvs[index_prev])
+					sub_v2_v2v2(edge_uv_init2, uvtc->initial_uvs[index_prev]->init_uv, uvtc->initial_uvs[index]->init_uv);
+				else {
+					luv = CustomData_bmesh_get(&em->bm->ldata, l_prev->head.data, CD_MLOOPUV);
+					sub_v2_v2v2(edge_uv_init2, luv->uv, uvtc->initial_uvs[index]->init_uv);
 				}
 
 				/* first project final edges to initial edges to get the translation along the edge axis */
@@ -1787,14 +1769,9 @@
 				edge_len_init = len_v3(edge_vec_init);
 				edge_len_init2 = len_v3(edge_vec_init2);
 
-				//printf("\nedge_uv_init %f %f\n", edge_uv_init[0], edge_uv_init[1]);
-				//printf("edge_uv_init2 %f %f\n", edge_uv_init2[0], edge_uv_init2[1]);
-
 				mul_v2_v2fl(uvdiff, edge_uv_init, -(edge_len_final - edge_len_init)/edge_len_init);
 				mul_v2_v2fl(uvdiff2, edge_uv_init2, -(edge_len_final2 - edge_len_init2)/edge_len_init2);
 
-				print_v2("\nuv_diff", uvdiff);
-				print_v2("uv_diff2", uvdiff2);
 				add_v2_v2(uv_tot, uvdiff);
 				add_v2_v2(uv_tot, uvdiff2);
 
@@ -1803,20 +1780,16 @@
 				//mul_m4_v3(modelviewprojmat, diff);
 			}
 
-			//printf("total loops %d\n", uv_counter);
 			mul_v2_fl(uv_tot, 1.0/uv_counter);
-			add_v2_v2(uv_tot, uvtc->initial_uvs[BM_elem_index_get(v)]->init_uv);
+			add_v2_v2(uv_tot, uvtc->initial_uvs[index]->init_uv);
 
-			uvtcuv = uvtc->initial_uvs[BM_elem_index_get(v)];
+			uvtcuv = uvtc->initial_uvs[index];
 			/* flush to actual uvs */
 			BM_ITER_ELEM(l, &iter, v, BM_LOOPS_OF_VERT) {
 				MLoopUV *luv;
-				printf("\nuv coordinate for vector %d", i);
-				print_v2("\ninitial =", uvtc->initial_uvs[BM_elem_index_get(v)]->init_uv);
 
 				luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
-				print_v2("pointed =", uvtcuv->uv);
-				BLI_assert(uvtcuv->uv == luv->uv);
+
 				copy_v2_v2(luv->uv, uv_tot);
 				uvtcuv = uvtcuv->next;
 			}




More information about the Bf-blender-cvs mailing list