[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30812] trunk/blender: == Sculpt ==

Nicholas Bishop nicholasbishop at gmail.com
Tue Jul 27 18:09:02 CEST 2010


Revision: 30812
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30812
Author:   nicholasbishop
Date:     2010-07-27 18:09:02 +0200 (Tue, 27 Jul 2010)

Log Message:
-----------
== Sculpt ==

Added a brush reset operator so that a user won't need to reload the default blend to get back default brush settings

* New brush.reset operator, resets a brush based on the currently-selected tool
* Added UI button in the tools panel

TODO:
* Only resets sculpt brushes right now, other paint modes should be added
* Sculpt polish tool exists only as a Brush, not as a tool; I'd suggest we make it a tool so it can be reset to defaults too

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_view3d_toolbar.py
    trunk/blender/source/blender/blenkernel/BKE_brush.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c

Modified: trunk/blender/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- trunk/blender/release/scripts/ui/space_view3d_toolbar.py	2010-07-27 15:33:21 UTC (rev 30811)
+++ trunk/blender/release/scripts/ui/space_view3d_toolbar.py	2010-07-27 16:09:02 UTC (rev 30812)
@@ -859,6 +859,7 @@
 
         if context.sculpt_object:
             col.prop(brush, "sculpt_tool", expand=False, text="")
+            col.operator("brush.reset")
         elif context.texture_paint_object:
             col.prop(brush, "imagepaint_tool", expand=False, text="")
         elif context.vertex_paint_object or context.weight_paint_object:

Modified: trunk/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_brush.h	2010-07-27 15:33:21 UTC (rev 30811)
+++ trunk/blender/source/blender/blenkernel/BKE_brush.h	2010-07-27 16:09:02 UTC (rev 30812)
@@ -44,6 +44,8 @@
 void make_local_brush(struct Brush *brush);
 void free_brush(struct Brush *brush);
 
+void brush_reset_sculpt(struct Brush *brush);
+
 /* image icon function */
 struct ImBuf *get_brush_icon(struct Brush *brush);
 

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2010-07-27 15:33:21 UTC (rev 30811)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2010-07-27 16:09:02 UTC (rev 30812)
@@ -62,25 +62,22 @@
 #include "RE_render_ext.h" /* externtex */
 #include "RE_shader_ext.h"
 
-/* Datablock add/copy/free/make_local */
-
-Brush *add_brush(const char *name)
+static void brush_set_defaults(Brush *brush)
 {
-	Brush *brush;
+	brush->blend = 0;
+	brush->flag = 0;
 
-	brush= alloc_libblock(&G.main->brush, ID_BR, name);
-
 	/* BRUSH SCULPT TOOL SETTINGS */
-	brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */
 	brush->size= 35; /* radius of the brush in pixels */
 	brush->alpha= 0.5f; /* brush strength/intensity probably variable should be renamed? */
 	brush->autosmooth_factor= 0.0f;
 	brush->crease_pinch_factor= 0.5f;
-	brush->sculpt_plane = SCULPT_DISP_DIR_VIEW;
+	brush->sculpt_plane = SCULPT_DISP_DIR_AREA;
 	brush->plane_offset= 0.0f; /* how far above or below the plane that is found by averaging the faces */
 	brush->plane_trim= 0.5f;
 	brush->clone.alpha= 0.5f;
 	brush->normal_weight= 0.0f;
+	brush->flag |= BRUSH_ALPHA_PRESSURE;
 
 	/* BRUSH PAINT TOOL SETTINGS */
 	brush->rgb[0]= 1.0f; /* default rgb color of the brush when painting - white */
@@ -102,6 +99,7 @@
 	default_mtex(&brush->mtex);
 
 	brush->texture_sample_bias= 0; /* value to added to texture samples */
+	brush->texture_overlay_alpha= 33;
 
 	/* brush appearance  */
 
@@ -112,7 +110,20 @@
 	brush->sub_col[0]= 0.39; /* subtract mode color is light blue */
 	brush->sub_col[1]= 0.39;
 	brush->sub_col[2]= 1.00;
+}
 
+/* Datablock add/copy/free/make_local */
+
+Brush *add_brush(const char *name)
+{
+	Brush *brush;
+
+	brush= alloc_libblock(&G.main->brush, ID_BR, name);
+
+	brush_set_defaults(brush);
+
+	brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */
+
 	 /* the default alpha falloff curve */
 	brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
 
@@ -212,6 +223,175 @@
 	}
 }
 
