[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12143] trunk/blender/source/blender: snap transform for UV editing, missing the draw circle at the moment.

Campbell Barton cbarton at metavr.com
Tue Sep 25 09:42:55 CEST 2007


Revision: 12143
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12143
Author:   campbellbarton
Date:     2007-09-25 09:42:55 +0200 (Tue, 25 Sep 2007)

Log Message:
-----------
snap transform for UV editing, missing the draw circle at the moment.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BIF_editsima.h
    trunk/blender/source/blender/src/editsima.c
    trunk/blender/source/blender/src/header_image.c
    trunk/blender/source/blender/src/space.c
    trunk/blender/source/blender/src/transform_snap.c

Modified: trunk/blender/source/blender/include/BIF_editsima.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editsima.h	2007-09-25 06:36:02 UTC (rev 12142)
+++ trunk/blender/source/blender/include/BIF_editsima.h	2007-09-25 07:42:55 UTC (rev 12143)
@@ -33,6 +33,8 @@
 struct Mesh;
 struct EditMesh;
 struct SpaceImage;
+struct EditFace;
+struct MTFace;
 
 /* id can be from 0 to 3 */
 #define TF_PIN_MASK(id) (TF_PIN1 << id)
@@ -117,4 +119,4 @@
 /* checks images for forced updates on frame change */
 void BIF_image_update_frame(void);
 
-
+void find_nearest_uv(struct MTFace **nearesttf, struct EditFace **nearestefa, unsigned int *nearestv, int *nearestuv);

Modified: trunk/blender/source/blender/src/editsima.c
===================================================================
--- trunk/blender/source/blender/src/editsima.c	2007-09-25 06:36:02 UTC (rev 12142)
+++ trunk/blender/source/blender/src/editsima.c	2007-09-25 07:42:55 UTC (rev 12143)
@@ -479,7 +479,7 @@
 	return (c1*c2 >= 0.0f);
 }
 
-static void find_nearest_uv(MTFace **nearesttf, EditFace **nearestefa, unsigned int *nearestv, int *nearestuv)
+void find_nearest_uv(MTFace **nearesttf, EditFace **nearestefa, unsigned int *nearestv, int *nearestuv)
 {
 	EditMesh *em= G.editMesh;
 	EditFace *efa;
@@ -490,9 +490,15 @@
 	getmouseco_areawin(mval);	
 
 	mindist= 0x7FFFFFF;
-	*nearesttf= NULL;
-	*nearestefa= NULL;
+	if (nearesttf) *nearesttf= NULL;
+	if (nearestefa) *nearestefa= NULL;
 	
+	if (nearestv) {
+		EditVert *ev;
+		for (i=0, ev=em->verts.first; ev; ev = ev->next, i++)
+			ev->tmp.l = i;
+	}
+	
 	for (efa= em->faces.first; efa; efa= efa->next) {
 		tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
 		if (SIMA_FACEDRAW_CHECK(efa, tf)) {
@@ -509,16 +515,17 @@
 						if (!nearest_uv_between(tf, nverts, i, mval, uval))
 							continue;
 
-					mindist= dist; 
-
-					*nearesttf= tf;
-					*nearestefa= efa;
+					mindist= dist;
 					*nearestuv= i;
-
-					if (i==0) *nearestv=  efa->v1->tmp.l;
-					else if (i==1) *nearestv=  efa->v2->tmp.l;
-					else if (i==2) *nearestv=  efa->v3->tmp.l;
-					else *nearestv=  efa->v4->tmp.l;
+					
+					if (nearesttf)		*nearesttf= tf;
+					if (nearestefa)		*nearestefa= efa;
+					if (nearestv) {
+						if (i==0) *nearestv=  efa->v1->tmp.l;
+						else if (i==1) *nearestv=  efa->v2->tmp.l;
+						else if (i==2) *nearestv=  efa->v3->tmp.l;
+						else *nearestv=  efa->v4->tmp.l;
+					}
 				}
 			}
 		}

