Merge branch 'blender-v4.3-release'

This commit is contained in:
Sean Kim
2024-10-29 13:11:21 -07:00
2 changed files with 31 additions and 9 deletions

View File

@@ -2059,6 +2059,23 @@ void calc_area_normal_and_center(const Depsgraph &depsgraph,
/** \name Generic Brush Utilities
* \{ */
/**
* Calculates the sign of the direction of the brush stroke, typically indicates whether the stroke
* will deform a surface inwards or outwards along the brush normal.
*/
static float brush_flip(const Brush &brush, const blender::ed::sculpt_paint::StrokeCache &cache)
{
if (brush.flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
return 1.0f;
}
const float dir = (brush.flag & BRUSH_DIR_IN) ? -1.0f : 1.0f;
const float pen_flip = cache.pen_flip ? -1.0f : 1.0f;
const float invert = cache.invert ? -1.0f : 1.0f;
return dir * pen_flip * invert;
}
/**
* Return modified brush strength. Includes the direction of the brush, positive
* values pull vertices, negative values push. Uses tablet pressure and a
@@ -2076,18 +2093,12 @@ static float brush_strength(const Sculpt &sd,
/* Primary strength input; square it to make lower values more sensitive. */
const float root_alpha = BKE_brush_alpha_get(scene, &brush);
const float alpha = root_alpha * root_alpha;
const float dir = (brush.flag & BRUSH_DIR_IN) ? -1.0f : 1.0f;
const float pressure = BKE_brush_use_alpha_pressure(&brush) ? cache.pressure : 1.0f;
const float pen_flip = cache.pen_flip ? -1.0f : 1.0f;
const float invert = cache.invert ? -1.0f : 1.0f;
float overlap = ups.overlap_factor;
/* Spacing is integer percentage of radius, divide by 50 to get
* normalized diameter. */
float flip = dir * invert * pen_flip;
if (brush.flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
flip = 1.0f;
}
const float flip = brush_flip(brush, cache);
/* Pressure final value after being tweaked depending on the brush. */
float final_pressure;
@@ -3169,7 +3180,7 @@ static void do_brush_action(const Depsgraph &depsgraph,
* stroke strength can become 0 during the stroke, but it can not change sign (the sign is
* determined in the beginning of the stroke. So here it is important to not switch to
* enhance brush in the middle of the stroke. */
if (ss.cache->bstrength < 0.0f) {
if (ss.cache->initial_direction_flipped) {
/* Invert mode, intensify details. */
do_enhance_details_brush(depsgraph, sd, ob, node_mask);
}
@@ -3867,6 +3878,7 @@ static void sculpt_update_cache_invariants(
copy_v3_v3(cache->initial_normal, ss.cursor_normal);
mode = RNA_enum_get(op->ptr, "mode");
cache->pen_flip = RNA_boolean_get(op->ptr, "pen_flip");
cache->invert = mode == BRUSH_STROKE_INVERT;
cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH;
cache->normal_weight = brush->normal_weight;
@@ -3899,6 +3911,8 @@ static void sculpt_update_cache_invariants(
copy_v2_v2(cache->mouse_event, cache->initial_mouse);
copy_v2_v2(ups->tex_mouse, cache->initial_mouse);
cache->initial_direction_flipped = brush_flip(*brush, *cache) < 0.0f;
/* Truly temporary data that isn't stored in properties. */
cache->vc = vc;
cache->brush = brush;
@@ -4245,7 +4259,6 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt &sd, Object &ob, Po
RNA_float_get_array(ptr, "location", cache.location);
}
cache.pen_flip = RNA_boolean_get(ptr, "pen_flip");
RNA_float_get_array(ptr, "mouse", cache.mouse);
RNA_float_get_array(ptr, "mouse_event", cache.mouse_event);

View File

@@ -164,6 +164,15 @@ struct StrokeCache {
} mirror_modifier_clip;
float2 initial_mouse;
/**
* Some brushes change behavior drastically depending on the directional value (i.e. the smooth
* and enhance details functionality being bound to the Smooth brush).
*
* Storing the initial direction allows discerning the behavior without checking the sign of the
* brush direction at every step, which would have ambiguity at 0.
*/
bool initial_direction_flipped;
/* Variants */
float radius;
float radius_squared;