Cleanup: Sculpt: Rename and move plane-based brush utilities
These utiltities aren't really specific to the scrape brush; they're used elsewhere too. With simpler names it feels better to put them in the common utilities file so they can be shared more easily. Pull Request: https://projects.blender.org/blender/blender/pulls/123152
This commit is contained in:
@@ -36,18 +36,6 @@ struct LocalData {
|
||||
Vector<float3> translations;
|
||||
};
|
||||
|
||||
BLI_NOINLINE static void calc_plane_side_factors(const Span<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const float4 &plane,
|
||||
const MutableSpan<float> 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<float3> 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);
|
||||
|
||||
@@ -76,8 +76,8 @@ static void calc_faces(const Sculpt &sd,
|
||||
|
||||
tls.translations.reinitialize(verts.size());
|
||||
const MutableSpan<float3> 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);
|
||||
|
||||
@@ -28,35 +28,6 @@
|
||||
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
BLI_NOINLINE void scrape_calc_translations(const Span<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const float4 &plane,
|
||||
const MutableSpan<float3> 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<float3> translations,
|
||||
const MutableSpan<float> 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<float3> translations;
|
||||
};
|
||||
|
||||
BLI_NOINLINE static void calc_plane_side_factors(const Span<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const float4 &plane,
|
||||
const MutableSpan<float> 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<float3> 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);
|
||||
|
||||
@@ -175,13 +175,28 @@ void calc_vert_neighbors_interior(OffsetIndices<int> faces,
|
||||
Span<int> verts,
|
||||
MutableSpan<Vector<int>> result);
|
||||
|
||||
void scrape_calc_translations(const Span<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const float4 &plane,
|
||||
const MutableSpan<float3> translations);
|
||||
void scrape_calc_plane_trim_limit(const Brush &brush,
|
||||
const StrokeCache &cache,
|
||||
const Span<float3> translations,
|
||||
const MutableSpan<float> factors);
|
||||
/** Find the translation from each vertex position to the closest point on the plane. */
|
||||
void calc_translations_to_plane(Span<float3> vert_positions,
|
||||
Span<int> verts,
|
||||
const float4 &plane,
|
||||
MutableSpan<float3> 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<float3> translations,
|
||||
MutableSpan<float> factors);
|
||||
|
||||
/** Ignore points below the plane. */
|
||||
void filter_below_plane_factors(Span<float3> vert_positions,
|
||||
Span<int> verts,
|
||||
const float4 &plane,
|
||||
MutableSpan<float> factors);
|
||||
|
||||
/* Ignore points above the plane. */
|
||||
void filter_above_plane_factors(Span<float3> vert_positions,
|
||||
Span<int> verts,
|
||||
const float4 &plane,
|
||||
MutableSpan<float> factors);
|
||||
|
||||
} // namespace blender::ed::sculpt_paint
|
||||
|
||||
@@ -6795,4 +6795,57 @@ void calc_vert_neighbors_interior(const OffsetIndices<int> faces,
|
||||
}
|
||||
}
|
||||
|
||||
void calc_translations_to_plane(const Span<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const float4 &plane,
|
||||
const MutableSpan<float3> 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<float3> translations,
|
||||
const MutableSpan<float> 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<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const float4 &plane,
|
||||
const MutableSpan<float> 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<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const float4 &plane,
|
||||
const MutableSpan<float> 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
|
||||
|
||||
Reference in New Issue
Block a user