[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44309] trunk/blender/source/blender: Stitch tool fully functional again.

Antony Riakiotakis kalast at gmail.com
Wed Feb 22 01:06:25 CET 2012


Revision: 44309
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44309
Author:   psy-fi
Date:     2012-02-22 00:06:15 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
Stitch tool fully functional again. Many thanks to Howard Trickey for proposing the loop winding criterion for normal disambiguation of edges. Unfortunately some extra memory has to be allocated for this to work correctly. If the tool had been initially written for bmesh I would have used the already present adjacency information to make it work, avoiding some extra allocations. Maybe a project for another day though, when I am more proficient with bmesh internals.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_mesh.h
    trunk/blender/source/blender/editors/mesh/bmesh_utils.c
    trunk/blender/source/blender/editors/uvedit/uvedit_draw.c
    trunk/blender/source/blender/editors/uvedit/uvedit_intern.h
    trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c

Modified: trunk/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mesh.h	2012-02-21 19:41:38 UTC (rev 44308)
+++ trunk/blender/source/blender/blenkernel/BKE_mesh.h	2012-02-22 00:06:15 UTC (rev 44309)
@@ -194,6 +194,8 @@
 	struct BMFace *face;
 	/* Index in the editFace of the uv */
 	struct BMLoop *l;
+	/* index in loop. */
+	unsigned short tfindex;
 	/* Whether this element is the first of coincident elements */
 	unsigned char separate;
 	/* general use flag */

Modified: trunk/blender/source/blender/editors/mesh/bmesh_utils.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/bmesh_utils.c	2012-02-21 19:41:38 UTC (rev 44308)
+++ trunk/blender/source/blender/editors/mesh/bmesh_utils.c	2012-02-22 00:06:15 UTC (rev 44309)
@@ -769,18 +769,17 @@
 	BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
 		island_number[j++] = INVALID_ISLAND;
 		if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT))) {
-			i = 0;
-			BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
+			BM_ITER_INDEX(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa, i) {
 				buf->l = l;
 				buf->face = efa;
 				buf->separate = 0;
 				buf->island = INVALID_ISLAND;
+				buf->tfindex = i;
 
 				buf->next = element_map->vert[BM_elem_index_get(l->v)];
 				element_map->vert[BM_elem_index_get(l->v)] = buf;
 
 				buf++;
-				i++;
 			}
 		}
 	}
@@ -865,6 +864,7 @@
 								islandbuf[islandbufsize].l = element->l;
 								islandbuf[islandbufsize].face = element->face;
 								islandbuf[islandbufsize].separate = element->separate;
+								islandbuf[islandbufsize].tfindex = element->tfindex;
 								islandbuf[islandbufsize].island =  nislands;
 								islandbufsize++;
 

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_draw.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_draw.c	2012-02-21 19:41:38 UTC (rev 44308)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_draw.c	2012-02-22 00:06:15 UTC (rev 44309)
@@ -877,6 +877,7 @@
 
 	/* finally draw stitch preview */
 	if(stitch_preview) {
+		int i, index = 0;
 		glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
 		glEnableClientState(GL_VERTEX_ARRAY);
 
@@ -887,13 +888,17 @@
 		glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_tris);
 		glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris*3);
 
-		glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_tris);
-		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-		UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
-		glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);
-		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-		UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
-		glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);
+		glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_polys);
+		for(i = 0; i < stitch_preview->num_polys; i++){
+			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+			UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
+			glDrawArrays(GL_POLYGON, index, stitch_preview->uvs_per_polygon[i]);
+			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+			UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
+			glDrawArrays(GL_POLYGON, index, stitch_preview->uvs_per_polygon[i]);
+
+			index += stitch_preview->uvs_per_polygon[i];
+		}
 		glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
 		/*UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
 		glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);*/

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_intern.h
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_intern.h	2012-02-21 19:41:38 UTC (rev 44308)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_intern.h	2012-02-22 00:06:15 UTC (rev 44309)
@@ -89,17 +89,18 @@
 /* object that stores display data for previewing before accepting stitching */
 typedef struct StitchPreviewer {
 	/* here we'll store the preview triangle indices of the mesh */
-	unsigned int *preview_tris;
-	/* here we store the actual uv vertices to display */
-	float *preview_coords;
+	float *preview_polys;
+	/* uvs per polygon. */
+	unsigned int *uvs_per_polygon;
+	/*number of preview polygons */
+	unsigned int num_polys;
 	/* preview data. These will be either the previewed vertices or edges depending on stitch mode settings */
 	float *preview_stitchable;
 	float *preview_unstitchable;
-	/* here we'll store the number of triangles and quads to be drawn */
-	unsigned int num_tris;
+	/* here we'll store the number of elements to be drawn */
 	unsigned int num_stitchable;
 	unsigned int num_unstitchable;
-
+	unsigned int preview_uvs;
 	/* ...and here we'll store the triangles*/
 	float *static_tris;
 	unsigned int num_static_tris;

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c	2012-02-21 19:41:38 UTC (rev 44308)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c	2012-02-22 00:06:15 UTC (rev 44309)
@@ -143,7 +143,10 @@
 	unsigned int *tris_per_island;
 } StitchState;
 
-
+typedef struct PreviewPosition{
+	int data_position;
+	int polycount_position;
+}PreviewPosition;
 /*
  * defines for UvElement flags
  */
