[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58409] branches/soc-2013-paint: Enable brush space attenuation for image painting as well as sculpting.

Antony Riakiotakis kalast at gmail.com
Fri Jul 19 17:27:34 CEST 2013


Revision: 58409
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58409
Author:   psy-fi
Date:     2013-07-19 15:27:34 +0000 (Fri, 19 Jul 2013)
Log Message:
-----------
Enable brush space attenuation for image painting as well as sculpting.
This makes it so that when using space with accumulate option, the
strength of the brush is attemuated to account for overlapping dabbing
of the brush. This way you don't get overblown areas while painting,
while still being able to paint over the same region repeatedly. To
enable this calculation, click on the lock icon next to the strength of
the brush when "accumulate" is selected.

This commit moves the attenuation factor calculation outside of sculpt
code and on stroke level. It also optimizes the curve integration to
only happen if the correct modes are enabled, while on sculpting it
occured always.

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/blenkernel/intern/paint.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2013-paint/source/blender/makesdna/DNA_scene_types.h
    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-07-19 15:27:23 UTC (rev 58408)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-07-19 15:27:34 UTC (rev 58409)
@@ -720,6 +720,12 @@
             self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
             self.prop_unified_size(row, context, brush, "use_pressure_size")
 
+            if capabilities.has_space_attenuation:
+                if brush.use_space_attenuation:
+                    row.prop(brush, "use_space_attenuation", toggle=True, text="", icon='LOCKED')
+                else:
+                    row.prop(brush, "use_space_attenuation", toggle=True, text="", icon='UNLOCKED')
+            
             row = col.row(align=True)
             self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength")
             self.prop_unified_strength(row, context, brush, "use_pressure_strength")

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-07-19 15:27:23 UTC (rev 58408)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-07-19 15:27:34 UTC (rev 58409)
@@ -701,6 +701,13 @@
             self.prop_unified_size(row, context, brush, "use_pressure_size")
 
             row = col.row(align=True)
+            
+            if capabilities.has_space_attenuation:
+                if brush.use_space_attenuation:
+                    row.prop(brush, "use_space_attenuation", toggle=True, text="", icon='LOCKED')
+                else:
+                    row.prop(brush, "use_space_attenuation", toggle=True, text="", icon='UNLOCKED')
+
             self.prop_unified_strength(row, context, brush, "strength", text="Strength")
             self.prop_unified_strength(row, context, brush, "use_pressure_strength")
 

Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c	2013-07-19 15:27:23 UTC (rev 58408)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c	2013-07-19 15:27:34 UTC (rev 58409)
@@ -117,6 +117,7 @@
 	}
 }
 
+
 void BKE_paint_reset_overlay_invalid(OverlayControlFlags flag)
 {
 	overlay_flags &= ~(flag);

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-07-19 15:27:23 UTC (rev 58408)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-07-19 15:27:34 UTC (rev 58409)
@@ -623,7 +623,9 @@
 {
 	PaintOperation *pop = paint_stroke_mode_data(stroke);
 	Scene *scene = CTX_data_scene(C);
-	Brush *brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint);
+	ToolSettings *toolsettings = CTX_data_tool_settings(C);
+	UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
+	Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
 
 	/* initial brush values. Maybe it should be considered moving these to stroke system */
 	float startsize = (float)BKE_brush_size_get(scene, brush);
@@ -640,7 +642,7 @@
 	size = RNA_float_get(itemptr, "size");
 
 	if (BKE_brush_use_alpha_pressure(scene, brush))
-		BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure));
+		BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * ups->overlap_factor));
 
 	BKE_brush_size_set(scene, brush, max_ff(1.0f, size));
 

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-07-19 15:27:23 UTC (rev 58408)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c	2013-07-19 15:27:34 UTC (rev 58409)
@@ -412,6 +412,7 @@
 	if (brush) {
 		BKE_paint_brush_set(paint, brush);
 		BKE_paint_invalidate_overlay_all();
+
 		WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
 		return OPERATOR_FINISHED;
 	}

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c	2013-07-19 15:27:23 UTC (rev 58408)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c	2013-07-19 15:27:34 UTC (rev 58409)
@@ -75,6 +75,7 @@
 	ViewContext vc;
 	bglMats mats;
 	Brush *brush;
+	UnifiedPaintSettings *ups;
 
 	/* Paint stroke can use up to PAINT_MAX_INPUT_SAMPLES prior inputs
 	 * to smooth the stroke */
@@ -152,7 +153,7 @@
 
 
 /* Initialize the stroke cache variants from operator properties */
