[Bf-blender-cvs] [febfaecd97b] temp_bmesh_multires: * Added new paint API method paint_stroke_apply_subspacing, for various things that need custom spacing (that is coaser than the brush radius), and refactored the existing dyntopo spacing code to use it.

Joseph Eagar noreply at git.blender.org
Sun May 2 23:40:08 CEST 2021


Commit: febfaecd97b421be70913548a0523027395ccc6b
Author: Joseph Eagar
Date:   Sun May 2 14:29:30 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBfebfaecd97b421be70913548a0523027395ccc6b

* Added new paint API method paint_stroke_apply_subspacing, for various
  things that need custom spacing (that is coaser than the brush radius),
  and refactored the existing dyntopo spacing code to use it.

* Added option to topology rake to ignore brush falloff settings
  (it forcibly uses Smooth falloff).

* Smooth and topology rake support custom spacing now.
  + This is especially important for the clay brush, which works
    better at smaller spacings and with a bit of autosmoothing.
    Now you can tell it to override the smooth spacing to be coarser,
    leading to much better performance.

* Topology rake now has a projection setting similar to autosmooth
  which defaults to 1.0 (to preserve current behavior).

The main motivation for this commit was to make topology rake work
better for normal brushes.  This is now possible, however it tends to
make the brush slower and also the settings are a bit fiddly.
We might want to make dedicated brush presets for this.

Btw, the UI for brush settings are becoming a real mess. Help!

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/intern/brush.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_smooth.c
M	source/blender/makesdna/DNA_brush_defaults.h
M	source/blender/makesdna/DNA_brush_enums.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/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 5b2bd5619dc..43df3766548 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -556,20 +556,40 @@ def brush_settings(layout, context, brush, popover=False):
 
         # auto_smooth_factor and use_inverse_smooth_pressure
         if capabilities.has_auto_smooth:
+            box = layout.box().column() #.column() is a bit more compact
+
             UnifiedPaintPanel.prop_unified(
-                layout,
+                box,
                 context,
                 brush,
                 "auto_smooth_factor",
                 pressure_name="use_inverse_smooth_pressure",
                 slider=True,
             )
+
+            box.prop(brush, "use_custom_auto_smooth_spacing", text="Custom Spacing")
+            if brush.use_custom_auto_smooth_spacing:
+               UnifiedPaintPanel.prop_unified(
+                    box,
+                    context,
+                    brush,
+                    "auto_smooth_spacing",
+                    slider=True,
+                    text="Spacing"
+                )                
             UnifiedPaintPanel.prop_unified(
-                layout,
+                box,
                 context,
                 brush,
                 "auto_smooth_projection",
-                slider=True,
+                slider=True
+            )
+            UnifiedPaintPanel.prop_unified(
+                box,
+                context,
+                brush,
+                "auto_smooth_radius_factor",
+                slider=True
             )
         elif brush.sculpt_tool == "SMOOTH":
             UnifiedPaintPanel.prop_unified(
@@ -577,7 +597,7 @@ def brush_settings(layout, context, brush, popover=False):
                 context,
                 brush,
                 "auto_smooth_projection",
-                slider=True,
+                slider=True
             )
         
 
@@ -588,10 +608,21 @@ def brush_settings(layout, context, brush, popover=False):
                 capabilities.has_topology_rake and
                 context.sculpt_object.use_dynamic_topology_sculpting
         ):
-            layout.prop(brush, "topology_rake_factor", slider=True)
-            layout.prop(brush, "use_curvature_rake")
+            box = layout.box().column() #.column() is a bit more compact
+            
+            box.prop(brush, "topology_rake_factor", slider=True)
+            box.prop(brush, "use_custom_topology_rake_spacing", text="Custom Spacing")
+
+            if brush.use_custom_topology_rake_spacing:
+                box.prop(brush, "topology_rake_spacing", text="Spacing")
+            box.prop(brush, "topology_rake_projection");
+
+            box.prop(brush, "topology_rake_radius_factor", slider=True)
+            box.prop(brush, "use_curvature_rake")
+            box.prop(brush, "ignore_falloff_for_topology_rake")
 