@@ -162,12 +165,13 @@
 static StitchPreviewer * stitch_preview_init(void)
 {
 	_stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), "stitch_previewer");
-	_stitch_preview->preview_tris = NULL;
-	_stitch_preview->preview_coords = NULL;
+	_stitch_preview->preview_polys = NULL;
 	_stitch_preview->preview_stitchable = NULL;
 	_stitch_preview->preview_unstitchable = NULL;
+	_stitch_preview->uvs_per_polygon = NULL;
 
-	_stitch_preview->num_tris = 0;
+	_stitch_preview->preview_uvs = 0;
+	_stitch_preview->num_polys = 0;
 	_stitch_preview->num_stitchable = 0;
 	_stitch_preview->num_unstitchable = 0;
 
@@ -183,10 +187,14 @@
 {
 	if(_stitch_preview)
 	{
-		if(_stitch_preview->preview_tris){
-			MEM_freeN(_stitch_preview->preview_tris);
-			_stitch_preview->preview_tris = NULL;
+		if(_stitch_preview->preview_polys){
+			MEM_freeN(_stitch_preview->preview_polys);
+			_stitch_preview->preview_polys = NULL;
 		}
+		if(_stitch_preview->uvs_per_polygon){
+			MEM_freeN(_stitch_preview->uvs_per_polygon);
+			_stitch_preview->uvs_per_polygon = NULL;
+		}
 		if(_stitch_preview->preview_stitchable){
 			MEM_freeN(_stitch_preview->preview_stitchable);
 			_stitch_preview->preview_stitchable = NULL;
@@ -199,10 +207,6 @@
 			MEM_freeN(_stitch_preview->static_tris);
 			_stitch_preview->static_tris = NULL;
 		}
-		if(_stitch_preview->preview_coords){
-			MEM_freeN(_stitch_preview->preview_coords);
-			_stitch_preview->preview_coords = NULL;
-		}
 
 		MEM_freeN(_stitch_preview);
 		_stitch_preview = NULL;
@@ -299,7 +303,7 @@
 
 
 /* calculate snapping for islands */
-static void stitch_calculate_island_snapping(StitchState *state, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final){
+static void stitch_calculate_island_snapping(StitchState *state, PreviewPosition *preview_position, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final){
 	int i;
 	UvElement *element;
 
@@ -330,18 +334,17 @@
 
 						stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, luv->uv);
 
-						luv->uv[0] += island_stitch_data[i].translation[0];
-						luv->uv[1] += island_stitch_data[i].translation[1];
+						add_v2_v2(luv->uv, island_stitch_data[i].translation);
 					}
 
-					else {//if(preview_position[BM_elem_index_get(efa)] != STITCH_NO_PREVIEW){
-						/* BMESH_TODO preview
-						stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->preview_tris[efa->tmp.l + 2*element->tfindex]);
+					else {
+						int face_preview_pos = preview_position[BM_elem_index_get(element->face)].data_position;
 
-						preview->preview_tris[efa->tmp.l + 2*element->tfindex]  += island_stitch_data[i].translation[0];
-						preview->preview_tris[efa->tmp.l + 2*element->tfindex + 1] += island_stitch_data[i].translation[1];
-						*/
-						(void)preview;
+						stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint,
+								preview->preview_polys + face_preview_pos + 2*element->tfindex);
+
+						add_v2_v2(preview->preview_polys + face_preview_pos + 2*element->tfindex,
+								island_stitch_data[i].translation);
 					}
 				}
 				/* cleanup */
@@ -494,24 +497,22 @@
 
 
 /* set preview buffer position of UV face in editface->tmp.l */
-static void stitch_set_face_preview_buffer_position(BMFace *efa, StitchPreviewer *preview, unsigned int *preview_position)
+static void stitch_set_face_preview_buffer_position(BMFace *efa, StitchPreviewer *preview, PreviewPosition *preview_position)
 {
 	int index = BM_elem_index_get(efa);
 
-	if(preview_position[index] == STITCH_NO_PREVIEW)
+	if(preview_position[index].data_position == STITCH_NO_PREVIEW)
 	{
-		//int num_of_tris = (efa->len > 2)? efa->len-2 : 0;
-		//preview->num_tris*3;
-
-		/* BMESH_TODO, count per face triangles */
-		//preview->num_tris += num_of_tris;
+		preview_position[index].data_position = preview->preview_uvs*2;
+		preview_position[index].polycount_position = preview->num_polys++;
+		preview->preview_uvs += efa->len;
 	}
 }
 
 
 /* setup face preview for all coincident uvs and their faces */
 static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data,
-		unsigned int *preview_position){
+		PreviewPosition *preview_position){
 	StitchPreviewer *preview = uv_get_stitch_previewer();
 
 	/* static island does not change so returning immediately */
@@ -531,7 +532,7 @@
 
 /* checks if uvs are indeed stitchable and registers so that they can be shown in preview */
 static void stitch_validate_stichability (UvElement *element, StitchState *state, IslandStitchData *island_stitch_data,
-		unsigned int *preview_position){
+		PreviewPosition *preview_position){
 	UvElement *element_iter;
 	StitchPreviewer *preview;
 	int vert_index;
@@ -579,7 +580,7 @@
 	/* used to map uv indices to uvaverage indices for selection */
 	unsigned int *uvfinal_map;
 	/* per face preview position in preview buffer */
-	unsigned int *preview_position;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list