Revision: 40933
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40933
Author:   psy-fi
Date:     2011-10-11 09:32:57 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
smart stitching
================
*edge selection and switching between uv-uv edge selection mode brought back.
*Also face preview in edge selection mode brought back.

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

Modified: 
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c 
2011-10-11 06:56:15 UTC (rev 40932)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c 
2011-10-11 09:32:57 UTC (rev 40933)
@@ -2240,7 +2240,8 @@
                                
stitch_set_face_preview_buffer_position(element_iter->face, preview);
 
                                uniqueIndex = state->map[element_iter - 
state->elementMap->buf];
-                               if(!(state->uvs[uniqueIndex]->flag & 
STITCH_STITCHABLE)){
+
+                               if(state->mode == VERT_STITCH && 
!(state->uvs[uniqueIndex]->flag & STITCH_STITCHABLE)){
                                        state->uvs[uniqueIndex]->flag |= 
STITCH_STITCHABLE;
                                        if(state->snapIslands){
                                                
island_stitch_data[element_iter->island].addedForPreview = 1;
@@ -2252,8 +2253,10 @@
                        int uniqueIndex;
                        /* if no limit exists all uvs are stitchable */
                        
stitch_set_face_preview_buffer_position(element_iter->face, preview);
+
                        uniqueIndex = state->map[element_iter - 
state->elementMap->buf];
-                       if(!(state->uvs[uniqueIndex]->flag & 
STITCH_STITCHABLE)){
+
+                       if(state->mode == VERT_STITCH && 
!(state->uvs[uniqueIndex]->flag & STITCH_STITCHABLE)){
                                state->uvs[uniqueIndex]->flag |= 
STITCH_STITCHABLE;
                                if(state->snapIslands){
                                        
island_stitch_data[element_iter->island].addedForPreview = 1;
@@ -2280,7 +2283,7 @@
        if(preview == NULL)
                return 0;
        preview->enabled = preview_enabled;
-       preview->mode = VERT_STITCH;
+       preview->mode = state->mode;
        /* each face holds its position in the preview buffer in tmp. -1 is 
uninitialized */
        for(efa = state->em->faces.first; efa; efa = efa->next){
                efa->tmp.l = -1;
@@ -2314,6 +2317,34 @@
                                preview->numOfUnstitchable++;
                        }
                }
+       }else{
+               for(i = 0; i < state->selection_size; i++){
+                       char stitchable1, stitchable2;
+                       UvEdge *edge = (UvEdge *)state->selection_stack[i];
+                       UvElement *element1 = state->uvs[edge->uv1];
+                       UvElement *element2 = state->uvs[edge->uv2];
+
+                       stitchable1 = determine_uv_stitchability(element1, 
state);
+                       stitchable2 = determine_uv_stitchability(element2, 
state);
+
+                       if(stitchable1 || stitchable2){
+                               /* Update only uv face preview that need to be 
updated */
+                               if(stitchable1){
+                                       
stitch_setup_preview_for_uv_group(element1, state, island_stitch_data);
+                               }
+                               if(stitchable2){
+                                       
stitch_setup_preview_for_uv_group(element2, state, island_stitch_data);
+                               }
+                               if(state->snapIslands){
+                                       
island_stitch_data[element1->island].addedForPreview = 1;
+                               }
+                               edge->flag |= STITCH_STITCHABLE;
+                               preview->numOfStitchable++;
+                       }else{
+                               /* Add to preview */
+                               preview->numOfUnstitchable++;
+                       }
+               }
        }
        /*****************************************
         *  Setup preview for stitchable islands *
@@ -2655,7 +2686,7 @@
        BLI_ghash_free(stitch_state->edgeHash, NULL, NULL);
        stitch_state->edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, 
"stitch_edge_hash");
        for(i = 0; i < stitch_state->total_edges; i++){
-               BLI_ghash_insert(stitch_state->edgeHash, &stitch_state->edges + 
i, NULL);
+               BLI_ghash_insert(stitch_state->edgeHash, stitch_state->edges + 
i, stitch_state->edges + i);
        }
 
        for(i = 0; i < stitch_state->total_edges; i++){
@@ -2859,6 +2890,7 @@
                                break;
                        }
                        return OPERATOR_RUNNING_MODAL;
+
                case IKEY:
                        if(event->val == KM_PRESS){
                                /* Here we just increase the number, it will be 
modded
@@ -2871,14 +2903,58 @@
                                break;
                        }
                        return OPERATOR_RUNNING_MODAL;
+
                /* Use Edge selection */
                case MKEY:
                        if(event->val == KM_PRESS){
-                               if(stitch_state->mode == EDGE_STITCH)
+                               void **new_selection = 
MEM_mallocN(sizeof(*new_selection)*stitch_state->elementMap->totalUVs, 
"uv_stitch_selection_stack");
+
+                               if(stitch_state->mode == EDGE_STITCH){
+                                       int i;
+                                       int total_uvs_selected = 0;
+
+                                       for(i = 0; i < 
stitch_state->selection_size; i++){
+                                               UvEdge *edge = 
stitch_state->selection_stack[i];
+
+                                               
if(!(stitch_state->uvs[edge->uv1]->flag & STITCH_SELECTED)){
+                                                       
stitch_state->uvs[edge->uv1]->flag |= STITCH_SELECTED;
+                                                       
new_selection[total_uvs_selected++] = stitch_state->uvs[edge->uv1];
+                                               }
+                                               
if(!(stitch_state->uvs[edge->uv2]->flag & STITCH_SELECTED)){
+                                                       
stitch_state->uvs[edge->uv2]->flag |= STITCH_SELECTED;
+                                                       
new_selection[total_uvs_selected++] = stitch_state->uvs[edge->uv2];
+                                               }
+
+                                               edge->flag &= ~STITCH_SELECTED;
+                                       }
+
                                        stitch_state->mode = VERT_STITCH;
-                               else
+                                       
MEM_freeN(stitch_state->selection_stack);
+                                       stitch_state->selection_size = 
total_uvs_selected;
+                               }
+                               else{
+                                       int i;
+                                       int total_edges_selected = 0;
+                                       for(i = 0; i < 
stitch_state->total_edges; i++){
+                                               UvEdge *edge = 
stitch_state->edges + i;
+
+                                               
if(stitch_state->uvs[edge->uv1]->flag & STITCH_SELECTED && 
stitch_state->uvs[edge->uv2]->flag & STITCH_SELECTED){
+                                                       edge->flag |= 
STITCH_SELECTED;
+                                                       
new_selection[total_edges_selected++] = edge;
+                                               }
+                                       }
+
+                                       /* Cleanup old uv element selection */
+                                       for(i = 0; i < 
stitch_state->selection_size; i++){
+                                               ((UvElement 
*)stitch_state->selection_stack[i])->flag &= ~STITCH_SELECTED;
+                                       }
                                        stitch_state->mode = EDGE_STITCH;
+                                       
MEM_freeN(stitch_state->selection_stack);
+                                       stitch_state->selection_size = 
total_edges_selected;
+                               }
 
+                               stitch_state->selection_stack = new_selection;
+
                                if(!stitch_process_data(stitch_state, scene, 0, 
1)){
                                        return stitch_cancel(C, op);
                                }
@@ -2907,8 +2983,8 @@
                                if(hit.efa)
                                {
                                        /* Add vertex to selection, deselect 
all common uv's of vert other
-                                        * than selected and update the 
preview. This behavior was decided because stitching
-                                        * becomes dependent on the order of 
stitching different uv's corresponding to the same vertex */
+                                        * than selected and update the 
preview. This behavior was decided so that
+                                        * you can do stuff like deselect the 
opposite stitchable vertex and the initial still gets deselected */
                                        if(stitch_state->mode == VERT_STITCH)
                                        {
                                                int uniqueIndex;
@@ -2942,42 +3018,38 @@
                                        }
                                        else
                                        {
-                                               /* same as above but for two 
verts. Maybe make a function for this after implementation is concrete */
-                                               UvElement *element = 
stitch_state->elementMap->vert[hit.vert];
+                                               UvEdge tmp_edge, *edge;
+                                               int nverts = hit.efa->v4? 4 : 3;
+                                               UvElement *element1 = 
get_uv_element(stitch_state->elementMap, hit.efa, hit.edge);
+                                               UvElement *element2 = 
get_uv_element(stitch_state->elementMap, hit.efa, (hit.edge+1)%nverts);
 
-                                               for(; element; element = 
element->next)
-                                               {
-                                                       int nverts = 
element->face->v4 ? 4 : 3;
-                                                       int nextflag = 0;
-                                                       if((nextflag = 
(*(&element->face->v1 + (1 + element->tfindex)%nverts))->tmp.l == hit.vert2) ||
-                                                               
(*(&element->face->v1 + (element->tfindex - 1 + nverts)%nverts))->tmp.l == 
hit.vert2)
-                                                       {
-                                                               MTFace *tface = 
 CustomData_em_get(&stitch_state->em->fdata, element->face->data, CD_MTFACE);
-                                                               
if(element->face == hit.efa)
-                                                               {
-                                                                       
if(nextflag)
-                                                                       {
-                                                                               
if(event->ctrl){
-                                                                               
        uvedit_uv_deselect(scene, element->face, tface, element->tfindex);
-                                                                               
}
-                                                                               
else{
-                                                                               
        uvedit_uv_select(scene, element->face, tface, element->tfindex);
-                                                                               
}
-                                                                       }else{
-                                                                               
if(event->ctrl){
-                                                                               
        uvedit_uv_deselect(scene, element->face, tface, (element->tfindex - 1 + 
nverts)%nverts);
-                                                                               
}
-                                                                               
else{
-                                                                               
        uvedit_uv_select(scene, element->face, tface, (element->tfindex - 1 + 
nverts)%nverts);
-                                                                               
}
+                                               int uniqueIndex = 
stitch_state->map[element1 - stitch_state->elementMap->buf];
+                                               int uniqueIndex2 = 
stitch_state->map[element2 - stitch_state->elementMap->buf];
+
+                                               if(uniqueIndex2 > uniqueIndex){
+                                                       tmp_edge.uv1 = 
uniqueIndex;
+                                                       tmp_edge.uv2 = 
uniqueIndex2;
+                                               }else{
+                                                       tmp_edge.uv1 = 
uniqueIndex2;
+                                                       tmp_edge.uv2 = 
uniqueIndex;
+                                               }
+
+                                               edge = (UvEdge 
*)BLI_ghash_lookup(stitch_state->edgeHash, &tmp_edge);
+
+                                               /* Add edge to selection */
+                                               if(!event->ctrl){
+                                                       if(!(edge->flag & 
STITCH_SELECTED)){
+                                                               edge->flag |= 
STITCH_SELECTED;
+                                                               
stitch_state->selection_stack[stitch_state->selection_size++] = edge;
+                                                       }
+                                               }else{
+                                                       if(edge->flag & 
STITCH_SELECTED){
+                                                               int i;
+                                                               for(i = 0; i < 
stitch_state->selection_size; i++){
+                                                                       
if(((UvEdge *)stitch_state->selection_stack[i]) == edge){
+                                                                               
--stitch_state->selection_size;
+                                                                               
stitch_state->selection_stack[i] = 
stitch_state->selection_stack[stitch_state->selection_size];
                                                                        }
-                                                               }else{
-                                                                       
if(nextflag)
-                                                                       {
-                                                                               
uvedit_uv_deselect(scene, element->face, tface, element->tfindex);
-                                                                       }else{
-                                                                               
uvedit_uv_deselect(scene, element->face, tface, (element->tfindex - 1 + 
nverts)%nverts);
-                                                                       }
                                                                }
                                                        }
                                                }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to