Fix #111490: paint radius set to 1 (shift-smoothing but brush missing) #111516

Merged
Philipp Oeser merged 5 commits from lichtwerk/blender:111490 into main 2023-08-29 13:44:42 +02:00
2 changed files with 61 additions and 36 deletions
Showing only changes of commit 98823b6c16 - Show all commits

View File

@ -441,7 +441,14 @@ void smooth_brush_toggle_off(const bContext *C, Paint *paint, StrokeCache *cache
/* The current brush should match with what we have stored in the cache. */
BLI_assert(brush == cache->brush);
/* Try to switch back to the saved/previous brush. */
/* Note: used for both vertexpaint and weightpaint, VPAINT_TOOL_BLUR & WPAINT_TOOL_BLUR are the
* same, see comments for eBrushVertexPaintTool & eBrushWeightPaintTool. */
/* If the smooth (blur) brush is missing, brush was not switched/affected in
* smooth_brush_toggle_on(). */
if (!BKE_paint_toolslots_brush_get(paint, WPAINT_TOOL_BLUR)) {
return;
}
BKE_brush_size_set(scene, brush, cache->saved_smooth_size);
brush = (Brush *)BKE_libblock_find_name(bmain, ID_BR, cache->saved_active_brush_name);
if (brush) {
@ -590,19 +597,27 @@ void last_stroke_update(Scene *scene, const float location[3])
void smooth_brush_toggle_on(const bContext *C, Paint *paint, StrokeCache *cache)
{
Scene *scene = CTX_data_scene(C);
Brush *brush = paint->brush;
int cur_brush_size = BKE_brush_size_get(scene, brush);
STRNCPY(cache->saved_active_brush_name, brush->id.name + 2);
/* Switch to the blur (smooth) brush. */
brush = BKE_paint_toolslots_brush_get(paint, WPAINT_TOOL_BLUR);
if (brush) {
BKE_paint_brush_set(paint, brush);
cache->saved_smooth_size = BKE_brush_size_get(scene, brush);
BKE_brush_size_set(scene, brush, cur_brush_size);
BKE_curvemapping_init(brush->curve);
/* Switch to the blur (smooth) brush if possible. */
/* Note: used for both vertexpaint and weightpaint, VPAINT_TOOL_BLUR & WPAINT_TOOL_BLUR are the
* same, see comments for eBrushVertexPaintTool & eBrushWeightPaintTool. */
Brush *smooth_brush = BKE_paint_toolslots_brush_get(paint, WPAINT_TOOL_BLUR);
if (!smooth_brush) {
printf(
"WARNING: Switching to the blur (smooth) brush not possible, corresponding brush not "
"found\n");
return;
}
Brush *cur_brush = paint->brush;
int cur_brush_size = BKE_brush_size_get(scene, cur_brush);
STRNCPY(cache->saved_active_brush_name, cur_brush->id.name + 2);
BKE_paint_brush_set(paint, smooth_brush);
cache->saved_smooth_size = BKE_brush_size_get(scene, smooth_brush);
BKE_brush_size_set(scene, smooth_brush, cur_brush_size);
BKE_curvemapping_init(smooth_brush->curve);
}
/** \} */
} // namespace blender::ed::sculpt_paint::vwpaint

View File

@ -4345,34 +4345,37 @@ static void sculpt_init_mirror_clipping(Object *ob, SculptSession *ss)
static void smooth_brush_toggle_on(const bContext *C, Paint *paint, StrokeCache *cache)
{
Scene *scene = CTX_data_scene(C);
Brush *brush = paint->brush;
Brush *cur_brush = paint->brush;
if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
cache->saved_mask_brush_tool = brush->mask_tool;
brush->mask_tool = BRUSH_MASK_SMOOTH;
if (cur_brush->sculpt_tool == SCULPT_TOOL_MASK) {
cache->saved_mask_brush_tool = cur_brush->mask_tool;
cur_brush->mask_tool = BRUSH_MASK_SMOOTH;
}
else if (ELEM(brush->sculpt_tool,
else if (ELEM(cur_brush->sculpt_tool,
SCULPT_TOOL_SLIDE_RELAX,
SCULPT_TOOL_DRAW_FACE_SETS,
SCULPT_TOOL_PAINT,
SCULPT_TOOL_SMEAR))
{
/* Do nothing, this tool has its own smooth mode. */
return;
}
else {
int cur_brush_size = BKE_brush_size_get(scene, brush);
STRNCPY(cache->saved_active_brush_name, brush->id.name + 2);
/* Switch to the smooth brush. */
brush = BKE_paint_toolslots_brush_get(paint, SCULPT_TOOL_SMOOTH);
if (brush) {
BKE_paint_brush_set(paint, brush);
cache->saved_smooth_size = BKE_brush_size_get(scene, brush);
BKE_brush_size_set(scene, brush, cur_brush_size);
BKE_curvemapping_init(brush->curve);
}
/* Switch to the smooth brush if possible. */
Brush *smooth_brush = BKE_paint_toolslots_brush_get(paint, SCULPT_TOOL_SMOOTH);
if (!smooth_brush) {
printf("WARNING: Switching to the smooth brush not possible, corresponding brush not found\n");
return;
}
int cur_brush_size = BKE_brush_size_get(scene, cur_brush);
STRNCPY(cache->saved_active_brush_name, cur_brush->id.name + 2);
BKE_paint_brush_set(paint, smooth_brush);
cache->saved_smooth_size = BKE_brush_size_get(scene, smooth_brush);
BKE_brush_size_set(scene, smooth_brush, cur_brush_size);
BKE_curvemapping_init(smooth_brush->curve);
}
static void smooth_brush_toggle_off(const bContext *C, Paint *paint, StrokeCache *cache)
@ -4392,13 +4395,20 @@ static void smooth_brush_toggle_off(const bContext *C, Paint *paint, StrokeCache
{
/* Do nothing. */
}
else {
/* Try to switch back to the saved/previous brush. */
BKE_brush_size_set(scene, brush, cache->saved_smooth_size);
brush = (Brush *)BKE_libblock_find_name(bmain, ID_BR, cache->saved_active_brush_name);
if (brush) {
BKE_paint_brush_set(paint, brush);
}
/* Note: used for both vertexpaint and weightpaint, VPAINT_TOOL_BLUR & WPAINT_TOOL_BLUR are the
* same, see comments for eBrushVertexPaintTool & eBrushWeightPaintTool. */
/* If the smooth brush is missing, brush was not switched/affected in smooth_brush_toggle_on().
*/
if (!BKE_paint_toolslots_brush_get(paint, SCULPT_TOOL_SMOOTH)) {
lichtwerk marked this conversation as resolved Outdated

It feels a bit redundant to be checking both BKE_paint_toolslots_brush_get(paint, SCULPT_TOOL_SMOOTH) and if (brush) {.

perhaps foo_on should clear saved_active_brush_name if the brush is not found, and here move BKE_brush_size_set(scene, brush, cache->saved_smooth_size); inside of the if (brush) {.

It feels a bit redundant to be checking both `BKE_paint_toolslots_brush_get(paint, SCULPT_TOOL_SMOOTH)` and `if (brush) {`. perhaps foo_on should clear `saved_active_brush_name` if the brush is not found, and here move `BKE_brush_size_set(scene, brush, cache->saved_smooth_size);` inside of the `if (brush) {`.

done

done
return;
}
BKE_brush_size_set(scene, brush, cache->saved_smooth_size);
brush = (Brush *)BKE_libblock_find_name(bmain, ID_BR, cache->saved_active_brush_name);
if (brush) {
BKE_paint_brush_set(paint, brush);
}
}