[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14071] trunk/blender/source/blender:

Brecht Van Lommel brechtvanlommel at pandora.be
Wed Mar 12 20:55:48 CET 2008


Revision: 14071
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14071
Author:   blendix
Date:     2008-03-12 20:55:37 +0100 (Wed, 12 Mar 2008)

Log Message:
-----------

Added two UV features (Apricot request):

- Alt+click edge loop select.
- Next to Align X/Y, Align Auto which will pick X or Y automatically,
  should give the expected result for nearly all cases.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_mesh.h
    trunk/blender/source/blender/blenkernel/intern/mesh.c
    trunk/blender/source/blender/include/BIF_editsima.h
    trunk/blender/source/blender/src/editmesh_lib.c
    trunk/blender/source/blender/src/editsima.c
    trunk/blender/source/blender/src/header_image.c

Modified: trunk/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mesh.h	2008-03-12 16:53:11 UTC (rev 14070)
+++ trunk/blender/source/blender/blenkernel/BKE_mesh.h	2008-03-12 19:55:37 UTC (rev 14071)
@@ -106,7 +106,7 @@
 typedef struct UvMapVert {
 	struct UvMapVert *next;
 	unsigned int f;
-	unsigned char tfindex, separate;
+	unsigned char tfindex, separate, flag;
 } UvMapVert;
 
 UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned int totface, unsigned int totvert, int selected, float *limit);

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c	2008-03-12 16:53:11 UTC (rev 14070)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c	2008-03-12 19:55:37 UTC (rev 14071)
@@ -1141,12 +1141,12 @@
 	if(totuv==0)
 		return NULL;
 	
-	vmap= (UvVertMap*)MEM_mallocN(sizeof(*vmap), "UvVertMap");
+	vmap= (UvVertMap*)MEM_callocN(sizeof(*vmap), "UvVertMap");
 	if (!vmap)
 		return NULL;
 
 	vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totvert, "UvMapVert*");
