[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14307] trunk/blender/source/blender: added a sloppy option for getting the active face, which returns the last selected if none is active, made the uv calculation aspect correction use the active faces image rather then the last used image viewports .

Campbell Barton ideasman42 at gmail.com
Tue Apr 1 15:35:52 CEST 2008


Revision: 14307
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14307
Author:   campbellbarton
Date:     2008-04-01 15:35:52 +0200 (Tue, 01 Apr 2008)

Log Message:
-----------
added a sloppy option for getting the active face, which returns the last selected if none is active, made the uv calculation aspect correction use the active faces image rather then the last used image viewports.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BDR_editface.h
    trunk/blender/source/blender/include/BIF_editmesh.h
    trunk/blender/source/blender/include/BIF_editsima.h
    trunk/blender/source/blender/src/drawimage.c
    trunk/blender/source/blender/src/drawobject.c
    trunk/blender/source/blender/src/editface.c
    trunk/blender/source/blender/src/editmesh.c
    trunk/blender/source/blender/src/editmesh_lib.c
    trunk/blender/source/blender/src/editmesh_mods.c
    trunk/blender/source/blender/src/editsima.c
    trunk/blender/source/blender/src/unwrapper.c

Modified: trunk/blender/source/blender/include/BDR_editface.h
===================================================================
--- trunk/blender/source/blender/include/BDR_editface.h	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/include/BDR_editface.h	2008-04-01 13:35:52 UTC (rev 14307)
@@ -38,7 +38,7 @@
 struct Mesh;
 struct MCol;
 
-struct MTFace *get_active_mtface(struct EditFace **efa, struct MCol **mcol, short sloppy);
+struct MTFace *get_active_mtface(struct EditFace **efa, struct MCol **mcol, int sloppy);
 void calculate_uv_map(unsigned short mapmode);
 void default_uv(float uv[][2], float size);
 void make_tfaces(struct Mesh *me);

Modified: trunk/blender/source/blender/include/BIF_editmesh.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editmesh.h	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/include/BIF_editmesh.h	2008-04-01 13:35:52 UTC (rev 14307)
@@ -262,6 +262,6 @@
 int EM_vertColorCheck(void); /* can we edit colors for this mesh?*/
 
 void EM_set_actFace(struct EditFace *efa);
-struct EditFace * EM_get_actFace(void);
+struct EditFace * EM_get_actFace(int sloppy);
 
 #endif

Modified: trunk/blender/source/blender/include/BIF_editsima.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editsima.h	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/include/BIF_editsima.h	2008-04-01 13:35:52 UTC (rev 14307)
@@ -63,8 +63,10 @@
 void mouseco_to_curtile(void);
 void mouse_select_sima(void);
 void snap_menu_sima(void);
-void aspect_sima(struct SpaceImage *sima, float *x, float *y);
+void image_pixel_aspect(struct Image *image, float *x, float *y);
+void image_final_aspect(struct Image *image, float *x, float *y);
 
+
 void select_invert_tface_uv(void);
 void select_swap_tface_uv(void);
 void mirrormenu_tface_uv(void);

Modified: trunk/blender/source/blender/src/drawimage.c
===================================================================
--- trunk/blender/source/blender/src/drawimage.c	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/src/drawimage.c	2008-04-01 13:35:52 UTC (rev 14307)
@@ -194,7 +194,7 @@
 		ImBuf *ibuf= imagewindow_get_ibuf(sima);
 		float xuser_asp, yuser_asp;
 		
