[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43305] branches/soc-2011-onion-uv-tools/ source/blender: Uv Sculpting:

Antony Riakiotakis kalast at gmail.com
Wed Jan 11 18:25:45 CET 2012


Revision: 43305
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43305
Author:   psy-fi
Date:     2012-01-11 17:25:44 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
Uv Sculpting:
=============
Bring back the uv grab tool toggle with G while in uv brush mode.
Also added Shift-LeftMouse drag becomes relax brush.

Modified Paths:
--------------
    branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_ops.c
    branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c
    branches/soc-2011-onion-uv-tools/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.c

Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_image.c	2012-01-11 16:48:22 UTC (rev 43304)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_image.c	2012-01-11 17:25:44 UTC (rev 43305)
@@ -5242,7 +5242,7 @@
 	if(settings->use_uv_sculpt) {
 		if(!settings->uvsculpt) {
 			settings->uvsculpt = MEM_callocN(sizeof(*settings->uvsculpt), "UV Smooth paint");
-			settings->uv_sculpt_tool = UV_SCULPT_TOOL_RELAX;
+			settings->uv_sculpt_tool = UV_SCULPT_TOOL_GRAB;
 			settings->uv_sculpt_settings = UV_SCULPT_LOCK_BORDERS | UV_SCULPT_ALL_ISLANDS;
 			settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN;
 		}

Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_ops.c	2012-01-11 16:48:22 UTC (rev 43304)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/paint_ops.c	2012-01-11 17:25:44 UTC (rev 43305)
@@ -699,11 +699,13 @@
 
 	WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
 	RNA_boolean_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
+	RNA_boolean_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "temp_relax", 1);
 
 	ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
 	ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
 
 	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_RELAX);
 	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_PINCH);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_GRAB);
 
 }

Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c	2012-01-11 16:48:22 UTC (rev 43304)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/sculpt_paint/sculpt_uv.c	2012-01-11 17:25:44 UTC (rev 43305)
@@ -85,7 +85,29 @@
 	char flag;
 }UvEdge;
 
+typedef struct UVInitialStrokeElement{
+	/* index to unique uv */
+	int uv;
 
+	/* strength of brush on initial position */
+	float strength;
+
+	/* initial uv position */
+	float initial_uv[2];
+}UVInitialStrokeElement;
+
+typedef struct UVInitialStroke{
+	/* Initial Selection,for grab brushes for instance */
+	UVInitialStrokeElement *initialSelection;
+
+	/* total initially selected UVs*/
+	int totalInitialSelected;
+
+	/* initial mouse coordinates */
+	float init_coord[2];
+}UVInitialStroke;
+
+
 /* custom data for uv smoothing brush */
 typedef struct UvSculptData{
 	/* Contains the first of each set of coincident uvs.
@@ -102,6 +124,9 @@
 	/* Need I say more? */
 	int totalUvEdges;
 
+	/* data for initial stroke, used by tools like grab */
+	UVInitialStroke *initial_stroke;
+
 	/* Timer to be used for airbrush-type brush */
 	wmTimer *timer;
 
@@ -265,7 +290,8 @@
 	float aspectRatio;
 	float alpha, zoomx, zoomy;
 	Brush *brush = paint_brush(sculptdata->uvsculpt);
-	tool = CTX_data_scene(C)->toolsettings->uv_sculpt_tool;
+	ToolSettings *toolsettings = CTX_data_tool_settings(C);
+	tool = RNA_boolean_get(op->ptr, "temp_relax")? UV_SCULPT_TOOL_RELAX : toolsettings->uv_sculpt_tool;
 
 	invert = RNA_boolean_get(op->ptr, "invert")? -1 : 1;
 	alpha = brush_alpha(brush);
@@ -322,7 +348,7 @@
 	 * Smooth Tool
 	 */
 	else if(tool == UV_SCULPT_TOOL_RELAX){
-		unsigned int method = CTX_data_scene(C)->toolsettings->uv_relax_method;
+		unsigned int method = toolsettings->uv_relax_method;
 		if(method == UV_SCULPT_TOOL_RELAX_HC){
 			HC_relaxation_iteration_uv(em, sculptdata, co, alpha, radius, aspectRatio);
 		}else{
@@ -330,6 +356,31 @@
 		}
 	}
 
+	/*
+	 * Grab Tool
+	 */
+	else if(tool == UV_SCULPT_TOOL_GRAB){
+		int i;
+		float diff[2];
+		sub_v2_v2v2(diff, co, sculptdata->initial_stroke->init_coord);
+
+		for(i = 0; i < sculptdata->initial_stroke->totalInitialSelected; i++ ){
+			UvElement *element;
+			int uvindex = sculptdata->initial_stroke->initialSelection[i].uv;
+			float strength = sculptdata->initial_stroke->initialSelection[i].strength;
+			sculptdata->uv[uvindex].uv[0] = sculptdata->initial_stroke->initialSelection[i].initial_uv[0] + strength*diff[0];
+			sculptdata->uv[uvindex].uv[1] = sculptdata->initial_stroke->initialSelection[i].initial_uv[1] + strength*diff[1];
+
+			for(element = sculptdata->uv[uvindex].element; element; element = element->next){
+				MTFace *mt;
+				if(element->separate && element != sculptdata->uv[uvindex].element)
+					break;
+				mt = CustomData_em_get(&em->fdata, element->face->data, CD_MTFACE);
+				copy_v2_v2(mt->uv[element->tfindex], sculptdata->uv[uvindex].uv);
+			}
+		}
+	}
+
 	BKE_mesh_end_editmesh(obedit->data, em);
 }
 
