snap transform for UV editing, missing the draw circle at the moment.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 25 Sep 2007 07:42:55 +0000 (07:42 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 25 Sep 2007 07:42:55 +0000 (07:42 +0000)
source/blender/include/BIF_editsima.h
source/blender/src/editsima.c
source/blender/src/header_image.c
source/blender/src/space.c
source/blender/src/transform_snap.c

index ec42f7d6a2a19d135ef531c84ec0c18e84ff5e17..b85749f9f95524554ccd23e278119fae53f65135 100644 (file)
@@ -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 @@ void pack_image_sima(void);
 /* 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);
index 91220be60093ba28fa4c74e4a1917ca23ce3d8b4..1b1c4c251d2304d4cc8e7a9dff01ecd30c31672b 100644 (file)
@@ -479,7 +479,7 @@ static int nearest_uv_between(MTFace *tf, int nverts, int id, short *mval, int *
        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,8 +490,14 @@ static void find_nearest_uv(MTFace **nearesttf, EditFace **nearestefa, unsigned
        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);
@@ -509,16 +515,17 @@ static void find_nearest_uv(MTFace **nearesttf, EditFace **nearestefa, unsigned
                                                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;
+                                       }
                                }
                        }
                }
index 3ee30991639be5385ecf2a54782f01b94e89b1ca..a44a9ecb2cfca1d25180b00ef38c6034de74bccd 100644 (file)
@@ -1187,6 +1187,23 @@ void image_buttons(void)
                }
                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 */
index 82807c0382fe43675e983db12d53239511059320..8563a0f634fdd37994c0507a991ae42de6c16a05 100644 (file)
@@ -4954,6 +4954,12 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        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 {
index ce3212c63fa7982fa28700bacdb5ea97cb06b486..3b632e8c4676bca1b23c44df8d529b2ff625d0de 100644 (file)
@@ -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 @@ void drawSnapping(TransInfo *t)
 {
        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);
                
+               char col[4];
                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 @@ void initSnapping(TransInfo *t)
 {
        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 @@ void CalcSnapGeometry(TransInfo *t, float *vec)
        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 @@ void CalcSnapGeometry(TransInfo *t, float *vec)
                                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)
                {