From bedd6f90ca70ede59adff10aaea4d0f17bf8d0b2 Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Tue, 18 Aug 2020 15:22:51 +0200 Subject: Sculpt: Erase Displacement Mesh Filter Same concept as the Multires Displacement Eraser Brush but implemented as a mesh Filter. This allows to delete the displacement of an entire area uniformly. Reviewed By: sergey Differential Revision: https://developer.blender.org/D8608 --- .../editors/sculpt_paint/sculpt_filter_mesh.c | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source/blender/editors/sculpt_paint/sculpt_filter_mesh.c') diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c index af77e35aebe..abfbe035928 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c @@ -177,6 +177,7 @@ void SCULPT_filter_cache_free(SculptSession *ss) MEM_SAFE_FREE(ss->filter_cache->surface_smooth_laplacian_disp); MEM_SAFE_FREE(ss->filter_cache->sharpen_factor); MEM_SAFE_FREE(ss->filter_cache->detail_directions); + MEM_SAFE_FREE(ss->filter_cache->limit_surface_co); MEM_SAFE_FREE(ss->filter_cache); } @@ -191,6 +192,7 @@ typedef enum eSculptMeshFilterTypes { MESH_FILTER_SURFACE_SMOOTH = 7, MESH_FILTER_SHARPEN = 8, MESH_FILTER_ENHANCE_DETAILS = 9, + MESH_FILTER_ERASE_DISPLACEMENT = 10, } eSculptMeshFilterTypes; static EnumPropertyItem prop_mesh_filter_types[] = { @@ -216,6 +218,11 @@ static EnumPropertyItem prop_mesh_filter_types[] = { 0, "Enhance Details", "Enhance the high frequency surface detail"}, + {MESH_FILTER_ERASE_DISPLACEMENT, + "ERASE_DISCPLACEMENT", + 0, + "Erase Displacement", + "Deletes the displacement of the Multires Modifier"}, {0, NULL, 0, NULL, NULL}, }; @@ -444,6 +451,12 @@ static void mesh_filter_task_cb(void *__restrict userdata, case MESH_FILTER_ENHANCE_DETAILS: { mul_v3_v3fl(disp, ss->filter_cache->detail_directions[vd.index], -fabsf(fade)); } break; + case MESH_FILTER_ERASE_DISPLACEMENT: { + fade = clamp_f(fade, 0.0f, 1.0f); + sub_v3_v3v3(disp, ss->filter_cache->limit_surface_co[vd.index], orig_co); + mul_v3_fl(disp, fade); + break; + } } SCULPT_filter_to_orientation_space(disp, ss->filter_cache); @@ -480,6 +493,16 @@ static void mesh_filter_enhance_details_init_directions(SculptSession *ss) } } +static void mesh_filter_init_limit_surface_co(SculptSession *ss) +{ + const int totvert = SCULPT_vertex_count_get(ss); + ss->filter_cache->limit_surface_co = MEM_malloc_arrayN( + 3 * sizeof(float), totvert, "limit surface co"); + for (int i = 0; i < totvert; i++) { + SCULPT_vertex_limit_surface_get(ss, i, ss->filter_cache->limit_surface_co[i]); + } +} + static void mesh_filter_sharpen_init_factors(SculptSession *ss) { const int totvert = SCULPT_vertex_count_get(ss); @@ -708,6 +731,10 @@ static int sculpt_mesh_filter_invoke(bContext *C, wmOperator *op, const wmEvent mesh_filter_enhance_details_init_directions(ss); } + if (RNA_enum_get(op->ptr, "type") == MESH_FILTER_ERASE_DISPLACEMENT) { + mesh_filter_init_limit_surface_co(ss); + } + 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[2] = deform_axis & MESH_FILTER_DEFORM_Z; -- cgit v1.2.3