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

Antony Riakiotakis kalast at gmail.com
Mon May 28 22:18:06 CEST 2012


Revision: 47136
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47136
Author:   psy-fi
Date:     2012-05-28 20:18:06 +0000 (Mon, 28 May 2012)
Log Message:
-----------
UV transform correction tool
============================

*Add struct UVTransCorrection for the tool and cleanup code for the
struct.
*After some thought it looks like I cannot use unwrap for this tool
since it will likely invalidate any custom uv layout made by the artist
and replace it with the position from the unwrapper. So I will do it
with the second method, by modifying the uvs based on the ratios of edge
lengths. This will probably require some mathematical correction that I
will have to work on.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/editors/transform/transform.c
    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.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform.c	2012-05-28 19:49:26 UTC (rev 47135)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform.c	2012-05-28 20:18:06 UTC (rev 47136)
@@ -74,6 +74,7 @@
 #include "ED_view3d.h"
 #include "ED_mesh.h"
 #include "ED_clip.h"
+#include "ED_uvedit.h"
 
 #include "UI_view2d.h"
 #include "WM_types.h"
@@ -1818,7 +1819,11 @@
 	/* stay here for now, maybe will find some other way to aviod duplicating in every transform
 	 * apply funtion */
 	if(t->flag & T_IMAGE_PRESERVE_CALC) {
-		calculateImageMaintainBounds(t);
+		/* can be invalidated if for instance we change the radius of proportional editing */
+		if(!t->uvtc->init)
+			calculateUVTransformCorrection(t);
+
+		//ED
 	}
 
 	/* If auto confirm is on, break after one pass */

Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h	2012-05-28 19:49:26 UTC (rev 47135)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h	2012-05-28 20:18:06 UTC (rev 47136)
@@ -66,6 +66,7 @@
 struct ARegion;
 struct ReportList;
 struct SmallHash;
+struct UVTransCorrect;
 
 typedef struct TransSnapPoint {
 	struct TransSnapPoint *next, *prev;
@@ -220,6 +221,16 @@
 	int curr_sv_index;
 } SlideData;
 
+/* 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;
+	int num_boundary_edges;
+	int num_unwrapped_faces;
+	char init;
+} UVTransCorrect;
+
 typedef struct TransData {
 	float  dist;         /* Distance needed to affect element (for Proportionnal Editing)                  */
 	float  rdist;        /* Distance to the nearest element (for Proportionnal Editing)                    */
@@ -333,7 +344,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 */
+	struct UVTransCorrect *uvtc; /* stores uv transform correction data */
 } TransInfo;
 
 
@@ -684,7 +695,7 @@
 
 void calculateCenterCursor2D(TransInfo *t);
 void calculatePropRatio(TransInfo *t);
