[Bf-blender-cvs] [e154bb6293c] soc-2016-pbvh-painting: Fix accidental nested loop in vertex paint smudge

Campbell Barton noreply at git.blender.org
Wed Apr 12 15:35:24 CEST 2017


Commit: e154bb6293c1b37fe885db5e950e3d3b8e04d099
Author: Campbell Barton
Date:   Wed Apr 12 23:22:39 2017 +1000
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rBe154bb6293c1b37fe885db5e950e3d3b8e04d099

Fix accidental nested loop in vertex paint smudge

Also use return for BKE_pbvh_get_ccgdm

===================================================================

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/editors/sculpt_paint/paint_vertex.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 18f72cea536..997609d9a7d 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -32,6 +32,7 @@
 
 struct CCGElem;
 struct CCGKey;
+struct CCGDerivedMesh;
 struct CustomData;
 struct DMFlagMat;
 struct MPoly;
@@ -142,7 +143,7 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
 
 /* multires level, only valid for type == PBVH_GRIDS */
 void BKE_pbvh_get_grid_key(const PBVH *pbvh, struct CCGKey *key);
-void BKE_pbvh_get_ccgdm(const PBVH *bvh, struct CCGDerivedMesh *ccgdm);
+struct CCGDerivedMesh *BKE_pbvh_get_ccgdm(const PBVH *bvh);
 
 /* Only valid for type == PBVH_BMESH */
 struct BMesh *BKE_pbvh_get_bmesh(PBVH *pbvh);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 028bb6eae02..aa54d12f926 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1332,8 +1332,8 @@ void BKE_pbvh_get_grid_key(const PBVH *bvh, CCGKey *key)
 	*key = bvh->gridkey;
 }
 
-void BKE_pbvh_get_ccgdm(const PBVH *bvh, struct CCGDerivedMesh **ccgdm) {
-	*ccgdm = bvh->ccgdm;
+CCGDerivedMesh *BKE_pbvh_get_ccgdm(const PBVH *bvh) {
+	return bvh->ccgdm;
 }
 
 
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 4b331adaba0..25ebf257751 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -757,10 +757,11 @@ static unsigned int vpaint_blend_tool(const int tool, const unsigned int col,
 }
 
 /* wpaint has 'wpaint_blend' */
-static unsigned int vpaint_blend(VPaint *vp, unsigned int col, unsigned int colorig,
-                                 const unsigned int paintcol, const int alpha_i,
-                                 /* pre scaled from [0-1] --> [0-255] */
-                                 const int brush_alpha_value_i)
+static unsigned int vpaint_blend(
+        VPaint *vp, unsigned int col, unsigned int colorig,
+        const unsigned int paintcol, const int alpha_i,
+        /* pre scaled from [0-1] --> [0-255] */
+        const int brush_alpha_value_i)
 {
 	Brush *brush = BKE_paint_brush(&vp->paint);
 	const int tool = brush->vertexpaint_tool;
@@ -1734,16 +1735,16 @@ static void vertex_paint_init_session_average_arrays(Object *ob)
 		BKE_pbvh_get_num_nodes(ob->sculpt->pbvh, &totNode);
 		Mesh *me = BKE_mesh_from_object(ob);
 
-		ob->sculpt->modes.vwpaint.total_color = 
-			MEM_callocN(totNode * 3 * sizeof(unsigned int), "total_color");
-		ob->sculpt->modes.vwpaint.total_weight = 
-			MEM_callocN(totNode * sizeof(double), "total_weight");
-		ob->sculpt->modes.vwpaint.tot_loops_hit = 
-			MEM_callocN(totNode * sizeof(unsigned int), "tot_loops_hit");
-		ob->sculpt->modes.vwpaint.max_weight = 
-			MEM_callocN(me->totvert * sizeof(float), "max_weight");
-		ob->sculpt->modes.vwpaint.previous_color = 
-			MEM_callocN(me->totloop * sizeof(unsigned int), "previous_color");
+		ob->sculpt->modes.vwpaint.total_color =
+		        MEM_callocN(totNode * 3 * sizeof(unsigned int), "total_color");
+		ob->sculpt->modes.vwpaint.total_weight =
+		        MEM_callocN(totNode * sizeof(double), "total_weight");
+		ob->sculpt->modes.vwpaint.tot_loops_hit =
+		        MEM_callocN(totNode * sizeof(unsigned int), "tot_loops_hit");
+		ob->sculpt->modes.vwpaint.max_weight =
+		        MEM_callocN(me->totvert * sizeof(float), "max_weight");
+		ob->sculpt->modes.vwpaint.previous_color =
+		        MEM_callocN(me->totloop * sizeof(unsigned int), "previous_color");
 	}
 }
 
