[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39498] branches/soc-2011-onion/source/ blender/editors/sculpt_paint: uv paint brushes

Antony Riakiotakis kalast at gmail.com
Wed Aug 17 19:17:15 CEST 2011


Revision: 39498
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39498
Author:   psy-fi
Date:     2011-08-17 17:17:14 +0000 (Wed, 17 Aug 2011)
Log Message:
-----------
uv paint brushes
=================
-edge pinning for current brushes.
-little bugfix in drawing code, resulted in crash when deleting object
-remove more unneeded stuff from original relaxation code.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_controls.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_controls.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_controls.c	2011-08-17 17:12:10 UTC (rev 39497)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_controls.c	2011-08-17 17:17:14 UTC (rev 39498)
@@ -415,7 +415,7 @@
 	if (!sd) /* XXX: TODO: remove sculpt dependency */
 		return;
 
-	if (ob->paint &&
+	if (ob && ob->paint &&
 		!(ob->paint->painting) &&
 		brush &&
 		brush->mtex.brush_map_mode == MTEX_MAP_MODE_TILED &&

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c	2011-08-17 17:12:10 UTC (rev 39497)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c	2011-08-17 17:17:14 UTC (rev 39498)
@@ -65,6 +65,7 @@
 
 #include "UI_view2d.h"
 
+#include <assert.h>
 
 #define MARK_BOUNDARY	1
 #define SELECTED		2
@@ -124,49 +125,14 @@
 	int ncounter;
 }Temp_UVData;
 
-void set_border_flag(struct EditMesh *em){
-	EditFace *efa;
-	EditEdge *eed;
 
-	/* clear flag */
-	for (efa=em->faces.first;efa;efa=efa->next){
-		efa->e1->f2 = 0;
-		efa->e2->f2 = 0;
-		efa->e3->f2 = 0;
-		if (efa->e4) efa->e4->f2 = 0;
-	}
-	/* find frontier edges, not shared by other faces */
-	for (efa=em->faces.first;efa;efa=efa->next){
-		efa->e1->f2++;
-		efa->e2->f2++;
-		efa->e3->f2++;
-		if (efa->e4) efa->e4->f2++;
-	}
 
-	/* clear flag verts */
-	for (eed = em->edges.first; eed; eed = eed->next){
-		eed->v1->f2 = 0;
-			eed->v2->f2 = 0;
-	}
-	/* propagate fromtier selection to verts */
-	for (eed = em->edges.first; eed; eed = eed->next){
-		if (eed->f2 == 1){ //is frontier
-			eed->v1->f2 = 1;
-			eed->v2->f2 = 1;
-		}
-	}
-}
-
-
 void HC_relaxation_iteration_uv(EditMesh *em, UvBrushData *brushdata, float mouse_coord[2], float alpha, float radius, float aspectRatio){
 	Temp_UVData *tmp_uvdata;
 	float diff[2];
 	int i;
 	Brush *brush = paint_brush(brushdata->uvpaint);
 
-	/* This will happen on initialization instead of here */
-	//if (edges) set_border_flag(em);
-
 	tmp_uvdata = (Temp_UVData *)MEM_callocN(brushdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
 
 	/* counting neighbors */
@@ -196,6 +162,12 @@
 
 	for (i = 0; i < brushdata->totalUniqueUvs; i++){
 		float dist;
+		/* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
+		 * If ever uv brushes get their own mode we should check for toolsettings option too */
+		if((brushdata->uv[i].flag & MARK_BOUNDARY)){
+			continue;
+		}
+
 		sub_v2_v2v2(diff, brushdata->uv[i].uv, mouse_coord);
 		diff[1] /= aspectRatio;
 		if((dist = dot_v2v2(diff, diff)) <= radius){
@@ -240,7 +212,6 @@
 		adr++;
 		eve= eve->next;
 	}
-	if (edges) set_border_flag(em);
 
 	eed= em->edges.first;
 	while(eed){
@@ -282,52 +253,7 @@
 	return OPERATOR_FINISHED;
 }
 
-static int relaxation_vertex_exec(bContext *C, wmOperator *op)
-{
-	int repeat = RNA_int_get(op->ptr, "repeat");
-	int edges = RNA_int_get(op->ptr, "edges");
-	int relax = RNA_int_get(op->ptr, "relax");
-	int i;
 
-	if (!repeat) repeat = 1;
-
-/*	for (i=0; i<repeat; i++) {
-		if (relax == 1) HC_relaxation_iteration_uv(C, edges);
-		else smooth_laplacian_uv(C, edges); //default
-	}*/
-
-	return OPERATOR_FINISHED;
-}
-
-#define SEL_LAPLACIAN 0
-#define SEL_HC        1
-
-static EnumPropertyItem select_all_smothings[] = {
-		{SEL_LAPLACIAN, "LAPLACIAN", 0, "Laplacian", "Improved laplacian relaxation with no shrinkage"},
-		{SEL_HC, "HC", 0, "HC Relaxation", "HC Relaxation with low shrinkage"},
-		{0, NULL, 0, NULL, NULL}
-	};
-
-void MESH_OT_relaxation_smooth(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name= "Laplacian Smooth";
-	ot->description= "Vertices relaxation with low shrinkage";
-	ot->idname= "MESH_OT_relaxation_smooth";
-
-	/* api callbacks */
-	ot->exec= relaxation_vertex_exec;
-	ot->poll= ED_operator_editmesh;
-
-	/* flags */
-	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
-	RNA_def_enum(ot->srna, "relax", select_all_smothings, SEL_LAPLACIAN, "Relaxation schemes", "Select relaxation scheme to execute");
-	RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Smooth Iterations", "", 1, INT_MAX);
-	RNA_def_boolean(ot->srna, "edges", 1, "Preserve border", "Preserves shape's edges");
-}
-
-
 static void uv_paint_stroke_apply(bContext *C, wmOperator *op, wmEvent *event, Object *obedit)
 {
 	float co[2], radius;
@@ -353,25 +279,37 @@
 	ED_space_image_size(sima, &width, &height);
 	aspectRatio = width/(float)height;
 	radius /= width;
+	/* We will compare squares to save some computation */
 	radius = radius*radius;
 
 	if(tool == UV_PAINT_TOOL_PINCH){
+		int i;
 		alpha *= invert;
-		for(efa = em->faces.first; efa; efa= efa->next){
-			int nverts, i;
-			MTFace *mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-			nverts = efa->v4 ? 4 : 3;
+		for (i = 0; i < brushdata->totalUniqueUvs; i++){
+			float dist, diff[2];
+			/* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start
+			 * If ever uv brushes get their own mode we should check for toolsettings option too */
+			if(brushdata->uv[i].flag & MARK_BOUNDARY){
+				continue;
+			}
 
-			for(i = 0; i < nverts; i++){
-				float diff[2], dist;
-				sub_v2_v2v2(diff, mt->uv[i], co);
-				diff[1] /= aspectRatio;
-				if((dist = dot_v2v2(diff, diff)) <= radius){
-					float strength;
-					strength = alpha*brush_curve_strength(brush, dist, radius);
-					normalize_v2(diff);
-					mt->uv[i][0] -= strength*diff[0]*0.001;
-					mt->uv[i][1] -= strength*diff[1]*0.001;
+			sub_v2_v2v2(diff, brushdata->uv[i].uv, co);
+			diff[1] /= aspectRatio;
+			if((dist = dot_v2v2(diff, diff)) <= radius){
+				UvElement *element;
+				float strength;
+				strength = alpha*brush_curve_strength(brush, dist, radius);
+				normalize_v2(diff);
+
+				brushdata->uv[i].uv[0] -= strength*diff[0]*0.001;
+				brushdata->uv[i].uv[1] -= strength*diff[1]*0.001;
+
+				for(element = brushdata->uv[i].element; element; element = element->next){
+					MTFace *mt;
+					if(element->separate && element != brushdata->uv[i].element)
+						break;
+					mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+					copy_v2_v2(mt->uv[element->tfindex], brushdata->uv[i].uv);
 				}
 			}
 		}
@@ -435,7 +373,7 @@
 	if((edge1->uv1 == edge2->uv1) && (edge1->uv2 == edge2->uv2)){
 		return 0;
 	}
-	return -1;
+	return 1;
 }
 
 
@@ -478,6 +416,7 @@
 		data->uv = MEM_mallocN(sizeof(*data->uv)*numOfSeparators, "uv_brush_unique_uvs");
 		data->uniqueUv = MEM_mallocN(sizeof(*data->uniqueUv)*data->elementMap->totalUVs, "uv_brush_unique_uv_map");
 		edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "uv_brush_edge_hash");
+		/* we have at most totalUVs edges*/
 		edges = MEM_mallocN(sizeof(*edges)*data->elementMap->totalUVs, "uv_brush_all_edges");
 		if(!data->uv || !data->uniqueUv || !edgeHash || !edges){
 			uv_paint_stroke_exit(C, op);
@@ -505,21 +444,21 @@
 			}
 		}
 
-		/* Now, to generate our uv connectivity data...Man, this is gonna be -slow-! */
+		/* Now, on to generate our uv connectivity data */
 		for(efa = em->faces.first, numOfSeparators = 0; efa; efa = efa->next){
 			int nverts = efa->v4 ? 4 : 3;
 			for(i = 0; i < nverts; i++){
-				int offset1 = get_uv_element_offset_from_face(data->elementMap, efa, i);
-				int offset2 = get_uv_element_offset_from_face(data->elementMap, efa, (i+1)%nverts);
+				int offset1 = data->uniqueUv[get_uv_element_offset_from_face(data->elementMap, efa, i)];
+				int offset2 = data->uniqueUv[get_uv_element_offset_from_face(data->elementMap, efa, (i+1)%nverts)];
+
+				edges[numOfSeparators].flag = 0;
 				if(offset1 < offset2){
-					edges[numOfSeparators].uv1 = data->uniqueUv[offset1];
-					edges[numOfSeparators].uv2 = data->uniqueUv[offset2];
-					edges[numOfSeparators].flag = 0;
+					edges[numOfSeparators].uv1 = offset1;
+					edges[numOfSeparators].uv2 = offset2;
 				}
 				else{
-					edges[numOfSeparators].uv1 = data->uniqueUv[offset2];
-					edges[numOfSeparators].uv2 = data->uniqueUv[offset1];
-					edges[numOfSeparators].flag = 0;
+					edges[numOfSeparators].uv1 = offset2;
+					edges[numOfSeparators].uv2 = offset1;
 				}
 				/* Hack! Set the value of the key to its flag. Now we can set the flag when an edge exists twice :) */
 				if(BLI_ghash_haskey(edgeHash, &edges[numOfSeparators])){
@@ -534,7 +473,6 @@
 			}
 		}
 
-//		printf("total Uvs %d, total edgeKeys %d\n", data->elementMap->totalUVs, BLI_ghash_size(edgeHash));
 		/* Allocate connectivity data, we allocate edges once */
 		data->uvedges = MEM_mallocN(sizeof(*data->uvedges)*BLI_ghash_size(edgeHash), "uv_brush_edge_connectivity_data");
 		if(!data->uvedges){
@@ -555,9 +493,21 @@
 			data->uvedges[i] = *((UvAdjacencyEdge *)BLI_ghashIterator_getKey(ghi));
 		}
 		data->totalUvEdges = BLI_ghash_size(edgeHash);
+
+		/* cleanup temporary stuff */
 		BLI_ghashIterator_free(ghi);
 		BLI_ghash_free(edgeHash, NULL, NULL);
 		MEM_freeN(edges);
+
+		/* */
+		if(ts->uv_paint_settings & UV_PAINT_PIN_EDGES){
+			for(i = 0; i < data->totalUvEdges; i++){
+				if(!data->uvedges[i].flag){
+					data->uv[data->uvedges[i].uv1].flag |= MARK_BOUNDARY;
+					data->uv[data->uvedges[i].uv2].flag |= MARK_BOUNDARY;
+				}
+			}
+		}
 	}
 
 	return op->customdata;




More information about the Bf-blender-cvs mailing list