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

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


Revision: 39500
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39500
Author:   psy-fi
Date:     2011-08-17 17:55:54 +0000 (Wed, 17 Aug 2011)
Log Message:
-----------
uv paint brushes
=================
-Laplacian relaxation smoothing for UVs.

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

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:44:38 UTC (rev 39499)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c	2011-08-17 17:55:54 UTC (rev 39500)
@@ -65,8 +65,6 @@
 
 #include "UI_view2d.h"
 
-#include <assert.h>
-
 #define MARK_BOUNDARY	1
 #define SELECTED		2
 
@@ -193,64 +191,64 @@
 	return;
 }
 
-static int smooth_laplacian_uv(bContext *C, int edges)
+static void smooth_laplacian_iteration_uv(EditMesh *em, UvBrushData *brushdata, float mouse_coord[2], float alpha, float radius, float aspectRatio)
 {
-	Object *obedit= CTX_data_edit_object(C);
-	EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
-	EditVert *eve;
-	EditEdge *eed;
-	Temp_UVData *adr, *adror, *data;
-	float delta[2], prev_co[2];
-	int index =0;
 
-	adr=adror=(Temp_UVData *)MEM_callocN((em->totvert)* sizeof(Temp_UVData), "Temporal data");
+	Temp_UVData *tmp_uvdata;
+	float diff[2];
+	int i;
+	Brush *brush = paint_brush(brushdata->uvpaint);
 
-	/* asigning memory */
-	eve= em->verts.first;
-	while(eve) {
-		eve->tmp.p = adr;
-		adr++;
-		eve= eve->next;
-	}
+	tmp_uvdata = (Temp_UVData *)MEM_callocN(brushdata->totalUniqueUvs * sizeof(Temp_UVData), "Temporal data");
 
-	eed= em->edges.first;
-	while(eed){
-		((Temp_UVData *)eed->v1->tmp.p)->ncounter++;
-		((Temp_UVData *)eed->v2->tmp.p)->ncounter++;
+	/* counting neighbors */
+	for (i = 0; i < brushdata->totalUvEdges; i++){
+		UvAdjacencyEdge *tmpedge = brushdata->uvedges+i;
+		tmp_uvdata[tmpedge->uv1].ncounter++;
+		tmp_uvdata[tmpedge->uv2].ncounter++;
 
-		add_v2_v2(((Temp_UVData *)eed->v2->tmp.p)->sum_co, eed->v1->co);
-		add_v2_v2(((Temp_UVData *)eed->v1->tmp.p)->sum_co, eed->v2->co);
+		add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_co, brushdata->uv[tmpedge->uv1].uv);
+		add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, brushdata->uv[tmpedge->uv2].uv);
+	}
 
-		eed = eed->next;
+	/* Original Lacplacian algorithm included removal of normal component of translation. here it is not
+	 * needed since we translate along the UV plane always.*/
+	for (i = 0; i < brushdata->totalUniqueUvs; i++){
+		copy_v2_v2(tmp_uvdata[i].p, tmp_uvdata[i].sum_co);
+		mul_v2_fl(tmp_uvdata[i].p, 1.f/tmp_uvdata[i].ncounter);
 	}
 
-	index= 0;
-	eve= em->verts.first;
-	while(eve){
-		if (!eve->f2 && (eve->f & SELECT)){
-			data = ((Temp_UVData *)eve->tmp.p);
-			copy_v2_v2(prev_co,eve->co);
-			mul_v2_fl(data->sum_co, 1.f/data->ncounter);
-			copy_v2_v2(eve->co, data->sum_co);
+	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;
+		}
 
-			/* remove movement along vertex normal */
-			sub_v2_v2v2(delta, eve->co,prev_co);
-			project_v2_v2v2(delta, delta, eve->no);
-			sub_v2_v2v2(eve->co,eve->co,delta);
+		sub_v2_v2v2(diff, brushdata->uv[i].uv, mouse_coord);
+		diff[1] /= aspectRatio;
+		if((dist = dot_v2v2(diff, diff)) <= radius){
+			UvElement *element;
+			float strength;
+			strength = alpha*brush_curve_strength(brush, dist, radius);
+
+			brushdata->uv[i].uv[0] = (1.0-strength)*brushdata->uv[i].uv[0] + strength*tmp_uvdata[i].p[0];
+			brushdata->uv[i].uv[1] = (1.0-strength)*brushdata->uv[i].uv[1] + strength*tmp_uvdata[i].p[1];
+
+			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);
+			}
 		}
-
-		eve->tmp.p= NULL;
-		eve= eve->next;
-		index++;
 	}
 
-	BKE_mesh_end_editmesh(obedit->data, em);
-	MEM_freeN(adror);
+	MEM_freeN(tmp_uvdata);
 
-	DAG_id_tag_update(obedit->data, 0);
-	WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
-	return OPERATOR_FINISHED;
+	return;
 }
 
 
@@ -318,6 +316,8 @@
 		unsigned int method = CTX_data_scene(C)->toolsettings->uv_relax_method;
 		if(method == UV_PAINT_TOOL_RELAX_HC){
 			HC_relaxation_iteration_uv(em, brushdata, co, alpha, radius, aspectRatio);
+		}else{
+			smooth_laplacian_iteration_uv(em, brushdata, co, alpha, radius, aspectRatio);
 		}
 	}
 




More information about the Bf-blender-cvs mailing list