[Bf-blender-cvs] [e7efe5c4b0f] soc-2016-pbvh-painting: added union in sculpt session for modes. Sculpt fields could use some tidying, but that might be outside the scope of this branch. Swapped out some free patterns with MEM_SAFE_FREE. Swapped a long out for an int, since there's no size difference.

Nathan Vollmer noreply at git.blender.org
Wed Apr 5 12:11:50 CEST 2017


Commit: e7efe5c4b0f32e661add59b40bb678df92d096ec
Author: Nathan Vollmer
Date:   Wed Apr 5 04:11:26 2017 -0600
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rBe7efe5c4b0f32e661add59b40bb678df92d096ec

added union in sculpt session for modes. Sculpt fields could use some tidying, but that might be outside the scope of this branch. Swapped out some free patterns with MEM_SAFE_FREE. Swapped a long out for an int, since there's no size difference.

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/sculpt_paint/paint_vertex.c

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index d8ef476988c..cac56ae66af 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -204,17 +204,24 @@ typedef struct SculptSession {
 	struct SculptStroke *stroke;
 	struct StrokeCache *cache;
 
-	int *vert_map_mem;
-	MeshElemMap *vert_to_loop;
-	int *poly_map_mem;
-	MeshElemMap *vert_to_poly;
-
-	unsigned int *total_color;
-	double *total_weight;
-	unsigned int *tot_loops_hit;
-	float *max_weight;
-	unsigned int *previous_color;
-	bool building_vp_handle;
+	union {
+		struct {
+			int *vert_map_mem;
+			MeshElemMap *vert_to_loop;
+			int *poly_map_mem;
+			MeshElemMap *vert_to_poly;
+
+			unsigned int *total_color;
+			double *total_weight;
+			unsigned int *tot_loops_hit;
+			float *max_weight;
+			unsigned int *previous_color;
+			bool building_vp_handle;
+		} vwpaint;
+		//struct {
+		//ToDo: identify sculpt-only fields
+		//} sculpt;
+	} modes;
 } SculptSession;
 
 void BKE_sculptsession_free(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 1554ff3d75f..9e7427394be 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2740,7 +2740,7 @@ void BKE_object_sculpt_modifiers_changed(Object *ob)
 {
 	SculptSession *ss = ob->sculpt;
 
-	if (ss && ss->building_vp_handle == false) {
+	if (ss && ss->modes.vwpaint.building_vp_handle == false) {
 		if (!ss->cache) {
 			/* we free pbvh on changes, except during sculpt since it can't deal with
 			 * changing PVBH node organization, we hope topology does not change in
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 07fe63929cd..d10a1830ea9 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -658,44 +658,17 @@ void BKE_sculptsession_free_deformMats(SculptSession *ss)
 
 void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss) {
 	/* Free maps */
-	if (ss->vert_to_loop) {
-		MEM_freeN(ss->vert_to_loop);
-		ss->vert_to_loop = NULL;
-	}
-	if (ss->vert_map_mem) {
-		MEM_freeN(ss->vert_map_mem);
-		ss->vert_map_mem = NULL;
-	}
-	if (ss->vert_to_poly) {
-		MEM_freeN(ss->vert_to_poly);
-		ss->vert_to_poly = NULL;
-	}
-	if (ss->poly_map_mem) {
-		MEM_freeN(ss->poly_map_mem);
-		ss->poly_map_mem = NULL;
-	}
+	MEM_SAFE_FREE(ss->modes.vwpaint.vert_to_loop);
+	MEM_SAFE_FREE(ss->modes.vwpaint.vert_map_mem);
+	MEM_SAFE_FREE(ss->modes.vwpaint.vert_to_poly);
+	MEM_SAFE_FREE(ss->modes.vwpaint.poly_map_mem);
 
 	/* Free average, blur, and spray brush arrays */
-	if (ss->tot_loops_hit) {
-		MEM_freeN(ss->tot_loops_hit);
-		ss->tot_loops_hit = NULL;
-	}
-	if (ss->total_color) {
-		MEM_freeN(ss->total_color);
-		ss->total_color = NULL;
-	}
-	if (ss->total_weight) {
-		MEM_freeN(ss->total_weight);
-		ss->total_weight = NULL;
-	}
-	if (ss->max_weight) {
-		MEM_freeN(ss->max_weight);
-		ss->max_weight = NULL;
-	}
-	if (ss->previous_color) {
-		MEM_freeN(ss->previous_color);
-		ss->previous_color = NULL;
-	}
+	MEM_SAFE_FREE(ss->modes.vwpaint.tot_loops_hit);
+	MEM_SAFE_FREE(ss->modes.vwpaint.total_color);
+	MEM_SAFE_FREE(ss->modes.vwpaint.total_weight);
+	MEM_SAFE_FREE(ss->modes.vwpaint.max_weight);
+	MEM_SAFE_FREE(ss->modes.vwpaint.previous_color);
 }
 
 /* Write out the sculpt dynamic-topology BMesh to the Mesh */
@@ -739,10 +712,7 @@ void BKE_sculptsession_bm_to_me_for_render(Object *object)
 			 */
 			BKE_object_free_derived_caches(object);
 
-			if (object->sculpt->pbvh) {
-				BKE_pbvh_free(object->sculpt->pbvh);
-				object->sculpt->pbvh = NULL;
-			}
+			MEM_SAFE_FREE(object->sculpt->pbvh);
 
 			sculptsession_bm_to_me_update_data_only(object, false);
 
@@ -876,7 +846,7 @@ void BKE_sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob,
 	ss->show_diffuse_color = (sd->flags & SCULPT_SHOW_DIFFUSE) != 0;
 
 	/* This flag prevents PBVH from being freed when creating the vp_handle for texture paint */
-	ss->building_vp_handle = false;
+	ss->modes.vwpaint.building_vp_handle = false;
 
 	if (need_mask) {
 		if (mmd == NULL) {
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 5ee2ae12b18..334087110ef 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -1666,32 +1666,42 @@ static void vertex_paint_init_session(Scene *scene, Object *ob)
 
 static void vertex_paint_init_session_maps(Object *ob) {
 	/* Create maps */
-	if (!ob->sculpt->vert_to_loop)
+	if (!ob->sculpt->modes.vwpaint.vert_to_loop)
 	{
 		Mesh *me = ob->data;
-		ob->sculpt->vert_map_mem = NULL;
-		ob->sculpt->vert_to_loop = NULL;
-		ob->sculpt->poly_map_mem = NULL;
-		ob->sculpt->vert_to_poly = NULL;
-		BKE_mesh_vert_loop_map_create(&ob->sculpt->vert_to_loop, &ob->sculpt->vert_map_mem, me->mpoly, me->mloop, me->totvert, me->totpoly, me->totloop);
-		BKE_mesh_vert_poly_map_create(&ob->sculpt->vert_to_poly, &ob->sculpt->poly_map_mem, me->mpoly, me->mloop, me->totvert, me->totpoly, me->totloop);
+		ob->sculpt->modes.vwpaint.vert_map_mem = NULL;
+		ob->sculpt->modes.vwpaint.vert_to_loop = NULL;
+		ob->sculpt->modes.vwpaint.poly_map_mem = NULL;
+		ob->sculpt->modes.vwpaint.vert_to_poly = NULL;
+		BKE_mesh_vert_loop_map_create(
+			&ob->sculpt->modes.vwpaint.vert_to_loop, 
+			&ob->sculpt->modes.vwpaint.vert_map_mem, 
+			me->mpoly, me->mloop, me->totvert, me->totpoly, me->totloop);
+		BKE_mesh_vert_poly_map_create(
+			&ob->sculpt->modes.vwpaint.vert_to_poly, 
+			&ob->sculpt->modes.vwpaint.poly_map_mem, 
+			me->mpoly, me->mloop, me->totvert, me->totpoly, me->totloop);
 	}
 }
 
 static void vertex_paint_init_session_average_arrays(Object *ob){
 	/* Create average brush arrays */
-	if (!ob->sculpt->tot_loops_hit) {
+	if (!ob->sculpt->modes.vwpaint.tot_loops_hit) {
 		int totNode = 0;
 		/* I think the totNodes might include internal nodes, and we really only need the tot leaves. */
 		BKE_pbvh_get_num_nodes(ob->sculpt->pbvh, &totNode);
 		Mesh *me = BKE_mesh_from_object(ob);
 
-		/* Need unsigned long to prevent overflow when averaging multiple whites, which take up an entire unsigned int each. */
-		ob->sculpt->total_color = MEM_callocN(totNode * 3 * sizeof(unsigned int), "total_color");
-		ob->sculpt->total_weight = MEM_callocN(totNode * sizeof(double), "total_weight");
-		ob->sculpt->tot_loops_hit = MEM_callocN(totNode * sizeof(unsigned int), "tot_loops_hit");
-		ob->sculpt->max_weight = MEM_callocN(me->totvert * sizeof(float), "max_weight");
-		ob->sculpt->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");
 	}
 }
 
@@ -2115,9 +2125,9 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
 	}
 
 	/* painting on subsurfs should give correct points too, this returns me->totvert amount */
-	ob->sculpt->building_vp_handle = true;
+	ob->sculpt->modes.vwpaint.building_vp_handle = true;
 	wpd->vp_handle = ED_vpaint_proj_handle_create(scene, ob, &wpd->vertexcosnos);
-	ob->sculpt->building_vp_handle = false;
+	ob->sculpt->modes.vwpaint.building_vp_handle = false;
 
 	/* imat for normals */
 	mul_m4_m4m4(mat, wpd->vc.rv3d->viewmat, ob->obmat);
@@ -2131,7 +2141,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
 	vertex_paint_init_session_average_arrays(ob);
 
 	for (int i = 0; i < me->totvert; ++i)
-		ss->max_weight[i] = -1.0;
+		ss->modes.vwpaint.max_weight[i] = -1.0;
 
 	return true;
 }
@@ -2304,8 +2314,8 @@ static void do_wpaint_brush_blur_task_cb_ex(
 			total_hit_loops = 0;
 			finalColor = 0;
 
-			for (int j = 0; j < ss->vert_to_poly[vertexIndex].count; j++) {
-				int polyIndex = ss->vert_to_poly[vertexIndex].indices[j];
+			for (int j = 0; j < ss->modes.vwpaint.vert_to_poly[vertexIndex].count; j++) {
+				int polyIndex = ss->modes.vwpaint.vert_to_poly[vertexIndex].indices[j];
 				MPoly *poly = &data->me->mpoly[polyIndex];
 
 				total_hit_loops += poly->totloop;
@@ -2365,8 +2375,8 @@ static void do_wpaint_brush_smudge_task_cb_ex(
 
 				/* Get the color of the loop in the opposite direction of the brush movement (this callback is specifically for smudge.) */
 				finalWeight = 0;
-				for (int j = 0; j < ss->vert_to_poly[vertexIndex].count; j++) {
-					int polyIndex = ss->vert_to_poly[vertexIndex].indices[j];
+				for (int j = 0; j < ss->modes.vwpaint.vert_to_poly[vertexIndex].count; j++) {
+					int polyIndex = ss->modes.vwpaint.vert_to_poly[vertexIndex].indices[j];
 					MPoly *poly = &data->me->mpoly[polyIndex];
 					for (int k = 0; k < poly->totloop; k++) {
 						unsigned int loopIndex = poly->loopstart + k;
@@ -2440,17 +2450,17 @@ static void do_wpaint_brush_draw_task_cb_ex(
 					dw = (data->vp->flag & VP_ONLYVGROUP) ? defvert_find_index(dv, data->wpi->active.index) :
 																									defvert_verify_index(dv, data->wpi->active.index);
 					currentWeight = dw->weight;
-					if (ss->max_weight[vertexIndex] < 0) {
-						ss->max_weight[vertexIndex] = min_ff(bstrength + dw->weight, 1.0f);
+					if (ss->modes.vwpaint.max_weight[vertexIndex] < 0) {
+						ss->modes.vwpaint.max_weight[vertexIndex] = min_ff(bstrength + dw->weight, 1.0f);
 					}
-					CLAMP(actualStrength, 0.0, ss->max_weight[vertexIndex] - dw->weight);
+					CLAMP(actualStrength, 0.0, ss->modes.vwpaint.max_weight[vertexIndex] - dw->weight);
 				}
 
 				/* Splash Prevention */
 				if (dot > 0.0){
 					switch (data->vp->flag) {
 						case VP_SPRAY:
-							if (currentWeight < ss->max_weight[vertexIndex])
+							if (currentWeigh

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list