[Bf-blender-cvs] [8f18ee27e71] sculpt-dev: Sculpt-dev: New displacement heal brush

Joseph Eagar noreply at git.blender.org
Tue Dec 21 17:35:08 CET 2021


Commit: 8f18ee27e711f4097f2042ae34a28164c12f4cff
Author: Joseph Eagar
Date:   Tue Dec 21 11:31:59 2021 -0500
Branches: sculpt-dev
https://developer.blender.org/rB8f18ee27e711f4097f2042ae34a28164c12f4cff

Sculpt-dev: New displacement heal brush

This brush goes through all
the grids inside each PBVH node under
the brush, converts coordinates to
tangent space, filters out extreme displacements
and then converts back.

Simple, but very effective.

TODO: make this into a mesh filter too.

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

A	release/datafiles/icons/brush.sculpt.displacement_heal.dat
M	source/blender/blenkernel/BKE_subdiv_ccg.h
M	source/blender/blenkernel/intern/subdiv_ccg.c
M	source/blender/blenlib/intern/lockfree_mempool.cc
M	source/blender/editors/datafiles/CMakeLists.txt
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_brushes.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/datafiles/icons/brush.sculpt.displacement_heal.dat b/release/datafiles/icons/brush.sculpt.displacement_heal.dat
new file mode 100644
index 00000000000..24960495f21
Binary files /dev/null and b/release/datafiles/icons/brush.sculpt.displacement_heal.dat differ
diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h
index b7d4ab8d8ed..ee702305709 100644
--- a/source/blender/blenkernel/BKE_subdiv_ccg.h
+++ b/source/blender/blenkernel/BKE_subdiv_ccg.h
@@ -315,6 +315,17 @@ void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg,
                                      const SubdivCCGCoord *coord,
                                      float r_point[3]);
 
+void BKE_subdiv_ccg_eval_limit_point_and_derivatives(const SubdivCCG *subdiv_ccg,
+                                                     const SubdivCCGCoord *coord,
+                                                     float r_point[3],
+                                                     float r_dPdu[3],
+                                                     float r_dPdv[3]);
+
+void BKE_subdiv_ccg_get_tangent_matrix(const SubdivCCG *subdiv_ccg,
+                                       const SubdivCCGCoord *coord,
+                                       float mat[3][3],
+                                       float r_point[3]);
+
 typedef enum SubdivCCGAdjacencyType {
   SUBDIV_CCG_ADJACENT_NONE,
   SUBDIV_CCG_ADJACENT_VERTEX,
diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c
index 77962ec924c..5471cdd920a 100644
--- a/source/blender/blenkernel/intern/subdiv_ccg.c
+++ b/source/blender/blenkernel/intern/subdiv_ccg.c
@@ -33,6 +33,8 @@
 #include "BLI_math_vector.h"
 #include "BLI_task.h"
 
+#include "multires_inline.h"
+
 #include "BKE_DerivedMesh.h"
 #include "BKE_ccg.h"
 #include "BKE_global.h"
@@ -2101,4 +2103,38 @@ void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg,
   BKE_subdiv_eval_limit_point(subdiv, ptex_face_index, u, v, r_point);
 }
 
