[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57877] branches/soc-2013-paint: Drag dot strokes for image painting.

Antony Riakiotakis kalast at gmail.com
Sat Jun 29 13:08:30 CEST 2013


Revision: 57877
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57877
Author:   psy-fi
Date:     2013-06-29 11:08:30 +0000 (Sat, 29 Jun 2013)
Log Message:
-----------
Drag dot strokes for image painting.

This was mostly working with undo code.

There is a tradeoff between doing undo traversal for images vs undo
initialiatio time:

The more area the user paints on, the more undo tiles are added to the
system. That makes restoring of the image slower after each step.
A way to optimize this is to completely delete the undo tiles after each
step. This also will make the undo steps use less memory.

However given that for a realistic, non-user-testing use case, the dabs
will be localized, better optimize the initialization case. In
projective texturing, which is the most performance hungry, indeed this
helps with performance, provided the use case is sane. I left the
clearing code ifdefed out just in case.

Also exposed anchored stroke options. They work with texture coordinates
well but not with paint brush size yet.

Modified Paths:
--------------
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_undo.c
    branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-06-29 11:02:36 UTC (rev 57876)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-06-29 11:08:30 UTC (rev 57877)
@@ -833,7 +833,7 @@
 
         col.label(text="Stroke Method:")
 
-        col.prop(brush, "texpaint_stroke_method", text="")
+        col.prop(brush, "stroke_method", text="")
 
         if brush.use_anchor:
             col.separator()
@@ -886,7 +886,8 @@
 
         layout.template_curve_mapping(brush, "curve")
 
-        row = layout.row(align=True)
+        col = layout.column(align=True)
+        row = col.row(align=True)
         row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'
         row.operator("brush.curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND'
         row.operator("brush.curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT'
@@ -894,9 +895,17 @@
         row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE'
         row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX'
 
-        sub = row.row()
-        sub.prop(brush, "cursor_overlay_alpha", text="Alpha")
-        sub.prop(brush, "use_cursor_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
+        col = layout.column(align=True)
+        col.separator()
+        
+        col.label(text="Overlay:")
+        row = col.row(align=True)
+        if brush.use_cursor_overlay:
+            row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
+        else:
+            row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
+        row.prop(brush, "cursor_overlay_alpha", text="Alpha")
+        row.prop(brush, "use_cursor_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
 
 
 class IMAGE_PT_tools_brush_appearance(BrushButtonsPanel, Panel):

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-06-29 11:02:36 UTC (rev 57876)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-06-29 11:08:30 UTC (rev 57877)
@@ -860,12 +860,10 @@
 
         col.label(text="Stroke Method:")
 
-        if context.sculpt_object:
-            col.prop(brush, "sculpt_stroke_method", text="")
-        elif context.image_paint_object:
-            col.prop(brush, "texpaint_stroke_method", text="")
-        else:
+        if context.sculpt_object or context.image_paint_object:
             col.prop(brush, "stroke_method", text="")
+        else:
+            col.prop(brush, "stroke_method_limited", text="")
 
         if brush.use_anchor:
             col.separator()

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-06-29 11:02:36 UTC (rev 57876)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-06-29 11:08:30 UTC (rev 57877)
@@ -150,10 +150,20 @@
 	else {
 		SWAP(unsigned int *, tmpibuf->rect, tile->rect.uint);
 	}
-	
-	if (restore)
+
+	if (restore) {
 		IMB_rectcpy(ibuf, tmpibuf, tile->x * IMAPAINT_TILE_SIZE,
 		            tile->y * IMAPAINT_TILE_SIZE, 0, 0, IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE);
+
+		/* swap the contents back or the undo tiles will now contain the dirty version
+		 * of the image that was copied to temporary imbuf at start of function */
+		if (ibuf->rect_float) {
+			SWAP(float *, tmpibuf->rect_float, tile->rect.fp);
+		}
+		else {
+			SWAP(unsigned int *, tmpibuf->rect, tile->rect.uint);
+		}
+	}
 }
 
 void *image_undo_find_tile(Image *ima, ImBuf *ibuf, int x_tile, int y_tile, unsigned short **mask)
@@ -516,6 +526,23 @@
 	return pop;
 }
 
+/* restore painting image to previous state. Used for anchored and drag-dot style brushes*/
+static void paint_stroke_restore(bContext *C)
+{
+	ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_IMAGE);
+	image_undo_restore(C, lb);
+
+/* keep these here, it helps to not traverse the whole undo tree if user is
+ * stroking all over the image, but this is not the ideal use case.
+ * There is a tradeoff between undo initialization time and restore time.
+ * Since the stroke is ideally localized, better optimize the initialization case */
+#if 0
+	image_undo_free(lb);
+	BLI_freelistN(lb);
+	undo_paint_push_count_reset(UNDO_PAINT_IMAGE);
+#endif
+}
+
 static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
 {
 	PaintOperation *pop = paint_stroke_mode_data(stroke);
@@ -539,6 +566,10 @@
 	if (BKE_brush_use_size_pressure(scene, brush))
 		BKE_brush_size_set(scene, brush, max_ff(1.0f, startsize * pressure));
 
+	if ((brush->flag & BRUSH_RESTORE_MESH) || (brush->flag & BRUSH_ANCHORED)) {
+		paint_stroke_restore(C);
+	}
+
 	if (pop->mode == PAINT_MODE_3D_PROJECT) {
 		paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse);
 	}

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-06-29 11:02:36 UTC (rev 57876)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-06-29 11:08:30 UTC (rev 57877)
@@ -1045,7 +1045,9 @@
 	}
 
 	/* set masking */
