[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44307] trunk/blender/source/blender/ editors/uvedit: uv stitch static island highlight ported to bmesh system.

Antony Riakiotakis kalast at gmail.com
Tue Feb 21 19:20:47 CET 2012


Revision: 44307
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44307
Author:   psy-fi
Date:     2012-02-21 18:20:47 +0000 (Tue, 21 Feb 2012)
Log Message:
-----------
uv stitch static island highlight ported to bmesh system.

Unfortunately since we are missing a way to tesselate uvs, the result will look good only on concave faces since we are essentially using a triangle fan to draw. When a tesselation of uv polygons is possible the tool should also change to use that instead. This will also influence the preview drawing code, coming next.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/uvedit/uvedit_intern.h
    trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_intern.h
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_intern.h	2012-02-21 18:15:28 UTC (rev 44306)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_intern.h	2012-02-21 18:20:47 UTC (rev 44307)
@@ -88,8 +88,10 @@
 
 /* object that stores display data for previewing before accepting stitching */
 typedef struct StitchPreviewer {
-	/* here we'll store the preview triangles of the mesh */
-	float *preview_tris;
+	/* 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;
 	/* preview data. These will be either the previewed vertices or edges depending on stitch mode settings */
 	float *preview_stitchable;
 	float *preview_unstitchable;

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c	2012-02-21 18:15:28 UTC (rev 44306)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c	2012-02-21 18:20:47 UTC (rev 44307)
@@ -140,7 +140,6 @@
 	/* island that stays in place */
 	int static_island;
 	/* store number of primitives per face so that we can allocate the active island buffer later */
-	unsigned int *quads_per_island;
 	unsigned int *tris_per_island;
 } StitchState;
 
@@ -164,6 +163,7 @@
 {
 	_stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), "stitch_previewer");
 	_stitch_preview->preview_tris = NULL;
+	_stitch_preview->preview_coords = NULL;
 	_stitch_preview->preview_stitchable = NULL;
 	_stitch_preview->preview_unstitchable = NULL;
 
@@ -199,6 +199,11 @@
 			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;
 	}
@@ -296,7 +301,6 @@
 /* calculate snapping for islands */
 static void stitch_calculate_island_snapping(StitchState *state, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final){
 	int i;
-	BMFace *efa;
 	UvElement *element;
 
 	for(i = 0; i <  state->element_map->totalIslands; i++){
@@ -322,8 +326,6 @@
 					l = BM_iter_at_index(state->em->bm, BM_LOOPS_OF_FACE, element->face, element->tfindex);
 					luv = CustomData_bmesh_get(&state->em->bm->ldata, l->head.data, CD_MLOOPUV);
 
-					efa = element->face;
-
 					if(final){
 
 						stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, luv->uv);
@@ -331,24 +333,16 @@
 						luv->uv[0] += island_stitch_data[i].translation[0];
 						luv->uv[1] += island_stitch_data[i].translation[1];
 					}
-					/* BMESH_TODO preview
-					else if(efa->tmp.l != STITCH_NO_PREVIEW){
-						if(efa->v4){
 
-							stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->preview_quads[efa->tmp.l + 2*element->tfindex]);
+					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]);
 
-							preview->preview_quads[efa->tmp.l + 2*element->tfindex] += island_stitch_data[i].translation[0];
-							preview->preview_quads[efa->tmp.l + 2*element->tfindex + 1] += island_stitch_data[i].translation[1];
-						}
-						else {
-
-							stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->preview_tris[efa->tmp.l + 2*element->tfindex]);
-
-							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;
+						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;
+					}
 				}
 				/* cleanup */
 				element->flag &= STITCH_SELECTED;
@@ -455,9 +449,6 @@
 		if(stitch_state->selection_stack){
 			MEM_freeN(stitch_state->selection_stack);
 		}
-		if(stitch_state->quads_per_island){
-			MEM_freeN(stitch_state->quads_per_island);
-		}
 		if(stitch_state->tris_per_island){
 			MEM_freeN(stitch_state->tris_per_island);
 		}
@@ -509,10 +500,11 @@
 
 	if(preview_position[index] == STITCH_NO_PREVIEW)
 	{
-		preview_position[index] = preview->num_tris*6;
+		//int num_of_tris = (efa->len > 2)? efa->len-2 : 0;
+		//preview->num_tris*3;
 
 		/* BMESH_TODO, count per face triangles */
-		//preview->num_tris += 4;
+		//preview->num_tris += num_of_tris;
 	}
 }
 
