Revision: 37610
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37610
Author:   psy-fi
Date:     2011-06-18 00:30:42 +0000 (Sat, 18 Jun 2011)
Log Message:
-----------
smart welding - preview drawing for uv's without limt. also erased some 
unnecessary code in the operator.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_draw.c
    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_draw.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_draw.c 
2011-06-17 22:45:33 UTC (rev 37609)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_draw.c 
2011-06-18 00:30:42 UTC (rev 37610)
@@ -525,17 +525,6 @@
                }
                
        }
-       
-       /* 2.5 draw test :) */
-       if((stitch_preview) && stitch_preview->enabled){
-               glColor4f(1.0, 1.0, 1.0, 1.0);
-               glBegin(GL_QUADS);
-               glVertex2f(-0.5, -0.5);
-               glVertex2f(0.5, -0.5);
-               glVertex2f(0.5, 0.5);
-               glVertex2f(-0.5, 0.5);
-               glEnd();
-       }
 
        /* 3. draw active face stippled */
 
@@ -845,6 +834,26 @@
                bglEnd();       
        }
 
+       /* finally draw stitch preview */
+       if((stitch_preview) && stitch_preview->enabled){
+               glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+               glColor4f(0.0, 1.0, 0.0, 0.5);
+               glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
+               glEnable(GL_VERTEX_ARRAY);
+               glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewTris);
+               glDrawArrays(GL_TRIANGLES, 0, stitch_preview->numOfTris*3);
+               glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewQuads);
+               glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
+               glColor4f(0.0, 0.0, 1.0, 0.5);
+               glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+               glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewTris);
+               glDrawArrays(GL_TRIANGLES, 0, stitch_preview->numOfTris*3);
+               glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewQuads);
+               glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
+               glPopClientAttrib();
+               glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+       }
+
        glPointSize(1.0);
        BKE_mesh_end_editmesh(obedit->data, em);
 }

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-17 22:45:33 UTC (rev 37609)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h       
2011-06-18 00:30:42 UTC (rev 37610)
@@ -42,11 +42,17 @@
 struct Object;
 struct wmOperatorType;
 
+/* Object that stores display data for previewing before accepting stitching */
 typedef struct StitchPreviewer {
-       float *previewQuads[4][2];
-       float *previewTris[2][2];
+       /* OpenGL requires different calls for Triangles and Quads.
+        * here we'll store the quads of the mesh */
+       float *previewQuads;
+       /* ...and here we'll store the triangles*/
+       float *previewTris;
+       /* here we'll store the number of triangles and quads to be drawn */
        unsigned int numOfTris;
        unsigned int numOfQuads;
+       /* 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-17 22:45:33 UTC (rev 37609)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-06-18 00:30:42 UTC (rev 37610)
@@ -46,6 +46,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
 #include "BLI_utildefines.h"
+#include "BLI_ghash.h"
 
 #include "BKE_context.h"
 #include "BKE_customdata.h"
@@ -1120,12 +1121,11 @@
 /* just for averaging UVs */
 typedef struct UVVertAverage {
        float uv[2];
-       int count;
+       unsigned short count;
 } UVVertAverage;
 
 /* stitch state object */
 typedef struct StitchState {
-       short preview;
        int use_limit;
        float limitDist;
        short selectMode;
@@ -1134,19 +1134,31 @@
 #define VERT_STITCH 1
 #define EDGE_STITCH 2
 
-/* Previewer stuff */
+/* Previewer stuff (see uvedit_intern.h for more info) */
 static StitchPreviewer *_stitch_preview;
 
-static StitchPreviewer * stitch_preview_init()
+static StitchPreviewer * stitch_preview_init(void)
 {
        _stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), 
"stitch_previewer");
+       _stitch_preview->previewQuads = NULL;
+       _stitch_preview->previewTris = NULL;
        return _stitch_preview;
 }
 
-static void stitch_preview_delete()
+static void stitch_preview_delete(void)
 {
        if(_stitch_preview)
        {
+               if(_stitch_preview->previewQuads)
+               {
+                       MEM_freeN(_stitch_preview->previewQuads);
+                       _stitch_preview->previewQuads = NULL;
+               }
+               if(_stitch_preview->previewTris)
+               {
+                       MEM_freeN(_stitch_preview->previewTris);
+                       _stitch_preview->previewTris = NULL;
+               }
                MEM_freeN(_stitch_preview);
                _stitch_preview = NULL;
        }
@@ -1186,16 +1198,8 @@
        return 1;
 }
 
