[Bf-blender-cvs] [1e4b49d3c1d] sculpt-dev: Sculpt-dev: Add brush_eval field to Paint

Joseph Eagar noreply at git.blender.org
Sat Nov 27 06:13:07 CET 2021


Commit: 1e4b49d3c1d1667e5bb643f5b10caaeae7bd4724
Author: Joseph Eagar
Date:   Fri Nov 26 21:10:14 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rB1e4b49d3c1d1667e5bb643f5b10caaeae7bd4724

Sculpt-dev: Add brush_eval field to Paint

* Paint now has a brush_eval field which
  is used in leu of ->brush if non-null.
* This lets us get rid of all the annoying:
  `brush = ss->cache ? ss->cache->brush : BKE_paint_brush`
  code.  Now it's just BKE_paint_brush.
* Used by SCULPT_run_command.
* Also fixed nasty scene spacing bug.

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/intern/brush_channel_define.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_brushes.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/makesdna/DNA_scene_types.h

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 355b24a6acc..9bc7195b16b 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -389,6 +389,7 @@ class UnifiedPaintPanel:
                 path = "sculpt.channels[\"%s\"]" % prop_name
 
         if need_path:
+            path = "tool_settings." + path
             return (ch, path)
         else:
             return ch
@@ -767,7 +768,7 @@ class UnifiedPaintPanel:
         prop_owner = ups if ups.use_unified_color else brush
 
         if context.mode == "SCULPT":
-            ch, path = UnifiedPaintPanel.get_channel(context, brush, prop_name, need_path=True)
+            ch = UnifiedPaintPanel.get_channel(context, brush, prop_name)
 
             if ch is not None:
                 print("FOUND CH", ch.idname)
@@ -1127,13 +1128,10 @@ class FalloffPanel(BrushPanel):
         mode = self.get_brush_mode(context)
         brush = settings.brush
 
-        if 0 and mode == "SCULPT" and "falloff_curve" in brush.channels:
+        if mode == "SCULPT" and "falloff_curve" in brush.channels:
             layout.label(text="Falloff")
             ch = UnifiedPaintPanel.get_channel(context, brush, "falloff_curve")
             layout.prop(ch.curve, "curve_preset", text="")
-
-            #UnifiedPaintPanel.channel_unified(layout, context, brush, "falloff_curve", use_negative_slope=True, header=True, text="")
-            return
         else:
             layout.label(text="Falloff")
             layout.prop(brush, "curve_preset", text="")
@@ -1152,8 +1150,8 @@ class FalloffPanel(BrushPanel):
             path += ".curve.curve"
             template_curve(layout, ch.curve, "curve", path, True)
 
-            #UnifiedPaintPanel.channel_unified(layout, context, brush, "falloff_shape", expand=True)
-            layout.prop(brush, "falloff_shape", expand=True)
+            UnifiedPaintPanel.channel_unified(layout, context, brush, "falloff_shape", expand=True)
+            #layout.prop(brush, "falloff_shape", expand=True)
 
             return
 
diff --git a/source/blender/blenkernel/intern/brush_channel_define.h b/source/blender/blenkernel/intern/brush_channel_define.h
index 1524e0a679e..1be82fa8336 100644
--- a/source/blender/blenkernel/intern/brush_channel_define.h
+++ b/source/blender/blenkernel/intern/brush_channel_define.h
@@ -200,7 +200,15 @@ MAKE_ENUM(blend,"Blending Mode","Brush blending mode",IMB_BLEND_MIX,{\
   })
 
   MAKE_FLOAT_EX(spacing,"Spacing","",10.0f,0.25f,1000.0f,1.0f,200.0f,false)
