Revision: 41344
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41344
Author:   psy-fi
Date:     2011-10-28 16:13:07 +0000 (Fri, 28 Oct 2011)
Log Message:
-----------
Smart stitch
=============
*Change the way selection is stored. Due to the fact that after stitching there 
is a rearrangement of islands, redoing the operator incorrectly added uvs for 
stitching. 
Now saving face and uv index which remain constant after stitching.

Modified Paths:
--------------
    branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
    branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.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-28 14:46:09 UTC (rev 41343)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c 
2011-10-28 16:13:07 UTC (rev 41344)
@@ -1322,20 +1322,13 @@
 /*
  * defines for UvElement flags
  */
-#ifndef STITCHNEW
-#define STITCH_PROCESSED 1
-#define STITCH_STITCHABLE 2
-#define STITCH_EDGE_PREVIEW 4
-#define STITCH_EDGE_STITCHABLE 8
-#define STITCH_USE_FOR_STITCHING 16
-#define STITCH_DO_UPDATE 32
-#else
 #define STITCH_SELECTED 1
 #define STITCH_STITCHABLE 2
 #define STITCH_PROCESSED 4
 #define STITCH_BOUNDARY 8
 #define STITCH_STITCHABLE_CANDIDATE 16
-#endif
+
+#define STITCH_NO_PREVIEW -1
 /* Previewer stuff (see uvedit_intern.h for more info) */
 static StitchPreviewer *_stitch_preview;
 
@@ -1470,7 +1463,7 @@
                                                mt->uv[element->tfindex][0] += 
island_stitch_data[i].translation[0];
                                                mt->uv[element->tfindex][1] += 
island_stitch_data[i].translation[1];
                                        }
