[Bf-blender-cvs] [58d7be56424] sculpt-dev: Sculpt-dev: add tool slot override to sculpt.brush_stroke

Joseph Eagar noreply at git.blender.org
Thu Nov 4 02:41:14 CET 2021


Commit: 58d7be56424bbb2d59474ca9f57f3cc51034edab
Author: Joseph Eagar
Date:   Wed Nov 3 18:34:33 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rB58d7be56424bbb2d59474ca9f57f3cc51034edab

Sculpt-dev: add tool slot override to sculpt.brush_stroke

* Sculpt.brush_stroke now has a property to override
  the tool slot.
* Note that this is somewhat different from how this
  was typically done in the past.  Instead of physically
  switching slots we instead load the overriding slot's
  brush's channels into ss->cache->tool_override_channels.

Basic idea is based off of {D6515}

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

M	source/blender/blenkernel/intern/brush_engine_presets.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_utils.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h

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

diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index 5882f7d2740..3f12f24f90b 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -1149,6 +1149,8 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
   ADDCH(autofset_spacing);
   ADDCH(autofset_use_spacing);
 
+  ADDCH(deform_target);
+
   switch (tool) {
     case SCULPT_TOOL_CLAY:
       if (set_mappings) {
@@ -1224,7 +1226,6 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
       ADDCH(boundary_offset);
       ADDCH(boundary_deform_type);
       ADDCH(boundary_falloff_type);
-      ADDCH(deform_target);
       break;
     case SCULPT_TOOL_CREASE:
       ADDCH(crease_pinch_factor);
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 527e573e92f..909918806f7 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -765,7 +765,7 @@ void PAINT_OT_image_paint(wmOperatorType *ot)
   /* flags */
   ot->flag = OPTYPE_BLOCKING;
 
-  paint_stroke_operator_properties(ot);
+  paint_stroke_operator_properties(ot, false);
 }
 
 bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index f6951b5b525..289c9ccf27e 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -376,7 +376,7 @@ void paint_get_tex_pixel_col(const struct MTex *mtex,
 void paint_sample_color(
     struct bContext *C, struct ARegion *region, int x, int y, bool texpaint_proj, bool palette);
 
-void paint_stroke_operator_properties(struct wmOperatorType *ot);
+void paint_stroke_operator_properties(struct wmOperatorType *ot, bool mode_skip_save);
 
 void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
 void BRUSH_OT_curve_preset_load(struct wmOperatorType *ot);
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 902de2375f5..bf5c383ceb7 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -210,7 +210,7 @@ void paint_get_tex_pixel_col(const MTex *mtex,
   clamp_v4(rgba, 0.0f, 1.0f);
 }
 
-void paint_stroke_operator_properties(wmOperatorType *ot)
+void paint_stroke_operator_properties(wmOperatorType *ot, bool mode_skip_save)
 {
   static const EnumPropertyItem stroke_mode_items[] = {
       {BRUSH_STROKE_NORMAL, "NORMAL", 0, "Regular", "Apply brush normally"},
@@ -232,12 +232,18 @@ void paint_stroke_operator_properties(wmOperatorType *ot)
   prop = RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
   RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
 
-  RNA_def_enum(ot->srna,
-               "mode",
-               stroke_mode_items,
-               BRUSH_STROKE_NORMAL,
-               "Stroke Mode",
-               "Action taken when a paint stroke is made");
+  prop = RNA_def_enum(ot->srna,
+                      "mode",
+                      stroke_mode_items,
+                      BRUSH_STROKE_NORMAL,
+                      "Stroke Mode",
+                      "Action taken when a paint stroke is made");
+
+  if (mode_skip_save) {
+    /* probably a good idea to enable this for all paint modes, since otherwise
+       keymaps can do weird things if a user forgets to explicitly set this prop - joeedh */
+    RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+  }
 }
 
 /* 3D Paint */
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 7eb8fe365c5..e8c13ec04e1 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -2591,7 +2591,7 @@ void PAINT_OT_weight_paint(wmOperatorType *ot)
   /* flags */
   ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;
 
-  paint_stroke_operator_properties(ot);
+  paint_stroke_operator_properties(ot, false);
 }
 
 /** \} */
@@ -3532,7 +3532,7 @@ void PAINT_OT_vertex_paint(wmOperatorType *ot)
   /* flags */
   ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;
 
-  paint_stroke_operator_properties(ot);
+  paint_stroke_operator_properties(ot, false);
 }
 
 /** \} */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 9d8d12348e2..e7fddcd2eec 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -141,6 +141,16 @@ static void do_symmetrical_brush_actions(
   will be used (taking inheritence into account).
 */
 
+static BrushChannelSet *sculpt_get_brush_channels(const SculptSession *ss, const Brush *br)
+{
+  if (ss->cache && ss->cache->tool_override_channels) {
+    return ss->cache->tool_override_channels;
+  }
+  else {
+    return br->channels;
+  }
+}
+
 float SCULPT_get_float_intern(const SculptSession *ss,
                               const char *idname,
                               const Sculpt *sd,
@@ -152,10 +162,11 @@ float SCULPT_get_float_intern(const SculptSession *ss,
     return BKE_brush_channelset_get_float(ss->cache->channels_final, idname, mapdata);
   }
   else if (br && sd && br->channels && sd->channels) {
-    return BKE_brush_channelset_get_final_float(br->channels, sd->channels, idname, mapdata);
+    return BKE_brush_channelset_get_final_float(
+        sculpt_get_brush_channels(ss, br), sd->channels, idname, mapdata);
   }
   else if (br && br->channels) {
-    return BKE_brush_channelset_get_float(br->channels, idname, mapdata);
+    return BKE_brush_channelset_get_float(sculpt_get_brush_channels(ss, br), idname, mapdata);
   }
   else if (sd && sd->channels) {
     return BKE_brush_channelset_get_float(sd->channels, idname, mapdata);
@@ -177,10 +188,11 @@ int SCULPT_get_int_intern(const SculptSession *ss,
     return BKE_brush_channelset_get_int(ss->cache->channels_final, idname, mapdata);
   }
   else if (br && br->channels && sd && sd->channels) {
-    return BKE_brush_channelset_get_final_int(br->channels, sd->channels, idname, mapdata);
+    return BKE_brush_channelset_get_final_int(
+        sculpt_get_brush_channels(ss, br), sd->channels, idname, mapdata);
   }
   else if (br && br->channels) {
-    return BKE_brush_channelset_get_int(br->channels, idname, mapdata);
+    return BKE_brush_channelset_get_int(sculpt_get_brush_channels(ss, br), idname, mapdata);
   }
   else if (sd && sd->channels) {
     return BKE_brush_channelset_get_int(sd->channels, idname, mapdata);
@@ -201,10 +213,12 @@ int SCULPT_get_vector_intern(
     return BKE_brush_channelset_get_vector(ss->cache->channels_final, idname, out, mapdata);
   }
   else if (br && br->channels && sd && sd->channels) {
-    return BKE_brush_channelset_get_final_vector(br->channels, sd->channels, idname, out, mapdata);
+    return BKE_brush_channelset_get_final_vector(
+        sculpt_get_brush_channels(ss, br), sd->channels, idname, out, mapdata);
   }
   else if (br && br->channels) {
-    return BKE_brush_channelset_get_vector(br->channels, idname, out, mapdata);
+    return BKE_brush_channelset_get_vector(
+        sculpt_get_brush_channels(ss, br), idname, out, mapdata);
   }
   else if (sd && sd->channels) {
     return BKE_brush_channelset_get_vector(sd->channels, idname, out, mapdata);
@@ -226,7 +240,7 @@ BrushChannel *SCULPT_get_final_channel_intern(const SculptSession *ss,
     ch = BKE_brush_channelset_lookup(ss->cache->channels_final, idname);
   }
   else if (br && br->channels && sd && sd->channels) {
-    ch = BKE_brush_channelset_lookup(br->channels, idname);
+    ch = BKE_brush_channelset_lookup(sculpt_get_brush_channels(ss, br), idname);
     BrushChannel *ch2 = BKE_brush_channelset_lookup(sd->channels, idname);
 
     if (ch2 && (!ch || (ch->flag & BRUSH_CHANNEL_INHERIT))) {
@@ -234,7 +248,7 @@ BrushChannel *SCULPT_get_final_channel_intern(const SculptSession *ss,
     }
   }
   else if (br && br->channels) {
-    ch = BKE_brush_channelset_lookup(br->channels, idname);
+    ch = BKE_brush_channelset_lookup(sculpt_get_brush_channels(ss, br), idname);
   }
   else if (sd && sd->channels) {
     ch = BKE_brush_channelset_lookup(sd->channels, idname);
@@ -2983,7 +2997,7 @@ 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) &&
+  return SCULPT_TOOL_HAS_TOPOLOGY_RAKE(SCULPT_get_tool(ss, brush)) &&
          (brush->topology_rake_factor > 0.0f) && (ss->bm != NULL);
 }
 
@@ -2992,10 +3006,10 @@ static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush
  */
 static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush)
 {
-  return ((SCULPT_TOOL_HAS_NORMAL_WEIGHT(brush->sculpt_tool) &&
+  return ((SCULPT_TOOL_HAS_NORMAL_WEIGHT(SCULPT_get_tool(ss, brush)) &&
            (ss->cache->normal_weight > 0.0f)) ||
 
-          ELEM(brush->sculpt_tool,
+          ELEM(SCULPT_get_tool(ss, brush),
                SCULPT_TOOL_BLOB,
                SCULPT_TOOL_CREASE,
                SCULPT_TOOL_DRAW,
@@ -3013,9 +3027,10 @@ static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush
 }
 /** \} */
 
-static bool sculpt_brush_needs_rake_rotation(const Brush *brush)
+static bool sculpt_brush_needs_rake_rotation(const SculptSession *ss, const Brush *brush)
 {
-  return SCULPT_TOOL_HAS_RAKE(brush->sculpt_tool) && (brush->rake_factor != 0.0f);
+  return SCULPT_TOOL_HAS_RAKE(SCULPT_get_tool(ss, brush)) &&
+         (SCULPT_get_float(ss, rake_factor, NULL, brush) != 0.0f);
 }
 
 typedef enum StrokeFlags {
@@ -3139,7 +3154,7 @@ bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *bru
       !(brush->flag & BRUSH_ANCHORED) && !(brush->flag & BRUSH_DRAG_DOT) &&
       (brush->cached_dyntopo.flag & (DYNTOPO_SUBDIVIDE | DYNTOPO_COLLAPSE | DYNTOPO_CLEANUP)) &&
       !(brush->cached_dyntopo.flag

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list