Modified: trunk/blender/source/blender/src/header_image.c
===================================================================
--- trunk/blender/source/blender/src/header_image.c	2007-09-25 06:36:02 UTC (rev 12142)
+++ trunk/blender/source/blender/src/header_image.c	2007-09-25 07:42:55 UTC (rev 12143)
@@ -1187,6 +1187,23 @@
 		}
 		uiBlockEndAlign(block);
 		
+		/* Snap copied right out of view3d header */
+			uiBlockBeginAlign(block);
+
+			if (G.scene->snap_flag & SCE_SNAP) {
+				uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEO,xco,0,XIC,YIC, &G.scene->snap_flag, 0, 0, 0, 0, "Use Snap or Grid (Shift Tab)");	
+				xco+= XIC;
+				uiDefButS(block, MENU, B_NOP, "Mode%t|Closest%x0|Center%x1|Median%x2",xco,0,70,YIC, &G.scene->snap_target, 0, 0, 0, 0, "Snap Target Mode");
+				xco+= 70;
+			} else {
+				uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEAR,xco,0,XIC,YIC, &G.scene->snap_flag, 0, 0, 0, 0, "Snap while Ctrl is held during transform (Shift Tab)");	
+				xco+= XIC;
+			}
+
+			uiBlockEndAlign(block);
+			xco+= 10;
+		/* end snap */
+			
 		/* Layer Menu */
 		layercount = CustomData_number_of_layers(&G.editMesh->fdata, CD_MTFACE); 
 		if (layercount>1 && layercount < 12) { /* could allow any number but limit of 11 means no malloc needed */

Modified: trunk/blender/source/blender/src/space.c
===================================================================
--- trunk/blender/source/blender/src/space.c	2007-09-25 06:36:02 UTC (rev 12142)
+++ trunk/blender/source/blender/src/space.c	2007-09-25 07:42:55 UTC (rev 12143)
@@ -4954,6 +4954,12 @@
 					G.sima->flag ^= SI_LOCAL_UV;
 				scrarea_queue_winredraw(curarea);
 				break;
+			case TABKEY:
+				if (G.qual == LR_SHIFTKEY) {
+					G.scene->snap_flag ^= SCE_SNAP;
+					allqueue(REDRAWHEADERS, 0);
+				}
+				break;
 			}
 		}
 	} else {

Modified: trunk/blender/source/blender/src/transform_snap.c
===================================================================
--- trunk/blender/source/blender/src/transform_snap.c	2007-09-25 06:36:02 UTC (rev 12142)
+++ trunk/blender/source/blender/src/transform_snap.c	2007-09-25 07:42:55 UTC (rev 12143)
@@ -56,6 +56,8 @@
 #include "BIF_mywindow.h"
 #include "BIF_resources.h"
 #include "BIF_screen.h"
+#include "BIF_editsima.h"
+#include "BIF_drawimage.h"
 
 #include "BKE_global.h"
 #include "BKE_utildefines.h"
@@ -96,32 +98,69 @@
 {
 	if ((t->tsnap.status & (SNAP_ON|POINT_INIT|TARGET_INIT)) == (SNAP_ON|POINT_INIT|TARGET_INIT) &&
 		(G.qual & LR_CTRLKEY)) {
-		float unitmat[4][4];
-		float size;
+		
 		char col[4];
-		
-		glDisable(GL_DEPTH_TEST);
-
-		size = get_drawsize(G.vd);
-		
-		size *= 0.5f * BIF_GetThemeValuef(TH_VERTEX_SIZE);
-		
 		BIF_GetThemeColor3ubv(TH_TRANSFORM, col);
 		glColor4ub(col[0], col[1], col[2], 128);
 		
-		glPushMatrix();
-		
-		glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
-		
-		/* sets view screen aligned */
-		glRotatef( -360.0f*saacos(G.vd->viewquat[0])/(float)M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]);
-		
-		Mat4One(unitmat);
-		drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat);
-		
-		glPopMatrix();
-		
-		if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);		
+		if (t->spacetype==SPACE_VIEW3D) {
+			float unitmat[4][4];
+			float size;
+			
+			glDisable(GL_DEPTH_TEST);
+	
+			size = get_drawsize(G.vd);
+			
+			size *= 0.5f * BIF_GetThemeValuef(TH_VERTEX_SIZE);
+			
+			glPushMatrix();
+			
+			glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
+			
+			/* sets view screen aligned */
+			glRotatef( -360.0f*saacos(G.vd->viewquat[0])/(float)M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]);
+			
+			Mat4One(unitmat);
+			drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat);
+			
+			glPopMatrix();
+			
+			if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);
+		} else if (t->spacetype==SPACE_IMAGE) {
+			/*This will not draw, and Im nor sure why - campbell */
+			
+			/*			
+			float xuser_asp, yuser_asp;
+			int wi, hi;
+			float w, h;
+			
+			calc_image_view(G.sima, 'f');	// float
+			myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
+			glLoadIdentity();
+			
+			aspect_sima(G.sima, &xuser_asp, &yuser_asp);
+			
+			transform_width_height_tface_uv(&wi, &hi);
+			w = (((float)wi)/256.0f)*G.sima->zoom * xuser_asp;
+			h = (((float)hi)/256.0f)*G.sima->zoom * yuser_asp;
+			
+			cpack(0xFFFFFF);
+			glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], 0.0f);
+			
+			//glRectf(0,0,1,1);
+			
+			setlinestyle(0);
+			cpack(0x0);
+			fdrawline(-0.020/w, 0, -0.1/w, 0);
+			fdrawline(0.1/w, 0, .020/w, 0);
+			fdrawline(0, -0.020/h, 0, -0.1/h);
+			fdrawline(0, 0.1/h, 0, 0.020/h);
+			
+			glTranslatef(-t->tsnap.snapPoint[0], -t->tsnap.snapPoint[1], 0.0f);
+			setlinestyle(0);
+			*/
+			
+		}
 	}
 }
 
