Revision: 37766
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37766
Author:   psy-fi
Date:     2011-06-23 20:46:06 +0000 (Thu, 23 Jun 2011)
Log Message:
-----------
smart stitch - previewable colors for vertices, vertices that can be stitched 
will be painted green while vertices that cannot be stitched will be red + fix 
for warning message on object scale != 1.0

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
    branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_unwrap_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-23 19:55:47 UTC (rev 37765)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_draw.c 
2011-06-23 20:46:06 UTC (rev 37766)
@@ -835,36 +835,44 @@
        }
 
        /* finally draw stitch preview */
-       if((stitch_preview) && stitch_preview->enabled){
+       if(stitch_preview){
                glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
-               glEnable(GL_BLEND);
-               glEnable(GL_VERTEX_ARRAY);
+               glEnableClientState(GL_VERTEX_ARRAY);
+               if(stitch_preview->enabled){
+                       glEnable(GL_BLEND);
 
-               glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewTris);
-               glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-               glColor4f(0.0, 1.0, 0.0, 0.2);
-               glDrawArrays(GL_TRIANGLES, 0, stitch_preview->numOfTris*3);
-               glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-               glColor4f(1.0, 0.0, 1.0, 0.2);
-               glDrawArrays(GL_TRIANGLES, 0, stitch_preview->numOfTris*3);
-               glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
-               glColor4f(0.0, 0.0, 1.0, 0.5);
-               glDrawArrays(GL_TRIANGLES, 0, stitch_preview->numOfTris*3);
+                       glVertexPointer(2, GL_FLOAT, 0, 
stitch_preview->previewTris);
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+                       glColor4f(0.5, 0.5, 0.0, 0.2);
+                       glDrawArrays(GL_TRIANGLES, 0, 
stitch_preview->numOfTris*3);
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+                       glColor4f(1.0, 0.0, 1.0, 0.2);
+                       glDrawArrays(GL_TRIANGLES, 0, 
stitch_preview->numOfTris*3);
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+                       glColor4f(0.0, 0.0, 1.0, 0.5);
+                       glDrawArrays(GL_TRIANGLES, 0, 
stitch_preview->numOfTris*3);
 
-               glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewQuads);
-               glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-               glColor4f(0.0, 1.0, 0.0, 0.5);
-               glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
-               glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-               glColor4f(1.0, 0.0, 1.0, 0.5);
-               glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
-               glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
-               glColor4f(0.0, 0.0, 1.0, 0.5);
-               glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
+                       glVertexPointer(2, GL_FLOAT, 0, 
stitch_preview->previewQuads);
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+                       glColor4f(0.5, 0.5, 0.0, 0.2);
+                       glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+                       glColor4f(1.0, 0.0, 1.0, 0.2);
+                       glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+                       glColor4f(0.0, 0.0, 1.0, 0.2);
+                       glDrawArrays(GL_QUADS, 0, stitch_preview->numOfQuads*4);
 
+                       glDisable(GL_BLEND);
+               }
+               glEnableClientState(GL_COLOR_ARRAY);
+               glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewPoints);
+               glColorPointer(4, GL_UNSIGNED_BYTE, 0, 
stitch_preview->previewPointColors);
+               glPointSize(5.0);
+               glDrawArrays(GL_POINTS, 0, stitch_preview->numOfPoints);
+
                glPopClientAttrib();
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-               glDisable(GL_BLEND);
        }
 
        glPointSize(1.0);

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-23 19:55:47 UTC (rev 37765)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h       
2011-06-23 20:46:06 UTC (rev 37766)
@@ -67,7 +67,7 @@
 #define TF_SEL_MASK(id) (TF_SEL1 << id)
 
 /* margin for scale to differ from 1.0 for printing debug info */
-#define UNWRAP_SCALE_EPSILON 0.0001
+#define UNWRAP_SCALE_EPSILON 0.00001
 
 /* geometric utilities */
 void uv_center(float uv[][2], float cent[2], int quad);

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-23 19:55:47 UTC (rev 37765)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-06-23 20:46:06 UTC (rev 37766)
@@ -73,6 +73,9 @@
 
 #include "uvedit_intern.h"
 