-static void paint_brush_update(bContext *C, UnifiedPaintSettings *ups,
+static void paint_brush_update(bContext *C,
                                          Brush *brush,
                                          PaintMode mode,
                                          struct PaintStroke *stroke,
@@ -161,6 +162,7 @@
                                          float location[3])
 {
 	Scene *scene = CTX_data_scene(C);
+	UnifiedPaintSettings *ups = stroke->ups;
 	bool location_sampled = false;
 	/* XXX: Use pressure value from first brush step for brushes which don't
 	 *      support strokes (grab, thumb). They depends on initial state and
@@ -277,13 +279,13 @@
 static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float mouse_in[2], float pressure)
 {
 	Scene *scene = CTX_data_scene(C);
-	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 	wmWindow *window = CTX_wm_window(C);
 	ARegion *ar = CTX_wm_region(C);
 	Paint *paint = BKE_paint_get_active_from_context(C);
 	PaintMode mode = BKE_paintmode_get_active_from_context(C);
 	Brush *brush = BKE_paint_brush(paint);
 	PaintStroke *stroke = op->customdata;
+	UnifiedPaintSettings *ups = stroke->ups;
 	float mouse_out[2];
 	PointerRNA itemptr;
 	float location[3];
@@ -328,7 +330,7 @@
 		}
 	}
 
-	paint_brush_update(C, ups, brush, mode, stroke, mouse_in, mouse_out, pressure, location);
+	paint_brush_update(C, brush, mode, stroke, mouse_in, mouse_out, pressure, location);
 
 	/* Add to stroke */
 	RNA_collection_add(op->ptr, "stroke", &itemptr);
@@ -394,6 +396,53 @@
 	return (size_clamp * spacing / 50.0f);
 }
 
+
+
+static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing)
+{
+	int i;
+	const int n = 100 / spacing;
+	const float h = spacing / 50.0f;
+	const float x0 = x - 1;
+
+	float sum;
+
+	sum = 0;
+	for (i = 0; i < n; i++) {
+		float xx;
+
+		xx = fabs(x0 + i * h);
+
+		if (xx < 1.0f)
+			sum += BKE_brush_curve_strength(br, xx, 1);
+	}
+
+	return sum;
+}
+
+static float paint_stroke_integrate_overlap(Brush *br, float spacing)
+{
+	int i;
+	int m;
+	float g;
+	float max;
+
+	if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100)))
+		return 1.0;
+
+	m = 10;
+	g = 1.0f / m;
+	max = 0;
+	for (i = 0; i < m; i++) {
+		float overlap = paint_stroke_overlapped_curve(br, i * g, spacing);
+
+		if (overlap > max)
+			max = overlap;
+	}
+
+	return 1.0/max;
+}
+
 static float paint_space_stroke_spacing_variable(const Scene *scene, PaintStroke *stroke, float pressure, float dpressure, float length)
 {
 	if (BKE_brush_use_size_pressure(scene, stroke->brush)) {
@@ -425,6 +474,7 @@
 {
 	const Scene *scene = CTX_data_scene(C);
 	PaintStroke *stroke = op->customdata;
+	UnifiedPaintSettings *ups = stroke->ups;
 	PaintMode mode = BKE_paintmode_get_active_from_context(C);
 	int cnt = 0;
 
@@ -448,6 +498,8 @@
 				mouse[1] = stroke->last_mouse_position[1] + dmouse[1] * spacing;
 				pressure = stroke->last_pressure + (spacing / length) * dpressure;
 
+				ups->overlap_factor = paint_stroke_integrate_overlap(stroke->brush, spacing);
+
 				paint_brush_stroke_add_step(C, op, mouse, pressure);
 
 				length -= spacing;
@@ -475,7 +527,8 @@
                               StrokeDone done, int event_type)
 {
 	PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
-
+	ToolSettings *toolsettings = CTX_data_tool_settings(C);
+	UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
 	Brush *br = stroke->brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
 	view3d_set_viewcontext(C, &stroke->vc);
 	if (stroke->vc.v3d)
@@ -487,6 +540,10 @@
 	stroke->redraw = redraw;
 	stroke->done = done;
 	stroke->event_type = event_type; /* for modal, return event */
+	stroke->ups = ups;
+
+	/* initialize here */
+	ups->overlap_factor = 1.0;
 	
 	BKE_paint_set_overlay_override(br->overlay_flags);
 
@@ -503,8 +560,7 @@
 static void stroke_done(struct bContext *C, struct wmOperator *op)
 {
 	struct PaintStroke *stroke = op->customdata;
-	Scene *scene = CTX_data_scene(C);
-	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
+	UnifiedPaintSettings *ups = stroke->ups;
 
 	ups->draw_anchored = false;
 	ups->draw_pressure = false;

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c	2013-07-19 15:27:23 UTC (rev 58408)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c	2013-07-19 15:27:34 UTC (rev 58409)
@@ -713,46 +713,6 @@
  *
  */
 
-static float overlapped_curve(Brush *br, float x)
-{
-	int i;
-	const int n = 100 / br->spacing;
-	const float h = br->spacing / 50.0f;
-	const float x0 = x - 1;
-
-	float sum;
-
-	sum = 0;
-	for (i = 0; i < n; i++) {
-		float xx;
-
-		xx = fabs(x0 + i * h);
-
-		if (xx < 1.0f)
-			sum += BKE_brush_curve_strength(br, xx, 1);
-	}
-
-	return sum;
-}
-
-static float integrate_overlap(Brush *br)
-{
-	int i;
-	int m = 10;
-	float g = 1.0f / m;
-	float max;
-
-	max = 0;
-	for (i = 0; i < m; i++) {
-		float overlap = overlapped_curve(br, i * g);
-
-		if (overlap > max)
-			max = overlap;
-	}
-
-	return max;
-}
-
 /* Uses symm to selectively flip any axis of a coordinate. */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list