-	buf= vmap->buf= (UvMapVert*)MEM_mallocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
+	buf= vmap->buf= (UvMapVert*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
 
 	if (!vmap->vert || !vmap->buf) {
 		free_uv_vert_map(vmap);

Modified: trunk/blender/source/blender/include/BIF_editsima.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editsima.h	2008-03-12 16:53:11 UTC (rev 14070)
+++ trunk/blender/source/blender/include/BIF_editsima.h	2008-03-12 19:55:37 UTC (rev 14071)
@@ -77,6 +77,7 @@
 void weld_align_tface_uv(char tool);
 void be_square_tface_uv(struct EditMesh *em);
 void select_pinned_tface_uv(void);
+void select_edgeloop_tface_uv(struct EditFace *efa, int a, int shift, int *flush);
 
 void sima_sample_color(void);
 

Modified: trunk/blender/source/blender/src/editmesh_lib.c
===================================================================
--- trunk/blender/source/blender/src/editmesh_lib.c	2008-03-12 16:53:11 UTC (rev 14070)
+++ trunk/blender/source/blender/src/editmesh_lib.c	2008-03-12 19:55:37 UTC (rev 14071)
@@ -2143,12 +2143,12 @@
 	if(totuv==0)
 		return NULL;
 	
-	vmap= (UvVertMap*)MEM_mallocN(sizeof(*vmap), "UvVertMap");
+	vmap= (UvVertMap*)MEM_callocN(sizeof(*vmap), "UvVertMap");
 	if (!vmap)
 		return NULL;
 
 	vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totverts, "UvMapVert*");
-	buf= vmap->buf= (UvMapVert*)MEM_mallocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
+	buf= vmap->buf= (UvMapVert*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
 
 	if (!vmap->vert || !vmap->buf) {
 		free_uv_vert_map(vmap);

Modified: trunk/blender/source/blender/src/editsima.c
===================================================================
--- trunk/blender/source/blender/src/editsima.c	2008-03-12 16:53:11 UTC (rev 14070)
+++ trunk/blender/source/blender/src/editsima.c	2008-03-12 19:55:37 UTC (rev 14071)
@@ -272,9 +272,30 @@
 	EditMesh *em = G.editMesh;
 	EditFace *efa;
 	MTFace *tface;
-	float cent[2];
+	float cent[2], min[2], max[2];
 	
 	if( is_uv_tface_editing_allowed()==0 ) return;
+
+	INIT_MINMAX2(min, max);
+
+	if(tool == 'a') {
+		for (efa= em->faces.first; efa; efa= efa->next) {
+			tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+			if (simaFaceDraw_Check(efa, tface)) {
+				if (simaUVSel_Check(efa, tface, 0))
+					DO_MINMAX2(tface->uv[0], min, max)
+				if (simaUVSel_Check(efa, tface, 1))
+					DO_MINMAX2(tface->uv[1], min, max)
+				if (simaUVSel_Check(efa, tface, 2))
+					DO_MINMAX2(tface->uv[2], min, max)
+				if (efa->v4 && simaUVSel_Check(efa, tface, 3))
+					DO_MINMAX2(tface->uv[3], min, max)
+			}
+		}
+
+		tool= (max[0]-min[0] >= max[1]-min[1])? 'y': 'x';
+	}
+
 	cent_tface_uv(cent, 0);
 
 	if(tool == 'x' || tool == 'w') {
@@ -403,15 +424,16 @@
 
 	if( is_uv_tface_editing_allowed()==0 ) return;
 
-	mode= pupmenu("Weld/Align%t|Weld%x1|Align X%x2|Align Y%x3");
+	mode= pupmenu("Weld/Align%t|Weld%x1|Align Auto%x2|Align X%x3|Align Y%x4");
 
 	if(mode==-1) return;
 	if(mode==1) weld_align_tface_uv('w');
-	else if(mode==2) weld_align_tface_uv('x');
-	else if(mode==3) weld_align_tface_uv('y');
+	else if(mode==2) weld_align_tface_uv('a');
+	else if(mode==3) weld_align_tface_uv('x');
+	else if(mode==4) weld_align_tface_uv('y');
 
 	if(mode==1) BIF_undo_push("Weld UV");
-	else if(mode==2 || mode==3) BIF_undo_push("Align UV");
+	else if(ELEM3(mode, 2, 3, 4)) BIF_undo_push("Align UV");
 }
 
 void select_invert_tface_uv(void)
@@ -502,6 +524,49 @@
 	return 0;
 }
 
+static void find_nearest_uv_edge(MTFace **nearesttf, EditFace **nearestefa, int *nearestedge)
+{
+	EditMesh *em= G.editMesh;
+	MTFace *tf;
+	EditFace *efa;
+	float mvalf[2], v1[2], v2[2];
+	int i, nverts, mindist, dist, uval1[2], uval2[2];
+	short mval[2];
+
+	getmouseco_areawin(mval);
+	mvalf[0]= mval[0];
+	mvalf[1]= mval[1];
+
+	mindist= 0x7FFFFFF;
+	*nearesttf= NULL;
+	*nearestefa= NULL;
+	*nearestedge= 0;
+	
+	for (efa= em->faces.first; efa; efa= efa->next) {
+		tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+		if(simaFaceDraw_Check(efa, tf)) {
+			nverts= efa->v4? 4: 3;
+			for(i=0; i<nverts; i++) {
+				uvco_to_areaco_noclip(tf->uv[i], uval1);
+				uvco_to_areaco_noclip(tf->uv[(i+1)%nverts], uval2);
+
+				v1[0]= uval1[0];
+				v1[1]= uval1[1];
+				v2[0]= uval2[0];
+				v2[1]= uval2[1];
+
+				dist= PdistVL2Dfl(mvalf, v1, v2);
+				if (dist < mindist) {
+					*nearesttf= tf;
+					*nearestefa= efa;
+					*nearestedge= i;
+					mindist= dist;
+				}
+			}
+		}
+	}
+}
+
 static void find_nearest_tface(MTFace **nearesttf, EditFace **nearestefa)
 {
 	EditMesh *em= G.editMesh;
@@ -626,9 +691,9 @@
 	EditFace *efa;
 	MTFace *tf, *nearesttf;
 	EditFace *nearestefa=NULL;
-	int a, selectsticky, actface, nearestuv, i;
+	int a, selectsticky, edgeloop, actface, nearestuv, nearestedge, i, shift;
 	char sticky= 0;
-	short flush = 0; /* 0 == dont flush, 1 == sel, -1 == desel;  only use when selection sync is enabled */
+	int flush = 0; /* 0 == dont flush, 1 == sel, -1 == desel;  only use when selection sync is enabled */
 	unsigned int hitv[4], nearestv;
 	float *hituv[4], limit[2];
 	
@@ -636,18 +701,21 @@
 
 	get_connected_limit_tface_uv(limit);
 	
+	edgeloop= G.qual & LR_ALTKEY;
+	shift= G.qual & LR_SHIFTKEY;
+
 	if (G.sima->flag & SI_SYNC_UVSEL) {
 		/* copy from mesh */
 		if (G.scene->selectmode == SCE_SELECT_FACE) {
 			actface= 1;
 			sticky= 0;
 		} else {
-			actface= (G.qual & LR_ALTKEY || G.sima->flag & SI_SELACTFACE);
+			actface= G.sima->flag & SI_SELACTFACE;
 			sticky= 2;
 		}
 	} else {
 		/* normal operation */
-		actface= (G.qual & LR_ALTKEY || G.sima->flag & SI_SELACTFACE);
+		actface= G.sima->flag & SI_SELACTFACE;
 		
 		switch(G.sima->sticky) {
 		case SI_STICKY_LOC:
@@ -666,7 +734,14 @@
 		}
 	}
 
-	if(actface) {
+	if(edgeloop) {
+		find_nearest_uv_edge(&nearesttf, &nearestefa, &nearestedge);
+		if(nearesttf==NULL)
+			return;
+
+		select_edgeloop_tface_uv(nearestefa, nearestedge, shift, &flush);
+	}
+	else if(actface) {
 		find_nearest_tface(&nearesttf, &nearestefa);
 		if(nearesttf==NULL)
 			return;
@@ -696,7 +771,7 @@
 		}
 	}
 
-	if(G.qual & LR_SHIFTKEY) {
+	if(!edgeloop && shift) {
 		/* (de)select face */
 		if(actface) {
 			if(simaFaceSel_Check(nearestefa, nearesttf)) {
@@ -772,7 +847,7 @@
 			}			
 		}
 	}
-	else {
+	else if(!edgeloop) {
 		/* select face and deselect other faces */ 
 		if(actface) {
 			for (efa= em->faces.first; efa; efa= efa->next) {
@@ -1782,6 +1857,208 @@
 	scrarea_queue_winredraw(curarea);
 }
 
+/* UV edge loop select, follows same rules as editmesh */
+
+static void uv_vertex_loop_flag(UvMapVert *first)
+{
+	UvMapVert *iterv;
+	int count= 0;
+
+	for(iterv=first; iterv; iterv=iterv->next) {
+		if(iterv->separate && iterv!=first)
+			break;
+
+		count++;
+	}
+	
+	if(count < 5)
+		first->flag= 1;
+}
+
+static UvMapVert *uv_vertex_map_get(UvVertMap *vmap, EditFace *efa, int a)
+{
+	UvMapVert *iterv, *first;
+	
+	first= get_uv_map_vert_EM(vmap, (*(&efa->v1 + a))->tmp.l);
+
+	for(iterv=first; iterv; iterv=iterv->next) {
+		if(iterv->separate)
+			first= iterv;
+		if(iterv->f == efa->tmp.l)
+			return first;
+	}
+	
+	return NULL;
+}
+
+static int uv_edge_tag_faces(UvMapVert *first1, UvMapVert *first2, int *totface)
+{
+	UvMapVert *iterv1, *iterv2;
+	EditFace *efa;
+	int tot = 0;
+
+	/* count number of faces this edge has */
+	for(iterv1=first1; iterv1; iterv1=iterv1->next) {
+		if(iterv1->separate && iterv1 != first1)
+			break;
+
+		for(iterv2=first2; iterv2; iterv2=iterv2->next) {
+			if(iterv2->separate && iterv2 != first2)
+				break;
+
+			if(iterv1->f == iterv2->f) {
+				/* if face already tagged, don't do this edge */
+				efa= EM_get_face_for_index(iterv1->f);
+				if(efa->f1)
+					return 0;
+
+				tot++;
+				break;
+			}
+		}
+	}
+
+	if(*totface == 0) /* start edge */
+		*totface= tot;
+	else if(tot != *totface) /* check for same number of faces as start edge */
+		return 0;
+
+	/* tag the faces */
+	for(iterv1=first1; iterv1; iterv1=iterv1->next) {
+		if(iterv1->separate && iterv1 != first1)
+			break;
+
+		for(iterv2=first2; iterv2; iterv2=iterv2->next) {
+			if(iterv2->separate && iterv2 != first2)
+				break;
+
+			if(iterv1->f == iterv2->f) {
+				efa= EM_get_face_for_index(iterv1->f);
+				efa->f1= 1;
+				break;
+			}
+		}
+	}
+
+	return 1;
+}
+
+void select_edgeloop_tface_uv(EditFace *startefa, int starta, int shift, int *flush)
+{
+	EditMesh *em= G.editMesh;
+	EditVert *eve;
+	EditFace *efa;
+	MTFace *tface;
+	UvVertMap *vmap;
+	UvMapVert *iterv1, *iterv2;
+	float limit[2];
+	int a, count, looking, nverts, starttotface, select;
+	
+	if( is_uv_tface_editing_allowed()==0 ) return;
+
+	/* setup */
+	EM_init_index_arrays(0, 0, 1);
+
+	get_connected_limit_tface_uv(limit);
+	vmap= make_uv_vert_map_EM(0, 0, limit);
+
+	for(count=0, eve=em->verts.first; eve; count++, eve= eve->next)
+		eve->tmp.l = count;
+
+	for(count=0, efa= em->faces.first; efa; count++, efa= efa->next) {
+		if(!shift) {
+			tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+			simaFaceSel_UnSet(efa, tface);
+		}
+
+		efa->tmp.l= count;
+		efa->f1= 0;
+	}
+	
+	/* set flags for first face and verts */
+	nverts= (startefa->v4)? 4: 3;
+	iterv1= uv_vertex_map_get(vmap, startefa, starta);
+	iterv2= uv_vertex_map_get(vmap, startefa, (starta+1)%nverts);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list