Cleanup: Consolidate clay thumb brush variables
Part of #126672. * Collects related variables into the `clay_thumb_brush` anonymous struct. * Use `std::array` instead of raw array for the rolling stabilizer average. Pull Request: https://projects.blender.org/blender/blender/pulls/126719
This commit is contained in:
@@ -212,15 +212,16 @@ void do_clay_thumb_brush(const Depsgraph &depsgraph,
|
||||
|
||||
/* Delay the first daub because grab delta is not setup. */
|
||||
if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(*ss.cache)) {
|
||||
ss.cache->clay_thumb_front_angle = 0.0f;
|
||||
ss.cache->clay_thumb_brush.front_angle = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Simulate the clay accumulation by increasing the plane angle as more samples are added to the
|
||||
* stroke. */
|
||||
if (SCULPT_stroke_is_main_symmetry_pass(*ss.cache)) {
|
||||
ss.cache->clay_thumb_front_angle += 0.8f;
|
||||
ss.cache->clay_thumb_front_angle = clamp_f(ss.cache->clay_thumb_front_angle, 0.0f, 60.0f);
|
||||
ss.cache->clay_thumb_brush.front_angle += 0.8f;
|
||||
ss.cache->clay_thumb_brush.front_angle = std::clamp(
|
||||
ss.cache->clay_thumb_brush.front_angle, 0.0f, 60.0f);
|
||||
}
|
||||
|
||||
if (math::is_zero(ss.cache->grab_delta_symmetry)) {
|
||||
@@ -247,7 +248,8 @@ void do_clay_thumb_brush(const Depsgraph &depsgraph,
|
||||
float4x4 imat;
|
||||
|
||||
invert_m4_m4(imat.ptr(), mat.ptr());
|
||||
rotate_v3_v3v3fl(normal_tilt, area_no_sp, imat[0], DEG2RADF(-ss.cache->clay_thumb_front_angle));
|
||||
rotate_v3_v3v3fl(
|
||||
normal_tilt, area_no_sp, imat[0], DEG2RADF(-ss.cache->clay_thumb_brush.front_angle));
|
||||
|
||||
/* Tilted plane (front part of the brush). */
|
||||
plane_from_point_normal_v3(plane_tilt, location, normal_tilt);
|
||||
@@ -297,13 +299,12 @@ void do_clay_thumb_brush(const Depsgraph &depsgraph,
|
||||
}
|
||||
}
|
||||
|
||||
float clay_thumb_get_stabilized_pressure(const blender::ed::sculpt_paint::StrokeCache &cache)
|
||||
float clay_thumb_get_stabilized_pressure(const StrokeCache &cache)
|
||||
{
|
||||
float final_pressure = 0.0f;
|
||||
for (int i = 0; i < SCULPT_CLAY_STABILIZER_LEN; i++) {
|
||||
final_pressure += cache.clay_pressure_stabilizer[i];
|
||||
}
|
||||
return final_pressure / SCULPT_CLAY_STABILIZER_LEN;
|
||||
const float pressure_sum = std::accumulate(cache.clay_thumb_brush.pressure_stabilizer.begin(),
|
||||
cache.clay_thumb_brush.pressure_stabilizer.end(),
|
||||
0.0f);
|
||||
return pressure_sum / cache.clay_thumb_brush.pressure_stabilizer.size();
|
||||
}
|
||||
|
||||
} // namespace blender::ed::sculpt_paint
|
||||
|
||||
@@ -4559,16 +4559,17 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt &sd, Object &ob, Po
|
||||
/* Clay stabilized pressure. */
|
||||
if (brush.sculpt_tool == SCULPT_TOOL_CLAY_THUMB) {
|
||||
if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(*ss.cache)) {
|
||||
for (int i = 0; i < SCULPT_CLAY_STABILIZER_LEN; i++) {
|
||||
ss.cache->clay_pressure_stabilizer[i] = 0.0f;
|
||||
}
|
||||
ss.cache->clay_pressure_stabilizer_index = 0;
|
||||
ss.cache->clay_thumb_brush.pressure_stabilizer.fill(0.0f);
|
||||
ss.cache->clay_thumb_brush.stabilizer_index = 0;
|
||||
}
|
||||
else {
|
||||
cache.clay_pressure_stabilizer[cache.clay_pressure_stabilizer_index] = cache.pressure;
|
||||
cache.clay_pressure_stabilizer_index += 1;
|
||||
if (cache.clay_pressure_stabilizer_index >= SCULPT_CLAY_STABILIZER_LEN) {
|
||||
cache.clay_pressure_stabilizer_index = 0;
|
||||
cache.clay_thumb_brush.pressure_stabilizer[cache.clay_thumb_brush.stabilizer_index] =
|
||||
cache.pressure;
|
||||
cache.clay_thumb_brush.stabilizer_index += 1;
|
||||
if (cache.clay_thumb_brush.stabilizer_index >=
|
||||
ss.cache->clay_thumb_brush.pressure_stabilizer.size())
|
||||
{
|
||||
cache.clay_thumb_brush.stabilizer_index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,8 +125,6 @@ enum class TransformDisplacementMode {
|
||||
}
|
||||
/* Defines how transform tools are going to apply its displacement. */
|
||||
|
||||
#define SCULPT_CLAY_STABILIZER_LEN 10
|
||||
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
/**
|
||||
@@ -282,11 +280,14 @@ struct StrokeCache {
|
||||
Array<float3> detail_directions;
|
||||
|
||||
/* Clay Thumb brush */
|
||||
/* Angle of the front tilting plane of the brush to simulate clay accumulation. */
|
||||
float clay_thumb_front_angle;
|
||||
/* Stores pressure samples to get an stabilized strength and radius variation. */
|
||||
float clay_pressure_stabilizer[SCULPT_CLAY_STABILIZER_LEN];
|
||||
int clay_pressure_stabilizer_index;
|
||||
struct {
|
||||
/* Angle of the front tilting plane of the brush to simulate clay accumulation. */
|
||||
float front_angle;
|
||||
/* Stores the last 10 pressure samples to get an stabilized strength and radius variation. */
|
||||
std::array<float, 10> pressure_stabilizer;
|
||||
int stabilizer_index;
|
||||
|
||||
} clay_thumb_brush;
|
||||
|
||||
/* Cloth brush */
|
||||
std::unique_ptr<cloth::SimulationData> cloth_sim;
|
||||
|
||||
Reference in New Issue
Block a user