-static int stitch_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
-{
-       if(!stitch_init(C, op))
-               return OPERATOR_CANCELLED;
 
-       WM_event_add_modal_handler(C, op);
-       return OPERATOR_RUNNING_MODAL;
-}
-
-static int stitch_uvs(bContext *C, wmOperator *op)
+static int stitch_uvs(bContext *C, wmOperator *op, int final)
 {
        Scene *scene;
        Object *obedit;
@@ -1205,12 +1209,28 @@
        Image *ima;
        MTFace *tf;
        StitchState *stitch_state;
+       StitchPreviewer *preview;
 
+       preview = uv_get_stitch_previewer();
+       preview->numOfQuads = 0;
+       preview->numOfTris = 0;
+
        stitch_state = (StitchState *)op->customdata;
        scene= CTX_data_scene(C);
        obedit= CTX_data_edit_object(C);
        em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
        ima= CTX_data_edit_image(C);
+
+       if(preview->previewQuads)
+       {
+               MEM_freeN(preview->previewQuads);
+               preview->previewQuads = NULL;
+       }
+       if(preview->previewTris)
+       {
+               MEM_freeN(preview->previewTris);
+               preview->previewTris = NULL;
+       }
        
        if(stitch_state->use_limit) {
                UvVertMap *vmap;
@@ -1261,8 +1281,13 @@
                                                tf = 
CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
 
                                                if(uvedit_uv_selected(scene, 
efa, tf, iterv->tfindex)) {
-                                                       
tf->uv[iterv->tfindex][0]= newuv[0];
-                                                       
tf->uv[iterv->tfindex][1]= newuv[1];
+                                                       if(final){
+                                                               
tf->uv[iterv->tfindex][0]= newuv[0];
+                                                               
tf->uv[iterv->tfindex][1]= newuv[1];
+                                                       }
+                                                       if(preview->enabled){
+
+                                                       }
                                                }
                                        }
                                }