+void BKE_subdiv_ccg_eval_limit_point_and_derivatives(const SubdivCCG *subdiv_ccg,
+                                                     const SubdivCCGCoord *coord,
+                                                     float r_point[3],
+                                                     float r_dPdu[3],
+                                                     float r_dPdv[3])
+{
+  Subdiv *subdiv = subdiv_ccg->subdiv;
+  int ptex_face_index;
+  float u, v;
+  subdiv_ccg_coord_to_ptex_coord(subdiv_ccg, coord, &ptex_face_index, &u, &v);
+  BKE_subdiv_eval_limit_point_and_derivatives(
+      subdiv, ptex_face_index, u, v, r_point, r_dPdu, r_dPdv);
+}
+
+void BKE_subdiv_ccg_get_tangent_matrix(const SubdivCCG *subdiv_ccg,
+                                       const SubdivCCGCoord *coord,
+                                       float mat[3][3],
+                                       float r_point[3])
+{
+  int ptex_face_index;
+  float u, v;
+  float du[3], dv[3];
+
+  const int face_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, coord->grid_index);
+  const SubdivCCGFace *faces = subdiv_ccg->faces;
+  const SubdivCCGFace *face = &faces[face_index];
+  const float corner = coord->grid_index - face->start_grid_index;
+
+  subdiv_ccg_coord_to_ptex_coord(subdiv_ccg, coord, &ptex_face_index, &u, &v);
+
+  BKE_subdiv_ccg_eval_limit_point_and_derivatives(subdiv_ccg, coord, r_point, du, dv);
+  BKE_multires_construct_tangent_matrix(mat, du, dv, corner);
+}
+
 /** \} */
