[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47903] branches/soc-2012-bratwurst: Texpaint tools

Antony Riakiotakis kalast at gmail.com
Thu Jun 14 16:19:11 CEST 2012


Revision: 47903
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47903
Author:   psy-fi
Date:     2012-06-14 14:19:05 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
Texpaint tools
===============
* Highly experimental but useful feature. Random brush size during
stroke. This can be quite useful for texture authoring but it may cause
strange things to happen if not configured right. State and memory
allocations (which makes the tool experimental) often depend on brush
size so I made a function to get the non-randomized size too. I will
most likely change the naming so that BKE_brush_size returns the non-
Still no crashes here and a few very cool things can be done with this
brush setting :)

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
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_ops.c
    branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.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-14 14:04:55 UTC (rev 47902)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-06-14 14:19:05 UTC (rev 47903)
@@ -643,6 +643,9 @@
             self.prop_unified_size(row, context, brush, "use_pressure_size")
 
             row = col.row(align=True)
+            row.prop(brush, "random_size", slider=True)
+
+            row = col.row(align=True)
             self.prop_unified_strength(row, context, brush, "strength", text="Strength")
             self.prop_unified_strength(row, context, brush, "use_pressure_strength")
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-14 14:04:55 UTC (rev 47902)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-14 14:19:05 UTC (rev 47903)
@@ -91,7 +91,7 @@
 struct ImBuf *BKE_brush_gen_radial_control_imbuf(struct Brush *br);
 
 /* unified strength and size */
-
+int BKE_brush_size_nonrandomized_get(const struct Scene *scene, struct Brush *brush);
 int  BKE_brush_size_get(const struct Scene *scene, struct Brush *brush);
 void BKE_brush_size_set(struct Scene *scene, struct Brush *brush, int value);
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-14 14:04:55 UTC (rev 47902)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-14 14:19:05 UTC (rev 47903)
@@ -102,6 +102,8 @@
 	brush->rate = 0.1f; /* time delay between dots of paint or sculpting when doing airbrush mode */
 
 	brush->jitter = 0.0f;
+	brush->random_size = 0.0;
+	brush->random_size_cache = 1.0;
 
 	/* BRUSH TEXTURE SETTINGS */
 	default_mtex(&brush->mtex);
@@ -296,6 +298,8 @@
 	BR_TEST_FLAG(BRUSH_CUSTOM_ICON);
 
 	BR_TEST(jitter, f);
+	BR_TEST(random_size, f);
+	BR_TEST(random_size_cache, f);
 	BR_TEST(spacing, d);
 	BR_TEST(smooth_stroke_radius, d);
 	BR_TEST(smooth_stroke_factor, f);
@@ -485,6 +489,14 @@
 	return 0;
 }
 
+/* reset the random size cache to a random value, proportional to the size of the brush.
+ * due to the many places BKE_brush_size_get is called it is not safe to generate a random
+ * number for every call. Instead we will generate a random number before each stroke */
+void BKE_brush_randomize_size(Brush *brush)
+{
+	brush->random_size_cache = (1.0 - brush->random_size/2.0) + brush->random_size*BLI_frand();
+}
+
 /* Brush Sampling */
 void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread, float angle)
 {
@@ -657,13 +669,20 @@
 		brush->size = size;
 }
 
-int BKE_brush_size_get(const Scene *scene, Brush *brush)
+int BKE_brush_size_nonrandomized_get(const Scene *scene, Brush *brush)
 {
 	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 
 	return (ups->flag & UNIFIED_PAINT_SIZE) ? ups->size : brush->size;
 }
 
+int BKE_brush_size_get(const Scene *scene, Brush *brush)
+{
+	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
+
+	return (ups->flag & UNIFIED_PAINT_SIZE) ? brush->random_size_cache*ups->size : brush->random_size_cache*brush->size;
+}
+
 int BKE_brush_use_locked_size(const Scene *scene, Brush *brush)
 {
 	const short us_flag = scene->toolsettings->unified_paint_settings.flag;
@@ -821,7 +840,7 @@
 	painter->firsttouch = 1;
 	painter->cache.lastsize = -1; /* force ibuf create in refresh */
 
-	painter->startsize = BKE_brush_size_get(scene, brush);
+	painter->startsize = BKE_brush_size_nonrandomized_get(scene, brush);
 	painter->startalpha = BKE_brush_alpha_get(scene, brush);
 	painter->startjitter = brush->jitter;
 	painter->startspacing = brush->spacing;
@@ -1116,6 +1135,8 @@
 	Brush *brush = painter->brush;
 	int totpaintops = 0;
 
+	BKE_brush_randomize_size(brush);
+
 	if (pressure == 0.0f) {
 		if (painter->lastpressure) // XXX - hack, operator misses
 			pressure = painter->lastpressure;

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-14 14:04:55 UTC (rev 47902)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-06-14 14:19:05 UTC (rev 47903)
@@ -2957,7 +2957,7 @@
 	
 	MemArena *arena; /* at the moment this is just ps->arena_mt[0], but use this to show were not multithreading */
 
-	const int diameter = 2 * BKE_brush_size_get(ps->scene, ps->brush);
+	const int diameter = 2 * BKE_brush_size_nonrandomized_get(ps->scene, ps->brush);
 	
 	/* ---- end defines ---- */
 	
@@ -4871,7 +4871,7 @@
 	if (pop->mode == PAINT_MODE_3D && (pop->s.tool == PAINT_TOOL_CLONE))
 		pop->s.tool = PAINT_TOOL_DRAW;
 	pop->s.blend = brush->blend;
-	pop->orig_brush_size = BKE_brush_size_get(scene, brush);
+	pop->orig_brush_size = BKE_brush_size_nonrandomized_get(scene, brush);
 
 	if (pop->mode != PAINT_MODE_2D) {
 		Object *ob = OBACT;
@@ -5226,7 +5226,7 @@
 	if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
 		ToolSettings *ts;
 		float zoomx, zoomy;
-		const float size = (float)BKE_brush_size_get(scene, brush);
+		const float size = (float)BKE_brush_size_nonrandomized_get(scene, brush);
 		short use_zoom;
 		float pixel_size;
 		float alpha = 0.5f;

Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_ops.c	2012-06-14 14:04:55 UTC (rev 47902)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_ops.c	2012-06-14 14:19:05 UTC (rev 47903)
@@ -99,7 +99,7 @@
 	if (brush) {
 		// pixel radius
 		{
-			const int old_size = BKE_brush_size_get(scene, brush);
+			const int old_size = BKE_brush_size_nonrandomized_get(scene, brush);
 			int size = (int)(scalar * old_size);
 
 			if (old_size == size) {

Modified: branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h	2012-06-14 14:04:55 UTC (rev 47902)
+++ branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h	2012-06-14 14:19:05 UTC (rev 47903)
@@ -69,6 +69,8 @@
 	short ob_mode;      /* & with ob->mode to see if the brush is compatible, use for display only. */
 	float weight;       /* brush weight */
 	int size;           /* brush diameter */
+	float random_size;  /* randomize brush diameter */
+	float random_size_cache; /* cache the random size */
 	int flag;           /* general purpose flag */
 	float jitter;       /* jitter the position of the brush */
 	int spacing;        /* spacing of paint operations */

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c	2012-06-14 14:04:55 UTC (rev 47902)
+++ branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c	2012-06-14 14:19:05 UTC (rev 47903)
@@ -618,6 +618,12 @@
 	RNA_def_property_ui_text(prop, "Unprojected Radius", "Radius of brush in Blender units");
 	RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+	prop = RNA_def_property(srna, "random_size", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "random_size");
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_ui_text(prop, "Randomize Radius", "Radius of brush changes while painting");
+	RNA_def_property_update(prop, 0, "rna_Brush_update");
+
 	prop = RNA_def_property(srna, "jitter", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "jitter");
 	RNA_def_property_range(prop, 0.0f, 1.0f);




More information about the Bf-blender-cvs mailing list