[Bf-blender-cvs] [7293c2b5e5d] sculpt-dev: Sculpt: enable dyntopo on paint brushes

Joseph Eagar noreply at git.blender.org
Mon Oct 11 22:29:46 CEST 2021


Commit: 7293c2b5e5d9db289d2af8cd2680a267682ac5cf
Author: Joseph Eagar
Date:   Mon Oct 11 13:27:47 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rB7293c2b5e5d9db289d2af8cd2680a267682ac5cf

Sculpt: enable dyntopo on paint brushes

* Paint brushes will now support
  dyntopo if "dyntopo disabled"
  (the one in their brush settings,
   not the global setting in the
   "Dynamic Topology" panel) is unchecked.
* Fixed dyntopo undo not properly handling
  pushing more then one undo type.

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

M	source/blender/blenkernel/BKE_brush_engine.h
M	source/blender/blenkernel/intern/brush_engine.c
M	source/blender/blenkernel/intern/brush_engine_presets.c
M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/makesdna/DNA_brush_enums.h

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

diff --git a/source/blender/blenkernel/BKE_brush_engine.h b/source/blender/blenkernel/BKE_brush_engine.h
index ea539b27c23..3eeac12863d 100644
--- a/source/blender/blenkernel/BKE_brush_engine.h
+++ b/source/blender/blenkernel/BKE_brush_engine.h
@@ -364,6 +364,7 @@ void BKE_brush_channelset_apply_mapping(BrushChannelSet *chset, BrushMappingData
 void BKE_brush_check_toolsettings(struct Sculpt *sd);
 void BKE_brush_channelset_ui_init(struct Brush *brush, int tool);
 void BKE_brush_channelset_check_radius(BrushChannelSet *chset);
+void BKE_builtin_apply_hard_edge_mode(BrushChannelSet *chset, bool do_apply);
 
 const char *BKE_brush_channel_category_get(BrushChannel *ch);
 void BKE_brush_channel_category_set(BrushChannel *ch, const char *str);
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index ec0b6f305f2..f2fa8ea47ec 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -1450,6 +1450,31 @@ void BKE_brush_commandset_inherit_all_mappings(BrushChannelSet *chset)
   }
 }
 
