Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_face_set.c
| Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata, | ||||
| 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 (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) { | if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) { | ||||
| MeshElemMap *vert_map = &ss->pmap[vd.index]; | MeshElemMap *vert_map = &ss->pmap[vd.index]; | ||||
| for (int j = 0; j < ss->pmap[vd.index].count; j++) { | for (int j = 0; j < ss->pmap[vd.index].count; j++) { | ||||
| const MPoly *p = &ss->mpoly[vert_map->indices[j]]; | const MPoly *p = &ss->mpoly[vert_map->indices[j]]; | ||||
| float poly_center[3]; | float poly_center[3]; | ||||
| BKE_mesh_calc_poly_center(p, &ss->mloop[p->loopstart], ss->mvert, poly_center); | BKE_mesh_calc_poly_center(p, &ss->mloop[p->loopstart], ss->mvert, poly_center); | ||||
| if (sculpt_brush_test_sq_fn(&test, poly_center)) { | if (sculpt_brush_test_sq_fn(&test, poly_center)) { | ||||
| 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); | ||||
| if (fade > 0.05f && ss->face_sets[vert_map->indices[j]] > 0) { | if (fade > 0.05f && ss->face_sets[vert_map->indices[j]] > 0) { | ||||
| ss->face_sets[vert_map->indices[j]] = abs(ss->cache->paint_face_set); | ss->face_sets[vert_map->indices[j]] = abs(ss->cache->paint_face_set); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS) { | else if (BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS) { | ||||
| { | { | ||||
| 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); | ||||
| if (fade > 0.05f) { | if (fade > 0.05f) { | ||||
| SCULPT_vertex_face_set_set(ss, vd.index, ss->cache->paint_face_set); | SCULPT_vertex_face_set_set(ss, vd.index, ss->cache->paint_face_set); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 16 Lines | 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 bool relax_face_sets = !(ss->cache->iteration_count % 3 == 0); | const bool relax_face_sets = !(ss->cache->iteration_count % 3 == 0); | ||||
| /* This operations needs a stregth tweak as the relax deformation is too weak by default. */ | /* This operations needs a stregth tweak as the relax deformation is too weak by default. */ | ||||
| if (relax_face_sets) { | if (relax_face_sets) { | ||||
| bstrength *= 2.0f; | bstrength *= 2.0f; | ||||
| } | } | ||||
| 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)) { | ||||
| if (relax_face_sets != SCULPT_vertex_has_unique_face_set(ss, vd.index)) { | if (relax_face_sets != SCULPT_vertex_has_unique_face_set(ss, vd.index)) { | ||||
| 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); | ||||
| SCULPT_relax_vertex(ss, &vd, fade * bstrength, relax_face_sets, vd.co); | SCULPT_relax_vertex(ss, &vd, fade * bstrength, relax_face_sets, vd.co); | ||||
| if (vd.mvert) { | if (vd.mvert) { | ||||
| vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | vd.mvert->flag |= ME_VERT_PBVH_UPDATE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 22 Lines | void SCULPT_do_draw_face_sets_brush(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); | ||||
| 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_relax_face_sets_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_relax_face_sets_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_draw_face_sets_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_draw_face_sets_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| } | } | ||||
| /* Face Sets Operators */ | /* Face Sets Operators */ | ||||
| typedef enum eSculptFaceGroupsCreateModes { | typedef enum eSculptFaceGroupsCreateModes { | ||||
| SCULPT_FACE_SET_MASKED = 0, | SCULPT_FACE_SET_MASKED = 0, | ||||
| SCULPT_FACE_SET_VISIBLE = 1, | SCULPT_FACE_SET_VISIBLE = 1, | ||||
| ▲ Show 20 Lines • Show All 744 Lines • Show Last 20 Lines | |||||