+#define STITCH_STITCHABLE 1
+#define STITCH_UNSTITCHABLE 2
+
 /************************* state testing ************************/
 
 int ED_uvedit_test(Object *obedit)
@@ -1237,6 +1240,7 @@
        /* Store Indices to editVerts */
        for(editVert = state->em->verts.first, i = 0; editVert; editVert = 
editVert->next, i++){
                editVert->tmp.t = i;
+               editVert->f1 = 0;
        }
 
        /* Make face array and initialize position in preview buffer */
@@ -1248,52 +1252,70 @@
        /* 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 UV selected... */
+               /* 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))
                                {
+                                       EditVert *vt = *(&(editFace->v1)+i);
                                        /* ...we'll iterate through all shared 
UV's of the corresponding vertex */
-                                       UvMapVert *mapVert = 
vmap->vert[(*(&(editFace->v1)+i))->tmp.t];
-                                       /* flag is not set anywhere so assuming 
it's safe to set to indicate use for preview */
-                                       mapVert->flag = 1;
+                                       UvMapVert *mapVert = 
vmap->vert[vt->tmp.t];
+                                       int numOfPreviewPoints = 0;
 
-                                       while(mapVert){
-                                               MTFace *tmptface;
+                                       /* Have we traversed this vertex 
before? */
+                                       if(vt->f1 == 0){
+                                               vt->f1 = STITCH_UNSTITCHABLE;
 
-                                               efa = faceArray[mapVert->f];
-                                               tmptface = 
CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+                                               while(mapVert){
+                                                       MTFace *tmptface;
 
-                                               preview->numOfPoints++;
+                                                       efa = 
faceArray[mapVert->f];
+                                                       tmptface = 
CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+                                                       numOfPreviewPoints++;
 
-                                               
uv_average[(*(&(editFace->v1)+i))->tmp.t].count++;
-                                               
uv_average[(*(&(editFace->v1)+i))->tmp.t].uv[0] += 
tmptface->uv[mapVert->tfindex][0];
-                                               
uv_average[(*(&(editFace->v1)+i))->tmp.t].uv[1] += 
tmptface->uv[mapVert->tfindex][1];
+                                                       /* should probably 
change these limits to something better. Still it will do for now. */
+                                                       if(fabs((mt->uv[i][0] - 
tmptface->uv[mapVert->tfindex][0]) > 0.001) ||
+                                                               
(fabs(mt->uv[i][1] - tmptface->uv[mapVert->tfindex][1]) > 0.001) ){
+                                                               vt->f1 = 
STITCH_STITCHABLE;
+                                                       }
 
-                                               mapVert = mapVert->next;
 
-                                               /* store position in the 
preview buffer */
-                                               if(efa->tmp.l == -1)
-                                               {
-                                                       if(efa->v4)
+                                                       
uv_average[vt->tmp.t].count++;
+                                                       
uv_average[vt->tmp.t].uv[0] += tmptface->uv[mapVert->tfindex][0];
+                                                       
uv_average[vt->tmp.t].uv[1] += tmptface->uv[mapVert->tfindex][1];
+
+                                                       mapVert = mapVert->next;
+
+                                                       /* store position in 
the preview buffer */
+                                                       if(efa->tmp.l == -1)
                                                        {
-                                                               efa->tmp.l = 
preview->numOfQuads*8;
-                                                               
preview->numOfQuads++;
+                                                               if(efa->v4)
+                                                               {
+                                                                       
efa->tmp.l = preview->numOfQuads*8;
+                                                                       
preview->numOfQuads++;
+                                                               }
+                                                               else {
+                                                                       
efa->tmp.l = preview->numOfTris*6;
+                                                                       
preview->numOfTris++;
+                                                               }
                                                        }
-                                                       else {
-                                                               efa->tmp.l = 
preview->numOfTris*6;
-                                                               
preview->numOfTris++;
-                                                       }
                                                }
+                                               /* Increase number of preview 
points accordingly */
+                                               if(vt->f1 == 
STITCH_UNSTITCHABLE)
+                                               {
+                                                       preview->numOfPoints++;
+                                               } else {
+                                                       preview->numOfPoints += 
numOfPreviewPoints;
+                                               }
                                        }
                                }
                        }
                }
        }
 
