[Bf-blender-cvs] [4794982] soc-2016-pbvh-painting: refactored some more. This commit also contains texture mode implementation in vertex paint.

Nathan Vollmer noreply at git.blender.org
Sun Aug 14 00:53:56 CEST 2016


Commit: 4794982f6fc9eb13192064a70359ed07875d2dbe
Author: Nathan Vollmer
Date:   Sat Aug 13 16:53:42 2016 -0600
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rB4794982f6fc9eb13192064a70359ed07875d2dbe

refactored some more. This commit also contains texture mode implementation in vertex paint.

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



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

diff --cc source/blender/blenloader/intern/versioning_defaults.c
index 52769233,a860164..8ca5dbe
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@@ -282,16 -282,16 +282,16 @@@ void BLO_update_defaults_startup_blend(
  		br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Average");
  		if (!br) {
  			br = BKE_brush_add(bmain, "Average", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
--		    br->vertexpaint_tool = PAINT_BLEND_AVERAGE;
--		    br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
++			br->vertexpaint_tool = PAINT_BLEND_AVERAGE;
++			br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
  		}
  
 -    br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Smudge");
 -    if (!br) {
 -      br = BKE_brush_add(bmain, "Smudge", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
 -      br->vertexpaint_tool = PAINT_BLEND_SMUDGE;
 -      br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
 -    }
 +		br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Smudge");
 +		if (!br) {
 +			br = BKE_brush_add(bmain, "Smudge", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
 +			br->vertexpaint_tool = PAINT_BLEND_SMUDGE;
 +			br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
 +		}
  	}
  }
  
diff --cc source/blender/editors/sculpt_paint/paint_vertex.c
index a1fe7b9,cb04808..e656a16
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@@ -2240,106 -2312,121 +2233,102 @@@ static float UNUSED_FUNCTION(wpaint_blu
  	return paintweight;
  }
  
 -/** \name Calculate Normal and Center
 -*
 -* Calculate geometry surrounding the brush center.
 -* (optionally using original coordinates).
 -*
 -* Functions are:
 -* - #calc_area_center
 -* - #calc_area_normal
 -* - #calc_area_normal_and_center
 -*
 -* \note These are all _very_ similar, when changing one, check others.
 -* \{ */
 -
  static void calc_area_normal_and_center_task_cb(void *userdata, const int n)
  {
 -  SculptThreadedTaskData *data = userdata;
 -  SculptSession *ss = data->ob->sculpt;
 -  float(*area_nos)[3] = data->area_nos;
 -  float(*area_cos)[3] = data->area_cos;
 -
 -  PBVHVertexIter vd;
 -  SculptBrushTest test;
 -  //SculptUndoNode *unode;
 +	SculptThreadedTaskData *data = userdata;
 +	SculptSession *ss = data->ob->sculpt;
 +	float(*area_nos)[3] = data->area_nos;
 +	float(*area_cos)[3] = data->area_cos;
  
 -  float private_co[2][3] = { { 0.0f } };
 -  float private_no[2][3] = { { 0.0f } };
 -  int   private_count[2] = { 0 };
 +	PBVHVertexIter vd;
 +	SculptBrushTest test;
  
 - // unode = sculpt_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
 -  sculpt_brush_test_init(ss, &test);
 +	float private_co[2][3] = { { 0.0f } };
 +	float private_no[2][3] = { { 0.0f } };
 +	int   private_count[2] = { 0 };
  
 -  //use_original = (ss->cache->original && (unode->co || unode->bm_entry));
 +	sculpt_brush_test_init(ss, &test);
  
- 
- 	BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
- 	{
- 		const float *co;
- 		const short *no_s;  /* bm_vert only */
 -  
+   BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
+   {
+     const float *co;
  
 -    co = vd.co;
 -    
 -    if (sculpt_brush_test_fast(&test, co)) {
 -      float no_buf[3];
 -      const float *no;
 -      int flip_index;
 -
 -      if (vd.no) {
 -        normal_short_to_float_v3(no_buf, vd.no);
 -        no = no_buf;
 -      }
 -      else {
 -        no = vd.fno;
 -      }
 +		co = vd.co;
  
 -      flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f);
 -      if (area_cos)
 -        add_v3_v3(private_co[flip_index], co);
 -      if (area_nos)
 -        add_v3_v3(private_no[flip_index], no);
 -      private_count[flip_index] += 1;
 -    }
 -  }
 -  BKE_pbvh_vertex_iter_end;
 -  
 +		if (sculpt_brush_test_fast(&test, co)) {
 +			float no_buf[3];
 +			const float *no;
 +			int flip_index;
  
 -  BLI_mutex_lock(&data->mutex);
 +			if (vd.no) {
 +				normal_short_to_float_v3(no_buf, vd.no);
 +				no = no_buf;
 +			}
 +			else {
 +				no = vd.fno;
 +			}
  
 -  /* for flatten center */
 -  if (area_cos) {
 -    add_v3_v3(area_cos[0], private_co[0]);
 -    add_v3_v3(area_cos[1], private_co[1]);
 -  }
 +			flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f);
 +			if (area_cos)
 +				add_v3_v3(private_co[flip_index], co);
 +			if (area_nos)
 +				add_v3_v3(private_no[flip_index], no);
 +			private_count[flip_index] += 1;
 +		}
 +	}
 +	BKE_pbvh_vertex_iter_end;
  
 -  /* for area normal */
 -  if (area_nos) {
 -    add_v3_v3(area_nos[0], private_no[0]);
 -    add_v3_v3(area_nos[1], private_no[1]);
 -  }
  
 -  /* weights */
 -  data->count[0] += private_count[0];
 -  data->count[1] += private_count[1];
 +	BLI_mutex_lock(&data->mutex);
 +
 +	/* for flatten center */
 +	if (area_cos) {
 +		add_v3_v3(area_cos[0], private_co[0]);
 +		add_v3_v3(area_cos[1], private_co[1]);
 +	}
 +
 +	/* for area normal */
 +	if (area_nos) {
 +		add_v3_v3(area_nos[0], private_no[0]);
 +		add_v3_v3(area_nos[1], private_no[1]);
 +	}
  
 -  BLI_mutex_unlock(&data->mutex);
 +	/* weights */
 +	data->count[0] += private_count[0];
 +	data->count[1] += private_count[1];
 +
 +	BLI_mutex_unlock(&data->mutex);
  }
  
  static void calc_area_normal(
 -  VPaint *vp, Object *ob,
 -  PBVHNode **nodes, int totnode,
 -  float r_area_no[3])
 +		VPaint *vp, Object *ob,
 +		PBVHNode **nodes, int totnode,
 +		float r_area_no[3])
  {
- 	const Brush *brush = BKE_paint_brush(&vp->paint);
- 	SculptSession *ss = ob->sculpt;
- 	int n;
+   int n;
  
 -  /* 0=towards view, 1=flipped */
 -  float area_nos[2][3] = { { 0.0f } };
 +	/* 0=towards view, 1=flipped */
 +	float area_nos[2][3] = { { 0.0f } };
  
 -  int count[2] = { 0 };
 +	int count[2] = { 0 };
  
 -  SculptThreadedTaskData data = {
 -    .vp = vp, .ob = ob, .nodes = nodes, .totnode = totnode,
 -    .area_cos = NULL, .area_nos = area_nos, .count = count,
 -  };
 -  BLI_mutex_init(&data.mutex);
 +	SculptThreadedTaskData data = {
 +		.vp = vp, .ob = ob, .nodes = nodes, .totnode = totnode,
 +		.area_cos = NULL, .area_nos = area_nos, .count = count,
 +	};
 +	BLI_mutex_init(&data.mutex);
  
 -  BLI_task_parallel_range(
 -    0, totnode, &data, calc_area_normal_and_center_task_cb,
 -    ((true & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT)); //Need to add OpenMP toggle in vpaint and wpaint
 +	BLI_task_parallel_range(
 +			0, totnode, &data, calc_area_normal_and_center_task_cb, true);
  
 -  BLI_mutex_end(&data.mutex);
 +	BLI_mutex_end(&data.mutex);
  
 -  /* for area normal */
 -  for (n = 0; n < ARRAY_SIZE(area_nos); n++) {
 -    if (normalize_v3_v3(r_area_no, area_nos[n]) != 0.0f) {
 -      break;
 -    }
 -  }
 +	/* for area normal */
 +	for (n = 0; n < ARRAY_SIZE(area_nos); n++) {
 +		if (normalize_v3_v3(r_area_no, area_nos[n]) != 0.0f) {
 +			break;
 +		}
 +	}
  }
  
  static float dot_vf3vs3(const float brushNormal[3], const short vertexNormal[3]){
@@@ -2637,59 -2732,70 +2620,61 @@@ static void calculate_average_weight(Sc
  
  static void wpaint_paint_leaves(bContext *C, Object *ob, Sculpt *sd, VPaint *vp, WPaintData *wpd, WeightPaintInfo *wpi, Mesh *me, PBVHNode **nodes, int totnode)
  {
 -  Brush *brush = ob->sculpt->cache->brush;//BKE_paint_brush(&sd->paint);
 -
 -  /* threaded loop over nodes */
 -  SculptThreadedTaskData data = {
 -    .sd = sd, .ob = ob, .brush = brush, .nodes = nodes,
 -  };
 -
 -  data.vp = vp;
 -  data.wpd = wpd;
 -  data.wpi = wpi;
 -  data.lcol = (unsigned int*)me->mloopcol;
 -  data.me = me;
 -  data.C = C;
 -  sd->flags |= SCULPT_USE_OPENMP; // Need to add toggle for OpenMP
 -  switch (brush->vertexpaint_tool) {
 -    case PAINT_BLEND_AVERAGE:
 -      calculate_average_weight(&data, nodes, totnode);
 -      BLI_task_parallel_range_ex(
 -        0, totnode, &data, NULL, 0, do_wpaint_brush_draw_task_cb_ex,
 -        ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 -      break;
 -    case PAINT_BLEND_SMUDGE:
 -      BLI_task_parallel_range_ex(
 -        0, totnode, &data, NULL, 0, do_wpaint_brush_smudge_task_cb_ex,
 -        ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 -      break;
 -    case PAINT_BLEND_BLUR:
 -      BLI_task_parallel_range_ex(
 -        0, totnode, &data, NULL, 0, do_wpaint_brush_blur_task_cb_ex,
 -        ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 -      break;
 -    default:
 -      BLI_task_parallel_range_ex(
 -        0, totnode, &data, NULL, 0, do_wpaint_brush_draw_task_cb_ex,
 -        ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 -      break;
 -  }
 +	Brush *brush = ob->sculpt->cache->brush;
 +
 +	/* threaded loop over nodes */
 +	SculptThreadedTaskData data = {
 +		.sd = sd, .ob = ob, .brush = brush, .nodes = nodes,
 +	};
 +
 +	data.vp = vp;
 +	data.wpd = wpd;
 +	data.wpi = wpi;
 +	data.lcol = (unsigned int*)me->mloopcol;
 +	data.me = me;
 +	data.C = C;
 +	switch (brush->vertexpaint_tool) {
 +		case PAINT_BLEND_AVERAGE:
 +			calculate_average_weight(&data, nodes, totnode);
 +			BLI_task_parallel_range_ex( 0, totnode, &data, NULL, 0, do_wpaint_brush_draw_task_cb_ex, true, false);
 +			break;
 +		case PAINT_BLEND_SMUDGE:
 +			BLI_task_parallel_range_ex( 0, totnode, &data, NULL, 0, do_wpaint_brush_smudge_task_cb_ex, true, false);
 +			break;
 +		case PAINT_BLEND_BLUR:
 +			BLI_task_parallel_range_ex( 0, totnode, &data, NULL, 0, do_wpaint_brush_blur_task_cb_ex, true, false);
 +			break;
 +		default:
 +			BLI_task_parallel_range_ex( 0, totnode, &data, NULL, 0, do_wpaint_brush_draw_task_cb_ex, true, false);
 +			break;
 +	}
  }
  
- static void wpaint_do_paint(bContext *C, Object *ob, VPaint *wp, Sculpt *sd, WPaintData *wpd, WeightPaintInfo *wpi, Mesh *me, Brush *brush, const char symm, const int axis, const int i, const float angle)
+ static void wpaint_do_paint(
+         bContext *C, Object *ob, VPaint *wp, Sculpt *sd, WPaintData *wpd, WeightPaintInfo *wpi, Mesh *me,
+         Brush *UNUSED(brush), const char symm, const int axis, const int i, const float angle)
  {
 -  SculptSession *ss = ob->sculpt;
 -  s

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list