Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt.c
| Show First 20 Lines • Show All 800 Lines • ▼ Show 20 Lines | SculptThreadedTaskData task_data = { | ||||
| .max_distance_squared = max_distance * max_distance, | .max_distance_squared = max_distance * max_distance, | ||||
| }; | }; | ||||
| copy_v3_v3(task_data.nearest_vertex_search_co, co); | copy_v3_v3(task_data.nearest_vertex_search_co, co); | ||||
| NearestVertexTLSData nvtd; | NearestVertexTLSData nvtd; | ||||
| nvtd.nearest_vertex_index = -1; | nvtd.nearest_vertex_index = -1; | ||||
| nvtd.nearest_vertex_distance_squared = FLT_MAX; | nvtd.nearest_vertex_distance_squared = FLT_MAX; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| settings.func_reduce = nearest_vertex_get_reduce; | settings.func_reduce = nearest_vertex_get_reduce; | ||||
| settings.userdata_chunk = &nvtd; | settings.userdata_chunk = &nvtd; | ||||
| settings.userdata_chunk_size = sizeof(NearestVertexTLSData); | settings.userdata_chunk_size = sizeof(NearestVertexTLSData); | ||||
| BKE_pbvh_parallel_range(0, totnode, &task_data, do_nearest_vertex_get_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &task_data, do_nearest_vertex_get_task_cb, &settings); | ||||
| MEM_SAFE_FREE(nodes); | MEM_SAFE_FREE(nodes); | ||||
| return nvtd.nearest_vertex_index; | return nvtd.nearest_vertex_index; | ||||
| } | } | ||||
| bool SCULPT_is_symmetry_iteration_valid(char i, char symm) | bool SCULPT_is_symmetry_iteration_valid(char i, char symm) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 455 Lines • ▼ Show 20 Lines | static void paint_mesh_restore_co(Sculpt *sd, Object *ob) | ||||
| * by a different thread. See T33787. */ | * by a different thread. See T33787. */ | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP) && !ss->bm, totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP) && !ss->bm, totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings); | ||||
| MEM_SAFE_FREE(nodes); | MEM_SAFE_FREE(nodes); | ||||
| } | } | ||||
| /*** BVH Tree ***/ | /*** BVH Tree ***/ | ||||
| static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect) | static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 607 Lines • ▼ Show 20 Lines | SculptThreadedTaskData data = { | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .totnode = totnode, | .totnode = totnode, | ||||
| .has_bm_orco = has_bm_orco, | .has_bm_orco = has_bm_orco, | ||||
| .use_area_cos = true, | .use_area_cos = true, | ||||
| }; | }; | ||||
| AreaNormalCenterTLSData anctd = {{{0}}}; | AreaNormalCenterTLSData anctd = {{{0}}}; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| settings.func_reduce = calc_area_normal_and_center_reduce; | settings.func_reduce = calc_area_normal_and_center_reduce; | ||||
| settings.userdata_chunk = &anctd; | settings.userdata_chunk = &anctd; | ||||
| settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData); | settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); | ||||
| /* For flatten center. */ | /* For flatten center. */ | ||||
| for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) { | for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) { | ||||
| if (anctd.count_co[n] != 0) { | if (anctd.count_co[n] != 0) { | ||||
| mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]); | mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| Show All 37 Lines | SculptThreadedTaskData data = { | ||||
| .totnode = totnode, | .totnode = totnode, | ||||
| .has_bm_orco = has_bm_orco, | .has_bm_orco = has_bm_orco, | ||||
| .use_area_nos = true, | .use_area_nos = true, | ||||
| .any_vertex_sampled = false, | .any_vertex_sampled = false, | ||||
| }; | }; | ||||
| AreaNormalCenterTLSData anctd = {{{0}}}; | AreaNormalCenterTLSData anctd = {{{0}}}; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, use_threading, totnode); | BKE_pbvh_parallel_range_settings(&settings, use_threading, totnode); | ||||
| settings.func_reduce = calc_area_normal_and_center_reduce; | settings.func_reduce = calc_area_normal_and_center_reduce; | ||||
| settings.userdata_chunk = &anctd; | settings.userdata_chunk = &anctd; | ||||
| settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData); | settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); | ||||
| /* For area normal. */ | /* For area normal. */ | ||||
| for (int i = 0; i < ARRAY_SIZE(anctd.area_nos); i++) { | for (int i = 0; i < ARRAY_SIZE(anctd.area_nos); i++) { | ||||
| if (normalize_v3_v3(r_area_no, anctd.area_nos[i]) != 0.0f) { | if (normalize_v3_v3(r_area_no, anctd.area_nos[i]) != 0.0f) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| Show All 19 Lines | SculptThreadedTaskData data = { | ||||
| .totnode = totnode, | .totnode = totnode, | ||||
| .has_bm_orco = has_bm_orco, | .has_bm_orco = has_bm_orco, | ||||
| .use_area_cos = true, | .use_area_cos = true, | ||||
| .use_area_nos = true, | .use_area_nos = true, | ||||
| }; | }; | ||||
| AreaNormalCenterTLSData anctd = {{{0}}}; | AreaNormalCenterTLSData anctd = {{{0}}}; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| settings.func_reduce = calc_area_normal_and_center_reduce; | settings.func_reduce = calc_area_normal_and_center_reduce; | ||||
| settings.userdata_chunk = &anctd; | settings.userdata_chunk = &anctd; | ||||
| settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData); | settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); | ||||
| /* For flatten center. */ | /* For flatten center. */ | ||||
| for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) { | for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) { | ||||
| if (anctd.count_co[n] != 0) { | if (anctd.count_co[n] != 0) { | ||||
| mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]); | mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 587 Lines • ▼ Show 20 Lines | static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, | ||||
| } | } | ||||
| float bstrength = data->strength; | float bstrength = data->strength; | ||||
| CLAMP(bstrength, 0.0f, 1.0f); | CLAMP(bstrength, 0.0f, 1.0f); | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * | const float fade = | ||||
| SCULPT_brush_strength_factor(ss, | bstrength * | ||||
| brush, | SCULPT_brush_strength_factor( | ||||
| vd.co, | ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, *vd.mask, vd.index, thread_id) * | ||||
| sqrtf(test.dist), | |||||
| vd.no, | |||||
| vd.fno, | |||||
| *vd.mask, | |||||
| vd.index, | |||||
| tls->thread_id) * | |||||
| ss->cache->pressure; | ss->cache->pressure; | ||||
| float avg[3], val[3]; | float avg[3], val[3]; | ||||
| SCULPT_bmesh_four_neighbor_average(avg, direction, vd.bm_vert); | SCULPT_bmesh_four_neighbor_average(avg, direction, vd.bm_vert); | ||||
| sub_v3_v3v3(val, avg, vd.co); | sub_v3_v3v3(val, avg, vd.co); | ||||
| madd_v3_v3v3fl(val, vd.co, val, fade); | madd_v3_v3v3fl(val, vd.co, val, fade); | ||||
| Show All 25 Lines | for (iteration = 0; iteration <= count; iteration++) { | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .strength = factor, | .strength = factor, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_topology_rake_bmesh_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_topology_rake_bmesh_task_cb_ex, &settings); | ||||
| } | } | ||||
| } | } | ||||
| static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, | static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = SCULPT_brush_strength_factor( | const float fade = SCULPT_brush_strength_factor( | ||||
| ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, vd.index, tls->thread_id); | ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, vd.index, thread_id); | ||||
| if (bstrength > 0.0f) { | if (bstrength > 0.0f) { | ||||
| (*vd.mask) += fade * bstrength * (1.0f - *vd.mask); | (*vd.mask) += fade * bstrength * (1.0f - *vd.mask); | ||||
| } | } | ||||
| else { | else { | ||||
| (*vd.mask) += fade * bstrength * (*vd.mask); | (*vd.mask) += fade * bstrength * (*vd.mask); | ||||
| } | } | ||||
| CLAMP(*vd.mask, 0.0f, 1.0f); | CLAMP(*vd.mask, 0.0f, 1.0f); | ||||
| Show All 13 Lines | static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| /* Threaded loop over nodes. */ | /* Threaded loop over nodes. */ | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_mask_brush_draw_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_mask_brush_draw_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| { | { | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| Brush *brush = BKE_paint_brush(&sd->paint); | Brush *brush = BKE_paint_brush(&sd->paint); | ||||
| switch ((BrushMaskTool)brush->mask_tool) { | switch ((BrushMaskTool)brush->mask_tool) { | ||||
| Show All 18 Lines | static void do_draw_brush_task_cb_ex(void *__restrict userdata, | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| /* Offset vertex. */ | /* Offset vertex. */ | ||||
| const float fade = SCULPT_brush_strength_factor(ss, | const float fade = SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], offset, fade); | mul_v3_v3fl(proxy[vd.i], offset, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 20 Lines | static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .offset = offset, | .offset = offset, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_draw_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_draw_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata, | static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float *offset = data->offset; | const float *offset = data->offset; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| /* Offset vertex. */ | /* Offset vertex. */ | ||||
| const float fade = SCULPT_brush_strength_factor(ss, | const float fade = SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| orig_data.co, | orig_data.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| orig_data.no, | orig_data.no, | ||||
| NULL, | NULL, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], offset, fade); | mul_v3_v3fl(proxy[vd.i], offset, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 20 Lines | static void do_draw_sharp_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .offset = offset, | .offset = offset, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_draw_sharp_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_draw_sharp_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Sculpt Topology Brush | /** \name Sculpt Topology Brush | ||||
| * \{ */ | * \{ */ | ||||
| static void do_topology_slide_task_cb_ex(void *__restrict userdata, | static void do_topology_slide_task_cb_ex(void *__restrict userdata, | ||||
| Show All 10 Lines | static void do_topology_slide_task_cb_ex(void *__restrict userdata, | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| const float fade = SCULPT_brush_strength_factor(ss, | const float fade = SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| orig_data.co, | orig_data.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| orig_data.no, | orig_data.no, | ||||
| NULL, | NULL, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| float current_disp[3]; | float current_disp[3]; | ||||
| float current_disp_norm[3]; | float current_disp_norm[3]; | ||||
| float final_disp[3]; | float final_disp[3]; | ||||
| zero_v3(final_disp); | zero_v3(final_disp); | ||||
| sub_v3_v3v3(current_disp, ss->cache->location, ss->cache->last_location); | sub_v3_v3v3(current_disp, ss->cache->location, ss->cache->last_location); | ||||
| normalize_v3_v3(current_disp_norm, current_disp); | normalize_v3_v3(current_disp_norm, current_disp); | ||||
| mul_v3_v3fl(current_disp, current_disp_norm, ss->cache->bstrength); | mul_v3_v3fl(current_disp, current_disp_norm, ss->cache->bstrength); | ||||
| SculptVertexNeighborIter ni; | SculptVertexNeighborIter ni; | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | static void do_topology_relax_task_cb_ex(void *__restrict userdata, | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n]); | BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n]); | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| const float fade = SCULPT_brush_strength_factor(ss, | const float fade = SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| orig_data.co, | orig_data.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| orig_data.no, | orig_data.no, | ||||
| NULL, | NULL, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| SCULPT_relax_vertex(ss, &vd, fade * bstrength, false, vd.co); | SCULPT_relax_vertex(ss, &vd, fade * bstrength, false, vd.co); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| BKE_pbvh_vertex_iter_end; | BKE_pbvh_vertex_iter_end; | ||||
| Show All 12 Lines | static void do_slide_relax_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| if (ss->cache->alt_smooth) { | if (ss->cache->alt_smooth) { | ||||
| for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_topology_relax_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_topology_relax_task_cb_ex, &settings); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_topology_slide_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_topology_slide_task_cb_ex, &settings); | ||||
| } | } | ||||
| } | } | ||||
| static void calc_sculpt_plane( | static void calc_sculpt_plane( | ||||
| Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3]) | Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3]) | ||||
| { | { | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| Brush *brush = BKE_paint_brush(&sd->paint); | Brush *brush = BKE_paint_brush(&sd->paint); | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | static void do_crease_brush_task_cb_ex(void *__restrict userdata, | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| /* Offset vertex. */ | /* Offset vertex. */ | ||||
| const float fade = SCULPT_brush_strength_factor(ss, | const float fade = SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| float val1[3]; | float val1[3]; | ||||
| float val2[3]; | float val2[3]; | ||||
| /* First we pinch. */ | /* First we pinch. */ | ||||
| sub_v3_v3v3(val1, test.location, vd.co); | sub_v3_v3v3(val1, test.location, vd.co); | ||||
| if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { | ||||
| project_plane_v3_v3v3(val1, val1, ss->cache->view_normal); | project_plane_v3_v3v3(val1, val1, ss->cache->view_normal); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | SculptThreadedTaskData data = { | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .spvc = &spvc, | .spvc = &spvc, | ||||
| .offset = offset, | .offset = offset, | ||||
| .flippedbstrength = flippedbstrength, | .flippedbstrength = flippedbstrength, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_pinch_brush_task_cb_ex(void *__restrict userdata, | static void do_pinch_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| float(*stroke_xz)[3] = data->stroke_xz; | float(*stroke_xz)[3] = data->stroke_xz; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| float x_object_space[3]; | float x_object_space[3]; | ||||
| float z_object_space[3]; | float z_object_space[3]; | ||||
| copy_v3_v3(x_object_space, stroke_xz[0]); | copy_v3_v3(x_object_space, stroke_xz[0]); | ||||
| copy_v3_v3(z_object_space, stroke_xz[1]); | copy_v3_v3(z_object_space, stroke_xz[1]); | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| float disp_center[3]; | float disp_center[3]; | ||||
| float x_disp[3]; | float x_disp[3]; | ||||
| float z_disp[3]; | float z_disp[3]; | ||||
| /* Calcualte displacement from the vertex to the brush center. */ | /* Calcualte displacement from the vertex to the brush center. */ | ||||
| sub_v3_v3v3(disp_center, test.location, vd.co); | sub_v3_v3v3(disp_center, test.location, vd.co); | ||||
| /* Project the displacement into the X vector (aligned to the stroke). */ | /* Project the displacement into the X vector (aligned to the stroke). */ | ||||
| mul_v3_v3fl(x_disp, x_object_space, dot_v3v3(disp_center, x_object_space)); | mul_v3_v3fl(x_disp, x_object_space, dot_v3v3(disp_center, x_object_space)); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .stroke_xz = stroke_xz, | .stroke_xz = stroke_xz, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_pinch_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_pinch_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_grab_brush_task_cb_ex(void *__restrict userdata, | static void do_grab_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float *grab_delta = data->grab_delta; | const float *grab_delta = data->grab_delta; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| orig_data.co, | orig_data.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| orig_data.no, | orig_data.no, | ||||
| NULL, | NULL, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], grab_delta, fade); | mul_v3_v3fl(proxy[vd.i], grab_delta, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 15 Lines | static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .grab_delta = grab_delta, | .grab_delta = grab_delta, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata, | static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict UNUSED(tls)) | const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| ▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | static void do_elastic_deform_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .grab_delta = grab_delta, | .grab_delta = grab_delta, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_elastic_deform_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_elastic_deform_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| ePaintSymmetryAreas SCULPT_get_vertex_symm_area(const float co[3]) | ePaintSymmetryAreas SCULPT_get_vertex_symm_area(const float co[3]) | ||||
| { | { | ||||
| ePaintSymmetryAreas symm_area = PAINT_SYMM_AREA_DEFAULT; | ePaintSymmetryAreas symm_area = PAINT_SYMM_AREA_DEFAULT; | ||||
| if (co[0] < 0.0f) { | if (co[0] < 0.0f) { | ||||
| symm_area |= PAINT_SYMM_AREA_X; | symm_area |= PAINT_SYMM_AREA_X; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | static void do_nudge_brush_task_cb_ex(void *__restrict userdata, | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], cono, fade); | mul_v3_v3fl(proxy[vd.i], cono, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 15 Lines | static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .cono = cono, | .cono = cono, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_nudge_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_nudge_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, | static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| Show All 10 Lines | const float pinch = do_pinch ? (2.0f * (0.5f - brush->crease_pinch_factor) * | ||||
| (len_v3(grab_delta) / ss->cache->radius)) : | (len_v3(grab_delta) / ss->cache->radius)) : | ||||
| 0.0f; | 0.0f; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], grab_delta, fade); | mul_v3_v3fl(proxy[vd.i], grab_delta, fade); | ||||
| /* Negative pinch will inflate, helps maintain volume. */ | /* Negative pinch will inflate, helps maintain volume. */ | ||||
| if (do_pinch) { | if (do_pinch) { | ||||
| float delta_pinch_init[3], delta_pinch[3]; | float delta_pinch_init[3], delta_pinch[3]; | ||||
| sub_v3_v3v3(delta_pinch, vd.co, test.location); | sub_v3_v3v3(delta_pinch, vd.co, test.location); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .spvc = &spvc, | .spvc = &spvc, | ||||
| .grab_delta = grab_delta, | .grab_delta = grab_delta, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_snake_hook_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_snake_hook_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_thumb_brush_task_cb_ex(void *__restrict userdata, | static void do_thumb_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float *cono = data->cono; | const float *cono = data->cono; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| orig_data.co, | orig_data.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| orig_data.no, | orig_data.no, | ||||
| NULL, | NULL, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], cono, fade); | mul_v3_v3fl(proxy[vd.i], cono, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 15 Lines | static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .cono = cono, | .cono = cono, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_thumb_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_thumb_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_rotate_brush_task_cb_ex(void *__restrict userdata, | static void do_rotate_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float angle = data->angle; | const float angle = data->angle; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| float vec[3], rot[3][3]; | float vec[3], rot[3][3]; | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| orig_data.co, | orig_data.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| orig_data.no, | orig_data.no, | ||||
| NULL, | NULL, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| sub_v3_v3v3(vec, orig_data.co, ss->cache->location); | sub_v3_v3v3(vec, orig_data.co, ss->cache->location); | ||||
| axis_angle_normalized_to_mat3(rot, ss->cache->sculpt_normal_symm, angle * fade); | axis_angle_normalized_to_mat3(rot, ss->cache->sculpt_normal_symm, angle * fade); | ||||
| mul_v3_m3v3(proxy[vd.i], rot, vec); | mul_v3_m3v3(proxy[vd.i], rot, vec); | ||||
| add_v3_v3(proxy[vd.i], ss->cache->location); | add_v3_v3(proxy[vd.i], ss->cache->location); | ||||
| sub_v3_v3(proxy[vd.i], orig_data.co); | sub_v3_v3(proxy[vd.i], orig_data.co); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| Show All 15 Lines | static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .angle = angle, | .angle = angle, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_rotate_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_rotate_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_layer_brush_task_cb_ex(void *__restrict userdata, | static void do_layer_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| Sculpt *sd = data->sd; | Sculpt *sd = data->sd; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const bool use_persistent_base = ss->layer_base && brush->flag & BRUSH_PERSISTENT; | const bool use_persistent_base = ss->layer_base && brush->flag & BRUSH_PERSISTENT; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { | ||||
| const float fade = SCULPT_brush_strength_factor(ss, | const float fade = SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| const int vi = vd.index; | const int vi = vd.index; | ||||
| float *disp_factor; | float *disp_factor; | ||||
| if (use_persistent_base) { | if (use_persistent_base) { | ||||
| disp_factor = &ss->layer_base[vi].disp; | disp_factor = &ss->layer_base[vi].disp; | ||||
| } | } | ||||
| else { | else { | ||||
| disp_factor = &ss->cache->layer_displacement_factor[vi]; | disp_factor = &ss->cache->layer_displacement_factor[vi]; | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_layer_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_layer_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_inflate_brush_task_cb_ex(void *__restrict userdata, | static void do_inflate_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| float val[3]; | float val[3]; | ||||
| if (vd.fno) { | if (vd.fno) { | ||||
| copy_v3_v3(val, vd.fno); | copy_v3_v3(val, vd.fno); | ||||
| } | } | ||||
| else { | else { | ||||
| normal_short_to_float_v3(val, vd.no); | normal_short_to_float_v3(val, vd.no); | ||||
| } | } | ||||
| Show All 15 Lines | static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| int SCULPT_plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3]) | int SCULPT_plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3]) | ||||
| { | { | ||||
| return (!(brush->flag & BRUSH_PLANE_TRIM) || | return (!(brush->flag & BRUSH_PLANE_TRIM) || | ||||
| ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_trim_squared))); | ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_trim_squared))); | ||||
| } | } | ||||
| Show All 39 Lines | static void do_flatten_brush_task_cb_ex(void *__restrict userdata, | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| float intr[3]; | float intr[3]; | ||||
| float val[3]; | float val[3]; | ||||
| closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | ||||
| sub_v3_v3v3(val, intr, vd.co); | sub_v3_v3v3(val, intr, vd.co); | ||||
| if (SCULPT_plane_trim(ss->cache, brush, val)) { | if (SCULPT_plane_trim(ss->cache, brush, val)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], val, fade); | mul_v3_v3fl(proxy[vd.i], val, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 27 Lines | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .area_no = area_no, | .area_no = area_no, | ||||
| .area_co = area_co, | .area_co = area_co, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_flatten_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_flatten_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Sculpt Clay Brush | /** \name Sculpt Clay Brush | ||||
| * \{ */ | * \{ */ | ||||
| typedef struct ClaySampleData { | typedef struct ClaySampleData { | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | static void do_clay_brush_task_cb_ex(void *__restrict userdata, | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = fabsf(ss->cache->bstrength); | const float bstrength = fabsf(ss->cache->bstrength); | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| float intr[3]; | float intr[3]; | ||||
| float val[3]; | float val[3]; | ||||
| closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | ||||
| sub_v3_v3v3(val, intr, vd.co); | sub_v3_v3v3(val, intr, vd.co); | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], val, fade); | mul_v3_v3fl(proxy[vd.i], val, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 25 Lines | SculptThreadedTaskData sample_data = { | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .totnode = totnode, | .totnode = totnode, | ||||
| .area_no = area_no, | .area_no = area_no, | ||||
| .area_co = ss->cache->location, | .area_co = ss->cache->location, | ||||
| }; | }; | ||||
| ClaySampleData csd = {{0}}; | ClaySampleData csd = {{0}}; | ||||
| PBVHParallelSettings sample_settings; | TaskParallelSettings sample_settings; | ||||
| BKE_pbvh_parallel_range_settings(&sample_settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&sample_settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| sample_settings.func_reduce = calc_clay_surface_reduce; | sample_settings.func_reduce = calc_clay_surface_reduce; | ||||
| sample_settings.userdata_chunk = &csd; | sample_settings.userdata_chunk = &csd; | ||||
| sample_settings.userdata_chunk_size = sizeof(ClaySampleData); | sample_settings.userdata_chunk_size = sizeof(ClaySampleData); | ||||
| BKE_pbvh_parallel_range(0, totnode, &sample_data, calc_clay_surface_task_cb, &sample_settings); | BLI_task_parallel_range(0, totnode, &sample_data, calc_clay_surface_task_cb, &sample_settings); | ||||
| float d_offset = (csd.plane_dist[0] + csd.plane_dist[1]); | float d_offset = (csd.plane_dist[0] + csd.plane_dist[1]); | ||||
| d_offset = min_ff(radius, d_offset); | d_offset = min_ff(radius, d_offset); | ||||
| d_offset = d_offset / radius; | d_offset = d_offset / radius; | ||||
| d_offset = 1.0f - d_offset; | d_offset = 1.0f - d_offset; | ||||
| displace = fabsf(initial_radius * (0.25f + offset + (d_offset * 0.15f))); | displace = fabsf(initial_radius * (0.25f + offset + (d_offset * 0.15f))); | ||||
| if (flip) { | if (flip) { | ||||
| displace = -displace; | displace = -displace; | ||||
| } | } | ||||
| mul_v3_v3v3(temp, area_no, ss->cache->scale); | mul_v3_v3v3(temp, area_no, ss->cache->scale); | ||||
| mul_v3_fl(temp, displace); | mul_v3_fl(temp, displace); | ||||
| copy_v3_v3(area_co, ss->cache->location); | copy_v3_v3(area_co, ss->cache->location); | ||||
| add_v3_v3(area_co, temp); | add_v3_v3(area_co, temp); | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .area_no = area_no, | .area_no = area_no, | ||||
| .area_co = area_co, | .area_co = area_co, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_clay_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_clay_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, | static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| float(*mat)[4] = data->mat; | float(*mat)[4] = data->mat; | ||||
| const float *area_no_sp = data->area_no_sp; | const float *area_no_sp = data->area_no_sp; | ||||
| const float *area_co = data->area_co; | const float *area_co = data->area_co; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const bool flip = (ss->cache->bstrength < 0.0f); | const bool flip = (ss->cache->bstrength < 0.0f); | ||||
| const float bstrength = flip ? -ss->cache->bstrength : ss->cache->bstrength; | const float bstrength = flip ? -ss->cache->bstrength : ss->cache->bstrength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SCULPT_brush_test_init(ss, &test); | SCULPT_brush_test_init(ss, &test); | ||||
| plane_from_point_normal_v3(test.plane_tool, area_co, area_no_sp); | plane_from_point_normal_v3(test.plane_tool, area_co, area_no_sp); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (SCULPT_brush_test_cube(&test, vd.co, mat, brush->tip_roundness)) { | if (SCULPT_brush_test_cube(&test, vd.co, mat, brush->tip_roundness)) { | ||||
| if (plane_point_side_flip(vd.co, test.plane_tool, flip)) { | if (plane_point_side_flip(vd.co, test.plane_tool, flip)) { | ||||
| float intr[3]; | float intr[3]; | ||||
| float val[3]; | float val[3]; | ||||
| closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | ||||
| sub_v3_v3v3(val, intr, vd.co); | sub_v3_v3v3(val, intr, vd.co); | ||||
| if (SCULPT_plane_trim(ss->cache, brush, val)) { | if (SCULPT_plane_trim(ss->cache, brush, val)) { | ||||
| /* The normal from the vertices is ignored, it causes glitch with planes, see: T44390. */ | /* The normal from the vertices is ignored, it causes glitch with planes, see: T44390. */ | ||||
| const float fade = bstrength * | const float fade = bstrength * | ||||
| SCULPT_brush_strength_factor(ss, | SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| ss->cache->radius * test.dist, | ss->cache->radius * test.dist, | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], val, fade); | mul_v3_v3fl(proxy[vd.i], val, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | SculptThreadedTaskData data = { | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .area_no_sp = area_no_sp, | .area_no_sp = area_no_sp, | ||||
| .area_co = area_co, | .area_co = area_co, | ||||
| .mat = mat, | .mat = mat, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_clay_strips_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_clay_strips_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_fill_brush_task_cb_ex(void *__restrict userdata, | static void do_fill_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float *area_no = data->area_no; | const float *area_no = data->area_no; | ||||
| const float *area_co = data->area_co; | const float *area_co = data->area_co; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| if (SCULPT_plane_point_side(vd.co, test.plane_tool)) { | if (SCULPT_plane_point_side(vd.co, test.plane_tool)) { | ||||
| float intr[3]; | float intr[3]; | ||||
| float val[3]; | float val[3]; | ||||
| closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | ||||
| sub_v3_v3v3(val, intr, vd.co); | sub_v3_v3v3(val, intr, vd.co); | ||||
| if (SCULPT_plane_trim(ss->cache, brush, val)) { | if (SCULPT_plane_trim(ss->cache, brush, val)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], val, fade); | mul_v3_v3fl(proxy[vd.i], val, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 29 Lines | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .area_no = area_no, | .area_no = area_no, | ||||
| .area_co = area_co, | .area_co = area_co, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_fill_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_fill_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| static void do_scrape_brush_task_cb_ex(void *__restrict userdata, | static void do_scrape_brush_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float *area_no = data->area_no; | const float *area_no = data->area_no; | ||||
| const float *area_co = data->area_co; | const float *area_co = data->area_co; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | plane_from_point_normal_v3(test.plane_tool, area_co, area_no); | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| if (!SCULPT_plane_point_side(vd.co, test.plane_tool)) { | if (!SCULPT_plane_point_side(vd.co, test.plane_tool)) { | ||||
| float intr[3]; | float intr[3]; | ||||
| float val[3]; | float val[3]; | ||||
| closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); | ||||
| sub_v3_v3v3(val, intr, vd.co); | sub_v3_v3v3(val, intr, vd.co); | ||||
| if (SCULPT_plane_trim(ss->cache, brush, val)) { | if (SCULPT_plane_trim(ss->cache, brush, val)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], val, fade); | mul_v3_v3fl(proxy[vd.i], val, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 29 Lines | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .area_no = area_no, | .area_no = area_no, | ||||
| .area_co = area_co, | .area_co = area_co, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_scrape_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_scrape_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Sculpt Clay Thumb Brush | /** \name Sculpt Clay Thumb Brush | ||||
| * \{ */ | * \{ */ | ||||
| static void do_clay_thumb_brush_task_cb_ex(void *__restrict userdata, | static void do_clay_thumb_brush_task_cb_ex(void *__restrict userdata, | ||||
| Show All 11 Lines | static void do_clay_thumb_brush_task_cb_ex(void *__restrict userdata, | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| const float bstrength = data->clay_strength; | const float bstrength = data->clay_strength; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| float plane_tilt[4]; | float plane_tilt[4]; | ||||
| float normal_tilt[3]; | float normal_tilt[3]; | ||||
| float imat[4][4]; | float imat[4][4]; | ||||
| invert_m4_m4(imat, mat); | invert_m4_m4(imat, mat); | ||||
| rotate_v3_v3v3fl(normal_tilt, area_no_sp, imat[0], DEG2RADF(-ss->cache->clay_thumb_front_angle)); | rotate_v3_v3v3fl(normal_tilt, area_no_sp, imat[0], DEG2RADF(-ss->cache->clay_thumb_front_angle)); | ||||
| Show All 24 Lines | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], val, fade); | mul_v3_v3fl(proxy[vd.i], val, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | SculptThreadedTaskData data = { | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .area_no_sp = area_no_sp, | .area_no_sp = area_no_sp, | ||||
| .area_co = ss->cache->location, | .area_co = ss->cache->location, | ||||
| .mat = mat, | .mat = mat, | ||||
| .clay_strength = clay_strength, | .clay_strength = clay_strength, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_clay_thumb_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_clay_thumb_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| static void do_gravity_task_cb_ex(void *__restrict userdata, | static void do_gravity_task_cb_ex(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| float *offset = data->offset; | float *offset = data->offset; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| float(*proxy)[3]; | float(*proxy)[3]; | ||||
| proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = SCULPT_brush_strength_factor(ss, | const float fade = SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| mul_v3_v3fl(proxy[vd.i], offset, fade); | mul_v3_v3fl(proxy[vd.i], offset, fade); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 18 Lines | static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float bstrength) | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .offset = offset, | .offset = offset, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings); | ||||
| } | } | ||||
| void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float (*vertCos)[3]) | void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float (*vertCos)[3]) | ||||
| { | { | ||||
| Mesh *me = (Mesh *)ob->data; | Mesh *me = (Mesh *)ob->data; | ||||
| float(*ofs)[3] = NULL; | float(*ofs)[3] = NULL; | ||||
| int a; | int a; | ||||
| const int kb_act_idx = ob->shapenr - 1; | const int kb_act_idx = ob->shapenr - 1; | ||||
| ▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | if (totnode) { | ||||
| SculptThreadedTaskData task_data = { | SculptThreadedTaskData task_data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings); | ||||
| /* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode deforms the | /* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode deforms the | ||||
| * vertices and uses regular coords undo. */ | * vertices and uses regular coords undo. */ | ||||
| if (brush->sculpt_tool == SCULPT_TOOL_DRAW_FACE_SETS && ss->cache->first_time && | if (brush->sculpt_tool == SCULPT_TOOL_DRAW_FACE_SETS && ss->cache->first_time && | ||||
| ss->cache->mirror_symmetry_pass == 0 && !ss->cache->alt_smooth) { | ss->cache->mirror_symmetry_pass == 0 && !ss->cache->alt_smooth) { | ||||
| SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | SCULPT_undo_push_node(ob, nodes[0], SCULPT_UNDO_FACE_SETS); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | static void sculpt_combine_proxies(Sculpt *sd, Object *ob) | ||||
| if (ss->cache->supports_gravity || (sculpt_tool_is_proxy_used(brush->sculpt_tool) == false)) { | if (ss->cache->supports_gravity || (sculpt_tool_is_proxy_used(brush->sculpt_tool) == false)) { | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings); | ||||
| } | } | ||||
| MEM_SAFE_FREE(nodes); | MEM_SAFE_FREE(nodes); | ||||
| } | } | ||||
| /*Copy the modified vertices from bvh to the active key. */ | /*Copy the modified vertices from bvh to the active key. */ | ||||
| static void sculpt_update_keyblock(Object *ob) | static void sculpt_update_keyblock(Object *ob) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | if (is_proxy_used) { | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .vertCos = vertCos, | .vertCos = vertCos, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, SCULPT_flush_stroke_deform_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &data, SCULPT_flush_stroke_deform_task_cb, &settings); | ||||
| if (vertCos) { | if (vertCos) { | ||||
| SCULPT_vertcos_to_key(ob, ss->shapekey_active, vertCos); | SCULPT_vertcos_to_key(ob, ss->shapekey_active, vertCos); | ||||
| MEM_freeN(vertCos); | MEM_freeN(vertCos); | ||||
| } | } | ||||
| MEM_SAFE_FREE(nodes); | MEM_SAFE_FREE(nodes); | ||||
| ▲ Show 20 Lines • Show All 2,174 Lines • Show Last 20 Lines | |||||