-               /* Initialize the preview buffers */
+       /* Initialize the preview buffers */
        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");
        preview->previewPoints = (float 
*)MEM_mallocN(preview->numOfPoints*sizeof(float)*2, "stitch_preview_points");
@@ -1316,35 +1338,47 @@
        }
 
        for(editVert = state->em->verts.first; editVert; editVert = 
editVert->next){
-                       short stitchable;
                        UvMapVert *mapVert = vmap->vert[editVert->tmp.t];
 
-                       if(mapVert->flag){
-                               /* UV's that have a corresponding stitchable UV 
have a mapVert->next */
-                               stitchable = (mapVert->next != NULL);
 
-                               while(mapVert){
-                                       float uv[2];
-                                       int averageBufIndex;
-                                       efa = faceArray[mapVert->f];
 
-                                       averageBufIndex = (*(&(efa->v1) + 
mapVert->tfindex))->tmp.t;
-                                       uv[0] = 
uv_average[averageBufIndex].uv[0]/uv_average[averageBufIndex].count;
-                                       uv[1] = 
uv_average[averageBufIndex].uv[1]/uv_average[averageBufIndex].count;
-                                       
preview->previewPoints[bufferIterator*2] = uv[0];
-                                       preview->previewPoints[bufferIterator*2 
+ 1] = uv[1];
-                                       /* stitchable uv's will be green, 
non-stitchable red */
-                                       
preview->previewPointColors[bufferIterator] = stitchable? 
(0x00FF0000):(0x0000FF00);
+                       if(editVert->f1 != 0){
+                               short stitchable = (editVert->f1 == 
STITCH_STITCHABLE);
 
-                                       if(efa->v4){
-                                               
preview->previewQuads[efa->tmp.l + 2*mapVert->tfindex] = uv[0];
-                                               
preview->previewQuads[efa->tmp.l + 2*mapVert->tfindex + 1] = uv[1];
+                               if(stitchable){
+                                       while(mapVert){
+                                               float uv[2];
+                                               int averageBufIndex;
+                                               efa = faceArray[mapVert->f];
+                                               mt = 
CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+                                               averageBufIndex = (*(&(efa->v1) 
+ mapVert->tfindex))->tmp.t;
+                                               uv[0] = 
uv_average[averageBufIndex].uv[0]/uv_average[averageBufIndex].count;
+                                               uv[1] = 
uv_average[averageBufIndex].uv[1]/uv_average[averageBufIndex].count;
+                                               
preview->previewPoints[bufferIterator*2] = mt->uv[mapVert->tfindex][0];
+                                               
preview->previewPoints[bufferIterator*2 + 1] = mt->uv[mapVert->tfindex][1];
+                                               /* stitchable uv's will be 
green, non-stitchable red */
+                                               
preview->previewPointColors[bufferIterator] = 0x0000FF00;
+
+                                               if(efa->v4){
+                                                       
preview->previewQuads[efa->tmp.l + 2*mapVert->tfindex] = uv[0];
+                                                       
preview->previewQuads[efa->tmp.l + 2*mapVert->tfindex + 1] = uv[1];
+                                               }
+                                               else {
+                                                       
preview->previewTris[efa->tmp.l + 2*mapVert->tfindex]  = uv[0];
+                                                       
preview->previewTris[efa->tmp.l + 2*mapVert->tfindex + 1] = uv[1];
+                                               }
+                                               mapVert = mapVert->next;
+                                               bufferIterator++;
                                        }
-                                       else {
-                                               preview->previewTris[efa->tmp.l 
+ 2*mapVert->tfindex]  = uv[0];

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