@@ -169,7 +208,7 @@
 {
 	resetSnapping(t);
 	
-	if (t->spacetype == SPACE_VIEW3D) { // Only 3D view (not UV)
+	if (t->spacetype == SPACE_VIEW3D || t->spacetype == SPACE_IMAGE) { // Only 3D view or UV
 		setSnappingCallback(t);
 
 		if (t->tsnap.applySnap != NULL && // A snapping function actually exist
@@ -328,6 +367,8 @@
 	if (G.obedit != NULL && G.obedit->type==OB_MESH)
 	{
 		/*if (G.scene->selectmode & B_SEL_VERT)*/
+		
+		if (t->spacetype == SPACE_VIEW3D)
 		{
 			EditVert *nearest=NULL;
 			float vec[3];
@@ -358,6 +399,36 @@
 				t->tsnap.status &= ~POINT_INIT;
 			}
 		}
+		else if (t->spacetype == SPACE_IMAGE)
+		{
+			
+			MTFace *nearesttf=NULL;
+			unsigned int face_corner;
+			
+			float vec[3];
+			int found = 0;
+			int dist = 40; // Use a user defined value here
+			
+			// use findnearestverts in vert mode, others in other modes
+			//nearest = findnearestvert(&dist, SELECT, 1);
+			find_nearest_uv(&nearesttf, NULL, NULL, &face_corner);
+			
+			if (nearesttf != NULL)
+			{
+				VECCOPY2D(t->tsnap.snapPoint, nearesttf->uv[face_corner]);
+				//Mat4MulVecfl(G.obedit->obmat, t->tsnap.snapPoint);
+				
+				t->tsnap.status |=  POINT_INIT;
+			}
+			else
+			{
+				t->tsnap.status &= ~POINT_INIT;
+			}
+			
+			
+		}
+		
+		
 		/*
 		if (G.scene->selectmode & B_SEL_EDGE)
 		{





More information about the Bf-blender-cvs mailing list