-                                       else if(efa->tmp.l != -1){
+                                       else if(efa->tmp.l != 
STITCH_NO_PREVIEW){
                                                if(efa->v4){
                                                        if(state->mode == 
EDGE_STITCH){
                                                                
stitch_uv_rotate(island_stitch_data[i].rotation, 
island_stitch_data[i].medianPoint, &preview->previewQuads[efa->tmp.l + 
2*element->tfindex]);
@@ -2179,7 +2172,7 @@
 /* Set preview buffer position of UV face in editface->tmp.l */
 static void stitch_set_face_preview_buffer_position(EditFace *efa, 
StitchPreviewer *preview)
 {
-       if(efa->tmp.l == -1)
+       if(efa->tmp.l == STITCH_NO_PREVIEW)
        {
                if(efa->v4)
                {
@@ -2280,7 +2273,7 @@
        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;
+               efa->tmp.l = STITCH_NO_PREVIEW;
        }
 
        island_stitch_data = 
MEM_callocN(sizeof(*island_stitch_data)*state->elementMap->totalIslands, 
"stitch_island_data");
@@ -2415,7 +2408,7 @@
                }
        }
 
-       printf("st %d, ust %d\n",preview->numOfStitchable, 
preview->numOfUnstitchable);
+//     printf("st %d, ust %d\n",preview->numOfStitchable, 
preview->numOfUnstitchable);
        /*****************************************
         *  Setup preview for stitchable islands *
         *****************************************/
@@ -2456,7 +2449,7 @@
 
                /* Copy data from MTFaces to the preview display buffers */
                for(efa = state->em->faces.first; efa; efa = efa->next){
-                       if(efa->tmp.l != -1)
+                       if(efa->tmp.l != STITCH_NO_PREVIEW)
                        {
                                MTFace *mt = 
CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
 
@@ -2608,7 +2601,7 @@
                                                        
mt->uv[element_iter->tfindex][1] = averageUvPosition[i].uv[1];
 
                                                        uvedit_uv_select(scene, 
efa, mt, element_iter->tfindex);
-                                               }else if(efa->tmp.l != -1){
+                                               }else if(efa->tmp.l != 
STITCH_NO_PREVIEW){
                                                        if(efa->v4){
                                                                
*(preview->previewQuads+efa->tmp.l + element_iter->tfindex*2) = 
averageUvPosition[i].uv[0];
                                                                
*(preview->previewQuads+efa->tmp.l + element_iter->tfindex*2 + 1) = 
averageUvPosition[i].uv[1];
@@ -2667,6 +2660,7 @@
 {
        int counter = 0, i;
        EditFace *efa;
+       EditMesh *em;
        GHashIterator* ghi;
        UvEdge *edges;
        StitchState *stitch_state = MEM_mallocN(sizeof(StitchState), 
"stitch_state");
@@ -2685,7 +2679,7 @@
        /* initialize state */
        stitch_state->use_limit = RNA_boolean_get(op->ptr, "use_limit");
        stitch_state->limitDist = RNA_float_get(op->ptr, "limit");
-       stitch_state->em = BKE_mesh_get_editmesh((Mesh*)obedit->data);
+       stitch_state->em = em = BKE_mesh_get_editmesh((Mesh*)obedit->data);
        stitch_state->mode = RNA_enum_get(op->ptr, "mode");
        stitch_state->snapIslands = RNA_boolean_get(op->ptr, "snap_islands");
        stitch_state->static_island = RNA_int_get(op->ptr, "static_island");
@@ -2817,16 +2811,23 @@
 
        /* Fill selection stack */
        if(RNA_property_is_set(op->ptr, "selection")){
-               int uniqueIndex;
+               int faceIndex, elementIndex, uniqueIndex;
+               UvElement *element;
+
+               EM_init_index_arrays(em, 0, 0, 1);
+
                RNA_BEGIN(op->ptr, itemptr, "selection") {
-                       /* This should change for redo */
-                       uniqueIndex = stitch_state->map[RNA_int_get(&itemptr, 
"index")];
+                       faceIndex = RNA_int_get(&itemptr, "face_index");
+                       elementIndex = RNA_int_get(&itemptr, "element_index");
+                       element = get_uv_element(stitch_state->elementMap, 
EM_get_face_for_index(faceIndex), elementIndex);
+                       uniqueIndex = stitch_state->map[element - 
stitch_state->elementMap->buf];
                        if(!(stitch_state->uvs[uniqueIndex]->flag & 
STITCH_SELECTED)){
                                
stitch_state->selection_stack[stitch_state->selection_size++] = 
stitch_state->uvs[uniqueIndex];
                                stitch_state->uvs[uniqueIndex]->flag |= 
STITCH_SELECTED;
                        }
                }
                RNA_END;
+               EM_free_index_arrays();
        } else {
                for(efa = stitch_state->em->faces.first ; efa; efa = efa->next){
                        int numOfVerts;
@@ -2884,6 +2885,7 @@
        stitch_state = (StitchState *)op->customdata;
 
        if(finished){
+               EditFace *efa;
                int i;
 
                RNA_float_set(op->ptr, "limit", stitch_state->limitDist);
@@ -2892,11 +2894,19 @@
                RNA_int_set(op->ptr, "static_island", 
stitch_state->static_island);
                RNA_enum_set(op->ptr, "mode", stitch_state->mode);
                RNA_boolean_set(op->ptr, "midpoint_snap", 
stitch_state->midpoints);
+
+               for(i = 0, efa = stitch_state->em->faces.first; efa; efa = 
efa->next, i++){
+                       efa->tmp.l = i;
+               }
                /* Store selection for re-execution of stitch */
                for(i = 0; i < stitch_state->selection_size; i++){
                        PointerRNA itemptr;
                        RNA_collection_add(op->ptr, "selection", &itemptr);
-                       RNA_int_set(&itemptr, "index", (UvElement 
*)stitch_state->selection_stack[i] - stitch_state->elementMap->buf);
+                       if(stitch_state->mode == VERT_STITCH){
+                               UvElement *element = (UvElement 
*)stitch_state->selection_stack[i];
+                               RNA_int_set(&itemptr, "face_index", 
element->face->tmp.l);
+                               RNA_int_set(&itemptr, "element_index", 
element->tfindex);
+                       }
                }
 
                uvedit_live_unwrap_update(sima, scene, obedit);
@@ -3112,7 +3122,7 @@
                        }
                        break;
 
-               /* Use Edge selection */
+               /* Switch between selection modes */
                case TKEY:
                        if(event->val == KM_PRESS){
                                EditVert *ev;

Modified: 
branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.c 
2011-10-28 14:46:09 UTC (rev 41343)
+++ branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.c 
2011-10-28 16:13:07 UTC (rev 41344)
@@ -3475,9 +3475,13 @@
        RNA_def_struct_ui_text(srna, "Selected Uv Element", "");
 
        /* store the index to the UV element selected */
-       prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
+       prop= RNA_def_property(srna, "element_index", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_flag(prop, PROP_IDPROPERTY);
-       RNA_def_property_ui_text(prop, "Index", "");
+       RNA_def_property_ui_text(prop, "Element Index", "");
+
+       prop= RNA_def_property(srna, "face_index", PROP_INT, PROP_UNSIGNED);
+       RNA_def_property_flag(prop, PROP_IDPROPERTY);
+       RNA_def_property_ui_text(prop, "Face Index", "");
 }
 
 

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

Reply via email to