[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46856] branches/soc-2012-bratwurst/source /blender/editors/transform: Maintain image transform tool

Antony Riakiotakis kalast at gmail.com
Mon May 21 21:52:42 CEST 2012


Revision: 46856
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46856
Author:   psy-fi
Date:     2012-05-21 19:52:41 +0000 (Mon, 21 May 2012)
Log Message:
-----------
Maintain image transform tool
==================================
Add intermediate function to detect boundary edges that will be
artificially pinned and faces to reunwrap. Still not 100% certain the
reunwrap method will work, still I hope it will do the trick. Still, a
similar function will likely be needed for the second method that I will
use, should the first one fail.

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-05-21 19:31:29 UTC (rev 46855)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h	2012-05-21 19:52:41 UTC (rev 46856)
@@ -324,6 +324,7 @@
 	void		*draw_handle_view;
 	void		*draw_handle_pixel;
 	void		*draw_handle_cursor;
+	struct BMVert **affected_verts; /* stores pointers to bmverts to access connectivity data */
 } TransInfo;
 
 
@@ -385,6 +386,9 @@
 	/* alternative transformation. used to add offset to tracking markers */
 #define T_ALT_TRANSFORM		(1 << 24)
 
+    /* calculation of image maintain tool */
+#define T_IMAGE_PRESERVE_CALC (1 << 25)
+
 /* TransInfo->modifiers */
 #define	MOD_CONSTRAINT_SELECT	0x01
 #define	MOD_PRECISION			0x02
@@ -665,6 +669,7 @@
 
 void calculateCenterCursor2D(TransInfo *t);
 void calculatePropRatio(TransInfo *t);
+void calculateImageMaintainBounds(TransInfo *t);
 
 void getViewVector(TransInfo *t, float coord[3], float vec[3]);
 

Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c	2012-05-21 19:31:29 UTC (rev 46855)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c	2012-05-21 19:52:41 UTC (rev 46856)
@@ -2029,6 +2029,11 @@
 	}
 	else t->total = countsel;
 
+	/* now we need to allocate store for affected verts if we do maintain image */
+	if(t->flag & T_IMAGE_PRESERVE_CALC) {
+		t->affected_verts = MEM_mallocN(t->total * sizeof(*t->affected_verts), "BMVert Map");
+	}
+
 	tob= t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(Mesh EditMode)");
 
 	copy_m3_m4(mtx, t->obedit->obmat);
@@ -2083,6 +2088,9 @@
 				
 				VertsToTransData(t, tob, em, eve, bweight);
 
+				if(t->flag & T_IMAGE_PRESERVE_CALC)
+					t->affected_verts[a] = eve;
+
 				/* selected */
 				if (selstate[a]) tob->flag |= TD_SELECTED;
 

Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c	2012-05-21 19:31:29 UTC (rev 46855)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c	2012-05-21 19:52:41 UTC (rev 46856)
@@ -1049,6 +1049,9 @@
 			v3d->twtype = 0;
 		}
 
+		if(ts->retain_image_pos)
+			t->flag |= T_IMAGE_PRESERVE_CALC;
+
 		if (v3d->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
 		t->around = v3d->around;
 		
@@ -1265,6 +1268,10 @@
 		if (t->flag & T_MODAL) {
 			v3d->twtype = t->twtype;
 		}
+		if(t->flag & T_IMAGE_PRESERVE_CALC) {
+			if(t->affected_verts)
+				MEM_freeN(t->affected_verts);
+		}
 	}
 	
 	if (t->mouse.data) {
@@ -1589,6 +1596,91 @@
 	}
 }
 
+/* this function detects boundary mesh elements that will encompass the faces to send to the unwrapper.
+ * These elements will be artificially pinned for this first attempt at the algorithm */
+void calculateImageMaintainBounds(TransInfo *t)
+{
+	int i, edge_counter = 0, boundary_edge_counter = 0;
+	BMIter iter;
+	BMFace *f;
+	BMEdge **edge_list, **edge_boundaries;
+	BMEdge *e;
+	GHashIterator *ghiter;
+	GHash *face_hash = BLI_ghash_ptr_new("maintain_image_face_hash");
+	GHash *edge_hash = BLI_ghash_ptr_new("maintain_image_edge_hash");
+	TransData *td = t->data;
+	char not_prop_edit = !(t->flag & T_PROP_EDIT);
+
+	/* store faces adjacent to verts */
+	for (i = 0 ; i < t->total; i++, td++) {
+		BMVert *v = t->affected_verts[i];
+
+		if(not_prop_edit || td->factor > 0.0) {
+			BM_ITER_ELEM(f, &iter, v, BM_FACES_OF_VERT) {
+				if(!BLI_ghash_haskey(face_hash, f)){
+					BLI_ghash_insert(face_hash, f, NULL);
+				}
+			}
+		}
+	}
+
+	ghiter = BLI_ghashIterator_new(face_hash);
+
+	/* count edges */
+	for(; BLI_ghashIterator_isDone(ghiter); BLI_ghashIterator_step(ghiter)) {
+		f = BLI_ghashIterator_getKey(ghiter);
+
+		BM_ITER_ELEM(e, &iter, f, BM_EDGES_OF_FACE) {
+			if(!BLI_ghash_haskey(edge_hash, e)) {
+				BLI_ghash_insert(edge_hash, e, NULL);
+				edge_counter++;
+			}
+		}
+	}
+
+	edge_list = MEM_mallocN(edge_counter*sizeof(*edge_list), "maintain_image_edge_list");
+	edge_boundaries = MEM_mallocN(edge_counter*sizeof(*edge_boundaries), "maintain_image_boundary_list");
+
+	BLI_ghashIterator_init(ghiter, edge_hash);
+	/* fill with count values */
+	for(i = 0; BLI_ghashIterator_isDone(ghiter); BLI_ghashIterator_step(ghiter)) {
+		edge_list[i++] = BLI_ghashIterator_getKey(ghiter);
+	}
+
+	BLI_ghashIterator_free(ghiter);
+	BLI_ghash_free(edge_hash, NULL, NULL);
+
+	/* count boundary edges edges */
+	for(i = 0; i < edge_counter; i++) {
+		int efc;
+
+		e = edge_list[i];
+		efc = BM_edge_face_count(e);
+
+		/* non-manifold case is ignored, should probably print a warning */
+		if(efc == 2) {
+			BMFace *f1, *f2;
+
+			BM_edge_face_pair(e, &f1, &f2);
+
+			if(BLI_ghash_haskey(face_hash, f1) && BLI_ghash_haskey(face_hash, f1))
+				/* ignore */
+				;
+			else {
+				edge_boundaries[boundary_edge_counter++] = e;
+			}
+		} else if(efc == 1) {
+			/* edges on boundaries of mesh are automatically added */
+			edge_boundaries[boundary_edge_counter++] = edge_list[i];
+		}
+
+	}
+
+	MEM_freeN(edge_boundaries);
+	MEM_freeN(edge_list);
+	BLI_ghash_free(face_hash, NULL, NULL);
+}
+
 void calculatePropRatio(TransInfo *t)
 {
 	TransData *td = t->data;




More information about the Bf-blender-cvs mailing list