Revision: 37882
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37882
Author:   psy-fi
Date:     2011-06-28 01:08:06 +0000 (Tue, 28 Jun 2011)
Log Message:
-----------
smart welding - using flags for uv evaluation + some cleanup and preparation 
stuff for edge stitching, fixed bug where new UV's would not be at the centre 
of new old ones. Still a strange crash remaining. investigating

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

Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h       
2011-06-28 00:40:39 UTC (rev 37881)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h       
2011-06-28 01:08:06 UTC (rev 37882)
@@ -49,8 +49,10 @@
        float *previewQuads;
        /* ...and here we'll store the triangles*/
        float *previewTris;
-       /* Preview points.These will be the selected vertices */
+       /* Preview points.These will be the previewed vertices */
        float *previewPoints;
+       /* Preview edges, for previewed edges */
+       float *previewEdges;
        /* Colors for selected vertices */
        unsigned int *previewPointColors;
 
@@ -58,6 +60,7 @@
        unsigned int numOfTris;
        unsigned int numOfQuads;
        unsigned int numOfPoints;
+       unsigned int numOfEdges;
        /* stores whether user desires preview display */
        char enabled;
 } StitchPreviewer;

Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-06-28 00:40:39 UTC (rev 37881)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-06-28 01:08:06 UTC (rev 37882)
@@ -73,8 +73,9 @@
 
 #include "uvedit_intern.h"
 
-#define STITCH_STITCHABLE 1
-#define STITCH_UNSTITCHABLE 2
+#define STITCH_PROCESSED 1
+#define STITCH_STITCHABLE 2
+#define STITCH_SELECTED        4
 
 /************************* state testing ************************/
 
@@ -1155,12 +1156,14 @@
        _stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), 
"stitch_previewer");
        _stitch_preview->previewQuads = NULL;
        _stitch_preview->previewTris = NULL;
+       _stitch_preview->previewEdges = NULL;
        _stitch_preview->previewPoints = NULL;
        _stitch_preview->previewPointColors = NULL;
 
        _stitch_preview->numOfQuads = 0;
        _stitch_preview->numOfTris = 0;
        _stitch_preview->numOfPoints = 0;
+       _stitch_preview->numOfEdges = 0;
 
        _stitch_preview->enabled = 1;
        return _stitch_preview;
@@ -1191,6 +1194,11 @@
                        MEM_freeN(_stitch_preview->previewPointColors);
                        _stitch_preview->previewPointColors = NULL;
                }
+               if(_stitch_preview->previewEdges)
+               {
+                       MEM_freeN(_stitch_preview->previewEdges);
+                       _stitch_preview->previewEdges = NULL;
+               }
                MEM_freeN(_stitch_preview);
                _stitch_preview = NULL;
        }
@@ -1223,16 +1231,18 @@
 }
 
 /* This function prepares the data of the previewer for display */
