[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44100] branches/bmesh/blender/source/ blender/editors: Initial port of stitch operator for bmesh.

Antony Riakiotakis kalast at gmail.com
Tue Feb 14 01:35:36 CET 2012


Revision: 44100
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44100
Author:   psy-fi
Date:     2012-02-14 00:35:29 +0000 (Tue, 14 Feb 2012)
Log Message:
-----------
Initial port of stitch operator for bmesh.

*operator now works with few limitations:

-still no preview(will be back soon)
-rotation will not work if only one uv is stitched between islands(will need method to calculate uv normal for manifold)

Also fixed island calculation for UvElements, fixes a crash when uv sculpting with "Sculpt all islands" turned off

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c
    branches/bmesh/blender/source/blender/editors/uvedit/uvedit_draw.c
    branches/bmesh/blender/source/blender/editors/uvedit/uvedit_intern.h
    branches/bmesh/blender/source/blender/editors/uvedit/uvedit_ops.c
    branches/bmesh/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c	2012-02-13 21:27:11 UTC (rev 44099)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c	2012-02-14 00:35:29 UTC (rev 44100)
@@ -713,6 +713,8 @@
 	UvElementMap *element_map;
 	UvElement *buf;
 	UvElement *islandbuf;
+	/* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */
+	int *island_number;
 
 	MLoopUV *luv;
 	int totverts, i, totuv, j, nislands = 0, islandbufsize = 0;
@@ -726,6 +728,11 @@
 	totverts = em->bm->totvert;
 	totuv = 0;
 
+	island_number = MEM_mallocN(sizeof(*stack)*em->bm->totface, "uv_island_number_face");
+	if (!island_number) {
+		return NULL;
+	}
+
 	/* generate UvElement array */
 	BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
 		if (!selected || ((!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) && BM_elem_flag_test(efa, BM_ELEM_SELECT)))
@@ -733,10 +740,12 @@
 	}
 
 	if (totuv == 0) {
+		MEM_freeN(island_number);
 		return NULL;
 	}
 	element_map = (UvElementMap *)MEM_callocN(sizeof(*element_map), "UvElementMap");
 	if (!element_map) {
+		MEM_freeN(island_number);
 		return NULL;
 	}
 	element_map->totalUVs = totuv;
@@ -745,10 +754,13 @@
 
 	if (!element_map->vert || !element_map->buf) {
 		EDBM_free_uv_element_map(element_map);
+		MEM_freeN(island_number);
 		return NULL;
 	}
 
+	j = 0;
 	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) {
@@ -821,13 +833,10 @@
 	}
 
 	if (do_islands) {
-		/* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */
-		int *island_number;
 		/* map holds the map from current vmap->buf to the new, sorted map */
 		map = MEM_mallocN(sizeof(*map)*totuv, "uvelement_remap");
 		stack = MEM_mallocN(sizeof(*stack)*em->bm->totface, "uv_island_face_stack");
 		islandbuf = MEM_callocN(sizeof(*islandbuf)*totuv, "uvelement_island_buffer");
-		island_number = MEM_mallocN(sizeof(*stack)*em->bm->totface, "uv_island_number_face");
 
 		for (i = 0; i < totuv; i++) {
 			if (element_map->buf[i].island == INVALID_ISLAND) {
@@ -911,8 +920,8 @@
 		element_map->totalIslands = nislands;
 		MEM_freeN(stack);
 		MEM_freeN(map);
-		MEM_freeN(island_number);
 	}
+	MEM_freeN(island_number);
 
 	return element_map;
 }

Modified: branches/bmesh/blender/source/blender/editors/uvedit/uvedit_draw.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/uvedit/uvedit_draw.c	2012-02-13 21:27:11 UTC (rev 44099)
+++ branches/bmesh/blender/source/blender/editors/uvedit/uvedit_draw.c	2012-02-14 00:35:29 UTC (rev 44100)
@@ -892,9 +892,6 @@
 		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->static_quads);
-		glDrawArrays(GL_QUADS, 0, stitch_preview->num_static_quads*4);
-
 		glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_tris);
 		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 		UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
@@ -905,18 +902,6 @@
 		glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
 		/*UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
 		glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_tris*3);*/
-
-		glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_quads);
-		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-		UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
-		glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);
-		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-		UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
-		glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);
-		glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
-		/*UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
-		glDrawArrays(GL_QUADS, 0, stitch_preview->num_quads*4);*/
-
 		glDisable(GL_BLEND);
 
 		/* draw vert preview */

Modified: branches/bmesh/blender/source/blender/editors/uvedit/uvedit_intern.h
===================================================================
--- branches/bmesh/blender/source/blender/editors/uvedit/uvedit_intern.h	2012-02-13 21:27:11 UTC (rev 44099)
+++ branches/bmesh/blender/source/blender/editors/uvedit/uvedit_intern.h	2012-02-14 00:35:29 UTC (rev 44100)
@@ -88,26 +88,19 @@
 
 /* object that stores display data for previewing before accepting stitching */
 typedef struct StitchPreviewer {
-	/* OpenGL requires different calls for Triangles and Quads.
-	 * here we'll store the quads of the mesh */
-	float *preview_quads;
-	/* ...and here we'll store the triangles*/
+	/* here we'll store the preview triangles of the mesh */
 	float *preview_tris;
 	/* 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;
-	unsigned int num_quads;
 	unsigned int num_stitchable;
 	unsigned int num_unstitchable;
 
-	/* store static island Quads */
-	float *static_quads;
 	/* ...and here we'll store the triangles*/
 	float *static_tris;
 	unsigned int num_static_tris;
-	unsigned int num_static_quads;
 } StitchPreviewer;
 
 StitchPreviewer *uv_get_stitch_previewer(void);