diff --git a/source/blender/blenlib/intern/lockfree_mempool.cc b/source/blender/blenlib/intern/lockfree_mempool.cc
index 3ebc6a90411..055de7b6a6f 100644
--- a/source/blender/blenlib/intern/lockfree_mempool.cc
+++ b/source/blender/blenlib/intern/lockfree_mempool.cc
@@ -202,13 +202,13 @@ extern "C" {
 
 BLI_lfmempool *BLI_lfmempool_create(int esize, int psize)
 {
-  LockFreePool *pool = OBJECT_GUARDED_NEW(LockFreePool, esize, psize);
+  LockFreePool *pool = MEM_new<LockFreePool>(__func__, esize, psize);
   return reinterpret_cast<BLI_lfmempool *>(pool);
 }
 
 void BLI_lfmempool_destroy(BLI_lfmempool *pool)
 {
-  OBJECT_GUARDED_DELETE(cast_pool(pool), LockFreePool);
+  MEM_delete<LockFreePool>(cast_pool(pool));
 }
 
 void *BLI_lfmempool_alloc(BLI_lfmempool *pool)
diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt
index 0f0864c3611..0d65d0b1d74 100644
--- a/source/blender/editors/datafiles/CMakeLists.txt
+++ b/source/blender/editors/datafiles/CMakeLists.txt
@@ -752,6 +752,7 @@ set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
   brush.sculpt.cloth
   brush.sculpt.crease
   brush.sculpt.displacement_eraser
+  brush.sculpt.displacement_heal
   brush.sculpt.displacement_smear
   brush.sculpt.draw
   brush.sculpt.draw_face_sets
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 6e17b74217e..c7ee8c49829 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3986,6 +3986,7 @@ static float brush_strength(const Sculpt *sd,
     case SCULPT_TOOL_LAYER:
     case SCULPT_TOOL_SYMMETRIZE:
       return alpha * flip * pressure * overlap * feather;
+    case SCULPT_TOOL_DISPLACEMENT_HEAL:
     case SCULPT_TOOL_DISPLACEMENT_ERASER:
       return alpha * pressure * overlap * feather;
     case SCULPT_TOOL_FAIRING:
@@ -4122,15 +4123,15 @@ static float brush_strength(const Sculpt *sd,
   }
 }
 
-float SCULPT_brush_strength_factor(SculptSession *ss,
-                                   const Brush *br,
-                                   const float brush_point[3],
-                                   const float len,
-                                   const short vno[3],
-                                   const float fno[3],
-                                   const float mask,
-                                   const SculptVertRef vertex_index,
-                                   const int thread_id)
+ATTR_NO_OPT float SCULPT_brush_strength_factor(SculptSession *ss,
+                                               const Brush *br,
+                                               const float brush_point[3],
+                                               const float len,
+                                               const short vno[3],
+                                               const float fno[3],
+                                               const float mask,
+                                               const SculptVertRef vertex_index,
+                                               const int thread_id)
 {
   StrokeCache *cache = ss->cache;
   const Scene *scene = cache->vc->scene;
@@ -5486,6 +5487,9 @@ void do_brush_action(
       SCULPT_enhance_details_brush(
           sd, ob, nodes, totnode, SCULPT_get_int(ss, enhance_detail_presteps, sd, brush));
       break;
+    case SCULPT_TOOL_DISPLACEMENT_HEAL:
+      SCULPT_do_displacement_heal_brush(sd, ob, nodes, totnode);
+      break;
   }
 
   bool apply_autosmooth = !ELEM(SCULPT_get_tool(ss, brush),
@@ -6052,6 +6056,8 @@ static void SCULPT_run_command(
     case SCULPT_TOOL_ENHANCE_DETAILS:
       SCULPT_enhance_details_brush(
           sd, ob, nodes, totnode, SCULPT_get_int(ss, enhance_detail_presteps, sd, brush));
+    case SCULPT_TOOL_DISPLACEMENT_HEAL:
+      SCULPT_do_displacement_heal_brush(sd, ob, nodes, totnode);
       break;
   }
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_brushes.c b/source/blender/editors/sculpt_paint/sculpt_brushes.c
index 3b7ddcb919a..6092eefb09b 100644
--- a/source/blender/editors/sculpt_paint/sculpt_brushes.c
+++ b/source/blender/editors/sculpt_paint/sculpt_brushes.c
@@ -82,6 +82,7 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_subdiv_ccg.h"
+#include "BKE_subdiv_eval.h"
 #include "BKE_subsurf.h"
 
 #include "DEG_depsgraph.h"
@@ -318,7 +319,6 @@ static void sculpt_project_v3_normal_align(SculptSession *ss,
 
 /************************************** Brushes ******************************/
 
-
 /* -------------------------------------------------------------------- */
 /** \name Sculpt Draw Brush
  * \{ */
@@ -622,7 +622,7 @@ void SCULPT_do_twist_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
   int totbit = 0;
 
   for (int i = 0; i < 3; i++) {
-    if (ss->cache->mirror_symmetry_pass & (1<<i)) {
+    if (ss->cache->mirror_symmetry_pass & (1 << i)) {
       totbit++;
     }
   }
@@ -1205,9 +1205,9 @@ static void calc_clay_surface_reduce(const void *__restrict UNUSED(userdata),
   join->plane_dist[1] = MIN2(csd->plane_dist[1], join->plane_dist[1]);
 }
 
-static void do_clay_brush_task_cb_ex(void *__restrict userdata,
-                                     const int n,
-                                     const TaskParallelTLS *__restrict tls)
+ATTR_NO_OPT static void do_clay_brush_task_cb_ex(void *__restrict userdata,
+                                                 const int n,
+                                                 const TaskParallelTLS *__restrict tls)
 {
   SculptThreadedTaskData *data = userdata;
   SculptSession *ss = data->ob->sculpt;
@@ -1262,7 +1262,7 @@ static void do_clay_brush_task_cb_ex(void *__restrict userdata,
   BKE_pbvh_node_mark_update(data->nodes[n]);
 }
 
-void SCULPT_do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
+ATTR_NO_OPT void SCULPT_do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
 {
   SculptSession *ss = ob->sculpt;
   Brush *brush = BKE_paint_brush(&sd->paint);
@@ -3620,7 +3620,6 @@ void SCULPT_fairing_brush_exec_fairing_for_cache(Sculpt *sd, Object *ob)
 
 /** \} */
 
-
 /* -------------------------------------------------------------------- */
 
 void SCULPT_do_auto_face_set(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
@@ -4235,3 +4234,166 @@ void SCULPT_do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
       break;
   }
 }
+
+BLI_INLINE SculptVertRef grid_xy_to_vertex(int x, int y, int grid_i, int gridsize)
+{
+  return (SculptVertRef){.i = grid_i * gridsize * gridsize + y * gridsize + x};
+}
+
+typedef struct DisplacementHealTaskData {
+  Object *ob;
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list