@@ -1276,24 +1301,25 @@
        }
        else {
                UVVertAverage *uv_average, *uvav;
-               int count;
-
-               // index and count verts
-               for(count=0, eve=em->verts.first; eve; count++, eve= eve->next)
-                       eve->tmp.l = count;
+               int tri_index = 0, quad_index = 0;
                
-               uv_average= MEM_callocN(sizeof(UVVertAverage)*count, "Stitch");
+               uv_average= MEM_callocN(sizeof(UVVertAverage)*em->totvert, 
"Stitch");
                
                // gather uv averages per vert
                for(efa= em->faces.first; efa; efa= efa->next) {
                        tf = CustomData_em_get(&em->fdata, efa->data, 
CD_MTFACE);
 
                        if(uvedit_face_visible(scene, ima, efa, tf)) {
+                               /* is face updated? */
+                               unsigned short tag = 0;
+
                                if(uvedit_uv_selected(scene, efa, tf, 0)) {
                                        uvav = uv_average + efa->v1->tmp.l;
                                        uvav->count++;
                                        uvav->uv[0] += tf->uv[0][0];
                                        uvav->uv[1] += tf->uv[0][1];
+                                       /* if count > 1, then this face will be 
drawn for preview */
+                                       tag = 1;
                                }
 
                                if(uvedit_uv_selected(scene, efa, tf, 1)) {
@@ -1301,6 +1327,7 @@
                                        uvav->count++;
                                        uvav->uv[0] += tf->uv[1][0];
                                        uvav->uv[1] += tf->uv[1][1];
+                                       tag = 1;
                                }
 
                                if(uvedit_uv_selected(scene, efa, tf, 2)) {
@@ -1308,6 +1335,7 @@
                                        uvav->count++;
                                        uvav->uv[0] += tf->uv[2][0];
                                        uvav->uv[1] += tf->uv[2][1];
+                                       tag = 1;
                                }
 
                                if(efa->v4 && uvedit_uv_selected(scene, efa, 
tf, 3)) {
@@ -1315,49 +1343,121 @@
                                        uvav->count++;
                                        uvav->uv[0] += tf->uv[3][0];
                                        uvav->uv[1] += tf->uv[3][1];
+                                       tag = 1;
                                }
+
+                               if(tag){
+                                       if(efa->v4){
+                                               preview->numOfQuads++;
+                                       }
+                                       else {
+                                               preview->numOfTris++;
+                                       }
+                               }
                        }
                }
                
+               if(preview->enabled && !final){
+                       preview->previewQuads = (float 
*)MEM_mallocN(preview->numOfQuads*sizeof(float)*8, "quad_uv_stitch_prev");
+                       preview->previewTris = (float 
*)MEM_mallocN(preview->numOfTris*sizeof(float)*6, "tri_uv_stitch_prev");
+               }
                // apply uv welding
                for(efa= em->faces.first; efa; efa= efa->next) {
                        tf = CustomData_em_get(&em->fdata, efa->data, 
CD_MTFACE);
 
                        if(uvedit_face_visible(scene, ima, efa, tf)) {
-                               if(uvedit_uv_selected(scene, efa, tf, 0)) {
-                                       uvav = uv_average + efa->v1->tmp.l;
-                                       tf->uv[0][0] = uvav->uv[0]/uvav->count;
-                                       tf->uv[0][1] = uvav->uv[1]/uvav->count;
-                               }
+                               if(final)
+                               {
+                                       if(uvedit_uv_selected(scene, efa, tf, 
0)) {
+                                               uvav = uv_average + 
efa->v1->tmp.l;
+                                               tf->uv[0][0] = 
uvav->uv[0]/uvav->count;
+                                               tf->uv[0][1] = 
uvav->uv[1]/uvav->count;
+                                       }
 
-                               if(uvedit_uv_selected(scene, efa, tf, 1)) {
-                                       uvav = uv_average + efa->v2->tmp.l;
-                                       tf->uv[1][0] = uvav->uv[0]/uvav->count;
-                                       tf->uv[1][1] = uvav->uv[1]/uvav->count;
-                               }
+                                       if(uvedit_uv_selected(scene, efa, tf, 
1)) {
+                                               uvav = uv_average + 
efa->v2->tmp.l;
+                                               tf->uv[1][0] = 
uvav->uv[0]/uvav->count;
+                                               tf->uv[1][1] = 
uvav->uv[1]/uvav->count;
+                                       }
 
-                               if(uvedit_uv_selected(scene, efa, tf, 2)) {
-                                       uvav = uv_average + efa->v3->tmp.l;
-                                       tf->uv[2][0] = uvav->uv[0]/uvav->count;
-                                       tf->uv[2][1] = uvav->uv[1]/uvav->count;
+                                       if(uvedit_uv_selected(scene, efa, tf, 
2)) {
+                                               uvav = uv_average + 
efa->v3->tmp.l;
+                                               tf->uv[2][0] = 
uvav->uv[0]/uvav->count;
+                                               tf->uv[2][1] = 
uvav->uv[1]/uvav->count;
+                                       }
+
+                                       if(efa->v4 && uvedit_uv_selected(scene, 
efa, tf, 3)) {
+                                               uvav = uv_average + 
efa->v4->tmp.l;
+                                               tf->uv[3][0] = 
uvav->uv[0]/uvav->count;
+                                               tf->uv[3][1] = 
uvav->uv[1]/uvav->count;
+                                       }
                                }
+                               if(preview->enabled && !final)
+                               {
+                                       float *uv_tmp;
+                                       char v1sel = uvedit_uv_selected(scene, 
efa, tf, 0);
+                                       char v2sel = uvedit_uv_selected(scene, 
efa, tf, 1);
+                                       char v3sel = uvedit_uv_selected(scene, 
efa, tf, 2);
+                                       char v4sel = efa->v4 && 
uvedit_uv_selected(scene, efa, tf, 3);
+                                       if(!(v1sel || v2sel || v3sel || v4sel))
+                                               continue;
+                                       if(efa->v4)
+                                       {
+                                               uv_tmp = 
preview->previewQuads+quad_index*8;
+                                               quad_index++;
+                                               memcpy(uv_tmp, &tf->uv[0][0], 
8*sizeof(float));
+                                       } else {
+                                               uv_tmp = 
preview->previewTris+tri_index*6;
+                                               memcpy(uv_tmp, &tf->uv[0][0], 
6*sizeof(float));
+                                               tri_index++;
+                                       }
+                                       if(v1sel) {
+                                               uvav = uv_average + 
efa->v1->tmp.l;
+                                               uv_tmp[0] = 
uvav->uv[0]/uvav->count;
+                                               uv_tmp[1] = 
uvav->uv[1]/uvav->count;
+                                       }
 
-                               if(efa->v4 && uvedit_uv_selected(scene, efa, 
tf, 3)) {
-                                       uvav = uv_average + efa->v4->tmp.l;
-                                       tf->uv[3][0] = uvav->uv[0]/uvav->count;
-                                       tf->uv[3][1] = uvav->uv[1]/uvav->count;
+                                       if(v2sel) {
+                                               uvav = uv_average + 
efa->v2->tmp.l;

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