-            layout.prop(brush.dyntopo, "disabled", text="Disable Dyntopo");
+        if context.sculpt_object.use_dynamic_topology_sculpting:
+            layout.prop(brush.dyntopo, "disabled", text="Disable Dyntopo")
             
         # normal_weight
         if capabilities.has_normal_weight:
@@ -946,8 +977,8 @@ def brush_settings_advanced(layout, context, brush, popover=False):
         col2 = col.column()
         col2.enabled = brush.use_automasking_concave
 
-        col2.prop(brush, "concave_mask_factor", text="Cavity Factor");
-        col2.prop(brush, "invert_automasking_concavity", text="Invert Cavity Mask");
+        col2.prop(brush, "concave_mask_factor", text="Cavity Factor")
+        col2.prop(brush, "invert_automasking_concavity", text="Invert Cavity Mask")
 
         # face masks automasking
         col.prop(brush, "use_automasking_face_sets", text="Face Sets")
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 8bd1e3a7ed9..bf0c3c52f99 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -251,6 +251,24 @@ static void brush_blend_read_data(BlendDataReader *reader, ID *id)
 {
   Brush *brush = (Brush *)id;
 
+  // detect old file data
+  if (brush->autosmooth_radius_factor == 0.0f) {
+    brush->autosmooth_radius_factor = 1.0f;
+  }
+
+  if (brush->topology_rake_radius_factor == 0.0f) {
+    brush->topology_rake_radius_factor = 1.0f;
+  }
+
+  if (brush->autosmooth_spacing == 0.0f) {
+    brush->autosmooth_spacing = 12;
+  }
+
+  if (brush->topology_rake_spacing == 0.0f) {
+    brush->topology_rake_spacing = 12;
+    brush->topology_rake_projection = 1.0f;
+  }
+
   /* Falloff curve. */
   BLO_read_data_address(reader, &brush->curve);
 
@@ -448,7 +466,12 @@ static void brush_defaults(Brush *brush)
   FROM_DEFAULT(hardness);
   FROM_DEFAULT(autosmooth_factor);
   FROM_DEFAULT(autosmooth_projection);
+  FROM_DEFAULT(autosmooth_radius_factor);
+  FROM_DEFAULT(autosmooth_spacing);
   FROM_DEFAULT(topology_rake_factor);
+  FROM_DEFAULT(topology_rake_radius_factor);
+  FROM_DEFAULT(topology_rake_projection);
+  FROM_DEFAULT(topology_rake_spacing);
   FROM_DEFAULT(crease_pinch_factor);
   FROM_DEFAULT(normal_radius_factor);
   FROM_DEFAULT(wet_paint_radius_factor);
@@ -1653,6 +1676,7 @@ void BKE_brush_debug_print_state(Brush *br)
 
   BR_TEST(autosmooth_factor, f);
   BR_TEST(autosmooth_projection, f);
+  BR_TEST(autosmooth_radius_factor, f);
 
   BR_TEST(topology_rake_factor, f);
 
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index c19679284b8..06f38027d8e 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -51,9 +51,9 @@ typedef struct CoNo {
   float no[3];
 } CoNo;
 
-#include "ED_view3d.h"
 #include "DNA_listBase.h"
 #include "DNA_scene_types.h"
+#include "ED_view3d.h"
 
 /* paint_stroke.c */
 typedef bool (*StrokeGetLocation)(struct bContext *C, float location[3], const float mouse[2]);
@@ -64,7 +64,6 @@ typedef void (*StrokeUpdateStep)(struct bContext *C,
 typedef void (*StrokeRedraw)(const struct bContext *C, struct PaintStroke *stroke, bool final);
 typedef void (*StrokeDone)(const struct bContext *C, struct PaintStroke *stroke);
 
-
 typedef struct PaintSample {
   float mouse[2];
   float pressure;
@@ -96,7 +95,7 @@ typedef struct PaintStroke {
   bool stroke_over_mesh;
   /* space distance covered so far */
   float stroke_distance;
-  float stroke_distance_t; //divided by brush radius
+  float stroke_distance_t;  // divided by brush radius
 
   /* Set whether any stroke step has yet occurred
    * e.g. in sculpt mode, stroke doesn't start until cursor
@@ -170,6 +169,19 @@ bool paint_poll(struct bContext *C);
 void paint_cursor_start(struct Paint *p, bool (*poll)(struct bContext *C));
 void paint_cursor_delete_textures(void);
 
+/**
+* used by various actions that have their own spacing that
+* is coarser then the brush spacing. e.g. sculpt dyntopo.
+*
+* \param state: pointer to a float used for internal state, should be initialized to zero at start of stroke
+* \return false if the action should be skipped.
+*
+*/
+bool paint_stroke_apply_subspacing(struct PaintStroke *stroke,
+                                   const float spacing,
+                                   const enum ePaintMode mode,
+                                   float *state);
+
 /* paint_vertex.c */
 bool weight_paint_poll(struct bContext *C);
 bool weight_paint_poll_ignore_tool(bContext *C);
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index ff4bbfe021f..bb9ebc37117 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -217,6 +217,26 @@ static bool paint_tool_require_inbetween_mouse_events(Brush *brush, ePaintMode m
   return true;
 }
 
+bool paint_stroke_apply_subspacing(struct PaintStroke *stroke,
+                                   const float spacing,
+                                   const enum ePaintMode mode,
+                                   float *state)
+{
+  if (!paint_space_stroke_enabled(stroke->brush, mode)) {
+    return true;
+  }
+
+  const float t = stroke->stroke_distance_t;
+
+  if (t != 0.0f && t < *state + spacing) {
+    return false;
+  }
+  else {
+    *state = t;
+    return true;
+  }
+}
+
 /* Initialize the stroke cache variants from operator properties */
 static bool paint_brush_update(bContext *C,
                                Brush *brush,
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 1f561419e07..36f09b35499 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -293,7 +293,7 @@ void SCULPT_vertex_persistent_normal_get(SculptSession *ss,
       BMVert *v = (BMVert *)index.i;
       float(*no2)[3] = BM_ELEM_CD_GET_VOID_P(v, cd_pers_no);
 
-      copy_v3_v3(no, (float*)no2);
+      copy_v3_v3(no, (float *)no2);
       return;
     }
 
@@ -1605,7 +1605,7 @@ static bool sculpt_tool_is_proxy_used(const char sculpt_tool)
 static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush *brush)
 {
   return SCULPT_TOOL_HAS_TOPOLOGY_RAKE(brush->sculpt_tool) &&
-         (brush->topology_rake_factor > 0.0f) && (ss->bm != NULL);
+            (brush->topology_rake_factor > 0.0f) && (ss->bm != NULL);
 }
 
 /**
@@ -3375,15 +3375,12 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
 
     if (use_curvature) {
       SCULPT_curvature_dir_get(ss, vd.vertex, direction2, false);
-      // SculptCurvatureData cdata;
-      // SCULPT_calc_principle_curvatures(ss, vd.vertex, &cdata);
-      // copy_v3_v3(direction2, cdata.principle[0]);
     }
     else {
       copy_v3_v3(direction2, direction);
     }
 
-    SCULPT_bmesh_four_neighbor_average(avg, direction2, vd.bm_vert);
+    SCULPT_bmesh_four_neighbor_average(avg, direction2, vd.bm_vert, data->rake_projection);
 
     sub_v3_v3v3(val, avg, vd.co);
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list