@@ -660,12 +652,14 @@
 	 * Setup the preview buffers and fill them with the appropriate data *
 	 *********************************************************************/
 	if(!final){
+		BMIter liter;
 		BMLoop *l;
 		MLoopUV *luv;
-		unsigned int tricount = 0;
+		unsigned int buffer_index = 0;
 		int stitchBufferIndex = 0, unstitchBufferIndex = 0;
 		/* initialize the preview buffers */
-		preview->preview_tris = (float *)MEM_mallocN(preview->num_tris*sizeof(float)*6, "tri_uv_stitch_prev");
+		preview->preview_tris = (unsigned int *)MEM_mallocN(preview->num_tris*sizeof(unsigned int)*3, "tri_uv_stitch_prev");
+		preview->preview_coords = (float *)MEM_mallocN(state->total_separate_uvs*sizeof(float)*2, "co_uv_stitch_prev");
 
 		preview->preview_stitchable = (float *)MEM_mallocN(preview->num_stitchable*sizeof(float)*2, "stitch_preview_stichable_data");
 		preview->preview_unstitchable = (float *)MEM_mallocN(preview->num_unstitchable*sizeof(float)*2, "stitch_preview_unstichable_data");
@@ -674,7 +668,7 @@
 
 		preview->num_static_tris = state->tris_per_island[state->static_island];
 		/* will cause cancel and freeing of all data structures so OK */
-		if(!preview->preview_tris || !preview->preview_stitchable || !preview->preview_unstitchable){
+		if(!preview->preview_tris || !preview->preview_stitchable || !preview->preview_unstitchable || !preview->preview_coords){
 			return 0;
 		}
 
@@ -692,10 +686,23 @@
 				}
 
 				if(element->island == state->static_island){
-					/* BMESH_TODO preview */
-					//memcpy(preview->static_tris + tricount*6, &mt->uv[0][0], 6*sizeof(float));
-					//tricount++;
-					(void)tricount;
+					int numoftris = efa->len - 2;
+					BMLoop *fl = BM_FACE_FIRST_LOOP(efa);
+					MLoopUV *fuv = CustomData_bmesh_get(&state->em->bm->ldata, fl->head.data, CD_MLOOPUV);
+					i = 0;
+					BM_ITER(l, &liter, state->em->bm, BM_LOOPS_OF_FACE, efa) {
+						if(i++ < numoftris){
+							/* using next since the first uv is already accounted for */
+							BMLoop *lnext = l->next;
+							MLoopUV *luvnext = CustomData_bmesh_get(&state->em->bm->ldata, lnext->next->head.data, CD_MLOOPUV);;
+							luv = CustomData_bmesh_get(&state->em->bm->ldata, lnext->head.data, CD_MLOOPUV);
+
+							memcpy(preview->static_tris + buffer_index, fuv->uv, 2*sizeof(float));
+							memcpy(preview->static_tris + buffer_index + 2, luv->uv, 2*sizeof(float));
+							memcpy(preview->static_tris + buffer_index + 4, luvnext->uv, 2*sizeof(float));
+							buffer_index += 6;
+						}else break;
+					}
 				}
 			}
 		}
@@ -1176,12 +1183,9 @@
 
 	/***** initialise static island preview data *****/
 
-	state->quads_per_island = MEM_mallocN(sizeof(*state->quads_per_island)*state->element_map->totalIslands,
-			"stitch island quads");
 	state->tris_per_island = MEM_mallocN(sizeof(*state->tris_per_island)*state->element_map->totalIslands,
 			"stitch island tris");
 	for(i = 0; i < state->element_map->totalIslands; i++){
-		state->quads_per_island[i] = 0;
 		state->tris_per_island[i] = 0;
 	}
 
@@ -1189,8 +1193,7 @@
 		UvElement *element = ED_get_uv_element(state->element_map, efa, 0);
 
 		if(element){
-			/* BMESH_TODO preview active island */
-			//state->tris_per_island[element->island]++;
+			state->tris_per_island[element->island] += (efa->len > 2)? efa->len-2 : 0;
 		}
 	}
 




More information about the Bf-blender-cvs mailing list