Final fix fo revision 14827
authorMartin Poirier <theeth@yahoo.com>
Wed, 14 May 2008 12:24:38 +0000 (12:24 +0000)
committerMartin Poirier <theeth@yahoo.com>
Wed, 14 May 2008 12:24:38 +0000 (12:24 +0000)
Fixing UV Quad Constraint when cancelling transform. Also, transdata conversion is a bit faster for all UV transforms.

Patch by Cambo, reviewed and revised.

source/blender/src/transform_conversions.c

index e42eedee1f72a0446e1db82e128fd45a75a65802..963a1027f2815af67eb452144faee69a744d8dc0 100644 (file)
@@ -2217,9 +2217,9 @@ static void UVsToTransData(TransData *td, TransData2D *td2d, float *uv, int sele
                td->flag |= TD_SELECTED;
                td->dist= 0.0;
        }
-       else
+       else {
                td->dist= MAXFLOAT;
-       
+       }
        Mat3One(td->mtx);
        Mat3One(td->smtx);
 }
@@ -2231,25 +2231,57 @@ static void createTransUVs(TransInfo *t)
        MTFace *tf;
        int count=0, countsel=0;
        int propmode = t->flag & T_PROP_EDIT;
-       
+       int efa_s1,efa_s2,efa_s3,efa_s4;
+
        EditMesh *em = G.editMesh;
        EditFace *efa;
        
        if(is_uv_tface_editing_allowed()==0) return;
 
        /* count */