Modified: branches/bmesh/blender/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/uvedit/uvedit_ops.c	2012-02-13 21:27:11 UTC (rev 44099)
+++ branches/bmesh/blender/source/blender/editors/uvedit/uvedit_ops.c	2012-02-14 00:35:29 UTC (rev 44100)
@@ -1595,176 +1595,7 @@
 	ot->poll= ED_operator_uvedit;
 }
 
-#if 0 // BMESH_TODO --- this function has been moved elsewhere
-/* ******************** stitch operator **************** */
 
-/* just for averaging UVs */
-typedef struct UVVertAverage {
-	float uv[2];
-	int count;
-} UVVertAverage;
-
-static int stitch_exec(bContext *C, wmOperator *op)
-{
-	Scene *scene;
-	Object *obedit;
-	BMEditMesh *em;
-	BMFace *efa;
-	BMLoop *l;
-	BMIter iter, liter;
-	BMVert *eve;
-	Image *ima;
-	SpaceImage *sima= CTX_wm_space_image(C);
-	MTexPoly *tf;
-	MLoopUV *luv;
-
-	scene= CTX_data_scene(C);
-	obedit= CTX_data_edit_object(C);
-	em= ((Mesh*)obedit->data)->edit_btmesh;
-	ima= CTX_data_edit_image(C);
-	sima= CTX_wm_space_image(C);
-	
-	if(RNA_boolean_get(op->ptr, "use_limit")) {
-		UvVertMap *vmap;
-		UvMapVert *vlist, *iterv;
-		float newuv[2], limit[2], pixels;
-		int a, vtot;
-
-		pixels= RNA_float_get(op->ptr, "limit");
-		uvedit_pixel_to_float(sima, limit, pixels);
-
-		EDBM_init_index_arrays(em, 0, 0, 1);
-		vmap= EDBM_make_uv_vert_map(em, 1, 0, limit);
-
-		if(vmap == NULL) {
-			return OPERATOR_CANCELLED;
-		}
-		
-		a = 0;
-		BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
-			vlist= EDBM_get_uv_map_vert(vmap, a);
-
-			while(vlist) {
-				newuv[0]= 0; newuv[1]= 0;
-				vtot= 0;
-
-				for(iterv=vlist; iterv; iterv=iterv->next) {
-					if((iterv != vlist) && iterv->separate)
-						break;
-
-					efa = EDBM_get_face_for_index(em, iterv->f);
-					tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
-					
-					l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
-					if (uvedit_uv_selected(em, scene, l)) {
-						luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
-
-						newuv[0] += luv->uv[0];
-						newuv[1] += luv->uv[1];
-						vtot++;
-					}
-				}
-
-				if(vtot > 1) {
-					newuv[0] /= vtot; newuv[1] /= vtot;
-
-					for(iterv=vlist; iterv; iterv=iterv->next) {
-						if((iterv != vlist) && iterv->separate)
-							break;
-
-						efa = EDBM_get_face_for_index(em, iterv->f);
-						tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
-						
-						l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
-						if (uvedit_uv_selected(em, scene, l)) {
-							luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
-
-							luv->uv[0] = newuv[0];
-							luv->uv[1] = newuv[1];
-							vtot++;
-						}
-					}
-				}
-
-				vlist= iterv;
-			}
-
-			a++;
-		}
-
-		EDBM_free_uv_vert_map(vmap);
-		EDBM_free_index_arrays(em);
-	}
-	else {
-		UVVertAverage *uv_average, *uvav;
-
-		BM_mesh_elem_index_ensure(em->bm, BM_VERT);
-
-		uv_average= MEM_callocN(sizeof(UVVertAverage)*em->bm->totvert, "Stitch");
-		
-		// gather uv averages per vert
-		BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
-			tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
-			if(!uvedit_face_visible(scene, ima, efa, tf))
-				continue;
-			
-			BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
-				if(uvedit_uv_selected(em, scene, l)) {
-					luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
-					uvav = uv_average + BM_elem_index_get(l->v);
-
-					uvav->count++;
-					uvav->uv[0] += luv->uv[0];
-					uvav->uv[1] += luv->uv[1];
-				}
-			}
-		}
-		
-		// apply uv welding
-		BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
-			tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
-			if(!uvedit_face_visible(scene, ima, efa, tf))
-				continue;
-			
-			BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
-				if(uvedit_uv_selected(em, scene, l)) {
-					luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
-					uvav = uv_average + BM_elem_index_get(l->v);
-					luv->uv[0] = uvav->uv[0]/uvav->count;
-					luv->uv[1] = uvav->uv[1]/uvav->count;
-				}
-			}
-		}
-
-		MEM_freeN(uv_average);
-	}
-
-	uvedit_live_unwrap_update(sima, scene, obedit);
-	DAG_id_tag_update(obedit->data, 0);
-	WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
-	return OPERATOR_FINISHED;
-}
-
-static void UV_OT_stitch(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name= "Stitch";
-	ot->description= "Stitch selected UV vertices by proximity";
-	ot->idname= "UV_OT_stitch";
-	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-	
-	/* api callbacks */
-	ot->exec= stitch_exec;
-	ot->poll= ED_operator_uvedit;
-
-	/* properties */
-	RNA_def_boolean(ot->srna, "use_limit", 1, "Use Limit", "Stitch UVs within a specified limit distance");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list