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.
This commit is contained in:
Joseph Eagar 2021-11-26 21:10:14 -08:00
parent a662f81822
commit 1e4b49d3c1
9 changed files with 58 additions and 48 deletions

View File

@ -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

View File

@ -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. "

View File

@ -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);
}

View File

@ -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_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
PBVHNode **nodes;
int totnode;

View File

@ -2200,7 +2200,7 @@ static void do_crease_brush_task_cb_ex(void *__restrict userdata,
void SCULPT_do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
float offset[3];
float bstrength = ss->cache->bstrength;
float flippedbstrength, crease_correction;
@ -2440,7 +2440,7 @@ static void do_grab_brush_task_cb_ex(void *__restrict userdata,
void SCULPT_do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
float grab_delta[3];
copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
@ -3905,7 +3905,7 @@ void SCULPT_bmesh_topology_rake(Sculpt *sd,
bool needs_origco)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
const float strength = bstrength; // clamp_f(bstrength, 0.0f, 1.0f);
Brush local_brush;
@ -4143,7 +4143,7 @@ void SCULPT_do_auto_face_set(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno
#endif
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
float directions[3][3];

View File

@ -2364,7 +2364,7 @@ static void sculpt_cloth_ensure_constraints_in_simulation_area(Sculpt *sd,
void SCULPT_do_cloth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
SCULPT_vertex_random_access_ensure(ss);

View File

@ -1710,7 +1710,7 @@ static void sculpt_uv_brush_cb(void *__restrict userdata,
void SCULPT_uv_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
float offset[3];
if (!ss->bm || BKE_pbvh_type(ss->pbvh) != PBVH_BMESH) {

View File

@ -301,7 +301,7 @@ static void sample_wet_paint_reduce(const void *__restrict UNUSED(userdata),
void SCULPT_do_paint_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
if (!SCULPT_has_colors(ss)) {
return;
@ -563,7 +563,7 @@ static void do_smear_store_prev_colors_task_cb_exec(void *__restrict userdata,
void SCULPT_do_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
{
SculptSession *ss = ob->sculpt;
Brush *brush = ss->cache ? ss->cache->brush : BKE_paint_brush(&sd->paint);
Brush *brush = BKE_paint_brush(&sd->paint);
if (!SCULPT_has_colors(ss)) {
return;

View File

@ -868,6 +868,7 @@ typedef struct PaintToolSlot {
/* Paint Tool Base */
typedef struct Paint {
struct Brush *brush;
struct Brush *brush_eval;
/* Each tool has its own active brush,
* The currently active tool is defined by the current 'brush'. */