Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c
| Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | static void calc_multiplane_scrape_surface_task_cb(void *__restrict userdata, | ||||
| MultiplaneScrapeSampleData *mssd = tls->userdata_chunk; | MultiplaneScrapeSampleData *mssd = tls->userdata_chunk; | ||||
| float(*mat)[4] = data->mat; | float(*mat)[4] = data->mat; | ||||
| 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, brush->falloff_shape); | ss, &test, brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| /* Apply the brush normal radius to the test before sampling. */ | /* Apply the brush normal radius to the test before sampling. */ | ||||
| float test_radius = sqrtf(test.radius_squared); | float test_radius = sqrtf(test.radius_squared); | ||||
| test_radius *= brush->normal_radius_factor; | test_radius *= brush->normal_radius_factor; | ||||
| test.radius_squared = test_radius * test_radius; | test.radius_squared = test_radius * test_radius; | ||||
| 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) | ||||
| { | { | ||||
| Show All 12 Lines | 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); | ||||
| /* Sample the normal and area of the +X and -X axis individually. */ | /* Sample the normal and area of the +X and -X axis individually. */ | ||||
| if (local_co[0] > 0.0f) { | if (local_co[0] > 0.0f) { | ||||
| madd_v3_v3fl(mssd->area_nos[0], normal, fade); | madd_v3_v3fl(mssd->area_nos[0], normal, fade); | ||||
| add_v3_v3(mssd->area_cos[0], vd.co); | add_v3_v3(mssd->area_cos[0], vd.co); | ||||
| mssd->area_count[0]++; | mssd->area_count[0]++; | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 39 Lines | static void do_multiplane_scrape_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); | |||||
| 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 local_co[3]; | float local_co[3]; | ||||
| bool deform = false; | bool deform = false; | ||||
| Show All 29 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, | ||||
| len_v3(local_co), | len_v3(local_co), | ||||
| 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 76 Lines • ▼ Show 20 Lines | SculptThreadedTaskData sample_data = { | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .totnode = totnode, | .totnode = totnode, | ||||
| .mat = mat, | .mat = mat, | ||||
| }; | }; | ||||
| MultiplaneScrapeSampleData mssd = {{{0}}}; | MultiplaneScrapeSampleData mssd = {{{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_multiplane_scrape_surface_reduce; | sample_settings.func_reduce = calc_multiplane_scrape_surface_reduce; | ||||
| sample_settings.userdata_chunk = &mssd; | sample_settings.userdata_chunk = &mssd; | ||||
| sample_settings.userdata_chunk_size = sizeof(MultiplaneScrapeSampleData); | sample_settings.userdata_chunk_size = sizeof(MultiplaneScrapeSampleData); | ||||
| BKE_pbvh_parallel_range( | BLI_task_parallel_range( | ||||
| 0, totnode, &sample_data, calc_multiplane_scrape_surface_task_cb, &sample_settings); | 0, totnode, &sample_data, calc_multiplane_scrape_surface_task_cb, &sample_settings); | ||||
| float sampled_plane_normals[2][3]; | float sampled_plane_normals[2][3]; | ||||
| float sampled_plane_co[2][3]; | float sampled_plane_co[2][3]; | ||||
| float sampled_cv[2][3]; | float sampled_cv[2][3]; | ||||
| float mid_co[3]; | float mid_co[3]; | ||||
| /* Use the area center of both planes to detect if we are sculpting along a concave or convex | /* Use the area center of both planes to detect if we are sculpting along a concave or convex | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | void SCULPT_do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| mul_v3_mat3_m4v3(plane_no, mat, area_no); | mul_v3_mat3_m4v3(plane_no, mat, area_no); | ||||
| rotate_v3_v3v3fl( | rotate_v3_v3v3fl( | ||||
| plane_no_rot, plane_no, y_axis, DEG2RADF(ss->cache->multiplane_scrape_angle * 0.5f)); | plane_no_rot, plane_no, y_axis, DEG2RADF(ss->cache->multiplane_scrape_angle * 0.5f)); | ||||
| mul_v3_mat3_m4v3(plane_no, mat_inv, plane_no_rot); | mul_v3_mat3_m4v3(plane_no, mat_inv, plane_no_rot); | ||||
| normalize_v3(plane_no); | normalize_v3(plane_no); | ||||
| plane_from_point_normal_v3(data.multiplane_scrape_planes[0], area_co, plane_no); | plane_from_point_normal_v3(data.multiplane_scrape_planes[0], area_co, plane_no); | ||||
| 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_multiplane_scrape_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_multiplane_scrape_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| void SCULPT_multiplane_scrape_preview_draw(const uint gpuattr, | void SCULPT_multiplane_scrape_preview_draw(const uint gpuattr, | ||||
| SculptSession *ss, | SculptSession *ss, | ||||
| const float outline_col[3], | const float outline_col[3], | ||||
| const float outline_alpha) | const float outline_alpha) | ||||
| { | { | ||||
| float local_mat_inv[4][4]; | float local_mat_inv[4][4]; | ||||
| ▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines | |||||