@@ -350,6 +401,12 @@
 	if(data->uvedges){
 		MEM_freeN(data->uvedges);
 	}
+	if(data->initial_stroke){
+		if(data->initial_stroke->initialSelection){
+			MEM_freeN(data->initial_stroke->initialSelection);
+		}
+		MEM_freeN(data->initial_stroke);
+	}
 
 	MEM_freeN(data);
 	op->customdata = NULL;
@@ -572,6 +629,66 @@
 				}
 			}
 		}
+
+		/* Allocate initial selection for grab tool */
+		if(ts->uv_sculpt_tool == UV_SCULPT_TOOL_GRAB){
+			float radius, radius_root;
+			unsigned int tool;
+			UvSculptData *sculptdata = (UvSculptData *)op->customdata;
+			SpaceImage *sima;
+			int width, height;
+			float aspectRatio;
+			float alpha, zoomx, zoomy;
+			Brush *brush = paint_brush(sculptdata->uvsculpt);
+			tool = CTX_data_scene(C)->toolsettings->uv_sculpt_tool;
+
+			alpha = brush_alpha(brush);
+
+			radius = brush_size(brush);
+			sima = CTX_wm_space_image(C);
+			ED_space_image_size(sima, &width, &height);
+			ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
+
+			aspectRatio = width/(float)height;
+			radius /= (width*zoomx);
+			radius = radius*radius;
+			radius_root = sqrt(radius);
+
+			/* Allocate selection stack */
+			data->initial_stroke = MEM_mallocN(sizeof(*data->initial_stroke), "uv_sculpt_initial_stroke");
+			if(!data->initial_stroke){
+				uv_sculpt_stroke_exit(C, op);
+			}
+			data->initial_stroke->initialSelection = MEM_mallocN(sizeof(*data->initial_stroke->initialSelection)*data->totalUniqueUvs, "uv_sculpt_initial_selection");
+			if(!data->initial_stroke->initialSelection){
+				uv_sculpt_stroke_exit(C, op);
+			}
+
+			copy_v2_v2(data->initial_stroke->init_coord, co);
+
+			counter = 0;
+
+			for(i = 0; i < data->totalUniqueUvs; i++){
+				float dist, diff[2];
+				if(data->uv[i].flag & MARK_BOUNDARY){
+					continue;
+				}
+
+				sub_v2_v2v2(diff, data->uv[i].uv, co);
+				diff[1] /= aspectRatio;
+				if((dist = dot_v2v2(diff, diff)) <= radius){
+					float strength;
+					strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
+
+					data->initial_stroke->initialSelection[counter].uv = i;
+					data->initial_stroke->initialSelection[counter].strength = strength;
+					copy_v2_v2(data->initial_stroke->initialSelection[counter].initial_uv, data->uv[i].uv);
+					counter++;
+				}
+			}
+
+			data->initial_stroke->totalInitialSelected = counter;
+		}
 	}
 
 	return op->customdata;
@@ -608,9 +725,10 @@
 	switch(event->type) {
 		case LEFTMOUSE:
 		case MIDDLEMOUSE:
-		case RIGHTMOUSE: // XXX hardcoded
+		case RIGHTMOUSE:
 			uv_sculpt_stroke_exit(C, op);
 			return OPERATOR_FINISHED;
+
 		case MOUSEMOVE:
 		case INBETWEEN_MOUSEMOVE:
 			uv_sculpt_stroke_apply(C, op, event, obedit);
@@ -646,4 +764,5 @@
 
 	/* props */
 	RNA_def_boolean(ot->srna, "invert", 0, "Invert", "Inverts the operator");
+	RNA_def_boolean(ot->srna, "temp_relax", 0, "Relax", "Relax Tool");
 }

Modified: branches/soc-2011-onion-uv-tools/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/makesdna/DNA_scene_types.h	2012-01-11 16:48:22 UTC (rev 43304)
+++ branches/soc-2011-onion-uv-tools/source/blender/makesdna/DNA_scene_types.h	2012-01-11 17:25:44 UTC (rev 43305)
@@ -647,6 +647,7 @@
 
 #define UV_SCULPT_TOOL_PINCH				1
 #define UV_SCULPT_TOOL_RELAX				2
+#define UV_SCULPT_TOOL_GRAB					3
 
 #define UV_SCULPT_TOOL_RELAX_LAPLACIAN	1
 #define UV_SCULPT_TOOL_RELAX_HC			2

Modified: branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.c	2012-01-11 16:48:22 UTC (rev 43304)
+++ branches/soc-2011-onion-uv-tools/source/blender/makesrna/intern/rna_scene.c	2012-01-11 17:25:44 UTC (rev 43305)
@@ -71,6 +71,7 @@
 EnumPropertyItem uv_sculpt_tool_items[] = {
 	{UV_SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", "Pinch UVs"},
 	{UV_SCULPT_TOOL_RELAX, "RELAX", 0, "Relax", "Relax UVs"},
+	{UV_SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", "Grab UVs"},
 	{0, NULL, 0, NULL, NULL}};
 
 



More information about the Bf-blender-cvs mailing list