-	s->do_masking = (s->brush->flag & BRUSH_AIRBRUSH ||
+	s->do_masking = ((s->brush->flag & BRUSH_AIRBRUSH) ||
+	                 (s->brush->flag & BRUSH_RESTORE_MESH) ||
+	                 (s->brush->flag & BRUSH_ANCHORED) ||
 	                 (s->brush->imagepaint_tool == PAINT_TOOL_SMEAR) ||
 	                 (s->brush->mtex.tex && !ELEM3(s->brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_3D)) ||
 	                 s->brush->flag & BRUSH_ACCUMULATE)

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c	2013-06-29 11:02:36 UTC (rev 57876)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c	2013-06-29 11:08:30 UTC (rev 57877)
@@ -3263,11 +3263,8 @@
 	}
 }
 
-static void project_paint_end(ProjPaintState *ps)
+static void project_paint_undo_push(ProjPaintState *ps)
 {
-	int a;
-	ProjPaintImage *projIma;
-
 	/* build undo data from original pixel colors */
 	if (U.uiflag & USER_GLOBALUNDO) {
 		ProjPixel *projPixel;
@@ -3279,6 +3276,7 @@
 		int bucket_tot = (ps->buckets_x * ps->buckets_y); /* we could get an X/Y but easier to loop through all possible buckets */
 		int bucket_index;
 		int tile_index;
+		int a;
 		int x_round, y_round;
 		int x_tile, y_tile;
 		int is_float = -1;
@@ -3353,8 +3351,16 @@
 		if (tmpibuf) IMB_freeImBuf(tmpibuf);
 		if (tmpibuf_float) IMB_freeImBuf(tmpibuf_float);
 	}
-	/* done calculating undo data */
+}
 
+
+static void project_paint_end(ProjPaintState *ps)
+{
+	int a;
+	ProjPaintImage *projIma;
+
+	project_paint_undo_push(ps);
+
 	/* dereference used image buffers */
 	for (a = 0, projIma = ps->projImages; a < ps->image_tot; a++, projIma++) {
 		BKE_image_release_ibuf(projIma->ima, projIma->ibuf, NULL);
@@ -4126,6 +4132,10 @@
 
 	if (project_paint_op(ps, prev_pos, pos))
 		ps->need_redraw = true;
+
+	if ((ps->brush->flag & BRUSH_RESTORE_MESH) ||
+	    (ps->brush->flag & BRUSH_ANCHORED))
+		project_paint_undo_push(ps);
 }
 
 
@@ -4144,7 +4154,9 @@
 		ps->blend = brush->blend;
 
 		/* disable for 3d mapping also because painting on mirrored mesh can create "stripes" */
-		ps->do_masking = (brush->flag & BRUSH_AIRBRUSH ||
+		ps->do_masking = ((brush->flag & BRUSH_AIRBRUSH) ||
+	                      (brush->flag & BRUSH_RESTORE_MESH) ||
+	                      (brush->flag & BRUSH_ANCHORED) ||
 		                  (brush->imagepaint_tool == PAINT_TOOL_SMEAR) ||
 		                  (brush->mtex.tex && !ELEM3(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_3D)) ||
 		                  brush->flag & BRUSH_ACCUMULATE)

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-06-29 11:02:36 UTC (rev 57876)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-06-29 11:08:30 UTC (rev 57877)
@@ -237,6 +237,7 @@
 void undo_paint_push_begin(int type, const char *name, UndoRestoreCb restore, UndoFreeCb free);
 struct ListBase *undo_paint_push_get_list(int type);
 void undo_paint_push_count_alloc(int type, int size);
+void undo_paint_push_count_reset(int type);
 void undo_paint_push_end(int type);
 
 /* paint_hide.c */

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c	2013-06-29 11:02:36 UTC (rev 57876)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c	2013-06-29 11:08:30 UTC (rev 57877)
@@ -1169,7 +1169,7 @@
 
 	/* */
 	kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
-	RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.sculpt_stroke_method");
+	RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.stroke_method");
 
 	kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
 	RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.use_smooth_stroke");
@@ -1203,7 +1203,7 @@
 	RNA_string_set(kmi->ptr, "data_path", "tool_settings.vertex_paint.brush.texture_angle_source_random");
 
 	kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
-	RNA_string_set(kmi->ptr, "data_path", "tool_settings.vertex_paint.brush.stroke_method");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list