[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53835] trunk/blender/source/blender: Unification of brush code

Antony Riakiotakis kalast at gmail.com
Wed Jan 16 04:20:37 CET 2013


Revision: 53835
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53835
Author:   psy-fi
Date:     2013-01-16 03:20:36 +0000 (Wed, 16 Jan 2013)
Log Message:
-----------
Unification of brush code

Move anchored and rake options away from Sculpt struct and to
UnifiedPaintSettings where they may be used by other tools in the future
(carefree whistle...)

No functionality should change but if it does I'll follow the screams...

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
    trunk/blender/source/blender/makesdna/DNA_scene_types.h

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-01-16 03:18:22 UTC (rev 53834)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-01-16 03:20:36 UTC (rev 53835)
@@ -116,7 +116,7 @@
 	snap->winy = vc->ar->winy;
 }
 
-static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc)
+static int load_tex(Brush *br, ViewContext *vc)
 {
 	static GLuint overlay_texture = 0;
 	static int init = 0;
@@ -130,10 +130,6 @@
 	int size;
 	int j;
 	int refresh;
-
-#ifndef _OPENMP
-	(void)sd; /* quied unused warning */
-#endif
 	
 	if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0;
 	
@@ -186,7 +182,7 @@
 
 		buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex");
 
-		#pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
+		#pragma omp parallel for schedule(static)
 		for (j = 0; j < size; j++) {
 			int i;
 			float y;
@@ -376,7 +372,7 @@
 /* Draw an overlay that shows what effect the brush's texture will
  * have on brush strength */
 /* TODO: sculpt only for now */
-static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
+static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
                                      ViewContext *vc, int x, int y)
 {
 	rctf quad;
@@ -401,7 +397,7 @@
 	             GL_VIEWPORT_BIT |
 	             GL_TEXTURE_BIT);
 
-	if (load_tex(sd, brush, vc)) {
+	if (load_tex(brush, vc)) {
 		glEnable(GL_BLEND);
 
 		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@@ -416,24 +412,24 @@
 			/* brush rotation */
 			glTranslatef(0.5, 0.5, 0);
 			glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ?
-			                           sd->last_angle : sd->special_rotation),
+			                           ups->last_angle : ups->special_rotation),
 			          0.0, 0.0, 1.0);
 			glTranslatef(-0.5f, -0.5f, 0);
 
 			/* scale based on tablet pressure */
-			if (sd->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) {
+			if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) {
 				glTranslatef(0.5f, 0.5f, 0);
-				glScalef(1.0f / sd->pressure_value, 1.0f / sd->pressure_value, 1);
+				glScalef(1.0f / ups->pressure_value, 1.0f / ups->pressure_value, 1);
 				glTranslatef(-0.5f, -0.5f, 0);
 			}
 
