[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37965] branches/soc-2011-onion/source/ blender/editors/uvedit: smart stitch - first 'complete' edge stitch commit - except that it's not working, bug fixing on the way

Antony Riakiotakis kalast at gmail.com
Thu Jun 30 02:58:41 CEST 2011


Revision: 37965
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37965
Author:   psy-fi
Date:     2011-06-30 00:58:40 +0000 (Thu, 30 Jun 2011)
Log Message:
-----------
smart stitch - first 'complete' edge stitch commit - except that it's not working, bug fixing on the way

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_draw.c
    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-29 23:52:09 UTC (rev 37964)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_draw.c	2011-06-30 00:58:40 UTC (rev 37965)
@@ -866,18 +866,17 @@
 			glDisable(GL_BLEND);
 		}
 		glEnableClientState(GL_COLOR_ARRAY);
+
+		glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewOrig);
+		glColorPointer(4, GL_UNSIGNED_BYTE, 0, stitch_preview->previewOrigColors);
 		if(stitch_preview->mode == VERT_STITCH){
 			/* draw vert preview */
-			glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewOrig);
-			glColorPointer(4, GL_UNSIGNED_BYTE, 0, stitch_preview->previewOrigColors);
 			glPointSize(5.0);
 			glDrawArrays(GL_POINTS, 0, stitch_preview->numOfOrig);
 		}
 		else
 		{
 			/* draw edge preview */
-			glVertexPointer(2, GL_FLOAT, 0, stitch_preview->previewOrig);
-			glColorPointer(4, GL_UNSIGNED_BYTE, 0, stitch_preview->previewOrigColors);
 			glDrawArrays(GL_LINES, 0, stitch_preview->numOfOrig);
 		}
 		glPopClientAttrib();

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-29 23:52:09 UTC (rev 37964)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c	2011-06-30 00:58:40 UTC (rev 37965)
@@ -1395,7 +1395,7 @@
 					{
 						char edgeSelFlag = TF_SEL_MASK(i) | TF_SEL_MASK((i+1)%vertsPerFace);
 
-						/* need another one of there for each of the 2 verts*/
+						/* need another one of these for each of the 2 verts*/
 						UvElement **commonVertMaps2 = MEM_mallocN(state->em->totface*sizeof(UvElement *), "commonVertMaps2");
 
 						/* Is this edge selected? */
@@ -1405,7 +1405,12 @@
 							UvElement *el_iter, *element2;
 							float uv1[2][2];
 							int nverts;
+							int stackSize = 0;
+							int index1, index2;
+							UVVertAverage uv_average_tmp[2];
 
+							memset(uv_average_tmp, sizeof(uv_average_tmp), 0);
+
 							v1 = *(&editFace->v1 + i);
 							v2 = *(&editFace->v1 + (i + 1)%vertsPerFace);
 
@@ -1427,15 +1432,22 @@
 								}
 							}
 
+							index1 = element - vmap->buf;
+							index2 = element2 - vmap->buf;
+
 							element->flag |= STITCH_PROCESSED;
 							element2->flag |= STITCH_PROCESSED;
-							//preview->numOfOrig++;
+							element->flag |= STITCH_EDGE_PREVIEW;
+							preview->numOfOrig++;
 
-							uv1[0][0] = mt->uv[element->tfindex][0];
-							uv1[0][1] = mt->uv[element->tfindex][1];
-							uv1[1][0] = mt->uv[(element->tfindex + 1)%vertsPerFace][0];
-							uv1[1][1] = mt->uv[(element->tfindex + 1)%vertsPerFace][1];
+							uv_average[index1].count++;
+							uv_average[index2].count++;
 
+							uv_average[index1].uv[0] = uv1[0][0] = mt->uv[element->tfindex][0];
+							uv_average[index1].uv[1] = uv1[0][1] = mt->uv[element->tfindex][1];
+							uv_average[index2].uv[0] = uv1[1][0] = mt->uv[(element2->tfindex)][0];
+							uv_average[index2].uv[1] = uv1[1][1] = mt->uv[(element2->tfindex)][1];
+
 							/* Now iterate through all faces and find potential stitchable edges */
 							for(el_iter = vmap->vert[v1->tmp.l]; el_iter; el_iter = el_iter->next){
 								char vertCheck = 0;
@@ -1478,129 +1490,112 @@
 										element->flag |= STITCH_STITCHABLE;
 										element2->flag |= STITCH_STITCHABLE;
 
+										uv_average_tmp[0].count++;
+										uv_average_tmp[1].count++;
+										uv_average_tmp[0].uv[0] += uv2[0][0];
+										uv_average_tmp[0].uv[1] += uv2[0][1];
+										uv_average_tmp[1].uv[0] += uv2[1][0];
+										uv_average_tmp[1].uv[1] += uv2[1][1];
+
 										/* We need the UvMapVert of the other uv too. */
 										for(el_iter2 = vmap->vert[v2->tmp.l]; el_iter2; el_iter2 = el_iter2->next){
 											if(el_iter2->face == efa)
 												break;
 										}
 
+										commonVertMaps[stackSize] = el_iter;
+										commonVertMaps2[stackSize++] = el_iter2;
+
 										if(vertCheck)
 										{
 											/* convention is to use the vertex at the beginning of the edge. This avoids ambiguity
 											 * in situations where two adjacent edges on the same face need to be stitched.  */
-											el_iter->flag |= STITCH_STITCHABLE;
+											el_iter->flag |= STITCH_EDGE_PREVIEW;
 										}
 										else {
 											/* We need to flag the UvMapVert corresponding to the other vert, for the reason
 											 * outlined above. */
-											el_iter2->flag |= STITCH_STITCHABLE;
+											el_iter2->flag |= STITCH_EDGE_PREVIEW;
 										}
-										//uv_average[el_iter - vmap->buf].count++;
-										//uv_average[el_iter - vmap->buf].uv[0] +=
 									}
 								}
 							}
-						}
-						MEM_freeN(commonVertMaps2);
-					}
-				}
-			}
-		}
+							if(element->flag & STITCH_STITCHABLE &&
+							element2->flag & STITCH_STITCHABLE){
+								uv_average[index1].count += uv_average_tmp[0].count;
+								uv_average[index1].uv[0] += uv_average_tmp[0].uv[0];
+								uv_average[index1].uv[1] += uv_average_tmp[0].uv[1];
 
-		MEM_freeN(commonVertMaps);
+								uv_average[index2].count += uv_average_tmp[1].count;
+								uv_average[index2].uv[0] += uv_average_tmp[1].uv[0];
+								uv_average[index2].uv[1] += uv_average_tmp[1].uv[1];
 
+								if(editFace->tmp.l == -1)
+								{
+									if(editFace->v4)
+									{
+										editFace->tmp.l = preview->numOfQuads*8;
+										preview->numOfQuads++;
+									}
+									else {
+										editFace->tmp.l = preview->numOfTris*6;
+										preview->numOfTris++;
+									}
+								}
 
-	if(0){
+								for(; stackSize > -1; stackSize--)
+								{
 
-		// Here we store the indices corresponding to UvMapVerts that contain the first vertex of the edge.*/
-		int *faceStack = MEM_mallocN(state->em->totface*sizeof(float)*8, "quad_uv_stitch_prev");
+									index1 = commonVertMaps[stackSize] - vmap->buf, index2 = commonVertMaps2[stackSize] - vmap->buf;
+									efa = commonVertMaps[stackSize]->face;
 
-		for(; 0;){
-			// simple check to see which of the two face vertices corresponds to the original */
-			char vertCheck = 0;
-			EditVert *v1, *v2;
-			UvElement *element;
-			int stackSize = 0;
+									commonVertMaps[stackSize]->flag |= STITCH_STITCHABLE;
+									commonVertMaps2[stackSize]->flag |= STITCH_STITCHABLE;
 
-			v1 = editEdge->v1;
-			v2 = editEdge->v2;
+									uv_average[index1].count += uv_average_tmp[0].count;
+									uv_average[index1].uv[0] += uv_average_tmp[0].uv[0];
+									uv_average[index1].uv[1] += uv_average_tmp[0].uv[1];
 
-			for(element = vmap->vert[v1->tmp.l]; element; element = element->next){
-				int nverts;
-				efa = element->face;
-				nverts = efa->v4 ? 4 : 3;
-				if((vertCheck = (*(&efa->v1 + (element->tfindex + 1)%nverts) == v2)) || (*(&efa->v1 + (element->tfindex + nverts - 1)%nverts) == v2)){
-					//element->flag |= (vertCheck) ? STITCH_EDGE_PLUS : 0;
-					faceStack[stackSize++] = element - vmap->buf;
+									uv_average[index2].count += uv_average_tmp[1].count;
+									uv_average[index2].uv[0] += uv_average_tmp[1].uv[0];
+									uv_average[index2].uv[1] += uv_average_tmp[1].uv[1];
+
+									if(efa->tmp.l == -1)
+									{
+										if(efa->v4)
+										{
+											efa->tmp.l = preview->numOfQuads*8;
+											preview->numOfQuads++;
+										} else {
+											efa->tmp.l = preview->numOfTris*6;
+											preview->numOfTris++;
+										}
+									}
+								}
+							}
+						}
+						MEM_freeN(commonVertMaps2);
+					}
 				}
 			}