-		aspect_sima(sima, &xuser_asp, &yuser_asp);
+		image_pixel_aspect(sima->image, &xuser_asp, &yuser_asp);
 		if(ibuf) {
 			xim= ibuf->x * xuser_asp;
 			yim= ibuf->y * yuser_asp;
@@ -2045,7 +2045,7 @@
 	unsigned int *rect;
 	float x1, y1;
 	short sx, sy, dx, dy, show_render= 0, show_viewer= 0;
-	float xuser_asp, yuser_asp;
+	float xuser_asp=1, yuser_asp=1;
 		/* If derived data is used then make sure that object
 		 * is up-to-date... might not be the case because updates
 		 * are normally done in drawview and could get here before
@@ -2070,9 +2070,8 @@
 	
 	what_image(sima);
 	
-	aspect_sima(sima, &xuser_asp, &yuser_asp);
-	
 	if(sima->image) {
+		image_pixel_aspect(sima->image, &xuser_asp, &yuser_asp);
 		
 		/* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */
 		if(sima->image->type==IMA_TYPE_COMPOSITE) {

Modified: trunk/blender/source/blender/src/drawobject.c
===================================================================
--- trunk/blender/source/blender/src/drawobject.c	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/src/drawobject.c	2008-04-01 13:35:52 UTC (rev 14307)
@@ -2061,7 +2061,7 @@
 static void draw_em_fancy(Object *ob, EditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, int dt)
 {
 	Mesh *me = ob->data;
-	EditFace *efa_act = EM_get_actFace(); /* annoying but active faces is stored differently */
+	EditFace *efa_act = EM_get_actFace(0); /* annoying but active faces is stored differently */
 	EditEdge *eed_act = NULL;
 	EditVert *eve_act = NULL;
 	

Modified: trunk/blender/source/blender/src/editface.c
===================================================================
--- trunk/blender/source/blender/src/editface.c	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/src/editface.c	2008-04-01 13:35:52 UTC (rev 14307)
@@ -341,14 +341,19 @@
 
 void correct_uv_aspect( void )
 {
-	float aspx, aspy;
+	float aspx=1, aspy=1;
+	EditMesh *em = G.editMesh;
+	EditFace *efa = EM_get_actFace(1);
+	MTFace *tface;
 	
-	transform_aspect_ratio_tface_uv(&aspx, &aspy);
+	if (efa) {
+		tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+		image_final_aspect(tface->tpage, &aspx, &aspy);
+	}
 	
 	if (aspx != aspy) {
-		MTFace *tface;
+		
 		EditMesh *em = G.editMesh;
-		EditFace *efa;
 		float scale;
 		
 		if (aspx > aspy) {
@@ -569,6 +574,8 @@
 		break;
 		}
 	default:
+		if ((G.scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT)==0)
+			correct_uv_aspect();
 		return;
 	} /* end switch mapmode */
 
@@ -615,38 +622,16 @@
 
 /* last_sel, use em->act_face otherwise get the last selected face in the editselections
  * at the moment, last_sel is mainly useful for gaking sure the space image dosnt flicker */
-MTFace *get_active_mtface(EditFace **act_efa, MCol **mcol, short sloppy)
+MTFace *get_active_mtface(EditFace **act_efa, MCol **mcol, int sloppy)
 {
 	EditMesh *em = G.editMesh;
 	EditFace *efa = NULL;
-	EditSelection *ese;
 	
 	if(!EM_texFaceCheck())
 		return NULL;
 	
-	if (sloppy)
-		efa = EM_get_actFace();
+	efa = EM_get_actFace(sloppy);
 	
-	/* first check the active face */
-	if ((sloppy && efa)==0) {
-		ese = em->selected.last;
-		for (; ese; ese=ese->prev){
-			if(ese->type == EDITFACE) {
-				efa = (EditFace *)ese->data;
-				
-				if (efa->h)	efa= NULL;
-				else		break;
-			}
-		}
-	}
-	
-	if (sloppy && !efa) {
-		for (efa= em->faces.first; efa; efa= efa->next) {
-			if (efa->f & SELECT)
-				break;
-		}
-	}
-	
 	if (efa) {
 		if (mcol) {
 			if (CustomData_has_layer(&em->fdata, CD_MCOL))

Modified: trunk/blender/source/blender/src/editmesh.c
===================================================================
--- trunk/blender/source/blender/src/editmesh.c	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/src/editmesh.c	2008-04-01 13:35:52 UTC (rev 14307)
@@ -1023,7 +1023,7 @@
 	MFace *mface;
 	MSelect *mselect;
 	EditVert *eve;
-	EditFace *efa;
+	EditFace *efa, *efa_act;
 	EditEdge *eed;
 	EditSelection *ese;
 	float *fp, *newkey, *oldkey, nor[3];
@@ -1238,6 +1238,7 @@
 	/* the faces */
 	a = 0;
 	efa= em->faces.first;
+	efa_act= EM_get_actFace(0);
 	i = 0;
 	me->act_face = -1;
 	while(efa) {
@@ -1295,7 +1296,7 @@
 		/* no index '0' at location 3 or 4 */
 		test_index_face(mface, &me->fdata, i, efa->v4?4:3);
 		
-		if (EM_get_actFace() == efa)
+		if (efa_act == efa)
 			me->act_face = a;
 
 #ifdef WITH_VERSE

Modified: trunk/blender/source/blender/src/editmesh_lib.c
===================================================================
--- trunk/blender/source/blender/src/editmesh_lib.c	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/src/editmesh_lib.c	2008-04-01 13:35:52 UTC (rev 14307)
@@ -78,9 +78,32 @@
 	G.editMesh->act_face = efa;
 }
 
-EditFace * EM_get_actFace(void)
+EditFace * EM_get_actFace(int sloppy)
 {
-	return (G.editMesh->act_face && G.editMesh->act_face->f & SELECT) ? G.editMesh->act_face : NULL ;
+	if (G.editMesh->act_face && G.editMesh->act_face->f & SELECT) {
+		return G.editMesh->act_face;
+	} else if (sloppy) {
+		EditFace *efa= NULL;
+		EditSelection *ese;
+		
+		ese = G.editMesh->selected.last;
+		for (; ese; ese=ese->prev){
+			if(ese->type == EDITFACE) {
+				efa = (EditFace *)ese->data;
+				
+				if (efa->h)	efa= NULL;
+				else		break;
+			}
+		}
+		if (efa==NULL) {
+			for (efa= G.editMesh->faces.first; efa; efa= efa->next) {
+				if (efa->f & SELECT)
+					break;
+			}
+		}
+		return efa; /* can still be null */
+	}
+	return NULL;
 }
 
 /* ********* Selection History ************ */

Modified: trunk/blender/source/blender/src/editmesh_mods.c
===================================================================
--- trunk/blender/source/blender/src/editmesh_mods.c	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/src/editmesh_mods.c	2008-04-01 13:35:52 UTC (rev 14307)
@@ -1521,7 +1521,7 @@
 		MTFace *tf, *tf_act = NULL;
 		MCol *mcol, *mcol_act = NULL;
 		
-		efa_act = EM_get_actFace();
+		efa_act = EM_get_actFace(0);
 		
 		if (efa_act) {
 			ret= pupmenu(

Modified: trunk/blender/source/blender/src/editsima.c
===================================================================
--- trunk/blender/source/blender/src/editsima.c	2008-04-01 11:14:34 UTC (rev 14306)
+++ trunk/blender/source/blender/src/editsima.c	2008-04-01 13:35:52 UTC (rev 14307)
@@ -219,8 +219,8 @@
 	int w, h;
 	float xuser_asp, yuser_asp;
 
-	if(G.sima) {
-		aspect_sima(G.sima, &xuser_asp, &yuser_asp);
+	if(G.sima && G.sima->image) {
+		image_pixel_aspect(G.sima->image, &xuser_asp, &yuser_asp);
 		
 		transform_width_height_tface_uv(&w, &h);
 		*aspx= (float)w/256.0f * xuser_asp;
@@ -2712,23 +2712,44 @@
 	allqueue(REDRAWBUTSEDIT, 0);
 }
 
-void aspect_sima(SpaceImage *sima, float *x, float *y)
+void image_pixel_aspect(Image *image, float *x, float *y)
 {
 	*x = *y = 1.0;
 	
-	if(		(sima->image == 0) ||
-			(sima->image->type == IMA_TYPE_R_RESULT) ||
-			(sima->image->type == IMA_TYPE_COMPOSITE) ||
-			(sima->image->tpageflag & IMA_TILES) ||
-			(sima->image->aspx==0.0 || sima->image->aspy==0.0)
+	if(		(image == NULL) ||
+			(image->type == IMA_TYPE_R_RESULT) ||
+			(image->type == IMA_TYPE_COMPOSITE) ||
+			(image->tpageflag & IMA_TILES) ||
+			(image->aspx==0.0 || image->aspy==0.0)
 	) {
 		return;
 	}
 	
 	/* x is always 1 */
-	*y = sima->image->aspy / sima->image->aspx;
+	*y = image->aspy / image->aspx;
 }
 
+void image_final_aspect(Image *image, float *x, float *y)
+{
+	*x = *y = 1.0;
+	
+	if(		(image == NULL) ||
+			(image->type == IMA_TYPE_R_RESULT) ||
+			(image->type == IMA_TYPE_COMPOSITE) ||
+			(image->tpageflag & IMA_TILES) ||
+			(image->aspx==0.0 || image->aspy==0.0)
+	) {
+		return;
+	} else {
+		ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
+		if (ibuf && ibuf->x && ibuf->y)  {
+			*y = (image->aspy * ibuf->y) / (image->aspx * ibuf->x);
+		} else {
+			/* x is always 1 */
+			*y = image->aspy / image->aspx;
+		}
+	}
+}
 
 /* Face selection tests  - Keep these together */
 

Modified: trunk/blender/source/blender/src/unwrapper.c
===================================================================
--- trunk/blender/source/blender/src/unwrapper.c	2008-04-01 11:14:34 UTC (rev 14306)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list