-			if (sd->draw_anchored) {
-				const float *aim = sd->anchored_initial_mouse;
+			if (ups->draw_anchored) {
+				const float *aim = ups->anchored_initial_mouse;
 				const rcti *win = &vc->ar->winrct;
-				quad.xmin = aim[0] - sd->anchored_size - win->xmin;
-				quad.ymin = aim[1] - sd->anchored_size - win->ymin;
-				quad.xmax = aim[0] + sd->anchored_size - win->xmin;
-				quad.ymax = aim[1] + sd->anchored_size - win->ymin;
+				quad.xmin = aim[0] - ups->anchored_size - win->xmin;
+				quad.ymin = aim[1] - ups->anchored_size - win->ymin;
+				quad.xmax = aim[0] + ups->anchored_size - win->xmin;
+				quad.ymax = aim[1] + ups->anchored_size - win->ymin;
 			}
 			else {
 				const int radius = BKE_brush_size_get(vc->scene, brush);
@@ -476,7 +472,7 @@
 
 /* Special actions taken when paint cursor goes over mesh */
 /* TODO: sculpt only for now */
-static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
+static void paint_cursor_on_hit(UnifiedPaintSettings *ups, Brush *brush, ViewContext *vc,
                                 const float location[3])
 {
 	float unprojected_radius, projected_radius;
@@ -484,8 +480,8 @@
 	/* update the brush's cached 3D radius */
 	if (!BKE_brush_use_locked_size(vc->scene, brush)) {
 		/* get 2D brush radius */
-		if (sd->draw_anchored)
-			projected_radius = sd->anchored_size;
+		if (ups->draw_anchored)
+			projected_radius = ups->anchored_size;
 		else {
 			if (brush->flag & BRUSH_ANCHORED)
 				projected_radius = 8;
@@ -498,8 +494,8 @@
 		                                                    projected_radius);
 
 		/* scale 3D brush radius by pressure */
-		if (sd->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush))
-			unprojected_radius *= sd->pressure_value;
+		if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush))
+			unprojected_radius *= ups->pressure_value;
 
 		/* set cached value in either Brush or UnifiedPaintSettings */
 		BKE_brush_unprojected_radius_set(vc->scene, brush, unprojected_radius);
@@ -509,6 +505,7 @@
 static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
 {
 	Scene *scene = CTX_data_scene(C);
+	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 	Paint *paint = paint_get_active_from_context(C);
 	Brush *brush = paint_brush(paint);
 	ViewContext vc;
@@ -534,7 +531,6 @@
 	/* TODO: as sculpt and other paint modes are unified, this
 	 * special mode of drawing will go away */
 	if (vc.obact->sculpt) {
-		Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
 		float location[3];
 		int pixel_radius, hit;
 
@@ -547,14 +543,14 @@
 			const float v = 1 - u;
 			const float r = 20;
 
-			const float dx = sd->last_x - x;
-			const float dy = sd->last_y - y;
+			const float dx = ups->last_x - x;
+			const float dy = ups->last_y - y;
 
 			if (dx * dx + dy * dy >= r * r) {
-				sd->last_angle = atan2(dx, dy);
+				ups->last_angle = atan2(dx, dy);
 
-				sd->last_x = u * sd->last_x + v * x;
-				sd->last_y = u * sd->last_y + v * y;
+				ups->last_x = u * ups->last_x + v * x;
+				ups->last_y = u * ups->last_y + v * y;
 			}
 		}
 
@@ -562,7 +558,7 @@
 		hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location);
 
 		/* draw overlay */
-		paint_draw_alpha_overlay(sd, brush, &vc, x, y);
+		paint_draw_alpha_overlay(ups, brush, &vc, x, y);
 
 		if (BKE_brush_use_locked_size(scene, brush))
 			BKE_brush_size_set(scene, brush, pixel_radius);
@@ -581,12 +577,12 @@
 
 		/* only do if brush is over the mesh */
 		if (hit)
-			paint_cursor_on_hit(sd, brush, &vc, location);
+			paint_cursor_on_hit(ups, brush, &vc, location);
 
-		if (sd->draw_anchored) {
-			final_radius = sd->anchored_size;
-			translation[0] = sd->anchored_initial_mouse[0] - vc.ar->winrct.xmin;
-			translation[1] = sd->anchored_initial_mouse[1] - vc.ar->winrct.ymin;
+		if (ups->draw_anchored) {
+			final_radius = ups->anchored_size;
+			translation[0] = ups->anchored_initial_mouse[0] - vc.ar->winrct.xmin;
+			translation[1] = ups->anchored_initial_mouse[1] - vc.ar->winrct.ymin;
 		}
 	}
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-01-16 03:18:22 UTC (rev 53834)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-01-16 03:20:36 UTC (rev 53835)
@@ -3654,6 +3654,7 @@
 static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mouse[2])
 {
 	StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
+	UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings;
 	Brush *brush = paint_brush(&sd->paint);
 	ViewContext *vc = paint_stroke_view_context(op->customdata);
 	Object *ob = CTX_data_active_object(C);
@@ -3762,7 +3763,7 @@
 		}
 	}
 
