Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
| Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | void SCULPT_filter_cache_free(SculptSession *ss) | ||||
| MEM_SAFE_FREE(ss->filter_cache->nodes); | MEM_SAFE_FREE(ss->filter_cache->nodes); | ||||
| MEM_SAFE_FREE(ss->filter_cache->mask_update_it); | MEM_SAFE_FREE(ss->filter_cache->mask_update_it); | ||||
| MEM_SAFE_FREE(ss->filter_cache->prev_mask); | MEM_SAFE_FREE(ss->filter_cache->prev_mask); | ||||
| MEM_SAFE_FREE(ss->filter_cache->normal_factor); | MEM_SAFE_FREE(ss->filter_cache->normal_factor); | ||||
| MEM_SAFE_FREE(ss->filter_cache->prev_face_set); | MEM_SAFE_FREE(ss->filter_cache->prev_face_set); | ||||
| MEM_SAFE_FREE(ss->filter_cache->automask); | MEM_SAFE_FREE(ss->filter_cache->automask); | ||||
| MEM_SAFE_FREE(ss->filter_cache->surface_smooth_laplacian_disp); | MEM_SAFE_FREE(ss->filter_cache->surface_smooth_laplacian_disp); | ||||
| MEM_SAFE_FREE(ss->filter_cache->sharpen_factor); | MEM_SAFE_FREE(ss->filter_cache->sharpen_factor); | ||||
| MEM_SAFE_FREE(ss->filter_cache->accum_disp); | |||||
| MEM_SAFE_FREE(ss->filter_cache); | MEM_SAFE_FREE(ss->filter_cache); | ||||
| } | } | ||||
| typedef enum eSculptMeshFilterTypes { | typedef enum eSculptMeshFilterTypes { | ||||
| MESH_FILTER_SMOOTH = 0, | MESH_FILTER_SMOOTH = 0, | ||||
| MESH_FILTER_SCALE = 1, | MESH_FILTER_SCALE = 1, | ||||
| MESH_FILTER_INFLATE = 2, | MESH_FILTER_INFLATE = 2, | ||||
| MESH_FILTER_SPHERE = 3, | MESH_FILTER_SPHERE = 3, | ||||
| ▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | switch (filter_type) { | ||||
| break; | break; | ||||
| } | } | ||||
| case MESH_FILTER_SHARPEN: { | case MESH_FILTER_SHARPEN: { | ||||
| const float smooth_ratio = ss->filter_cache->sharpen_smooth_ratio; | const float smooth_ratio = ss->filter_cache->sharpen_smooth_ratio; | ||||
| /* This filter can't work at full strength as it needs multiple iterations to reach a | /* This filter can't work at full strength as it needs multiple iterations to reach a | ||||
| * stable state. */ | * stable state. */ | ||||
| fade = clamp_f(fade, 0.0f, 0.5f); | fade = clamp_f(fade, 0.0f, 0.5f); | ||||
| float disp_sharpen[3] = {0.0f, 0.0f, 0.0f}; | |||||
| SculptVertexNeighborIter ni; | |||||
| SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vd.index, ni) { | |||||
| float disp_n[3]; | |||||
| sub_v3_v3v3( | |||||
| disp_n, SCULPT_vertex_co_get(ss, ni.index), SCULPT_vertex_co_get(ss, vd.index)); | |||||
| mul_v3_fl(disp_n, ss->filter_cache->sharpen_factor[ni.index]); | |||||
| add_v3_v3(disp_sharpen, disp_n); | |||||
| } | |||||
| SCULPT_VERTEX_NEIGHBORS_ITER_END(ni); | |||||
| float disp_sharpen[3]; | |||||
| copy_v3_v3(disp_sharpen, ss->filter_cache->accum_disp[vd.index]); | |||||
| mul_v3_fl(disp_sharpen, 1.0f - ss->filter_cache->sharpen_factor[vd.index]); | mul_v3_fl(disp_sharpen, 1.0f - ss->filter_cache->sharpen_factor[vd.index]); | ||||
sergey: float disp_sharpen[3] = {0.0f, 0.0f, 0.0f}; | |||||
| float disp_avg[3]; | float disp_avg[3]; | ||||
| float avg_co[3]; | float avg_co[3]; | ||||
| SCULPT_neighbor_coords_average(ss, avg_co, vd.index); | SCULPT_neighbor_coords_average(ss, avg_co, vd.index); | ||||
| sub_v3_v3v3(disp_avg, avg_co, vd.co); | sub_v3_v3v3(disp_avg, avg_co, vd.co); | ||||
| mul_v3_v3fl( | mul_v3_v3fl( | ||||
| disp_avg, disp_avg, smooth_ratio * pow2f(ss->filter_cache->sharpen_factor[vd.index])); | disp_avg, disp_avg, smooth_ratio * pow2f(ss->filter_cache->sharpen_factor[vd.index])); | ||||
| add_v3_v3v3(disp, disp_avg, disp_sharpen); | add_v3_v3v3(disp, disp_avg, disp_sharpen); | ||||
| Show All 40 Lines | static void mesh_filter_sharpen_init_factors(SculptSession *ss) | ||||
| max_factor = 1.0f / max_factor; | max_factor = 1.0f / max_factor; | ||||
| for (int i = 0; i < totvert; i++) { | for (int i = 0; i < totvert; i++) { | ||||
| ss->filter_cache->sharpen_factor[i] *= max_factor; | ss->filter_cache->sharpen_factor[i] *= max_factor; | ||||
| ss->filter_cache->sharpen_factor[i] = 1.0f - pow2f(1.0f - ss->filter_cache->sharpen_factor[i]); | ss->filter_cache->sharpen_factor[i] = 1.0f - pow2f(1.0f - ss->filter_cache->sharpen_factor[i]); | ||||
| } | } | ||||
| } | } | ||||
| static void mesh_filter_sharpen_accumulate_displacement(SculptSession *ss) | |||||
| { | |||||
| const int totvert = SCULPT_vertex_count_get(ss); | |||||
| for (int i = 0; i < totvert; i++) { | |||||
| zero_v3(ss->filter_cache->accum_disp[i]); | |||||
| } | |||||
| for (int i = 0; i < totvert; i++) { | |||||
| SculptVertexNeighborIter ni; | |||||
| SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, i, ni) { | |||||
| float disp_n[3]; | |||||
| sub_v3_v3v3(disp_n, SCULPT_vertex_co_get(ss, i), SCULPT_vertex_co_get(ss, ni.index)); | |||||
| mul_v3_fl(disp_n, ss->filter_cache->sharpen_factor[i]); | |||||
| add_v3_v3(ss->filter_cache->accum_disp[ni.index], disp_n); | |||||
| } | |||||
| SCULPT_VERTEX_NEIGHBORS_ITER_END(ni); | |||||
| } | |||||
| } | |||||
| static void mesh_filter_surface_smooth_displace_task_cb( | static void mesh_filter_surface_smooth_displace_task_cb( | ||||
| void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) | void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| PBVHNode *node = data->nodes[i]; | PBVHNode *node = data->nodes[i]; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static int sculpt_mesh_filter_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| float len = event->prevclickx - event->mval[0]; | float len = event->prevclickx - event->mval[0]; | ||||
| filter_strength = filter_strength * -len * 0.001f * UI_DPI_FAC; | filter_strength = filter_strength * -len * 0.001f * UI_DPI_FAC; | ||||
| SCULPT_vertex_random_access_init(ss); | SCULPT_vertex_random_access_init(ss); | ||||
| bool needs_pmap = sculpt_mesh_filter_needs_pmap(filter_type, use_face_sets); | bool needs_pmap = sculpt_mesh_filter_needs_pmap(filter_type, use_face_sets); | ||||
| BKE_sculpt_update_object_for_edit(depsgraph, ob, needs_pmap, false); | BKE_sculpt_update_object_for_edit(depsgraph, ob, needs_pmap, false); | ||||
| if (filter_type == MESH_FILTER_SHARPEN) { | |||||
| mesh_filter_sharpen_accumulate_displacement(ss); | |||||
| } | |||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .nodes = ss->filter_cache->nodes, | .nodes = ss->filter_cache->nodes, | ||||
| .filter_type = filter_type, | .filter_type = filter_type, | ||||
| .filter_strength = filter_strength, | .filter_strength = filter_strength, | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | ss->filter_cache->surface_smooth_shape_preservation = RNA_float_get( | ||||
| op->ptr, "surface_smooth_shape_preservation"); | op->ptr, "surface_smooth_shape_preservation"); | ||||
| ss->filter_cache->surface_smooth_current_vertex = RNA_float_get( | ss->filter_cache->surface_smooth_current_vertex = RNA_float_get( | ||||
| op->ptr, "surface_smooth_current_vertex"); | op->ptr, "surface_smooth_current_vertex"); | ||||
| } | } | ||||
| if (RNA_enum_get(op->ptr, "type") == MESH_FILTER_SHARPEN) { | if (RNA_enum_get(op->ptr, "type") == MESH_FILTER_SHARPEN) { | ||||
| ss->filter_cache->sharpen_smooth_ratio = RNA_float_get(op->ptr, "sharpen_smooth_ratio"); | ss->filter_cache->sharpen_smooth_ratio = RNA_float_get(op->ptr, "sharpen_smooth_ratio"); | ||||
| ss->filter_cache->sharpen_factor = MEM_mallocN(sizeof(float) * totvert, "sharpen factor"); | ss->filter_cache->sharpen_factor = MEM_mallocN(sizeof(float) * totvert, "sharpen factor"); | ||||
| ss->filter_cache->accum_disp = MEM_mallocN(3 * sizeof(float) * totvert, "orco"); | |||||
| mesh_filter_sharpen_init_factors(ss); | mesh_filter_sharpen_init_factors(ss); | ||||
| } | } | ||||
| ss->filter_cache->enabled_axis[0] = deform_axis & MESH_FILTER_DEFORM_X; | ss->filter_cache->enabled_axis[0] = deform_axis & MESH_FILTER_DEFORM_X; | ||||
| ss->filter_cache->enabled_axis[1] = deform_axis & MESH_FILTER_DEFORM_Y; | ss->filter_cache->enabled_axis[1] = deform_axis & MESH_FILTER_DEFORM_Y; | ||||
| ss->filter_cache->enabled_axis[2] = deform_axis & MESH_FILTER_DEFORM_Z; | ss->filter_cache->enabled_axis[2] = deform_axis & MESH_FILTER_DEFORM_Z; | ||||
| ▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines | |||||
float disp_sharpen[3] = {0.0f, 0.0f, 0.0f};