[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38422] branches/soc-2011-onion/source/ blender/editors/uvedit/uvedit_ops.c: seams from islands commit #2

Antony Riakiotakis kalast at gmail.com
Sat Jul 16 01:27:26 CEST 2011


Revision: 38422
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38422
Author:   psy-fi
Date:     2011-07-15 23:27:26 +0000 (Fri, 15 Jul 2011)
Log Message:
-----------
seams from islands commit #2
============================
-After a lot of experimentation setting on one mode of operation: If one of the UV's is disconnected, tag seam. The other scheme(tagging if both uv's were disconnected) was giving a lot of false cases and strange results. Completely reimplemented operator. Should work correctly now. This needed a lot of trial and error and I am afraid the logic is not easy to follow but I think it works, at least it does in 2 difficult cases I've fed it with.

Looks like that's it! enjoy your new tool under UV's->Seams From Islands :)

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

Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c	2011-07-15 20:44:19 UTC (rev 38421)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c	2011-07-15 23:27:26 UTC (rev 38422)
@@ -73,15 +73,6 @@
 
 #include "uvedit_intern.h"
 
-#define SFI_ISLAND_SEMANTICS 1
-#define SFI_EDGE_SEMANTICS 2
-
-EnumPropertyItem island_to_seam_items[] = {
-	{SFI_ISLAND_SEMANTICS, "ISLAND_SEMANTICS", 0, "Island Semantics", "Tag seams only if both of its UVs are unconnected"},
-	{SFI_EDGE_SEMANTICS, "EDGE_SEMANTICS", 0, "Edge Semantics", "Tag seams even if one of its UVs is unconnected"},
-	{0, NULL, 0, NULL, NULL}};
-
-
 /************************* state testing ************************/
 
 int ED_uvedit_test(Object *obedit)
@@ -3887,6 +3878,7 @@
 	RNA_def_int_vector(ot->srna, "tile", 2, NULL, 0, INT_MAX, "Tile", "Tile coordinate.", 0, 10);
 }
 
+
 static int seams_from_islands_exec(bContext *C, wmOperator *op)
 {
 	UvVertMap *vmap;
@@ -3894,7 +3886,6 @@
 	EditMesh *em;
 	EditEdge *editedge;
 	float limit[2] = {STD_UV_CONNECT_LIMIT, STD_UV_CONNECT_LIMIT};
-	int operationMode = RNA_enum_get(op->ptr,  "island_to_seam_items");
 
 	em = BKE_mesh_get_editmesh(ob->data);
 	if(!EM_texFaceCheck(em)){
@@ -3902,41 +3893,86 @@
 		BKE_mesh_end_editmesh(ob->data, em);
 	}
 
-	/* important, make_uv_vert_map sets tmp.l of editverts to their index,
-	 * will be used later */
-	vmap = EM_make_uv_vert_map(em, 0, 1, limit);
+	/* This code sets editvert->tmp.l to the index. This will be useful later on. */
+	EM_init_index_arrays(em, 0, 0, 1);
+	vmap = EM_make_uv_vert_map(em, 0, 0, limit);
 
 	for(editedge = em->edges.first; editedge; editedge = editedge->next){
-		char flag1 = 0, flag2 = 0;
-		UvMapVert *mapVert, *initMapVert;
-		/* first clean previous seam flag */
-		editedge->seam = 0;
+			/* flags to determine if we uv is separated from first editface match */
+			char separated1 = 0, separated2;
+			/* set to denote edge must be flagged as seam */
+			char faces_separated = 0;
+			/* flag to keep track if uv1 is disconnected from first editface match */
+			char v1coincident = 1;
+			/* For use with v1coincident. v1coincident will change only if we've had commonFaces */
+			int commonFaces = 0;
 
-		initMapVert = vmap->vert[editedge->v1->tmp.l];
-		for(mapVert = initMapVert; mapVert; mapVert = mapVert->next){
-			/* if there are uv's that are not coincident, flag the vert */
-			if(mapVert->separate && mapVert != initMapVert){
-				flag1 = 1;
-				break;
+			EditFace *efa1, *efa2;
+
+			UvMapVert *mv1, *mvinit1, *mv2, *mvinit2, *mviter;
+			/* mv2cache stores the first of the list of coincident uv's for later comparison
+			 * mv2sep holds the last separator and is copied to mv2cache hen a hit is first found */
+			UvMapVert *mv2cache = NULL, *mv2sep;
+
+			mvinit1 = vmap->vert[editedge->v1->tmp.l];
+
+			editedge->seam = 0;
+
+			for(mv1 = mvinit1; mv1 && !faces_separated; mv1 = mv1->next){
+				if(mv1->separate && commonFaces){
+					v1coincident = 0;
+				}
+
+				separated2 = 0;
+				efa1 = EM_get_face_for_index(mv1->f);
+				mvinit2 = vmap->vert[editedge->v2->tmp.l];
+
+				for(mv2 = mvinit2; mv2; mv2 = mv2->next){
+					if(mv2->separate){
+						mv2sep = mv2;
+					}
+
+					efa2 = EM_get_face_for_index(mv2->f);
+					if(efa1 == efa2){
+						/* if v1 is not coincident no point in comparing */
+						if(v1coincident){
+							/* have we found previously anything? */
+							if(mv2cache){
+								/* flag seam unless proved to be coincident with previous hit */
+								separated2 = 1;
+								for(mviter = mv2cache; mviter; mviter = mviter->next){
+									if(mviter->separate && mviter != mv2cache)
+										break;
+									/* coincident with previous hit, do not flag seam */
+									if(mviter == mv2)
+										separated2 = 0;
+								}
+							}
+							/* First hit case, store the hit in the cache */
+							else {
+								mv2cache = mv2sep;
+								commonFaces = 1;
+							}
+						}else {
+							separated1 = 1;
+						}
+
+						if(separated1 || separated2){
+							faces_separated = 1;
+							break;
+						}
+					}
+				}
 			}
-		}
 
-		initMapVert = vmap->vert[editedge->v2->tmp.l];
-		for(mapVert = initMapVert; mapVert; mapVert = mapVert->next){
-			/* if there are uv's that are not coincident, flag the vert */
-			if(mapVert->separate && mapVert != initMapVert){
-				flag2 = 1;
-				break;
+			if(faces_separated){
+				editedge->seam = 1;
 			}
-		}
 
-		if(flag1 && flag2){
-			editedge->seam = 1;
-		}
 	}
 
 	EM_free_uv_vert_map(vmap);
-
+	EM_free_index_arrays();
 	BKE_mesh_end_editmesh(ob->data, em);
 
 	DAG_id_tag_update(ob->data, 0);
@@ -3945,6 +3981,7 @@
 	return OPERATOR_FINISHED;
 }
 
+
 static void UV_OT_seams_from_islands(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -3952,15 +3989,12 @@
 	ot->description= "Set mesh seams according to island setup in the UV editor";
 	ot->idname= "UV_OT_seams_from_islands";
 
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
 	/* api callbacks */
 	ot->exec= seams_from_islands_exec;
-	ot->poll= ED_operator_image_active;	/* requires space image */;
-
-	/* properties */
-	RNA_def_enum(ot->srna, "island_to_seam_items", island_to_seam_items, 1, "Semantics", "");
-
-	/* flags */
-	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+	ot->poll= ED_operator_uvmap;
 }
 
 /* ************************** registration **********************************/




More information about the Bf-blender-cvs mailing list