Commit: bedd6f90ca70ede59adff10aaea4d0f17bf8d0b2
Author: Pablo Dobarro
Date:   Tue Aug 18 15:22:51 2020 +0200
Branches: master
https://developer.blender.org/rBbedd6f90ca70ede59adff10aaea4d0f17bf8d0b2

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

===================================================================

M       source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M       source/blender/editors/sculpt_paint/sculpt_intern.h

===================================================================

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;
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h 
b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 6e170ad64fe..df81deeb9d4 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -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;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to