[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56833] trunk/blender/source/blender/ editors/sculpt_paint/paint_image_2d.c: Fix #35355: 2D image paint View mapping mode was dependent on zoom, this was

Brecht Van Lommel brechtvanlommel at pandora.be
Wed May 15 23:03:58 CEST 2013


Revision: 56833
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56833
Author:   blendix
Date:     2013-05-15 21:03:57 +0000 (Wed, 15 May 2013)
Log Message:
-----------
Fix #35355: 2D image paint View mapping mode was dependent on zoom, this was
wrong, it should just fit the texture in the brush circle.

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

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-05-15 20:38:17 UTC (rev 56832)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-05-15 21:03:57 UTC (rev 56833)
@@ -517,7 +517,7 @@
 		brush_painter_imbuf_update(painter, NULL, x1, y2, x2, ibuf->y, 0, 0);
 }
 
-static void brush_painter_2d_tex_mapping(ImagePaintState *s, int size, const float startpos[2], const float pos[2], int mapmode, rctf *mapping)
+static void brush_painter_2d_tex_mapping(ImagePaintState *s, int size, const float startpos[2], const float pos[2], const float mouse[2], int mapmode, rctf *mapping)
 {
 	float invw = 1.0f / (float)s->canvas->x;
 	float invh = 1.0f / (float)s->canvas->y;
@@ -528,7 +528,7 @@
 	ipos[0] = (int)floorf((pos[0] - size / 2) + 1.0f);
 	ipos[1] = (int)floorf((pos[1] - size / 2) + 1.0f);
 
-	if (ELEM(mapmode, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_VIEW)) {
+	if (mapmode == MTEX_MAP_MODE_STENCIL) {
 		/* map from view coordinates of brush to region coordinates */
 		UI_view2d_to_region_no_clip(s->v2d, ipos[0] * invw, ipos[1] * invh, &xmin, &ymin);
 		UI_view2d_to_region_no_clip(s->v2d, (ipos[0] + size) * invw, (ipos[1] + size) * invh, &xmax, &ymax);
@@ -541,27 +541,27 @@
 	}
 	else if (mapmode == MTEX_MAP_MODE_3D) {
 		/* 3D mapping, just mapping to canvas 0..1  */
-		mapping->xmin = ipos[0] * invw;
-		mapping->ymin = ipos[1] * invh;
-		mapping->xmax = size * invw / (float)size;
-		mapping->ymax = size * invh / (float)size;
+		mapping->xmin = 2.0f * (ipos[0] * invw - 0.5f);
+		mapping->ymin = 2.0f * (ipos[1] * invh - 0.5f);
+		mapping->xmax = 2.0f * invw;
+		mapping->ymax = 2.0f * invh;
 	}
-	else {
-		/* other mapping */
-		mapping->xmin = -size * 0.5f + 0.5f;
-		mapping->ymin = -size * 0.5f + 0.5f;
+	else if (ELEM(mapmode, MTEX_MAP_MODE_VIEW, MTEX_MAP_MODE_RANDOM)) {
+		/* view mapping */
+		mapping->xmin = mouse[0] - size * 0.5f + 0.5f;
+		mapping->ymin = mouse[1] - size * 0.5f + 0.5f;
 		mapping->xmax = 1.0f;
 		mapping->ymax = 1.0f;
 	}
-
-	if (mapmode == MTEX_MAP_MODE_TILED) {
-		/* offset relative to start position for tiled */
-		mapping->xmin += (int)pos[0] - (int)startpos[0];
-		mapping->ymin += (int)pos[1] - (int)startpos[1];
+	else /* if (mapmode == MTEX_MAP_MODE_TILED) */ {
+		mapping->xmin = -size * 0.5f + 0.5f + (int)pos[0] - (int)startpos[0];
+		mapping->ymin = -size * 0.5f + 0.5f + (int)pos[1] - (int)startpos[1];
+		mapping->xmax = 1.0f;
+		mapping->ymax = 1.0f;
 	}
 }
 
-static void brush_painter_2d_refresh_cache(ImagePaintState *s, BrushPainter *painter, const float pos[2])
+static void brush_painter_2d_refresh_cache(ImagePaintState *s, BrushPainter *painter, const float pos[2], const float mouse[2])
 {
 	const Scene *scene = painter->scene;
 	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
@@ -589,7 +589,7 @@
 		else
 			do_partial_update = true;
 
-		brush_painter_2d_tex_mapping(s, size, painter->startpaintpos, pos,
+		brush_painter_2d_tex_mapping(s, size, painter->startpaintpos, pos, mouse,
 		                             brush->mtex.brush_map_mode, &painter->tex_mapping);
 	}
 
@@ -603,8 +603,8 @@
 		else
 			do_partial_update = true;
 
-		brush_painter_2d_tex_mapping(s, size, painter->startpaintpos,
-		                             pos, brush->mask_mtex.brush_map_mode, &painter->mask_mapping);
+		brush_painter_2d_tex_mapping(s, size, painter->startpaintpos, pos, mouse,
+		                             brush->mask_mtex.brush_map_mode, &painter->mask_mapping);
 	}
 
 	if (do_view || do_random)
@@ -1063,7 +1063,7 @@
 	 */
 	brush_painter_2d_require_imbuf(painter, (ibuf->rect_float != NULL), !is_data, s->do_masking);
 
-	brush_painter_2d_refresh_cache(s, painter, newuv);
+	brush_painter_2d_refresh_cache(s, painter, newuv, mval);
 
 	if (paint_2d_op(s, painter->cache.ibuf, painter->cache.mask, olduv, newuv))
 		s->need_redraw = true;




More information about the Bf-blender-cvs mailing list