-  MAKE_BOOL(use_scene_spacing, "Scene Spacing", "Space brush in 3d space", false)
+  MAKE_ENUM(use_scene_spacing, "Spacing Mode", "Calculate the brush spacing using view or scene distance", 0, {\
+      {0, "VIEW", "NONE", "View", "Calculate brush spacing relative to the view"},
+      {1,
+       "SCENE",
+       "NONE",
+       "Scene",
+       "Calculate brush spacing relative to the scene using the stroke location"},
+      {-1}
+  })
 
   MAKE_FLOAT_EX(topology_rake,"Topology Rake","Automatically align edges to the brush direction to "
     "generate cleaner topology and define sharp features. "
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index b06d302ba1d..ce879af228a 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -614,7 +614,7 @@ ePaintMode BKE_paintmode_get_from_tool(const struct bToolRef *tref)
 
 Brush *BKE_paint_brush(Paint *p)
 {
-  return p ? p->brush : NULL;
+  return p ? (p->brush_eval ? p->brush_eval : p->brush) : NULL;
 }
 
 void BKE_paint_brush_set(Paint *p, Brush *br)
@@ -2084,7 +2084,7 @@ void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
     BKE_mesh_update_customdata_pointers(orig_me, true);
     DEG_id_tag_update(&orig_me->id, ID_RECALC_GEOMETRY_ALL_MODES);
   }
