[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55297] trunk/blender/source/blender: Support for rake in 2D image painting.

Antony Riakiotakis kalast at gmail.com
Fri Mar 15 10:48:51 CET 2013


Revision: 55297
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55297
Author:   psy-fi
Date:     2013-03-15 09:48:51 +0000 (Fri, 15 Mar 2013)
Log Message:
-----------
Support for rake in 2D image painting.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-15 09:46:37 UTC (rev 55296)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-15 09:48:51 UTC (rev 55297)
@@ -565,15 +565,37 @@
 /* Brush Sampling for 2D brushes. when we unify the brush systems this will be necessarily a separate function */
 float BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], struct ImagePool *pool)
 {
+	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 	MTex *mtex = &brush->mtex;
 
 	if (mtex && mtex->tex) {
 		float co[3], tin, tr, tg, tb, ta;
+		float x = xy[0], y = xy[1];
 		int hasrgb;
-		const int radius = BKE_brush_size_get(scene, brush);
+		int radius = BKE_brush_size_get(scene, brush);
+		float rotation = -mtex->rot;
 
-		co[0] = xy[0] / radius;
-		co[1] = xy[1] / radius;
+		if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
+			rotation += ups->brush_rotation;
+			radius = ups->pixel_radius;
+		}
+
+		x /= radius;
+		y /= radius;
+
+		if (rotation > 0.001f || rotation < -0.001f) {
+			const float angle    = atan2f(y, x) + rotation;
+			const float flen     = sqrtf(x * x + y * y);
+
+			x = flen * cosf(angle);
+			y = flen * sinf(angle);
+		}
+
+		x *= brush->mtex.size[0];
+		y *= brush->mtex.size[1];
+
+		co[0] = x + brush->mtex.ofs[0];
+		co[1] = y + brush->mtex.ofs[1];
 		co[2] = 0.0f;
 
 		hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, 0, pool);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-03-15 09:46:37 UTC (rev 55296)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-03-15 09:48:51 UTC (rev 55297)
@@ -96,6 +96,7 @@
 	int lastsize;
 	float lastalpha;
 	float lastjitter;
+	float last_rotation;
 
 	ImBuf *ibuf;
 	ImBuf *texibuf;
@@ -335,6 +336,7 @@
 static void brush_painter_2d_refresh_cache(BrushPainter *painter, const float pos[2], int use_color_correction)
 {
 	const Scene *scene = painter->scene;
+	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 	Brush *brush = painter->brush;
 	BrushPainterCache *cache = &painter->cache;
 	MTex *mtex = &brush->mtex;
@@ -343,10 +345,16 @@
 	const int diameter = 2 * BKE_brush_size_get(scene, brush);
 	const float alpha = BKE_brush_alpha_get(scene, brush);
 	const bool do_tiled = ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_3D);
+	float rotation = -mtex->rot;
 
+	if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
+		rotation += ups->brush_rotation;
+	}
+
 	if (diameter != cache->lastsize ||
 	    alpha != cache->lastalpha ||
-	    brush->jitter != cache->lastjitter)
+	    brush->jitter != cache->lastjitter ||
+	    rotation != cache->last_rotation)
 	{
 		if (cache->ibuf) {
 			IMB_freeImBuf(cache->ibuf);
@@ -370,6 +378,7 @@
 		cache->lastsize = diameter;
 		cache->lastalpha = alpha;
 		cache->lastjitter = brush->jitter;
+		cache->last_rotation = rotation;
 	}
 	else if (do_tiled && mtex && mtex->tex) {
 		int dx = (int)painter->lastpaintpos[0] - (int)pos[0];




More information about the Bf-blender-cvs mailing list