+ATTR_NO_OPT static void commandlist_add_dyntopo(BrushChannelSet *chset,
+                                                BrushCommandList *cl,
+                                                Brush *brush,
+                                                int tool,
+                                                bool hard_edge_mode,
+                                                float radius_base)
+{
+
+  if (!BKE_brush_channelset_get_int(chset, "dyntopo_disabled", NULL)) {
+    BrushCommand *cmd = BKE_brush_command_init(BKE_brush_commandlist_add(cl, chset, true),
+                                               SCULPT_TOOL_DYNTOPO);
+    BKE_builtin_apply_hard_edge_mode(cmd->params, hard_edge_mode);
+
+    float spacing = BKE_brush_channelset_get_float(chset, "dyntopo_spacing", NULL);
+    float radius2 = BKE_brush_channelset_get_float(chset, "dyntopo_radius_scale", NULL);
+
+    radius2 *= radius_base;
+
+    int_set_uninherit(cmd->params, use_ctrl_invert, false);
+    float_set_uninherit(cmd->params, spacing, spacing);
+    float_set_uninherit(cmd->params, radius, radius2);
+
+    BKE_brush_commandset_inherit_all_mappings(cmd->params);
+  }
+}
 static void bke_builtin_commandlist_create_paint(Brush *brush,
                                                  BrushChannelSet *chset,
                                                  BrushCommandList *cl,
@@ -1460,6 +1485,7 @@ static void bke_builtin_commandlist_create_paint(Brush *brush,
 
   cmd = BKE_brush_commandlist_add(cl, chset, true);
   BKE_brush_command_init(cmd, tool);
+  BKE_brush_commandset_inherit_all_mappings(cmd->params);
 
   float radius = BRUSHSET_GET_FLOAT(chset, radius, NULL);
 
@@ -1496,6 +1522,8 @@ static void bke_builtin_commandlist_create_paint(Brush *brush,
     float_set_uninherit(cmd->params, radius, radius * autosmooth_scale);
     float_set_uninherit(cmd->params, projection, autosmooth_projection);
     float_set_uninherit(cmd->params, spacing, autosmooth_spacing);
+
+    BKE_brush_commandset_inherit_all_mappings(cmd->params);
   }
 
   float vcol_boundary = BKE_brush_channelset_get_float(chset, "vcol_boundary_factor", NULL);
@@ -1508,11 +1536,15 @@ static void bke_builtin_commandlist_create_paint(Brush *brush,
     float_set_uninherit(cmd->params, radius, radius * GETF("vcol_boundary_radius_scale"));
     float_set_uninherit(cmd->params, spacing, GETF("vcol_boundary_spacing"));
     float_set_uninherit(cmd->params, strength, vcol_boundary);
+
+    BKE_brush_commandset_inherit_all_mappings(cmd->params);
   }
 
 #undef GETF
 
-  BKE_brush_commandset_inherit_all_mappings(cmd->params);
+  bool hard_edge_mode = BRUSHSET_GET_INT(chset, hard_edge_mode, NULL);
+  commandlist_add_dyntopo(chset, cl, brush, tool, hard_edge_mode, radius);
+
   // float
 }
 
@@ -1567,6 +1599,7 @@ void BKE_builtin_commandlist_create(Brush *brush,
   cmd = BKE_brush_commandlist_add(cl, chset, true);
   BKE_brush_command_init(cmd, tool);
   BKE_builtin_apply_hard_edge_mode(cmd->params, hard_edge_mode);
+  BKE_brush_commandset_inherit_all_mappings(cmd->params);
 
   float radius = BKE_brush_channelset_get_float(chset, "radius", NULL);
 
@@ -1603,6 +1636,7 @@ void BKE_builtin_commandlist_create(Brush *brush,
   if (!no_autosmooth && autosmooth > 0.0f) {
     cmd = BKE_brush_command_init(BKE_brush_commandlist_add(cl, chset, true), SCULPT_TOOL_SMOOTH);
     BKE_builtin_apply_hard_edge_mode(cmd->params, hard_edge_mode);
+    BKE_brush_commandset_inherit_all_mappings(cmd->params);
 
     BrushChannel *ch = BRUSHSET_ENSURE_BUILTIN(cmd->params, falloff_curve);
     BrushChannel *ch2 = BRUSHSET_LOOKUP(chset, autosmooth_falloff_curve);
@@ -1667,25 +1701,12 @@ void BKE_builtin_commandlist_create(Brush *brush,
     float_set_uninherit(cmd->params, radius, radius * topology_rake_scale);
     float_set_uninherit(cmd->params, projection, topology_rake_projection);
     float_set_uninherit(cmd->params, spacing, topology_rake_spacing);
-  }
-
-  /* build dyntopo command */
-
-  if (!BKE_brush_channelset_get_int(chset, "dyntopo_disabled", NULL)) {
-    cmd = BKE_brush_command_init(BKE_brush_commandlist_add(cl, chset, true), SCULPT_TOOL_DYNTOPO);
-    BKE_builtin_apply_hard_edge_mode(cmd->params, hard_edge_mode);
 
-    float spacing = BKE_brush_channelset_get_float(chset, "dyntopo_spacing", NULL);
-    float radius2 = BKE_brush_channelset_get_float(chset, "dyntopo_radius_scale", NULL);
-
-    radius2 *= radius;
-
-    int_set_uninherit(cmd->params, use_ctrl_invert, false);
-    float_set_uninherit(cmd->params, spacing, spacing);
-    float_set_uninherit(cmd->params, radius, radius2);
+    BKE_brush_commandset_inherit_all_mappings(cmd->params);
   }
 
-  BKE_brush_commandset_inherit_all_mappings(cmd->params);
+  /* build dyntopo command */
+  commandlist_add_dyntopo(chset, cl, brush, tool, hard_edge_mode, radius);
 }
 
 void BKE_brush_channelset_read_lib(BlendLibReader *reader, ID *id, BrushChannelSet *chset)
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index 780cdc84489..cc7571fa294 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -1461,6 +1461,9 @@ void BKE_brush_channelset_ui_init(Brush *brush, int tool)
       break;
     case SCULPT_TOOL_PAINT:
       SHOWWRK(color);
+      SHOWWRK(dyntopo_disabled);
+      SHOWCTX(dyntopo_disabled);
+
       SHOWWRK(secondary_color);
       SHOWWRK(wet_mix);
       SHOWWRK(wet_persistence);
@@ -1614,6 +1617,7 @@ void BKE_brush_builtin_create(Brush *brush, int tool)
       GETCH(slide_deform_type)->ivalue = BRUSH_SLIDE_DEFORM_DRAG;
       break;
     case SCULPT_TOOL_PAINT:
+      BRUSHSET_SET_BOOL(chset, dyntopo_disabled, true);
       BRUSHSET_SET_FLOAT(chset, hardness, 0.4f);
       BRUSHSET_SET_FLOAT(chset, spacing, 10.0f);
       BRUSHSET_SET_FLOAT(chset, strength, 0.6f);
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 939a9cb26af..8c3166e5056 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -1842,6 +1842,11 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
       if (brush->channels && brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
         BKE_brush_channelset_ui_init(brush, brush->sculpt_tool);
       }
+      else if (brush->channels &&
+               ELEM(brush->sculpt_plane, SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR)) {
+        BKE_brush_channelset_ui_init(brush, brush->sculpt_tool);
+        BRUSHSET_SET_BOOL(brush->channels, dyntopo_disabled, true);
+      }
     }
   }
   /**
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 86ad71b612f..a034c9aeca7 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -930,8 +930,11 @@ typedef struct SculptUndoNode {
   /* Sculpt Face Sets */
   int *face_sets;
 
-  bool *nodemap;
+  // dyntopo stuff
+
+  int *nodemap;
   int nodemap_size;
+  int typemask;
 
   size_t undo_size;
   // int gen, lasthash;
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.c b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
index 97ee7ba3552..3cc8ef5a77c 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_color.c
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
@@ -121,13 +121,13 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata,
   const float bstrength = fabsf(ss->cache->bstrength);
 
   PBVHVertexIter vd;
-  PBVHColorBufferNode *color_buffer;
+  // PBVHColorBufferNode *color_buffer;
 
   SculptOrigVertData orig_data;
   SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n], SCULPT_UNDO_COLOR);
   orig_data.datatype = SCULPT_UNDO_COLOR;
 