-  
+
   if (cl) {
     BKE_id_attributes_active_color_set(&orig_me->id, cl);
   }
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index c5e9f839136..1c9071a04e5 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3197,7 +3197,7 @@ static void paint_mesh_restore_co_task_cb(void *__restrict userdata,
 static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
 {
   SculptSession *ss = ob->sculpt;
-  Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
+  Brush *brush = BKE_paint_brush(&sd->paint);
 
   PBVHNode **nodes;
   int totnode;
@@ -3826,7 +3826,7 @@ void SCULPT_calc_area_center(
     Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_co[3])
 {
   SculptSession *ss = ob->sculpt;
-  const Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
+  const Brush *brush = BKE_paint_brush(&sd->paint);
   const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
   int n;
 
@@ -3874,9 +3874,7 @@ void SCULPT_calc_area_center(
 void SCULPT_calc_area_normal(
     Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
 {
-  SculptSession *ss = ob->sculpt;
-
-  const Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
+  const Brush *brush = BKE_paint_brush(&sd->paint);
   SCULPT_pbvh_calc_area_normal(brush, ob, nodes, totnode, true, r_area_no);
 }
 
@@ -3928,7 +3926,7 @@ void SCULPT_calc_area_normal_and_center(
     Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
 {
   SculptSession *ss = ob->sculpt;
-  const Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
+  const Brush *brush = BKE_paint_brush(&sd->paint);
   const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
   int n;
 
@@ -4422,7 +4420,7 @@ static void calc_sculpt_normal(
     Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
 {
   const SculptSession *ss = ob->sculpt;
-  const Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
+  const Brush *brush = BKE_paint_brush(&sd->paint);
 
   switch (brush->sculpt_plane) {
     case SCULPT_DISP_DIR_VIEW:
@@ -5812,8 +5810,15 @@ static void SCULPT_run_command(
   BrushRunCommandData *data = userdata;
   BrushCommand *cmd = data->cmd;
 
-  float radius = BRUSHSET_GET_FLOAT(cmd->params_mapped, radius, NULL);
-  radius = paint_calc_object_space_radius(ss->cache->vc, ss->cache->true_location, radius);
+  float radius;
+
+  if (BRUSHSET_GET_INT(cmd->params_mapped, radius_unit, NULL)) {
+    radius = BRUSHSET_GET_FLOAT(cmd->params_mapped, unprojected_radius, NULL);
+  }
+  else {
+    radius = BRUSHSET_GET_FLOAT(cmd->params_mapped, radius, NULL);
+    radius = paint_calc_object_space_radius(ss->cache->vc, ss->cache->true_location, radius);
+  }
 
   ss->cache->radius = radius;
   ss->cache->radius_squared = radius * radius;
@@ -5853,9 +5858,11 @@ static void SCULPT_run_command(
 
   brush2->sculpt_tool = cmd->tool;
   BrushChannelSet *channels_final = ss->cache->channels_final;
-  ss->cache->channels_final = cmd->params_mapped;
+
+  ss->cache->channels_final = brush2->channels = cmd->params_mapped;
 
   ss->cache->brush = brush2;
+  sd->paint.brush_eval = brush2;
 
   ups->alpha = BRUSHSET_GET_FLOAT(cmd->params_final, strength, NULL);
 
@@ -6123,22 +6130,6 @@ static void SCULPT_run_commandlist(
     // Load parameters into brush2 for compatibility with old code
     BKE_brush_channelset_compat_load(cmd->params_final, &brush2, false);
 
-    ss->cache->brush = &brush2;
-
-    if (cmd->tool == SCULPT_TOOL_SMOOTH) {
-      ss->cache->bstrength = brush2.alpha;
-
-      if (ss->cache->invert && BRUSHSET_GET_INT(cmd->params_final, use_ctrl_invert, NULL)) {
-        ss->cache->bstrength = -ss->cache->bstrength;
-      }
-    }
-    else {
-      ss->cache->bstrength = brush_strength(
-          sd, ss->cache, calc_symmetry_feather(sd, ss->cache), ups);
-    }
-
-    brush2.alpha = fabs(ss->cache->bstrength);
-
     /* With these options enabled not all required nodes are inside the original brush radius, so
      * the brush can produce artifacts in some situations. */
     if (cmd->tool == SCULPT_TOOL_DRAW && BKE_brush_channelset_get_int(cmd->params_final,
@@ -6158,9 +6149,15 @@ static void SCULPT_run_commandlist(
       has_dyntopo = false;
     }
 
-    float radius = BRUSHSET_GET_FLOAT(
-        ss->cache->channels_final, radius, &ss->cache->input_mapping);
-    radius = paint_calc_object_space_radius(ss->cache->vc, ss->cache->true_location, radius);
+    float radius;
+
+    if (BRUSHSET_GET_INT(cmd->params_final, radius_unit, NULL)) {
+      radius = BRUSHSET_GET_FLOAT(cmd->params_final, unprojected_radius, &ss->cache->input_mapping);
+    }
+    else {
+      radius = BRUSHSET_GET_FLOAT(cmd->params_final, radius, &ss->cache->input_mapping);
+      radius = paint_calc_object_space_radius(ss->cache->vc, ss->cache->true_location, radius);
+    };
 
     radius_max = max_ff(radius_max, radius);
     ss->cache->brush = brush;
@@ -6170,10 +6167,14 @@ static void SCULPT_run_commandlist(
   PBVHType type = BKE_pbvh_type(ss->pbvh);
   if (ELEM(SCULPT_get_tool(ss, brush), SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR) &&
       !ELEM(type, PBVH_BMESH, PBVH_FACES)) {
+    ss->cache->brush = oldbrush;
+    sd->paint.brush_eval = NULL;
     return;
   }
 
   if (SCULPT_get_tool(ss, brush) == SCULPT_TOOL_ARRAY && !ELEM(type, PBVH_FACES, PBVH_BMESH)) {
+    ss->cache->brush = oldbrush;
+    sd->paint.brush_eval = NULL;
     return;
   }
 
@@ -6243,7 +6244,9 @@ static void SCULPT_run_commandlist(
       SCULPT_cloth_brush_do_simulation_step(sd, ob, ss->cache->cloth_sim, nodes, totnode);
     }
   }
+
   ss->cache->brush = oldbrush;
+  sd->paint.brush_eval = NULL;
   ss->cache->radius = start_radius;
   ss->cache->radius_squared = start_radius * start_radius;
 }
@@ -6328,7 +6331,7 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata,
 void sculpt_combine_proxies(Sculpt *sd, Object *ob)
 {
   SculptSession *ss = ob->sculpt;
-  Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list