Page MenuHome
Paste P1136

Multires Smooth
ActivePublic

Authored by Pablo Dobarro (pablodp606) on Thu, Oct 10, 4:00 AM.
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 2d329ff3bca..6c1494784b1 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2513,6 +2513,83 @@ static void do_smooth_brush_mesh_task_cb_ex(void *__restrict userdata,
BKE_pbvh_vertex_iter_end;
}
+static void do_smooth_brush_grids_task_cb_ex(void *__restrict userdata,
+ const int n,
+ const TaskParallelTLS *__restrict tls)
+{
+ SculptThreadedTaskData *data = userdata;
+ SculptSession *ss = data->ob->sculpt;
+ Sculpt *sd = data->sd;
+ const Brush *brush = data->brush;
+ const bool smooth_mask = data->smooth_mask;
+ float bstrength = data->strength;
+
+ PBVHVertexIter vd;
+
+ CLAMP(bstrength, 0.0f, 1.0f);
+
+ SculptBrushTest test;
+ SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape(
+ ss, &test, data->brush->falloff_shape);
+
+ BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
+ {
+ if (sculpt_brush_test_sq_fn(&test, vd.co)) {
+ const float fade = bstrength * tex_strength(ss,
+ brush,
+ vd.co,
+ sqrtf(test.dist),
+ vd.no,
+ vd.fno,
+ smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f),
+ vd.index,
+ tls->thread_id);
+ if (smooth_mask) {
+ float val = 0;
+ int count = 0;
+ SculptVertexNeighborIter ni;
+ sculpt_vertex_neighbors_iter_begin(ss, vd.index, ni)
+ {
+ val += sculpt_vertex_mask_get(ss, ni.index);
+ count++;
+ }
+ sculpt_vertex_neighbors_iter_end(ni);
+ if (count > 0) {
+ val = val / (float)count;
+ }
+ val *= fade * bstrength;
+ *vd.mask += val;
+ CLAMP(*vd.mask, 0.0f, 1.0f);
+ }
+ else {
+ float avg[3], val[3];
+ int count = 0;
+ zero_v3(avg);
+ SculptVertexNeighborIter ni;
+ sculpt_vertex_neighbors_iter_begin(ss, vd.index, ni)
+ {
+ add_v3_v3(avg, sculpt_vertex_co_get(ss, ni.index));
+ count++;
+ }
+ sculpt_vertex_neighbors_iter_end(ni);
+ if (count > 0) {
+ mul_v3_fl(avg, 1.0f/(float)count);
+ }
+ sub_v3_v3v3(val, avg, vd.co);
+
+ madd_v3_v3v3fl(val, vd.co, val, fade);
+
+ sculpt_clip(sd, ss, vd.co, val);
+ }
+
+ if (vd.mvert) {
+ vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+ }
+ }
+ }
+ BKE_pbvh_vertex_iter_end;
+}
+
static void do_smooth_brush_bmesh_task_cb_ex(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict tls)
@@ -2829,6 +2906,7 @@ static void smooth(Sculpt *sd,
switch (type) {
case PBVH_GRIDS: {
+ /*
int gridsize;
size_t size;
SculptDoBrushSmoothGridDataChunk *data_chunk;
@@ -2842,9 +2920,10 @@ static void smooth(Sculpt *sd,
settings.userdata_chunk = data_chunk;
settings.userdata_chunk_size = size;
- BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_multires_task_cb_ex, &settings);
+ */
+ BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_grids_task_cb_ex, &settings);
- MEM_freeN(data_chunk);
+ // MEM_freeN(data_chunk);
break;
}
case PBVH_FACES: