diff --git a/source/blender/editors/sculpt_paint/brushes/fill.cc b/source/blender/editors/sculpt_paint/brushes/fill.cc index 8fba366b06d..e00d1123fea 100644 --- a/source/blender/editors/sculpt_paint/brushes/fill.cc +++ b/source/blender/editors/sculpt_paint/brushes/fill.cc @@ -36,18 +36,6 @@ struct LocalData { Vector translations; }; -BLI_NOINLINE static void calc_plane_side_factors(const Span vert_positions, - const Span verts, - const float4 &plane, - const MutableSpan factors) -{ - for (const int i : verts.index_range()) { - if (plane_point_side_v3(plane, vert_positions[verts[i]]) > 0.0f) { - factors[i] = 0.0f; - } - } -} - static void calc_faces(const Sculpt &sd, const Brush &brush, const float4 &plane, @@ -87,12 +75,12 @@ static void calc_faces(const Sculpt &sd, scale_factors(factors, strength); - calc_plane_side_factors(positions_eval, verts, plane, factors); + filter_above_plane_factors(positions_eval, verts, plane, factors); tls.translations.reinitialize(verts.size()); const MutableSpan translations = tls.translations; - scrape_calc_translations(positions_eval, verts, plane, translations); - scrape_calc_plane_trim_limit(brush, *ss.cache, translations, factors); + calc_translations_to_plane(positions_eval, verts, plane, translations); + filter_plane_trim_limit_factors(brush, *ss.cache, translations, factors); scale_translations(translations, factors); clip_and_lock_translations(sd, ss, positions_eval, verts, translations); diff --git a/source/blender/editors/sculpt_paint/brushes/flatten.cc b/source/blender/editors/sculpt_paint/brushes/flatten.cc index 21bc817eb9d..db77507bc72 100644 --- a/source/blender/editors/sculpt_paint/brushes/flatten.cc +++ b/source/blender/editors/sculpt_paint/brushes/flatten.cc @@ -76,8 +76,8 @@ static void calc_faces(const Sculpt &sd, tls.translations.reinitialize(verts.size()); const MutableSpan translations = tls.translations; - scrape_calc_translations(positions_eval, verts, plane, translations); - scrape_calc_plane_trim_limit(brush, *ss.cache, translations, factors); + calc_translations_to_plane(positions_eval, verts, plane, translations); + filter_plane_trim_limit_factors(brush, *ss.cache, translations, factors); scale_translations(translations, factors); clip_and_lock_translations(sd, ss, positions_eval, verts, translations); diff --git a/source/blender/editors/sculpt_paint/brushes/scrape.cc b/source/blender/editors/sculpt_paint/brushes/scrape.cc index 734d88fc60a..f4a47bb848a 100644 --- a/source/blender/editors/sculpt_paint/brushes/scrape.cc +++ b/source/blender/editors/sculpt_paint/brushes/scrape.cc @@ -28,35 +28,6 @@ namespace blender::ed::sculpt_paint { -BLI_NOINLINE void scrape_calc_translations(const Span vert_positions, - const Span verts, - const float4 &plane, - const MutableSpan translations) -{ - for (const int i : verts.index_range()) { - const float3 &position = vert_positions[verts[i]]; - float3 closest; - closest_to_plane_normalized_v3(closest, plane, position); - translations[i] = closest - position; - } -} - -BLI_NOINLINE void scrape_calc_plane_trim_limit(const Brush &brush, - const StrokeCache &cache, - const Span translations, - const MutableSpan factors) -{ - if (!(brush.flag & BRUSH_PLANE_TRIM)) { - return; - } - const float threshold = cache.radius_squared * cache.plane_trim_squared; - for (const int i : translations.index_range()) { - if (math::length_squared(translations[i]) <= threshold) { - factors[i] = 0.0f; - } - } -} - inline namespace scrape_cc { struct LocalData { @@ -65,18 +36,6 @@ struct LocalData { Vector translations; }; -BLI_NOINLINE static void calc_plane_side_factors(const Span vert_positions, - const Span verts, - const float4 &plane, - const MutableSpan factors) -{ - for (const int i : verts.index_range()) { - if (plane_point_side_v3(plane, vert_positions[verts[i]]) <= 0.0f) { - factors[i] = 0.0f; - } - } -} - static void calc_faces(const Sculpt &sd, const Brush &brush, const float4 &plane, @@ -116,12 +75,12 @@ static void calc_faces(const Sculpt &sd, scale_factors(factors, strength); - calc_plane_side_factors(positions_eval, verts, plane, factors); + filter_below_plane_factors(positions_eval, verts, plane, factors); tls.translations.reinitialize(verts.size()); const MutableSpan translations = tls.translations; - scrape_calc_translations(positions_eval, verts, plane, translations); - scrape_calc_plane_trim_limit(brush, *ss.cache, translations, factors); + calc_translations_to_plane(positions_eval, verts, plane, translations); + filter_plane_trim_limit_factors(brush, *ss.cache, translations, factors); scale_translations(translations, factors); clip_and_lock_translations(sd, ss, positions_eval, verts, translations); diff --git a/source/blender/editors/sculpt_paint/mesh_brush_common.hh b/source/blender/editors/sculpt_paint/mesh_brush_common.hh index f4e66b83edb..4028642340b 100644 --- a/source/blender/editors/sculpt_paint/mesh_brush_common.hh +++ b/source/blender/editors/sculpt_paint/mesh_brush_common.hh @@ -175,13 +175,28 @@ void calc_vert_neighbors_interior(OffsetIndices faces, Span verts, MutableSpan> result); -void scrape_calc_translations(const Span vert_positions, - const Span verts, - const float4 &plane, - const MutableSpan translations); -void scrape_calc_plane_trim_limit(const Brush &brush, - const StrokeCache &cache, - const Span translations, - const MutableSpan factors); +/** Find the translation from each vertex position to the closest point on the plane. */ +void calc_translations_to_plane(Span vert_positions, + Span verts, + const float4 &plane, + MutableSpan translations); + +/** Ignore points that fall below the "plane trim" threshold for the brush. */ +void filter_plane_trim_limit_factors(const Brush &brush, + const StrokeCache &cache, + Span translations, + MutableSpan factors); + +/** Ignore points below the plane. */ +void filter_below_plane_factors(Span vert_positions, + Span verts, + const float4 &plane, + MutableSpan factors); + +/* Ignore points above the plane. */ +void filter_above_plane_factors(Span vert_positions, + Span verts, + const float4 &plane, + MutableSpan factors); } // namespace blender::ed::sculpt_paint diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 344d6b59657..dca7381ea3d 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -6795,4 +6795,57 @@ void calc_vert_neighbors_interior(const OffsetIndices faces, } } +void calc_translations_to_plane(const Span vert_positions, + const Span verts, + const float4 &plane, + const MutableSpan translations) +{ + for (const int i : verts.index_range()) { + const float3 &position = vert_positions[verts[i]]; + float3 closest; + closest_to_plane_normalized_v3(closest, plane, position); + translations[i] = closest - position; + } +} + +void filter_plane_trim_limit_factors(const Brush &brush, + const StrokeCache &cache, + const Span translations, + const MutableSpan factors) +{ + if (!(brush.flag & BRUSH_PLANE_TRIM)) { + return; + } + const float threshold = cache.radius_squared * cache.plane_trim_squared; + for (const int i : translations.index_range()) { + if (math::length_squared(translations[i]) <= threshold) { + factors[i] = 0.0f; + } + } +} + +void filter_below_plane_factors(const Span vert_positions, + const Span verts, + const float4 &plane, + const MutableSpan factors) +{ + for (const int i : verts.index_range()) { + if (plane_point_side_v3(plane, vert_positions[verts[i]]) <= 0.0f) { + factors[i] = 0.0f; + } + } +} + +void filter_above_plane_factors(const Span vert_positions, + const Span verts, + const float4 &plane, + const MutableSpan factors) +{ + for (const int i : verts.index_range()) { + if (plane_point_side_v3(plane, vert_positions[verts[i]]) > 0.0f) { + factors[i] = 0.0f; + } + } +} + } // namespace blender::ed::sculpt_paint