[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15186] branches/apricot/source/blender: UV Mirror now detects the bounding box of UV islands to get the mirror center

Campbell Barton ideasman42 at gmail.com
Tue Jun 10 11:43:27 CEST 2008


Revision: 15186
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15186
Author:   campbellbarton
Date:     2008-06-10 11:42:33 +0200 (Tue, 10 Jun 2008)

Log Message:
-----------
UV Mirror now detects the bounding box of UV islands to get the mirror center
Access mirror now from the UVs menu (dont use mesh mirror)
Added vertical mirroring (can only do U or V mirror)
 - mirror dosnt work with quad constrained or PET yet.

Modified Paths:
--------------
    branches/apricot/source/blender/include/BIF_meshtools.h
    branches/apricot/source/blender/makesdna/DNA_space_types.h
    branches/apricot/source/blender/src/header_image.c
    branches/apricot/source/blender/src/meshtools.c
    branches/apricot/source/blender/src/transform.c
    branches/apricot/source/blender/src/transform_conversions.c
    branches/apricot/source/blender/src/transform_generics.c

Modified: branches/apricot/source/blender/include/BIF_meshtools.h
===================================================================
--- branches/apricot/source/blender/include/BIF_meshtools.h	2008-06-10 05:12:51 UTC (rev 15185)
+++ branches/apricot/source/blender/include/BIF_meshtools.h	2008-06-10 09:42:33 UTC (rev 15186)
@@ -43,7 +43,7 @@
 extern long mesh_octree_table(struct Object *ob, float *co, char mode);
 extern int mesh_get_x_mirror_vert(struct Object *ob, int index);
 extern struct EditVert *editmesh_get_x_mirror_vert(struct Object *ob, float *co);
-extern float *editmesh_get_x_mirror_uv(struct Object *ob, float *co, float *face_cent);
+extern float *editmesh_get_mirror_uv(int axis, float *co, float *mirrCent, float *face_cent);
 extern int *mesh_get_x_mirror_faces(struct Object *ob);
 
 #endif

Modified: branches/apricot/source/blender/makesdna/DNA_space_types.h
===================================================================
--- branches/apricot/source/blender/makesdna/DNA_space_types.h	2008-06-10 05:12:51 UTC (rev 15185)
+++ branches/apricot/source/blender/makesdna/DNA_space_types.h	2008-06-10 09:42:33 UTC (rev 15186)
@@ -526,6 +526,8 @@
 #define SI_DRAW_TILE	1<<19 
 #define SI_SMOOTH_UV	1<<20
 #define SI_DRAW_STRETCH	1<<21
+#define SI_XMIRROR_ISLE	1<<22
+#define SI_YMIRROR_ISLE	1<<23
 
 /* SpaceIpo->flag */
 #define SIPO_LOCK_VIEW			1<<0

Modified: branches/apricot/source/blender/src/header_image.c
===================================================================
--- branches/apricot/source/blender/src/header_image.c	2008-06-10 05:12:51 UTC (rev 15185)
+++ branches/apricot/source/blender/src/header_image.c	2008-06-10 09:42:33 UTC (rev 15186)
@@ -1024,6 +1024,22 @@
 	case 14:
 		average_charts_tface_uv();
 		break;
+	case 15: /* x mirror */
+		if (G.sima->flag & SI_XMIRROR_ISLE) {
+			G.sima->flag &= ~SI_XMIRROR_ISLE;
+		} else {
+			G.sima->flag &= ~SI_YMIRROR_ISLE;
+			G.sima->flag |= SI_XMIRROR_ISLE;
+		}	
+		break;
+	case 16: /* y mirror */
+		if (G.sima->flag & SI_YMIRROR_ISLE) {
+			G.sima->flag &= ~SI_YMIRROR_ISLE;
+		} else {
+			G.sima->flag &= ~SI_XMIRROR_ISLE;
+			G.sima->flag |= SI_YMIRROR_ISLE;
+		}
+		break;
 	}
 }
 
@@ -1046,6 +1062,9 @@
 	if(G.sima->flag & SI_CLIP_UV) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Layout Clipped to Image Size|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
 	else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Layout Clipped to Image Size|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
 
