[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47538] branches/soc-2012-bratwurst: Texture Rake for texture painting

Antony Riakiotakis kalast at gmail.com
Wed Jun 6 21:49:29 CEST 2012


Revision: 47538
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47538
Author:   psy-fi
Date:     2012-06-06 19:49:25 +0000 (Wed, 06 Jun 2012)
Log Message:
-----------
Texture Rake for texture painting
=================================
* Do some initial coding and exposing of the tool for the user. The
result is again, jumpy, still it will provide a good base so commiting.
I will need to cleanup which options appear to the user as well.

LOTS of state for texture painting, I will have to verify that I am
touching the right state.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
    branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-06-06 19:36:26 UTC (rev 47537)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-06-06 19:49:25 UTC (rev 47538)
@@ -721,7 +721,7 @@
         if brush.use_paint_image:
             col.prop(brush, "use_fixed_texture")
 
-        if context.sculpt_object:
+        if context.sculpt_object or context.image_paint_object:
             sculpt_brush_texture_settings(col, brush)
 
             # use_texture_overlay and texture_overlay_alpha

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-06 19:36:26 UTC (rev 47537)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-06 19:49:25 UTC (rev 47538)
@@ -67,7 +67,7 @@
 float BKE_brush_curve_strength(struct Brush *br, float p, const float len); /* used for sculpt */
 
 /* sampling */
-void BKE_brush_sample_tex(const struct Scene *scene, struct Brush *brush, const float xy[2], float rgba[4], const int thread);
+void BKE_brush_sample_tex(const struct Scene *scene, struct Brush *brush, const float xy[2], float rgba[4], const int thread, float angle);
 void BKE_brush_imbuf_new(const struct Scene *scene, struct Brush *brush, short flt, short texfalloff, int size,
                          struct ImBuf **imbuf, int use_color_correction);
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-06 19:36:26 UTC (rev 47537)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-06 19:49:25 UTC (rev 47538)
@@ -486,19 +486,28 @@
 }
 
 /* Brush Sampling */
-void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread)
+void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread, float angle)
 {
 	MTex *mtex = &brush->mtex;
 
 	if (mtex && mtex->tex) {
+		float co_angle, length;
 		float co[3], tin, tr, tg, tb, ta;
 		int hasrgb;
 		const int radius = BKE_brush_size_get(scene, brush);
 
-		co[0] = xy[0] / radius;
-		co[1] = xy[1] / radius;
+		co[0] = ((xy[0] - radius/2) / radius);
+		co[1] = ((xy[1] - radius/2) / radius);
 		co[2] = 0.0f;
 
+		length = normalize_v2(co);
+		co_angle = acos(co[0]);
+		co_angle = (co[1] > 0)? co_angle : - co_angle;
+
+		co_angle -= angle;
+		co[0] = cos(co_angle)*length + 0.5;
+		co[1] = sin(co_angle)*length + 0.5;
+
 		hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread);
 
 		if (hasrgb) {
@@ -558,10 +567,10 @@
 					dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 				}
 				else if (texfall == 1) {
-					BKE_brush_sample_tex(scene, brush, xy, dstf, 0);
+					BKE_brush_sample_tex(scene, brush, xy, dstf, 0, 0);
 				}
 				else {
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
 					mul_v3_v3v3(dstf, rgba, brush_rgb);
 					dstf[3] = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 				}
@@ -588,11 +597,11 @@
 					dst[3] = FTOCHAR(alpha_f);
 				}
 				else if (texfall == 1) {
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
 					rgba_float_to_uchar(dst, rgba);
 				}
 				else if (texfall == 2) {
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
 					mul_v3_v3(rgba, brush->rgb);
 					alpha_f = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 
@@ -601,7 +610,7 @@
 					dst[3] = FTOCHAR(alpha_f);
 				}
 				else {
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
 					alpha_f = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 
 					dst[0] = crgb[0];
@@ -898,7 +907,7 @@
 					xy[0] = x + xoff;
 					xy[1] = y + yoff;
 
-					BKE_brush_sample_tex(scene, brush, xy, tf, 0);
+					BKE_brush_sample_tex(scene, brush, xy, tf, 0, 0);
 				}
 
 				bf[0] = tf[0] * mf[0];