-	cache->special_rotation = (brush->flag & BRUSH_RAKE) ? sd->last_angle : 0;
+	cache->special_rotation = (brush->flag & BRUSH_RAKE) ? ups->last_angle : 0;
 
 	cache->first_time = 1;
 
@@ -3771,7 +3772,7 @@
 	sculpt_omp_start(sd, ss);
 }
 
-static void sculpt_update_brush_delta(Sculpt *sd, Object *ob, Brush *brush)
+static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Brush *brush)
 {
 	SculptSession *ss = ob->sculpt;
 	StrokeCache *cache = ss->cache;
@@ -3836,17 +3837,17 @@
 		copy_v3_v3(cache->old_grab_location, grab_location);
 
 		if (tool == SCULPT_TOOL_GRAB)
-			copy_v3_v3(sd->anchored_location, cache->true_location);
+			copy_v3_v3(ups->anchored_location, cache->true_location);
 		else if (tool == SCULPT_TOOL_THUMB)
-			copy_v3_v3(sd->anchored_location, cache->orig_grab_location);
+			copy_v3_v3(ups->anchored_location, cache->orig_grab_location);
 
 		if (ELEM(tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB)) {
 			/* location stays the same for finding vertices in brush radius */
 			copy_v3_v3(cache->true_location, cache->orig_grab_location);
 
-			sd->draw_anchored = 1;
-			copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse);
-			sd->anchored_size = cache->pixel_radius;
+			ups->draw_anchored = 1;
+			copy_v2_v2(ups->anchored_initial_mouse, cache->initial_mouse);
+			ups->anchored_size = cache->pixel_radius;
 		}
 	}
 }
@@ -3857,6 +3858,7 @@
                                          PointerRNA *ptr)
 {
 	Scene *scene = CTX_data_scene(C);
+	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 	SculptSession *ss = ob->sculpt;
 	StrokeCache *cache = ss->cache;
 	Brush *brush = paint_brush(&sd->paint);
@@ -3885,8 +3887,8 @@
 
 	/* Truly temporary data that isn't stored in properties */
 
-	sd->draw_pressure =  1;
-	sd->pressure_value = cache->pressure;
+	ups->draw_pressure =  1;
+	ups->pressure_value = cache->pressure;
 
 	cache->previous_pixel_radius = cache->pixel_radius;
 	cache->pixel_radius = BKE_brush_size_get(scene, brush);
@@ -3932,7 +3934,7 @@
 		const float dx = cache->mouse[0] - cache->initial_mouse[0];
 		const float dy = cache->mouse[1] - cache->initial_mouse[1];
 
-		sd->anchored_size = cache->pixel_radius = sqrt(dx * dx + dy * dy);
+		ups->anchored_size = cache->pixel_radius = sqrt(dx * dx + dy * dy);
 
 		cache->special_rotation = atan2(dx, dy) + M_PI;
 
@@ -3944,27 +3946,27 @@
 			halfway[1] = dy * 0.5f + cache->initial_mouse[1];
 
 			if (sculpt_stroke_get_location(C, out, halfway)) {
-				copy_v3_v3(sd->anchored_location, out);
-				copy_v2_v2(sd->anchored_initial_mouse, halfway);
+				copy_v3_v3(ups->anchored_location, out);
+				copy_v2_v2(ups->anchored_initial_mouse, halfway);
 				copy_v2_v2(cache->tex_mouse, halfway);
-				copy_v3_v3(cache->true_location, sd->anchored_location);
-				sd->anchored_size /= 2.0f;
+				copy_v3_v3(cache->true_location, ups->anchored_location);
+				ups->anchored_size /= 2.0f;
 				cache->pixel_radius  /= 2.0f;
 				hit = 1;
 			}
 		}
 
 		if (!hit)
-			copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse);
+			copy_v2_v2(ups->anchored_initial_mouse, cache->initial_mouse);
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list