+void brush_debug_print_state(Brush *br)
+{
+	Brush def;
+
+	/* create a fake brush and set it to the defaults */
+	memset(&def, 0, sizeof(Brush));
+	brush_set_defaults(&def);
+	
+#define BR_TEST(field, t)					\
+	if(br->field != def.field)				\
+		printf("br->" #field " = %" #t ";\n", br->field)
+
+#define BR_TEST_FLAG(_f)				\
+	if((br->flag & _f) && !(def.flag & _f))		\
+		printf("br->flag |= " #_f ";\n");	\
+	else if(!(br->flag & _f) && (def.flag & _f))	\
+		printf("br->flag &= ~" #_f ";\n")
+	
+
+	/* print out any non-default brush state */
+	BR_TEST(normal_weight, f);
+
+	BR_TEST(blend, d);
+	BR_TEST(size, d);
+
+	/* br->flag */
+	BR_TEST_FLAG(BRUSH_AIRBRUSH);
+	BR_TEST_FLAG(BRUSH_TORUS);
+	BR_TEST_FLAG(BRUSH_ALPHA_PRESSURE);
+	BR_TEST_FLAG(BRUSH_SIZE_PRESSURE);
+	BR_TEST_FLAG(BRUSH_JITTER_PRESSURE);
+	BR_TEST_FLAG(BRUSH_SPACING_PRESSURE);
+	BR_TEST_FLAG(BRUSH_FIXED_TEX);
+	BR_TEST_FLAG(BRUSH_RAKE);
+	BR_TEST_FLAG(BRUSH_ANCHORED);
+	BR_TEST_FLAG(BRUSH_DIR_IN);
+	BR_TEST_FLAG(BRUSH_SPACE);
+	BR_TEST_FLAG(BRUSH_SMOOTH_STROKE);
+	BR_TEST_FLAG(BRUSH_PERSISTENT);
+	BR_TEST_FLAG(BRUSH_ACCUMULATE);
+	BR_TEST_FLAG(BRUSH_LOCK_ALPHA);
+	BR_TEST_FLAG(BRUSH_ORIGINAL_NORMAL);
+	BR_TEST_FLAG(BRUSH_OFFSET_PRESSURE);
+	BR_TEST_FLAG(BRUSH_SPACE_ATTEN);
+	BR_TEST_FLAG(BRUSH_ADAPTIVE_SPACE);
+	BR_TEST_FLAG(BRUSH_LOCK_SIZE);
+	BR_TEST_FLAG(BRUSH_TEXTURE_OVERLAY);
+	BR_TEST_FLAG(BRUSH_EDGE_TO_EDGE);
+	BR_TEST_FLAG(BRUSH_RESTORE_MESH);
+	BR_TEST_FLAG(BRUSH_INVERSE_SMOOTH_PRESSURE);
+	BR_TEST_FLAG(BRUSH_RANDOM_ROTATION);
+	BR_TEST_FLAG(BRUSH_PLANE_TRIM);
+	BR_TEST_FLAG(BRUSH_FRONTFACE);
+	BR_TEST_FLAG(BRUSH_CUSTOM_ICON);
+
+	BR_TEST(jitter, f);
+	BR_TEST(spacing, d);
+	BR_TEST(smooth_stroke_radius, d);
+	BR_TEST(smooth_stroke_factor, f);
+	BR_TEST(rate, f);
+
+	BR_TEST(alpha, f);
+
+	BR_TEST(sculpt_plane, d);
+
+	BR_TEST(plane_offset, f);
+
+	BR_TEST(autosmooth_factor, f);
+
+	BR_TEST(crease_pinch_factor, f);
+
+	BR_TEST(plane_trim, f);
+
+	BR_TEST(texture_sample_bias, f);
+	BR_TEST(texture_overlay_alpha, d);
+
+	BR_TEST(add_col[0], f);
+	BR_TEST(add_col[1], f);
+	BR_TEST(add_col[2], f);
+	BR_TEST(sub_col[0], f);
+	BR_TEST(sub_col[1], f);
+	BR_TEST(sub_col[2], f);
+
+	printf("\n");
+	
+#undef BR_TEST
+#undef BR_TEST_FLAG
+}
+
+void brush_reset_sculpt(Brush *br)
+{
+	/* enable this to see any non-default
+	   settings used by a brush:
+
+	   brush_debug_print_state(br);
+	*/
+
+	brush_set_defaults(br);
+	brush_curve_preset(br, CURVE_PRESET_SMOOTH);
+
+	switch(br->sculpt_tool) {
+	case SCULPT_TOOL_CLAY:
+		br->flag |= BRUSH_FRONTFACE;
+		break;
+	case SCULPT_TOOL_CREASE:
+		br->flag |= BRUSH_DIR_IN;
+		br->alpha = 0.25;
+		break;
+	case SCULPT_TOOL_FILL:
+		br->add_col[1] = 1;
+		br->sub_col[0] = 0.25;
+		br->sub_col[1] = 1;
+		break;
+	case SCULPT_TOOL_FLATTEN:
+		br->add_col[1] = 1;
+		br->sub_col[0] = 0.25;
+		br->sub_col[1] = 1;
+		break;
+	case SCULPT_TOOL_INFLATE:
+		br->add_col[0] = 0.750000;
+		br->add_col[1] = 0.750000;
+		br->add_col[2] = 0.750000;
+		br->sub_col[0] = 0.250000;
+		br->sub_col[1] = 0.250000;
+		br->sub_col[2] = 0.250000;
+		break;
+	case SCULPT_TOOL_NUDGE:
+		br->add_col[0] = 0.250000;
+		br->add_col[1] = 1.000000;
+		br->add_col[2] = 0.250000;
+		break;
+	case SCULPT_TOOL_PINCH:
+		br->add_col[0] = 0.750000;
+		br->add_col[1] = 0.750000;
+		br->add_col[2] = 0.750000;
+		br->sub_col[0] = 0.250000;
+		br->sub_col[1] = 0.250000;
+		br->sub_col[2] = 0.250000;
+		break;
+	case SCULPT_TOOL_SCRAPE:
+		br->add_col[1] = 1.000000;
+		br->sub_col[0] = 0.250000;
+		br->sub_col[1] = 1.000000;
+		break;
+	case SCULPT_TOOL_ROTATE:
+		break;
+	case SCULPT_TOOL_SMOOTH:
+		br->flag &= ~BRUSH_SPACE_ATTEN;
+		br->spacing = 5;
+		br->add_col[0] = 0.750000;
+		br->add_col[1] = 0.750000;
+		br->add_col[2] = 0.750000;
+		break;
+	case SCULPT_TOOL_GRAB:
+	case SCULPT_TOOL_SNAKE_HOOK:
+	case SCULPT_TOOL_THUMB:
+		br->size = 75;
+		br->flag &= ~BRUSH_ALPHA_PRESSURE;
+		br->flag &= ~BRUSH_SPACE;
+		br->flag &= ~BRUSH_SPACE_ATTEN;
+		br->add_col[0] = 0.250000;
+		br->add_col[1] = 1.000000;
+		br->add_col[2] = 0.250000;
+		break;
+	default:
+		break;
+	}
+}
+
 /* Library Operations */
 
 int brush_set_nr(Brush **current_brush, int nr, const char *name)

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2010-07-27 15:33:21 UTC (rev 30811)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2010-07-27 16:09:02 UTC (rev 30812)
@@ -154,6 +154,35 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+static int brush_reset_exec(bContext *C, wmOperator *op)
+{
+	Paint *paint = paint_get_active(CTX_data_scene(C));
+	Brush *brush = paint_brush(paint);
+	Object *ob = CTX_data_active_object(C);
+
+	if(!ob) return OPERATOR_CANCELLED;
+
+	if(ob->mode & OB_MODE_SCULPT)
+		brush_reset_sculpt(brush);
+	/* TODO: other modes */
+
+	return OPERATOR_FINISHED;
+}
+
+void BRUSH_OT_reset(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Reset Brush";
+	ot->description= "Return brush to defaults based on current tool";
+	ot->idname= "BRUSH_OT_reset";
+	
+	/* api callbacks */
+	ot->exec= brush_reset_exec;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 /**************************** registration **********************************/
 
 void ED_operatortypes_paint(void)
@@ -162,8 +191,8 @@
 	WM_operatortype_append(BRUSH_OT_add);
 	WM_operatortype_append(BRUSH_OT_scale_size);
 	WM_operatortype_append(BRUSH_OT_curve_preset);
+	WM_operatortype_append(BRUSH_OT_reset);
 
-
 	/* image */
 	WM_operatortype_append(PAINT_OT_texture_paint_toggle);
 	WM_operatortype_append(PAINT_OT_texture_paint_radial_control);
@@ -175,7 +204,6 @@
 	WM_operatortype_append(PAINT_OT_project_image);
 	WM_operatortype_append(PAINT_OT_image_from_view);
 
-
 	/* weight */
 	WM_operatortype_append(PAINT_OT_weight_paint_toggle);
 	WM_operatortype_append(PAINT_OT_weight_paint_radial_control);





More information about the Bf-blender-cvs mailing list