Revision: 38389
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38389
Author:   psy-fi
Date:     2011-07-14 11:32:33 +0000 (Thu, 14 Jul 2011)
Log Message:
-----------
some cleanup, and snapping related code (still nothing functional) 

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c

Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-07-14 09:54:03 UTC (rev 38388)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-07-14 11:32:33 UTC (rev 38389)
@@ -1127,13 +1127,13 @@
 /* stitch state object */
 typedef struct StitchState {
        /* edge or vertex stitch mode */
-       short mode;
+       char mode;
        /* use limit flag */
-       short use_limit;
+       char use_limit;
        /* limit to operator, same as original operator */
        float limitDist;
-       /* operate on vertex uvs or whole edge uvs */
-       short operationMode;
+       /* snap uv islands together during stitching */
+       char snapIslands;
        /* editmesh, cached for use in modal handler */
        EditMesh *em;
        /* vertmap, contains vertices sharing uv's in linked lists. */
@@ -1223,7 +1223,7 @@
                                (!mode)? '*':' ',
                                uv_get_stitch_previewer()->enabled?'*':' ',
                                stitch_state->use_limit?'*':' ',
-                               ' ',
+                               stitch_state->snapIslands?'*' :' ',
                                stitch_state->limitDist);
                ED_area_headerprint(sa, msg);
        }
@@ -1244,6 +1244,18 @@
        }
 }
 
+struct IslandStitchData;
+
+/* This is a straightforward implementation, couunt the uv's in the island 
that will move and take the mean displacement and apply it to all
+ * elements of the island except from the stitchable */
+typedef struct IslandStitchData{
+       /* rotation can be used only for edges, for vertices there is no such 
notion */
+       float rotation;
+       float translation;
+       int numOfElements;
+}IslandStitchData;
+
+
 /* This function prepares the data of the previewer for display */
 static int stitch_process_data(StitchState *state, int final, Scene *scene, 
int doIndexInit)
 {
@@ -1256,7 +1268,9 @@
        EditFace *editFace, *efa;
        //**faceArray;
        EditVert *editVert;
-       /* This holds uv's that must be updated if the initial uv is 
stitchable. */
+       IslandStitchData *island_stitch_data = NULL;
+
+       /* This holds uv's corresponding to the same vertex that must be 
updated if one of them is stitchable. */
        UvElement **commonVertMaps;
 
        MTFace *mt;
@@ -1283,322 +1297,323 @@
 
        /* Make face array and initialize position in preview buffer */
        for(editFace = state->em->faces.first, i = 0; editFace; editFace = 
editFace->next, i++){
-                       editFace->tmp.l = -1;
-               }
+               editFace->tmp.l = -1;
+       }
 
-               /* The maximum number of faces that a UV can be part of is 
totfaces. We allocate this here to avoid allocating
-               * this too many times on the fly */
-               commonVertMaps = 
MEM_mallocN(state->em->totface*sizeof(UvElement *), "commonVertMaps");
+       /* The maximum number of faces that a UV can be part of is totfaces. We 
allocate this here to avoid allocating
+       * this too many times on the fly */
+       commonVertMaps = 
MEM_mallocN(state->em->totface*sizeof(*commonVertMaps), "commonVertMaps");
 
+       if(state->snapIslands){
+               island_stitch_data = 
MEM_callocN(sizeof(*island_stitch_data)*state->vmap->numOfIslands, 
"stitch_island_data");
+       }
 