-static int stitch_process_data(StitchState *state, int final)
+static int stitch_process_data(StitchState *state, int final, Scene *scene)
 {
        StitchPreviewer *preview = uv_get_stitch_previewer();
        UVVertAverage *uv_average;
        UvVertMap *vmap = state->vmap;
        UvMapVert *mapVert = vmap->buf;
        int i;
+       int numOfEdges = 0;
        int bufferIterator = 0;
        EditFace *editFace, *efa, **faceArray;
        EditVert *editVert;
+       EditEdge *editEdge;
        MTFace *mt;
        short preview_enabled = preview->enabled;
        const char FACE_UVS_SELECTED = TF_SEL1 | TF_SEL2 | TF_SEL3 | TF_SEL4;
@@ -1250,6 +1260,7 @@
         * nevertheless :p */
        uv_average = (UVVertAverage 
*)MEM_callocN(state->vmap->numOfUVs*sizeof(UVVertAverage), "stitch_averages");
 
+       /* This serves exactly as the EM_init_arrays with the added advantage 
that we can initialize the preview buffer position. */
        faceArray = (EditFace **)MEM_mallocN(state->em->totface*sizeof(EditFace 
*), "stitch preview faceArray");
        /* Store Indices to editVerts */
        for(editVert = state->em->verts.first, i = 0; editVert; editVert = 
editVert->next, i++){
@@ -1262,85 +1273,90 @@
                        editFace->tmp.l = -1;
                }
 
+       /* If mode is edge mode initialize the edge position on preview buffer 
to -1 (invalid) */
+       if(state->mode == EDGE_STITCH){
+               for(editEdge = state->em->edges.first; editEdge; editEdge = 
editEdge->next){
+                       editEdge->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(UvMapVert *), 
"commonVertMaps");
 
-       /* 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;
+       if(state->mode == VERT_STITCH){
+               /* 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;
 
-                       for(i = 0; i < vertsPerFace; i++){
-                               if(mt->flag & TF_SEL_MASK(i))
-                               {
-                                       int averageIndex;
-                                       int iter = 0;
-                                       int iter2;
-                                       UvMapVert *mv_iter;
-                                       EditVert *vt = *(&(editFace->v1)+i);
-                                       /* ...we'll iterate through all shared 
UV's of the corresponding vertex */
-                                       mv_iter = vmap->vert[vt->tmp.t];
-                                       /* Original vertex will be previewed, 
of course */
-                                       preview->numOfPoints++;
+                               for(i = 0; i < vertsPerFace; i++){
+                                       if(mt->flag & TF_SEL_MASK(i))
+                                       {
+                                               int averageIndex;
+                                               int iter = 0;
+                                               int iter2;
+                                               UvMapVert *mv_iter;
+                                               EditVert *vt = 
*(&(editFace->v1)+i);
+                                               /* ...we'll iterate through all 
shared UV's of the corresponding vertex */
+                                               mv_iter = vmap->vert[vt->tmp.t];
+                                               /* Original vertex will be 
previewed, of course */
+                                               preview->numOfPoints++;
 
-                                       /* First we need the UVMapVert that 
corresponds to our uv */
-                                       for(;mv_iter; mv_iter =  mv_iter->next)
-                                       {
-                                               /* Here we assume face does not 
use the same vertex twice. */
-                                               if(faceArray[mv_iter->f] == 
editFace)
+                                               /* First we need the UVMapVert 
that corresponds to our uv */
+                                               for(;mv_iter; mv_iter =  
mv_iter->next)
                                                {
-                                                       mapVert = mv_iter;
-                                                       /* If the selected UV 
has not been flagged as stichable or anything at all, tag it as unstitchable */
-                                                       if(!mapVert->flag)
+                                                       UvMapVert *sep;
+                                                       if(mv_iter->separate)
+                                                               sep = mv_iter;
+                                                       /* Here we assume face 
does not use the same vertex twice. */
+                                                       
if(faceArray[mv_iter->f] == editFace)
                                                        {
-                                                               mapVert->flag = 
STITCH_UNSTITCHABLE;
+                                                               /* Assign first 
UV coincident */
+                                                               mapVert = sep;
+                                                               averageIndex = 
mapVert - vmap->buf;
                                                        }
-                                                       averageIndex = mapVert 
- vmap->buf;
                                                }
-                                       }
-                                       /* if uv is stitchable, it has already 
been processed */
-                                       if(mapVert->flag != STITCH_STITCHABLE)
-                                       {
-                                               
uv_average[averageIndex].count++;
+
+                                               uv_average[averageIndex].count 
= 1;
                                                uv_average[averageIndex].uv[0] 
= mt->uv[i][0];
                                                uv_average[averageIndex].uv[1] 
= mt->uv[i][1];
 
                                                for(mv_iter = 
vmap->vert[vt->tmp.t], iter = 0; mv_iter; mv_iter = mv_iter->next){
                                                        MTFace *tmptface;
 
-                                                       if(mv_iter == mapVert)
+                                                       if(mv_iter == mapVert){
                                                                continue;
+                                                       }
 
                                                        efa = 
faceArray[mv_iter->f];
                                                        tmptface = 
CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
 
                                                        if(fabs((mt->uv[i][0] - 
tmptface->uv[mv_iter->tfindex][0]) < STD_UV_CONNECT_LIMIT) &&
-                                                               
(fabs(mt->uv[i][1] - tmptface->uv[mv_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++] = mv_iter;
+                                                               
(fabs(mt->uv[i][1] - tmptface->uv[mv_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++] = mv_iter;
                                                        } else {
                                                                
if((!state->use_limit) || ( (fabs(mt->uv[i][0] - 
tmptface->uv[mv_iter->tfindex][0]) < state->limitDist
                                                                        && 
fabs(mt->uv[i][1] - tmptface->uv[mv_iter->tfindex][1]) < state->limitDist) ))
                                                                {
                                                                        
commonVertMaps[iter++] = mv_iter;
-                                                                       /* 
pointer arithmetic to the rescue */
-                                                                       
mapVert->flag = STITCH_STITCHABLE;
-                                                                       
if(!(mv_iter->flag))
-                                                                               
preview->numOfPoints++;
-                                                                       
mv_iter->flag = STITCH_STITCHABLE;
-
-                                                                       
uv_average[averageIndex].count++;
-                                                                       
uv_average[averageIndex].uv[0] += tmptface->uv[mv_iter->tfindex][0];
-                                                                       
uv_average[averageIndex].uv[1] += tmptface->uv[mv_iter->tfindex][1];
+                                                                       
mapVert->flag |= STITCH_STITCHABLE;
+                                                                       
if(mv_iter->separate){
+                                                                               
uv_average[averageIndex].count++;
+                                                                               
uv_average[averageIndex].uv[0] += tmptface->uv[mv_iter->tfindex][0];
+                                                                               
uv_average[averageIndex].uv[1] += tmptface->uv[mv_iter->tfindex][1];
+                                                                       }
                                                                }
                                                        }
                                                }
+
+                                               mapVert->flag |= 
STITCH_PROCESSED;
                                                /* here we update coincident 
uvs */
-                                               if(mapVert->flag == 
STITCH_STITCHABLE)
+                                               if(mapVert->flag & 
STITCH_STITCHABLE)
                                                {
                                                        /* add original face to 
preview */
                                                        if(editFace->tmp.l == 
-1)
@@ -1363,7 +1379,9 @@
                                                                averageIndex2 = 
mv_iter - vmap->buf;
                                                                
preview->numOfPoints++;
 
-                                                               mv_iter->flag = 
STITCH_STITCHABLE;
+                                                               mv_iter->flag 
|= STITCH_STITCHABLE;
+                                                               mv_iter->flag 
|= STITCH_PROCESSED;
+                                                               /* += because 
of a complex scenario involving */
                                                                
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];
@@ -1385,9 +1403,12 @@
                                }
                        }
                }
+
+               MEM_freeN(commonVertMaps);
+
+       } else {
+
        }
-
-       MEM_freeN(commonVertMaps);
        if(!final)
        {
                /* Initialize the preview buffers */
@@ -1410,7 +1431,7 @@
                        }
                }
                for(mapVert = vmap->buf, i = 0; i < state->vmap->numOfUVs; 
mapVert++, i++){
-                       if(mapVert->flag == STITCH_STITCHABLE){
+                       if(mapVert->flag & STITCH_STITCHABLE){
                                float uv[2];
                                int averageBufIndex;
 
@@ -1437,7 +1458,8 @@
                                /* reset flag, vertapMapbuffer is persistent 
and will be used on next run too! */
                                mapVert->flag = 0;
                        }
-                       else if(mapVert->flag == STITCH_UNSTITCHABLE)
+                       /* stitchable are always processed so this code 
actually tests non-stitchness */

@@ 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