+	uiDefIconTextBut(block, BUTM, 1, (G.sima->flag & SI_YMIRROR_ISLE)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, "V Mirror Island|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 16, "");
+	uiDefIconTextBut(block, BUTM, 1, (G.sima->flag & SI_XMIRROR_ISLE)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, "U Mirror Island|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 15, "");
+
 	uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");	
 
 	if(G.sima->flag & SI_LIVE_UNWRAP) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Live Unwrap Transform", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
@@ -1202,7 +1221,7 @@
 		int layercount;
 		
 		uiDefIconTextButS(block, ICONTEXTROW, B_NOP, ICON_ROTATE,
-				"Pivot: %t|Bounding Box Center %x0|Median Point %x3|2D Cursor %x1",
+				"Pivot: %t|Bounding Box Center %x0|Median Point %x3|2D Cursor %x1|Island Centers %x2",
 				xco,0,XIC+10,YIC, &(G.v2d->around), 0, 3.0, 0, 0,
 				"Rotation/Scaling Pivot (Hotkeys: Comma, Shift Comma, Period)");
 		xco+= XIC + 18;

Modified: branches/apricot/source/blender/src/meshtools.c
===================================================================
--- branches/apricot/source/blender/src/meshtools.c	2008-06-10 05:12:51 UTC (rev 15185)
+++ branches/apricot/source/blender/src/meshtools.c	2008-06-10 09:42:33 UTC (rev 15186)
@@ -883,7 +883,7 @@
 }
 
 extern void uv_center(float uv[][2], float cent[2], void * isquad);
-float *editmesh_get_x_mirror_uv(Object *ob, float *uv, float *face_cent)
+float *editmesh_get_mirror_uv(int axis, float *uv, float *mirrCent, float *face_cent)
 {
 	float vec[2];
 	float cent_vec[2];
@@ -895,12 +895,25 @@
 	   )
 		return NULL;
 	
-	vec[0]= -((uv[0])-G.v2d->cursor[0]) + G.v2d->cursor[0];
-	vec[1]= uv[1];
-
-	cent_vec[0]= -((face_cent[0])-G.v2d->cursor[0]) + G.v2d->cursor[0];	
-	cent_vec[1] = face_cent[1];
+	if (axis) {
+		vec[0]= uv[0];
+		vec[1]= -((uv[1])-mirrCent[1]) + mirrCent[1];
 	
+		cent_vec[0] = face_cent[0];
+		cent_vec[1]= -((face_cent[1])-mirrCent[1]) + mirrCent[1];
+	} else {
+		vec[0]= -((uv[0])-mirrCent[0]) + mirrCent[0];
+		vec[1]= uv[1];
+	
+		cent_vec[0]= -((face_cent[0])-mirrCent[0]) + mirrCent[0];	
+		cent_vec[1] = face_cent[1];
+	}
+	
+	/*
+	G.v2d->cursor[0] = mirrCent[0];
+	G.v2d->cursor[1] = mirrCent[1];
+	*/
+	
 	/* TODO - Optimize */
 	{
 		EditFace *efa;

Modified: branches/apricot/source/blender/src/transform.c
===================================================================
--- branches/apricot/source/blender/src/transform.c	2008-06-10 05:12:51 UTC (rev 15185)
+++ branches/apricot/source/blender/src/transform.c	2008-06-10 09:42:33 UTC (rev 15186)
@@ -2119,12 +2119,12 @@
 
 	/* local constraint shouldn't alter center */
 	if (t->around == V3D_LOCAL) {
-		if (t->flag & T_OBJECT) {
+		if (t->flag & T_OBJECT || t->spacetype==SPACE_IMAGE) {
 			VECCOPY(center, td->center);
 		}
 		else if (t->flag & T_EDIT) {
 			
-			if(G.vd->around==V3D_LOCAL && (G.scene->selectmode & SCE_SELECT_FACE)) {
+			if(G.vd->around==V3D_LOCAL && (G.scene->selectmode & SCE_SELECT_FACE || t->spacetype==SPACE_IMAGE)) { /* Image types canrotate about island center */
 				VECCOPY(center, td->center);
 			}
 			else {

Modified: branches/apricot/source/blender/src/transform_conversions.c
===================================================================
--- branches/apricot/source/blender/src/transform_conversions.c	2008-06-10 05:12:51 UTC (rev 15185)
+++ branches/apricot/source/blender/src/transform_conversions.c	2008-06-10 09:42:33 UTC (rev 15186)
@@ -2188,7 +2188,7 @@
 
 /* ********************* UV ****************** */
 
-static void UVsToTransData(TransData *td, TransData2D *td2d, float *uv, int selected)
+static void UVsToTransData(TransData *td, TransData2D *td2d, float *uv, float *cent, int selected)
 {
 	float aspx, aspy;
 
@@ -2205,7 +2205,13 @@
 
 	td->flag = 0;
 	td->loc = td2d->loc;
-	VECCOPY(td->center, td->loc);
+	
+	if (cent) {
+		VECCOPY(td->center, cent);  /* island center */
+	} else {
+		VECCOPY(td->center, td->loc);
+	}
+
 	VECCOPY(td->iloc, td->loc);
 
 	memset(td->axismtx, 0, sizeof(td->axismtx));
@@ -2224,6 +2230,143 @@
 	Mat3One(td->smtx);
 }
 
+static void calcUVIslands(int *totisland, int **island_index, float **island_boundbox, float **island_center)
+{
+	EditMesh *em = G.editMesh;
+	EditFace *efa;
+
+	int change, a, i, nverts;
+	
+	UvVertMap *vmap=NULL;
+	UvMapVert *vlist, *iterv, *startv;
+	float limit[2];
+	int totface = G.totface; /* I dont like this. but EM_init_index_arrays uses it - Campbell */
+	
+	int		*faceIsleIndex = NULL; /* face verts island index */
+	float	*uvIsleBounds = NULL;
+	float	*uvIsleCenters = NULL;
+	
+	get_connected_limit_tface_uv(limit);
+	vmap= make_uv_vert_map_EM(1, 1, limit);
+	
+	
+	faceIsleIndex = MEM_callocN(totface*sizeof(int), "uvisland");
+
+	for (a=0; a<totface; a++) {
+		faceIsleIndex[a] = a;
+	}
+	
+	change = 1;
+	while(change) {
+		change = 0;
+
+		for (a=0, efa= em->faces.first; efa; a++, efa= efa->next) {
+			nverts= efa->v4 ? 4:3;
+			for(i=0; i<nverts; i++) {		
+				vlist= get_uv_map_vert_EM(vmap, (*(&efa->v1 + i))->tmp.l);
+				startv = vlist;
+				
+				/* get the startv for this face */
+				for(iterv=vlist; iterv; iterv=iterv->next) {
+					if(iterv->separate)
+						startv= iterv;
+					if(iterv->f == a) /* 'a' is the current efa index */
+						break;
+				}
+				
+				/* set the index of all connecting faces to the lowest, and set the change value so we keep looping */
+				for(iterv=startv; iterv; iterv=iterv->next) {
+					if((startv != iterv) && (iterv->separate)) {
+						break;
+					} else {
+						if (faceIsleIndex[iterv->f] != faceIsleIndex[a]) {
+							change = 1;
+							faceIsleIndex[iterv->f] = faceIsleIndex[a] = MIN2(faceIsleIndex[iterv->f], faceIsleIndex[a]);
+						}
+					}
+				}
+			}
+		}
+	}
+	
+	free_uv_vert_map_EM(vmap);
+	vmap = NULL;
+	
+	{
+		char	*uvIsleTag; /* temporary tagging of islands */
+		uvIsleTag = MEM_callocN(totface * sizeof(char), "uvisland char");
+	
+		for (a=0; a<totface; a++) {
+			uvIsleTag[ faceIsleIndex[a] ] = 1;
+		}
+		*totisland = 0;
+
+		for (a=0; a<totface; a++) {
+			if (uvIsleTag[ a ]) {
+				/*  push back the indicies so they point to an array the size of totisland, rather then totfaces */
+				if (faceIsleIndex[a] != *totisland) { /* its possible these indicies match though not likely */
+					int old_index = faceIsleIndex[a];
+
+					for (i=0; i<totface; i++) {
+						if (old_index == faceIsleIndex[i]) {
+							faceIsleIndex[i] = *totisland;
+						}
+					}
+				}
+				(*totisland)++;
+			}		
+		}
+		MEM_freeN(uvIsleTag);
+	}
+	
+	uvIsleBounds = MEM_callocN((*totisland) * sizeof(float) * 4, "uvisland cent"); /* this is inefficient since there may only be 1 island */
+
+	/* initialize bounds */
+	for (i=0; i<(*totisland); i++) {
+		uvIsleBounds[(i*4)] =	MAXFLOAT;
+		uvIsleBounds[(i*4)+1] =-MAXFLOAT;
+	
+		uvIsleBounds[(i*4)+2] =	MAXFLOAT;
+		uvIsleBounds[(i*4)+3] =-MAXFLOAT;
+	}
+	
+	
+	for (efa= em->faces.first, a=0; efa; efa= efa->next, a++) {
+		MTFace *tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+		if (simaFaceDraw_Check(efa, tf)) {
+			efa->tmp.p = tf;
+		} else {
+			efa->tmp.p = NULL;
+		}
+	
+		i = faceIsleIndex[a]; /* the faces island index */
+		if (efa->v4) {
+			uvIsleBounds[(i*4)] =	MIN2(uvIsleBounds[(i*4)],	MIN4(tf->uv[0][0], tf->uv[1][0], tf->uv[2][0], tf->uv[3][0]));
+			uvIsleBounds[(i*4)+1] =	MAX2(uvIsleBounds[(i*4)+1],  MAX4(tf->uv[0][0], tf->uv[1][0], tf->uv[2][0], tf->uv[3][0]));
+		
+			uvIsleBounds[(i*4)+2] =	MIN2(uvIsleBounds[(i*4)+2],  MIN4(tf->uv[0][1], tf->uv[1][1], tf->uv[2][1], tf->uv[3][1]));
+			uvIsleBounds[(i*4)+3] =	MAX2(uvIsleBounds[(i*4)+3],  MAX4(tf->uv[0][1], tf->uv[1][1], tf->uv[2][1], tf->uv[3][1]));
+		} else {
+			uvIsleBounds[(i*4)] =	MIN2(uvIsleBounds[(i*4)],	MIN3(tf->uv[0][0], tf->uv[1][0], tf->uv[2][0]));
+			uvIsleBounds[(i*4)+1] =	MAX2(uvIsleBounds[(i*4)+1],	MAX3(tf->uv[0][0], tf->uv[1][0], tf->uv[2][0]));
+		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list