+		}
 
-			// Check if faces found comply with stitchability restrictions */
-			for(i = 0; i < stackSize; i++)
-			{
-				int faceIter;
-				float uv1[2][2];
-				int nverts;
-				element = vmap->buf + faceStack[i];
-				editFace = element->face;
-				nverts = (editFace->v4)? 4 : 3;
-				mt = CustomData_em_get(&state->em->fdata, editFace->data, CD_MTFACE);
+		MEM_freeN(commonVertMaps);
 
-				// Take uv's of first face */
-				uv1[0][0] = mt->uv[element->tfindex][0];
-				uv1[0][1] = mt->uv[element->tfindex][1];
-				//uv1[1][0] = (element->flag & STITCH_EDGE_PLUS)? mt->uv[(element->tfindex + 1)%nverts][0] : mt->uv[(element->tfindex + nverts - 1)%nverts][0];
-				//uv1[1][1] = (element->flag & STITCH_EDGE_PLUS)? mt->uv[(element->tfindex + 1)%nverts][1] : mt->uv[(element->tfindex + nverts - 1)%nverts][1];
 
-				// iterate through all of the rest faces and check if they are */
-				for(faceIter = i+1; faceIter < stackSize; faceIter++){
-					float uv2[2][2];
-					MTFace *tmptface;
-					UvElement *mapVertIter = vmap->buf + faceStack[faceIter];
-					efa = mapVertIter->face;
-					nverts = (efa->v4)? 4 : 3;
 
-					tmptface = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
-
-					// Take uv's of second face */
-					uv2[0][0] = tmptface->uv[mapVertIter->tfindex][0];
-					uv2[0][1] = tmptface->uv[mapVertIter->tfindex][1];
-					//uv2[1][0] = (mapVertIter->flag & STITCH_EDGE_PLUS)? tmptface->uv[(mapVertIter->tfindex + 1)%nverts][0] : tmptface->uv[(mapVertIter->tfindex + nverts - 1)%nverts][0];
-					//uv2[1][1] = (mapVertIter->flag & STITCH_EDGE_PLUS)? tmptface->uv[(mapVertIter->tfindex + 1)%nverts][1] : tmptface->uv[(mapVertIter->tfindex + nverts - 1)%nverts][1];
-
-					// Actual checks */
-					if(fabs((uv1[0][0] - uv2[0][0]) < STD_UV_CONNECT_LIMIT) &&
-						(fabs(uv1[0][1] - uv2[0][1]) < STD_UV_CONNECT_LIMIT) &&
-						fabs((uv1[1][0] - uv2[1][0]) < STD_UV_CONNECT_LIMIT) &&
-						(fabs(uv1[1][1] - uv2[1][1]) < STD_UV_CONNECT_LIMIT))
-					{
-						// Coincident UV's so non-stitchable edge. */
-						continue;
-					}
-					else if(state->use_limit && ( fabs(uv1[0][0] - uv2[0][0]) > state->limitDist ||
-						fabs(uv1[0][1] - uv2[0][1]) > state->limitDist ||
-						fabs(uv1[1][0] - uv2[1][0]) > state->limitDist ||
-						fabs(uv1[1][1] - uv2[1][1]) > state->limitDist))
-					{
-						// Both UVs out of stitch range */
-						continue;
-					}
-					else {
-						// Stitchable case, do the necessary stuff */
-					}
-				}
-			}
-		}
-	}
-
 	if(!final)
 	{
 		/* 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");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list