-       for (efa= em->faces.first; efa; efa= efa->next) {
-               tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-               if (simaFaceDraw_Check(efa, tf)) {
-                       if (simaUVSel_Check(efa, tf, 0)) countsel++; 
-                       if (simaUVSel_Check(efa, tf, 1)) countsel++; 
-                       if (simaUVSel_Check(efa, tf, 2)) countsel++; 
-                       if (efa->v4 && simaUVSel_Check(efa, tf, 3)) countsel++;
-                       if(propmode)
-                               count += (efa->v4)? 4: 3;
+       if (G.sima->flag & SI_BE_SQUARE && !propmode) {
+               for (efa= em->faces.first; efa; efa= efa->next) {
+                       /* store face pointer for second loop, prevent second lookup */
+                       tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+                       if (simaFaceDraw_Check(efa, tf)) {
+                               efa->tmp.p = tf;
+                               
+                               efa_s1 = simaUVSel_Check(efa, tf, 0);
+                               efa_s2 = simaUVSel_Check(efa, tf, 1);
+                               efa_s3 = simaUVSel_Check(efa, tf, 2);
+                               if (efa->v4) {
+                                       efa_s4 = simaUVSel_Check(efa, tf, 3);
+                                       if ( efa_s1 || efa_s2 || efa_s3 || efa_s4 ) {
+                                               countsel += 4; /* all corners of this quad need their edges moved. so we must store TD for each */
+                                       }
+                               } else {
+                                       /* tri's are delt with normally when SI_BE_SQUARE's enabled */
+                                       if (efa_s1) countsel++; 
+                                       if (efa_s2) countsel++; 
+                                       if (efa_s3) countsel++;
+                               }
+                       } else {
+                               efa->tmp.p = NULL;
+                       }
+               }
+       } else {
+               for (efa= em->faces.first; efa; efa= efa->next) {
+                       tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+                       if (simaFaceDraw_Check(efa, tf)) {
+                               efa->tmp.p = tf;
+                               
+                               if (simaUVSel_Check(efa, tf, 0)) countsel++; 
+                               if (simaUVSel_Check(efa, tf, 1)) countsel++; 
+                               if (simaUVSel_Check(efa, tf, 2)) countsel++; 
+                               if (efa->v4 && simaUVSel_Check(efa, tf, 3)) countsel++;
+                               if(propmode)
+                                       count += (efa->v4)? 4: 3;
+                       } else {
+                               efa->tmp.p = NULL;
+                       }
                }
        }
-
+       
        /* note: in prop mode we need at least 1 selected */
        if (countsel==0) return;
        
@@ -2264,21 +2296,66 @@ static void createTransUVs(TransInfo *t)
 
        td= t->data;
        td2d= t->data2d;
-       for (efa= em->faces.first; efa; efa= efa->next) {
-               tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-               if (simaFaceDraw_Check(efa, tf)) {
-                       if(propmode || simaUVSel_Check(efa, tf, 0))
-                               UVsToTransData(td++, td2d++, tf->uv[0], simaUVSel_Check(efa, tf, 0));
-                       if(propmode || simaUVSel_Check(efa, tf, 1))
-                               UVsToTransData(td++, td2d++, tf->uv[1], simaUVSel_Check(efa, tf, 1));
-                       if(propmode || simaUVSel_Check(efa, tf, 2))
-                               UVsToTransData(td++, td2d++, tf->uv[2], simaUVSel_Check(efa, tf, 2));
+       
+       if (G.sima->flag & SI_BE_SQUARE && !propmode) {
+               for (efa= em->faces.first; efa; efa= efa->next) {
+                       tf=(MTFace *)efa->tmp.p;
+                       if (tf) {
+                               efa_s1 = simaUVSel_Check(efa, tf, 0);
+                               efa_s2 = simaUVSel_Check(efa, tf, 1);
+                               efa_s3 = simaUVSel_Check(efa, tf, 2);
+                               
+                               if (efa->v4) {
+                                       efa_s4 = simaUVSel_Check(efa, tf, 3);
+                                       
+                                       if ( efa_s1 || efa_s2 || efa_s3 || efa_s4 ) {
+                                               /* all corners of this quad need their edges moved. so we must store TD for each */
+
+                                               UVsToTransData(td, td2d, tf->uv[0], efa_s1);
+                                               if (!efa_s1)    td->flag |= TD_SKIP;
+                                               td++; td2d++;
+
+                                               UVsToTransData(td, td2d, tf->uv[1], efa_s2);
+                                               if (!efa_s2)    td->flag |= TD_SKIP;
+                                               td++; td2d++;
 
-                       if(efa->v4 && (propmode || simaUVSel_Check(efa, tf, 3)))
-                               UVsToTransData(td++, td2d++, tf->uv[3], simaUVSel_Check(efa, tf, 3));
+                                               UVsToTransData(td, td2d, tf->uv[2], efa_s3);
+                                               if (!efa_s3)    td->flag |= TD_SKIP;
+                                               td++; td2d++;
+
+                                               UVsToTransData(td, td2d, tf->uv[3], efa_s4);
+                                               if (!efa_s4)    td->flag |= TD_SKIP;
+                                               td++; td2d++;
+                                       }
+                               } else {
+                                       /* tri's are delt with normally when SI_BE_SQUARE's enabled */
+                                       if (efa_s1) UVsToTransData(td++, td2d++, tf->uv[0], 1); 
+                                       if (efa_s2) UVsToTransData(td++, td2d++, tf->uv[1], 1); 
+                                       if (efa_s3) UVsToTransData(td++, td2d++, tf->uv[2], 1);
+                               }
+                       }
+               }
+       } else {
+               for (efa= em->faces.first; efa; efa= efa->next) {
+                       /*tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+                       if (simaFaceDraw_Check(efa, tf)) {*/
+                       if ((tf=(MTFace *)efa->tmp.p)) {
+                               if (propmode) {
+                                       UVsToTransData(td++, td2d++, tf->uv[0], simaUVSel_Check(efa, tf, 0));
+                                       UVsToTransData(td++, td2d++, tf->uv[1], simaUVSel_Check(efa, tf, 1));
+                                       UVsToTransData(td++, td2d++, tf->uv[2], simaUVSel_Check(efa, tf, 2));
+                                       if(efa->v4)
+                                               UVsToTransData(td++, td2d++, tf->uv[3], simaUVSel_Check(efa, tf, 3));
+                               } else {
+                                       if(simaUVSel_Check(efa, tf, 0))                         UVsToTransData(td++, td2d++, tf->uv[0], 1);
+                                       if(simaUVSel_Check(efa, tf, 1))                         UVsToTransData(td++, td2d++, tf->uv[1], 1);
+                                       if(simaUVSel_Check(efa, tf, 2))                         UVsToTransData(td++, td2d++, tf->uv[2], 1);
+                                       if(efa->v4 && simaUVSel_Check(efa, tf, 3))      UVsToTransData(td++, td2d++, tf->uv[3], 1);
+                               }
+                       }
                }
        }
-
+       
        if (G.sima->flag & SI_LIVE_UNWRAP)
                unwrap_lscm_live_begin();
 }
@@ -2306,9 +2383,8 @@ void flushTransUVs(TransInfo *t)
                        td->loc2d[1]= floor(height*td->loc2d[1] + 0.5f)/height;
                }
        }
-
-       /* always call this, also for cancel (it transforms non-selected vertices...) */
-       if((G.sima->flag & SI_BE_SQUARE) && (t->state != TRANS_CANCEL))
+       
+       if((G.sima->flag & SI_BE_SQUARE) && (t->flag & T_PROP_EDIT)==0 && (t->state != TRANS_CANCEL)) 
                be_square_tface_uv(em);
 
        /* this is overkill if G.sima->lock is not set, but still needed */