-  color_buffer = BKE_pbvh_node_color_buffer_get(data->nodes[n]);
+  // color_buffer = BKE_pbvh_node_color_buffer_get(data->nodes[n]);
 
   SculptBrushTest test;
   SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
@@ -187,16 +187,19 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata,
     float wet_mix_color[4];
     float buffer_color[4];
 
+    MSculptVert *mv = SCULPT_vertex_get_mdyntopo(ss, vd.vertex);
+    float *color_buffer = mv->origcolor;
+
     mul_v4_v4fl(paint_color, brush_color, fade * ss->cache->paint_brush.flow);
     mul_v4_v4fl(wet_mix_color, data->wet_mix_sampled_color, fade * ss->cache->paint_brush.flow);
 
     /* Interpolate with the wet_mix color for wet paint mixing. */
     blend_color_interpolate_float(
         paint_color, paint_color, wet_mix_color, ss->cache->paint_brush.wet_mix);
-    blend_color_mix_float(color_buffer->color[vd.i], color_buffer->color[vd.i], paint_color);
+    blend_color_mix_float(color_buffer, color_buffer, paint_color);
 
     /* Final mix over the original color using brush alpha. */
-    mul_v4_v4fl(buffer_color, color_buffer->color[vd.i], alpha);
+    mul_v4_v4fl(buffer_c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list