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
This commit is contained in:
Pablo Dobarro 2020-08-18 15:22:51 +02:00
parent 0957189d4a
commit bedd6f90ca
2 changed files with 30 additions and 0 deletions

View File

@ -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;

View File

@ -985,6 +985,9 @@ typedef struct FilterCache {
float viewmat[4][4];
float viewmat_inv[4][4];
/* Displacement eraser. */
float (*limit_surface_co)[3];
/* unmasked nodes */
PBVHNode **nodes;
int totnode;