-void calculateImageMaintainBounds(TransInfo *t);
+void calculateUVTransformCorrection(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-28 19:49:26 UTC (rev 47135)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c	2012-05-28 20:18:06 UTC (rev 47136)
@@ -1939,7 +1939,7 @@
 	TransDataExtension *tx = NULL;
 	BMEditMesh *em = BMEdit_FromObject(t->obedit);
 	BMesh *bm = em->bm;
-	BMVert *eve;
+	BMVert *eve, **affected_verts;
 	BMIter iter;
 	BMVert *eve_act = NULL;
 	float *mappedcos = NULL, *quats= NULL;
@@ -2043,7 +2043,8 @@
 
 	/* 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");
+		t->uvtc = MEM_callocN(sizeof(*t->uvtc), "UVTransformCorrect");
+		t->uvtc->affected_verts = affected_verts = MEM_mallocN(t->total * sizeof(*t->uvtc->affected_verts), "BMVert Map");
 	}
 
 	tob= t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(Mesh EditMode)");
@@ -2107,7 +2108,7 @@
 					tx++;
 
 				if(t->flag & T_IMAGE_PRESERVE_CALC)
-					t->affected_verts[i] = eve;
+					affected_verts[i] = 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-28 19:49:26 UTC (rev 47135)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c	2012-05-28 20:18:06 UTC (rev 47136)
@@ -1215,6 +1215,22 @@
 	return 1;
 }
 
+void deleteUVTransCorrect(struct UVTransCorrect *uvtc)
+{
+	if(uvtc->boundary_edges) {
+		MEM_freeN(uvtc->boundary_edges);
+		uvtc->boundary_edges = NULL;
+	}
+	if(uvtc->unwrapped_faces) {
+		MEM_freeN(uvtc->unwrapped_faces);
+		uvtc->unwrapped_faces = NULL;
+	}
+	if(uvtc->affected_verts) {
+		MEM_freeN(uvtc->affected_verts);
+		uvtc->affected_verts = NULL;
+	}
+}
+
 /* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
 void postTrans(bContext *C, TransInfo *t)
 {
@@ -1269,9 +1285,10 @@
 			v3d->twtype = t->twtype;
 		}
 		if(t->flag & T_IMAGE_PRESERVE_CALC) {
-			if(t->affected_verts) {
-				MEM_freeN(t->affected_verts);
-				t->affected_verts = NULL;
+			if(t->uvtc) {
+				deleteUVTransCorrect(t->uvtc);
+				MEM_freeN(t->uvtc);
+				t->uvtc = NULL;
 			}
 		}
 	}
@@ -1600,7 +1617,7 @@
 
 /* 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)
+void calculateUVTransformCorrection(TransInfo *t)
 {
 	int i, edge_counter = 0, boundary_edge_counter = 0;
 	BMIter iter;
@@ -1611,11 +1628,18 @@
 	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;
+	UVTransCorrect *uvtc = t->uvtc;
 	char not_prop_edit = !(t->flag & T_PROP_EDIT);
 
+	/* cleanup previous data if it exists */
+	if(uvtc->boundary_edges)
+		MEM_freeN(uvtc->boundary_edges);
+	if(uvtc->unwrapped_faces)
+		MEM_freeN(uvtc->unwrapped_faces);
+
 	/* store faces adjacent to verts */
 	for (i = 0 ; i < t->total; i++, td++) {
-		BMVert *v = t->affected_verts[i];
+		BMVert *v = uvtc->affected_verts[i];
 
 		if(not_prop_edit || td->factor > 0.0) {
 			BM_ITER_ELEM(f, &iter, v, BM_FACES_OF_VERT) {
@@ -1641,7 +1665,8 @@
 	}
 
 	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");
+	/* allocate more than we will need to avoid recounting */
+	uvtc->boundary_edges = edge_boundaries = MEM_mallocN(edge_counter*sizeof(*edge_boundaries), "maintain_image_boundary_list");
 
 	BLI_ghashIterator_init(ghiter, edge_hash);
 	/* fill with count values */
@@ -1678,7 +1703,18 @@
 
 	}
 
-	MEM_freeN(edge_boundaries);
+	uvtc->num_boundary_edges = boundary_edge_counter;
+	uvtc->unwrapped_faces = MEM_mallocN(BLI_ghash_size(face_hash)*sizeof(*uvtc->unwrapped_faces), "maintain_image_face_list");
+
+	BLI_ghashIterator_init(ghiter, face_hash);
+	/* fill with count values */
+	for(i = 0; !BLI_ghashIterator_isDone(ghiter); BLI_ghashIterator_step(ghiter)) {
+		uvtc->unwrapped_faces[i++] = BLI_ghashIterator_getKey(ghiter);
+	}
+
+	uvtc->num_unwrapped_faces = i;
+	uvtc->init = TRUE;
+
 	MEM_freeN(edge_list);
 	BLI_ghash_free(face_hash, NULL, NULL);
 }
@@ -1788,4 +1824,9 @@
 		}
 		t->proptext[0]= '\0';
 	}
+
+	/* we need to redetect boundaries for uv */
+	if(t->flag & T_IMAGE_PRESERVE_CALC) {
+		t->uvtc->init = 0;
+	}
 }




More information about the Bf-blender-cvs mailing list