[Bf-blender-cvs] [186bd1759f0] master: Pose brush: Smooth Iterations Brush Property

Pablo Dobarro noreply at git.blender.org
Thu Nov 21 18:38:33 CET 2019


Commit: 186bd1759f05c71c5c44391a5925b0f43cbd3383
Author: Pablo Dobarro
Date:   Sun Nov 17 01:09:08 2019 +0100
Branches: master
https://developer.blender.org/rB186bd1759f05c71c5c44391a5925b0f43cbd3383

Pose brush: Smooth Iterations Brush Property

The smooth iterations of the pose factor were hardcoded to 4. This works fine in most situations when you are posing a low poly mesh, which is the main use case of this tool. I added the smooth iterations as a brush property in case you need to pose a high poly mesh directly without producing artifacts.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D6157

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/makesdna/DNA_brush_defaults.h
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 63e5aa53077..2f260b59c4f 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -426,6 +426,8 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
             elif brush.sculpt_tool == 'POSE':
                 row = col.row()
                 row.prop(brush, "pose_offset")
+                row = col.row()
+                row.prop(brush, "pose_smooth_iterations")
             elif brush.sculpt_tool == 'GRAB':
                 col.separator()
                 row = col.row()
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 794876ec444..15a9b0b9c6a 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -981,6 +981,7 @@ void BKE_brush_sculpt_reset(Brush *br)
       br->flag &= ~BRUSH_SPACE_ATTEN;
       break;
     case SCULPT_TOOL_POSE:
+      br->pose_smooth_iterations = 4;
       br->flag &= ~BRUSH_ALPHA_PRESSURE;
       br->flag &= ~BRUSH_SPACE;
       br->flag &= ~BRUSH_SPACE_ATTEN;
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 488cf6b0213..33a0da7457f 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -3934,7 +3934,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 
   {
     /* Versioning code until next subversion bump goes here. */
-
     for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
       for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
         sa->flag &= ~AREA_FLAG_UNUSED_6;
@@ -3972,5 +3971,12 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
         br->dash_samples = 20;
       }
     }
+
+    /* Pose brush smooth iterations */
+    if (!DNA_struct_elem_find(fd->filesdna, "Brush", "float", "pose_smooth_itereations")) {
+      for (Brush *br = bmain->brushes.first; br; br = br->id.next) {
+        br->pose_smooth_iterations = 4;
+      }
+    }
   }
 }
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 6cda6ccac06..b7fb49d357f 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3940,7 +3940,7 @@ static void sculpt_pose_brush_init(
   };
 
   /* Smooth the pose brush factor for cleaner deformation */
-  for (int i = 0; i < 4; i++) {
+  for (int i = 0; i < br->pose_smooth_iterations; i++) {
     PBVHParallelSettings settings;
     BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode);
     BKE_pbvh_parallel_range(0, totnode, &data, pose_brush_init_task_cb_ex, &settings);
@@ -5705,7 +5705,12 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
     BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
   }
   else if (brush->sculpt_tool == SCULPT_TOOL_POSE) {
-    float final_radius = ss->cache->radius * (1 + brush->pose_offset);
+    /* After smoothing the pose factor an arbitrary number of times, the pose factor values can
+     * expand to nodes that are not inside the original radius of the brush. Using a slightly
+     * bigger radius should prevent those artifacts. */
+    /* We can optimize this further by removing the nodes that have all 0 values in the pose factor
+     * after calculating it. */
+    float final_radius = ss->cache->radius * 1.5f * (1.0f + brush->pose_offset);
     SculptSearchSphereData data = {
         .ss = ss,
         .sd = sd,
diff --git a/source/blender/makesdna/DNA_brush_defaults.h b/source/blender/makesdna/DNA_brush_defaults.h
index ff1f8c9a1c0..9d3689ce4ee 100644
--- a/source/blender/makesdna/DNA_brush_defaults.h
+++ b/source/blender/makesdna/DNA_brush_defaults.h
@@ -95,6 +95,7 @@
  \
     /* sculpting defaults to the draw tool for new brushes */ \
     .sculpt_tool = SCULPT_TOOL_DRAW, \
+    .pose_smooth_iterations = 4, \
  \
     /* A kernel radius of 1 has almost no effect (T63233). */ \
     .blur_kernel_radius = 2, \
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index c55ab81a733..a7e15ac9547 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -334,6 +334,9 @@ typedef struct Brush {
 
   /* pose */
   float pose_offset;
+  int pose_smooth_iterations;
+
+  char _pad2[4];
 
   /* multiplane scrape */
   float multiplane_scrape_angle;
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 86b1ed92349..321f3815691 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1887,6 +1887,15 @@ static void rna_def_brush(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Plane Angle", "Angle between the planes of the crease");
   RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+  prop = RNA_def_property(srna, "pose_smooth_iterations", PROP_INT, PROP_UNSIGNED);
+  RNA_def_property_int_sdna(prop, NULL, "pose_smooth_iterations");
+  RNA_def_property_range(prop, 0, 100);
+  RNA_def_property_ui_text(
+      prop,
+      "Smooth Iterations",
+      "Smooth iterations applied after calculating the pose factor of each vertex");
+  RNA_def_property_update(prop, 0, "rna_Brush_update");
+
   prop = RNA_def_property(srna, "auto_smooth_factor", PROP_FLOAT, PROP_FACTOR);
   RNA_def_property_float_sdna(prop, NULL, "autosmooth_factor");
   RNA_def_property_float_default(prop, 0);



More information about the Bf-blender-cvs mailing list