@@ -929,7 +938,7 @@
 					xy[0] = x + xoff;
 					xy[1] = y + yoff;
 
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
 					rgba_float_to_uchar(t, rgba);
 				}
 

Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-06-06 19:36:26 UTC (rev 47537)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-06-06 19:49:25 UTC (rev 47538)
@@ -142,6 +142,11 @@
 static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint);
 
 
+typedef struct BrushRotationState {
+		float last_orientation[2]; /* orientation in screen space*/
+		float last_angle; /* last angle, stores angle to */
+} BrushRotationState;
+
 typedef struct ImagePaintState {
 	SpaceImage *sima;
 	View2D *v2d;
@@ -262,6 +267,7 @@
 
 	Brush *brush;
 	short tool, blend;
+	BrushRotationState rotation_state;
 	Object *ob;
 	/* end similarities with ImagePaintState */
 	
@@ -3403,7 +3409,14 @@
 		mul_m4_v4(ps->projectMat, projCo);
 		ps->cloneOffset[0] = mouse[0] - ((float)(ps->winx / 2.0f) + (ps->winx / 2.0f) * projCo[0] / projCo[3]);
 		ps->cloneOffset[1] = mouse[1] - ((float)(ps->winy / 2.0f) + (ps->winy / 2.0f) * projCo[1] / projCo[3]);
-	}	
+	}
+
+	/* reset rake state */
+	if(ps->brush && ps->brush->flag & BRUSH_RAKE) {
+		ps->rotation_state.last_angle = 0.0;
+		ps->rotation_state.last_orientation[0] = 1.0;
+		ps->rotation_state.last_orientation[0] = 0.0;
+	}
 }	
 
 static void project_paint_end(ProjPaintState *ps)
@@ -3923,7 +3936,7 @@
 					if (falloff > 0.0f) {
 						if (ps->is_texbrush) {
 							/* note, for clone and smear, we only use the alpha, could be a special function */
-							BKE_brush_sample_tex(ps->scene, ps->brush, projPixel->projCoSS, rgba, thread_index);
+							BKE_brush_sample_tex(ps->scene, ps->brush, projPixel->projCoSS, rgba, thread_index, ps->rotation_state.last_angle);
 							alpha = rgba[3];
 						}
 						else {
@@ -4042,7 +4055,22 @@
 	if (!project_bucket_iter_init(ps, pos)) {
 		return 0;
 	}
-	
+
+	if(ps->brush->flag & BRUSH_RAKE) {
+		float mdiff[2];
+
+		sub_v2_v2v2(mdiff, pos, lastpos);
+
+		if(len_v2(mdiff) > 0.001) {
+			float angle;
+			normalize_v2(mdiff);
+			angle = acos(mdiff[0]);
+			ps->rotation_state.last_orientation[0] = mdiff[0];
+			ps->rotation_state.last_orientation[0] = mdiff[1];
+			ps->rotation_state.last_angle = (mdiff[1] > 0)? angle : -angle;
+		}
+	}
+
 	if (ps->thread_tot > 1)
 		BLI_init_threads(&threads, do_projectpaint_thread, ps->thread_tot);
 	
@@ -4104,7 +4132,7 @@
 	
 	pos[0] = (float)(mval_i[0]);
 	pos[1] = (float)(mval_i[1]);
-	
+
 	// we may want to use this later 
 	// BKE_brush_painter_require_imbuf(painter, ((ibuf->rect_float)? 1: 0), 0, 0);
 	
@@ -4405,6 +4433,10 @@
 
 	imapaint_convert_brushco(ibufb, pos, bpos);
 
+	/* prints coordinates in image pixel space */
+	print_v2("position", pos);
+	print_v2("last position", lastpos);
+
 	/* lift from canvas */
 	if (s->tool == PAINT_TOOL_SOFTEN) {
 		imapaint_lift_soften(s->canvas, ibufb, bpos, torus);




More information about the Bf-blender-cvs mailing list