-               /* Count number of points/faces so that we allocate appropriate 
buffer */
-               for(editFace = state->em->faces.first ; editFace; 
editFace=editFace->next){
-                       mt = CustomData_em_get(&state->em->fdata, 
editFace->data, CD_MTFACE);
-                       /* if face has any UV's selected... */
-                       if(mt->flag & FACE_UVS_SELECTED){
-                               int vertsPerFace = editFace->v4 ? 4 : 3;
+       /* Iterate over all faces and find selected uv's */
+       for(editFace = state->em->faces.first ; editFace; 
editFace=editFace->next){
+               mt = CustomData_em_get(&state->em->fdata, editFace->data, 
CD_MTFACE);
+               /* if face has any UV's selected... */
+               if(mt->flag & FACE_UVS_SELECTED){
+                       int vertsPerFace = editFace->v4 ? 4 : 3;
 
-                               for(i = 0; i < vertsPerFace; i++){
-                                       /************ Vert stitching case 
**********************/
-                                       if(state->mode == VERT_STITCH){
-                                               if(mt->flag & TF_SEL_MASK(i))
+                       for(i = 0; i < vertsPerFace; i++){
+                               /************ Vert stitching case 
**********************/
+                               if(state->mode == VERT_STITCH){
+                                       if(mt->flag & TF_SEL_MASK(i))
+                                       {
+                                               int averageIndex;
+                                               int iter = 0;
+                                               int iter2;
+                                               UvElement *el_iter;
+                                               EditVert *vt = 
*(&(editFace->v1)+i);
+                                               /* ...we'll iterate through all 
shared UV's of the corresponding vertex */
+                                               el_iter = vmap->vert[vt->tmp.l];
+                                               /* Original vertex will be 
previewed, of course */
+                                               preview->numOfOrig++;
+
+                                               /* First we need the UVMapVert 
that corresponds to our uv */
+                                               for(;el_iter; el_iter =  
el_iter->next)
                                                {
-                                                       int averageIndex;
-                                                       int iter = 0;
-                                                       int iter2;
-                                                       UvElement *el_iter;
-                                                       EditVert *vt = 
*(&(editFace->v1)+i);
-                                                       /* ...we'll iterate 
through all shared UV's of the corresponding vertex */
-                                                       el_iter = 
vmap->vert[vt->tmp.l];
-                                                       /* Original vertex will 
be previewed, of course */
-                                                       preview->numOfOrig++;
-
-                                                       /* First we need the 
UVMapVert that corresponds to our uv */
-                                                       for(;el_iter; el_iter = 
 el_iter->next)
+                                                       /* Here we assume face 
does not use the same vertex twice. */
+                                                       if(el_iter->face == 
editFace)
                                                        {
-                                                               /* Here we 
assume face does not use the same vertex twice. */
-                                                               
if(el_iter->face == editFace)
-                                                               {
-                                                                       /* 
Assign first UV coincident */
-                                                                       element 
= el_iter;
-                                                                       
averageIndex = element - vmap->buf;
-                                                               }
+                                                               /* Assign first 
UV coincident */
+                                                               element = 
el_iter;
+                                                               averageIndex = 
element - vmap->buf;
                                                        }
+                                               }
 
-                                                       
uv_average[averageIndex].count ++;
-                                                       
uv_average[averageIndex].uv[0] += mt->uv[i][0];
-                                                       
uv_average[averageIndex].uv[1] += mt->uv[i][1];
+                                               uv_average[averageIndex].count 
++;
+                                               uv_average[averageIndex].uv[0] 
+= mt->uv[i][0];
+                                               uv_average[averageIndex].uv[1] 
+= mt->uv[i][1];
 
-                                                       for(el_iter = 
vmap->vert[vt->tmp.l], iter = 0; el_iter; el_iter = el_iter->next){
-                                                               MTFace 
*tmptface;
+                                               for(el_iter = 
vmap->vert[vt->tmp.l], iter = 0; el_iter; el_iter = el_iter->next){
+                                                       MTFace *tmptface;
 
-                                                               if(el_iter == 
element){
-                                                                       
continue;
-                                                               }
+                                                       if(el_iter == element){
+                                                               continue;
+                                                       }
 
-                                                               efa = 
el_iter->face;
-                                                               tmptface = 
CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+                                                       efa = el_iter->face;
+                                                       tmptface = 
CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
 
-                                                               
if(fabs((mt->uv[i][0] - tmptface->uv[el_iter->tfindex][0]) < 
STD_UV_CONNECT_LIMIT) &&
-                                                                               
(fabs(mt->uv[i][1] - tmptface->uv[el_iter->tfindex][1]) < STD_UV_CONNECT_LIMIT))
-                                                               {
-                                                                       /* if 
the uv being iterated is coincident with the original, just add it to be 
updated later if
-                                                                        * 
original uv is stitchable */
-                                                                       
commonVertMaps[iter++] = el_iter;
+                                                       if(fabs((mt->uv[i][0] - 
tmptface->uv[el_iter->tfindex][0]) < STD_UV_CONNECT_LIMIT) &&
+                                                               
(fabs(mt->uv[i][1] - tmptface->uv[el_iter->tfindex][1]) < STD_UV_CONNECT_LIMIT))
+                                                       {
+                                                               /* if the uv 
being iterated is coincident with the original, just add it to be updated later 
if
+                                                                * original uv 
is stitchable */
+                                                               
commonVertMaps[iter++] = el_iter;
+                                                       }
+                                                       else 
if((!state->use_limit) || ( (fabs(mt->uv[i][0] - 
tmptface->uv[el_iter->tfindex][0]) < state->limitDist
+                                                               && 
fabs(mt->uv[i][1] - tmptface->uv[el_iter->tfindex][1]) < state->limitDist) ))
+                                                       {
+                                                               
commonVertMaps[iter++] = el_iter;
+                                                               element->flag 
|= STITCH_STITCHABLE;
+                                                               
if(el_iter->separate){
+                                                                       
uv_average[averageIndex].count++;
+                                                                       
uv_average[averageIndex].uv[0] += tmptface->uv[el_iter->tfindex][0];
+                                                                       
uv_average[averageIndex].uv[1] += tmptface->uv[el_iter->tfindex][1];
                                                                }
-                                                               else 
if((!state->use_limit) || ( (fabs(mt->uv[i][0] - 
tmptface->uv[el_iter->tfindex][0]) < state->limitDist
-                                                                       && 
fabs(mt->uv[i][1] - tmptface->uv[el_iter->tfindex][1]) < state->limitDist) ))
-                                                               {
-                                                                       
commonVertMaps[iter++] = el_iter;
-                                                                       
element->flag |= STITCH_STITCHABLE;
-                                                                       
if(el_iter->separate){
-                                                                               
uv_average[averageIndex].count++;
-                                                                               
uv_average[averageIndex].uv[0] += tmptface->uv[el_iter->tfindex][0];
-                                                                               
uv_average[averageIndex].uv[1] += tmptface->uv[el_iter->tfindex][1];
-                                                                       }
-                                                               }
                                                        }
+                                               }
 
-                                                       element->flag |= 
STITCH_PROCESSED;
-                                                       /* here we update 
coincident uvs */
-                                                       if(element->flag & 
STITCH_STITCHABLE)
+                                               element->flag |= 
STITCH_PROCESSED;
+                                               /* here we update coincident 
uvs */
+                                               if(element->flag & 
STITCH_STITCHABLE)
+                                               {
+                                                       /* add original face to 
preview */
+                                                       
stitch_update_face_preview_index(editFace, preview);
+                                                       for(iter2 = 0; iter2 < 
iter; iter2++)
                                                        {
-                                                               /* add original 
face to preview */
-                                                               
stitch_update_face_preview_index(editFace, preview);
-                                                               for(iter2 = 0; 
iter2 < iter; iter2++)
-                                                               {
-                                                                       int 
averageIndex2;
-                                                                       el_iter 
= commonVertMaps[iter2];
-                                                                       efa = 
el_iter->face;
-                                                                       
averageIndex2 = el_iter - vmap->buf;
-                                                                       
preview->numOfOrig++;
+                                                               int 
averageIndex2;
+                                                               el_iter = 
commonVertMaps[iter2];
+                                                               efa = 
el_iter->face;
+                                                               averageIndex2 = 
el_iter - vmap->buf;
+                                                               
preview->numOfOrig++;
 
-                                                                       
el_iter->flag |= STITCH_STITCHABLE;
-                                                                       
//el_iter->flag |= STITCH_PROCESSED;
+                                                               el_iter->flag 
|= STITCH_STITCHABLE;
+                                                               //el_iter->flag 
|= STITCH_PROCESSED;
 
-                                                                       
uv_average[averageIndex2].count += uv_average[averageIndex].count;
-                                                                       
uv_average[averageIndex2].uv[0] += uv_average[averageIndex].uv[0];
-                                                                       
uv_average[averageIndex2].uv[1] += uv_average[averageIndex].uv[1];
+                                                               
uv_average[averageIndex2].count += uv_average[averageIndex].count;
+                                                               
uv_average[averageIndex2].uv[0] += uv_average[averageIndex].uv[0];
+                                                               
uv_average[averageIndex2].uv[1] += uv_average[averageIndex].uv[1];
 
-                                                                       
stitch_update_face_preview_index(efa, preview);
-                                                               }
+                                                               
stitch_update_face_preview_index(efa, preview);
                                                        }
                                                }
-                                       /****************** Edge stitching case 
*************************/
-                                       } else
+                                       }
+                               /****************** Edge stitching case 
*************************/
+                               } else {
+                                       /* Is this edge selected? */
+                                       if(mt->flag & TF_SEL_MASK(i) && 
mt->flag & TF_SEL_MASK((i+1)%vertsPerFace))
                                        {
-                                               /* Is this edge selected? */

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to