@@ -2353,13 +2354,18 @@ static void calc_brushdata_symm(
 	}
 }
 
-static void get_brush_alpha_data(Scene *scene, SculptSession *ss, Brush *brush,
-	float *brush_size_pressure, float *brush_alpha_value, float *brush_alpha_pressure) {
-	*brush_size_pressure =
-		BKE_brush_size_get(scene, brush) * (BKE_brush_use_size_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
-	*brush_alpha_value = BKE_brush_alpha_get(scene, brush);
-	*brush_alpha_pressure =
-		*brush_alpha_value * (BKE_brush_use_alpha_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
+static void get_brush_alpha_data(
+        Scene *scene, SculptSession *ss, Brush *brush,
+        float *r_brush_size_pressure, float *r_brush_alpha_value, float *r_brush_alpha_pressure)
+{
+	*r_brush_size_pressure =
+	        BKE_brush_size_get(scene, brush) *
+	        (BKE_brush_use_size_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
+	*r_brush_alpha_value =
+	        BKE_brush_alpha_get(scene, brush);
+	*r_brush_alpha_pressure =
+	        *r_brush_alpha_value *
+	        (BKE_brush_use_alpha_pressure(scene, brush) ? ss->cache->pressure : 1.0f);
 }
 
 static void do_wpaint_brush_blur_task_cb_ex(
@@ -2367,6 +2373,7 @@ static void do_wpaint_brush_blur_task_cb_ex(
 {
 	SculptThreadedTaskData *data = userdata;
 	SculptSession *ss = data->ob->sculpt;
+	CCGDerivedMesh *ccgdm = BKE_pbvh_get_ccgdm(ss->pbvh);
 
 	Brush *brush = data->brush;
 	StrokeCache *cache = ss->cache;
@@ -2374,9 +2381,6 @@ static void do_wpaint_brush_blur_task_cb_ex(
 	const float brush_strength = cache->bstrength;
 	float brush_size_pressure, brush_alpha_value, brush_alpha_pressure;
 	get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure);
-	int total_hit_loops;
-	CCGDerivedMesh *ccgdm = NULL;
-	BKE_pbvh_get_ccgdm(ss->pbvh, &ccgdm);
 	const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
 	const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
 
@@ -2390,20 +2394,21 @@ static void do_wpaint_brush_blur_task_cb_ex(
 
 		if (sculpt_brush_test_sq(&test, vd.co)) {
 			/* For grid based pbvh, take the vert whose loop coopresponds to the current grid.
-			Otherwise, take the current vert. */
+			 * Otherwise, take the current vert. */
 			float grid_alpha = 1.0;
 			int v_index;
 			if (ccgdm) {
 				v_index = data->me->mloop[vd.grid_indices[vd.g]].v;
 				grid_alpha = 1.0 / vd.gridsize;
 			}
-			else
+			else {
 				v_index = vd.vert_indices[vd.i];
+			}
 			const char v_flag = data->me->mvert[v_index].flag;
 			/* If the vertex is selected */
 			if (!(use_face_sel || use_vert_sel) || v_flag & SELECT) {
 				/* Get the average poly weight */
-				total_hit_loops = 0;
+				int total_hit_loops = 0;
 				float weight_final = 0.0f;
 				for (int j = 0; j < ss->modes.vwpaint.vert_to_poly[v_index].count; j++) {
 					const int p_index = ss->modes.vwpaint.vert_to_poly[v_index].indices[j];
@@ -2423,15 +2428,16 @@ static void do_wpaint_brush_blur_task_cb_ex(
 				if (total_hit_loops != 0) {
 					const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
 					const float view_dot = (vd.no) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0;
-					const float final_alpha = view_dot * brush_fade * brush_strength
-						* grid_alpha * brush_alpha_pressure;
+					const float final_alpha =
+					        view_dot * brush_fade * brush_strength *
+					        grid_alpha * brush_alpha_pressure;
 					weight_final /= total_hit_loops;
 
 					/* Only paint visable verts */
 					if (view_dot > 0.0) {
 						do_weight_paint_vertex(
-							data->vp, data->ob, data->wpi,
-							v_index, final_alpha, weight_final);
+						        data->vp, data->ob, data->wpi,
+						        v_index, final_alpha, weight_final);
 					}
 				}
 			}
@@ -2445,14 +2451,14 @@ static void do_wpaint_brush_smudge_task_cb_ex(
 {
 	SculptThreadedTaskData *data = userdata;
 	SculptSession *ss = data->ob->sculpt;
+	CCGDerivedMesh *ccgdm = BKE_pbvh_get_ccgdm(ss->pbvh);
+
 	Brush *brush = data->brush;
 	Scene *scene = CTX_data_scene(data->C);
 	StrokeCache *cache = ss->cache;
 	const float brush_strength = cache->bstrength;
 	float brush_size_pressure, brush_alpha_value, brush_alpha_pressure;
 	get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure);
-	CCGDerivedMesh *ccgdm = NULL;
-	BKE_pbvh_get_ccgdm(ss->pbvh, &ccgdm);
 	const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
 	const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
 	float brush_dir[3];
@@ -2475,15 +2481,16 @@ static void do_wpaint_brush_smudge_task_cb_ex(
 				const float view_dot = (vd.no) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0;
 
 				/* For grid based pbvh, take the vert whose loop cooresponds to the current grid. 
-					Otherwise, take the current vert. */
+				 * Otherwise, take the current vert. */
 				int v_index;
 				float grid_alpha = 1.0;
 				if (ccgdm) {
 					v_index = data->me->mloop[vd.grid_indices[vd.g]].v;
 					grid_alpha = 1.0 / vd.gridsize;
 				}
-				else
+				else {
 					v_index = vd.vert_indices[vd.i];
+				}
 				const MVert *mv_curr = &data->me->mvert[v_index];
 				const char v_flag = data->me->mvert[v_index].flag;
 				/* If the vertex is selected */
@@ -2523,10 +2530,12 @@ static void do_wpaint_brush_smudge_task_cb_ex(
 					/* Apply weight to vertex */
 					if (do_color && view_dot > 0.0) {
 						const float brush_fade = BKE_brush_curve_strength(brush, test.dist, cache->radius);
-						const float final_alpha = view_dot * brush_fade * brush_strength
-							* grid_alpha * brush_alpha_pressure;
+						const float final_alpha =
+						        view_dot * brush_fade * brush_strength *
+						        grid_alpha * brush_alpha_pressure;
 						do_weight_paint_vertex(
-							data->vp, data->ob, data->wpi, v_index, final_alpha, (float)weight_final);
+						        data->vp, data->ob, data->wpi,
+						        v_index, final_alpha, (float)weight_final);
 					}
 				}
 			}
@@ -2541,6 +2550,7 @@ static void do_wpaint_brush_draw_task_cb_ex(
 {
 	SculptThreadedTaskData *data = userdata;
 	SculptSession *ss = data->ob->sculpt;
+	CCGDerivedMesh *ccgdm = BKE_pbvh_get_ccgdm(ss->pbvh);
 	Scene *scene = CTX_data_scene(data->C);
 
 	Brush *brush = data->brush;
@@ -2551,8 +2561,6 @@ static void do_wpaint_brush_draw_task_cb_ex(
 	get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure);
 	const bool use_face_sel = (data->me->editfl

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list