Curves: Support pressure in sculpt brushes
Multiply the radius and strength of sculpt brushes by the pressure when "use pressure" is turned on. The brush system isn't responsible for this, so the pressure needs to be stored in `StrokeExtension`. Differential Revision: https://developer.blender.org/D14996
This commit is contained in:
parent
a89f829f12
commit
cea37b3127
|
@ -179,7 +179,7 @@ struct AddOperationExecutor {
|
|||
curves_sculpt_ = scene_->toolsettings->curves_sculpt;
|
||||
brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint);
|
||||
brush_settings_ = brush_->curves_sculpt_settings;
|
||||
brush_radius_re_ = BKE_brush_size_get(scene_, brush_);
|
||||
brush_radius_re_ = brush_radius_get(*scene_, *brush_, stroke_extension);
|
||||
brush_pos_re_ = stroke_extension.mouse_position;
|
||||
|
||||
use_front_face_ = brush_->flag & BRUSH_FRONTFACE;
|
||||
|
|
|
@ -126,8 +126,8 @@ struct CombOperationExecutor {
|
|||
|
||||
curves_sculpt_ = scene_->toolsettings->curves_sculpt;
|
||||
brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint);
|
||||
brush_radius_re_ = BKE_brush_size_get(scene_, brush_);
|
||||
brush_strength_ = BKE_brush_alpha_get(scene_, brush_);
|
||||
brush_radius_re_ = brush_radius_get(*scene_, *brush_, stroke_extension);
|
||||
brush_strength_ = brush_strength_get(*scene_, *brush_, stroke_extension);
|
||||
|
||||
curves_to_world_mat_ = object_->obmat;
|
||||
world_to_curves_mat_ = curves_to_world_mat_.inverted();
|
||||
|
|
|
@ -99,7 +99,7 @@ struct DeleteOperationExecutor {
|
|||
|
||||
curves_sculpt_ = scene_->toolsettings->curves_sculpt;
|
||||
brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint);
|
||||
brush_radius_re_ = BKE_brush_size_get(scene_, brush_);
|
||||
brush_radius_re_ = brush_radius_get(*scene_, *brush_, stroke_extension);
|
||||
|
||||
brush_pos_re_ = stroke_extension.mouse_position;
|
||||
brush_pos_prev_re_ = stroke_extension.is_first ? stroke_extension.mouse_position :
|
||||
|
|
|
@ -321,8 +321,8 @@ struct CurvesEffectOperationExecutor {
|
|||
|
||||
const CurvesSculpt &curves_sculpt = *scene_->toolsettings->curves_sculpt;
|
||||
brush_ = BKE_paint_brush_for_read(&curves_sculpt.paint);
|
||||
brush_radius_re_ = BKE_brush_size_get(scene_, brush_);
|
||||
brush_strength_ = BKE_brush_alpha_get(scene_, brush_);
|
||||
brush_radius_re_ = brush_radius_get(*scene_, *brush_, stroke_extension);
|
||||
brush_strength_ = brush_strength_get(*scene_, *brush_, stroke_extension);
|
||||
brush_radius_sq_re_ = pow2f(brush_radius_re_);
|
||||
falloff_shape_ = eBrushFalloffShape(brush_->falloff_shape);
|
||||
|
||||
|
|
|
@ -24,8 +24,17 @@ using bke::CurvesGeometry;
|
|||
struct StrokeExtension {
|
||||
bool is_first;
|
||||
float2 mouse_position;
|
||||
float pressure;
|
||||
};
|
||||
|
||||
float brush_radius_get(const Scene &scene,
|
||||
const Brush &brush,
|
||||
const StrokeExtension &stroke_extension);
|
||||
|
||||
float brush_strength_get(const Scene &scene,
|
||||
const Brush &brush,
|
||||
const StrokeExtension &stroke_extension);
|
||||
|
||||
/**
|
||||
* Base class for stroke based operations in curves sculpt mode.
|
||||
*/
|
||||
|
|
|
@ -74,6 +74,28 @@ using blender::bke::CurvesGeometry;
|
|||
/** \name * SCULPT_CURVES_OT_brush_stroke
|
||||
* \{ */
|
||||
|
||||
float brush_radius_get(const Scene &scene,
|
||||
const Brush &brush,
|
||||
const StrokeExtension &stroke_extension)
|
||||
{
|
||||
const float initial_radius = BKE_brush_size_get(&scene, &brush);
|
||||
if (BKE_brush_use_size_pressure(&brush)) {
|
||||
return initial_radius * stroke_extension.pressure;
|
||||
}
|
||||
return initial_radius;
|
||||
}
|
||||
|
||||
float brush_strength_get(const Scene &scene,
|
||||
const Brush &brush,
|
||||
const StrokeExtension &stroke_extension)
|
||||
{
|
||||
const float initial_radius = BKE_brush_alpha_get(&scene, &brush);
|
||||
if (BKE_brush_use_alpha_pressure(&brush)) {
|
||||
return initial_radius * stroke_extension.pressure;
|
||||
}
|
||||
return initial_radius;
|
||||
}
|
||||
|
||||
static std::unique_ptr<CurvesSculptStrokeOperation> start_brush_operation(bContext &C,
|
||||
wmOperator &op)
|
||||
{
|
||||
|
@ -128,6 +150,7 @@ static void stroke_update_step(bContext *C,
|
|||
|
||||
StrokeExtension stroke_extension;
|
||||
RNA_float_get_array(stroke_element, "mouse", stroke_extension.mouse_position);
|
||||
stroke_extension.pressure = RNA_float_get(stroke_element, "pressure");
|
||||
|
||||
if (!op_data->operation) {
|
||||
stroke_extension.is_first = true;
|
||||
|
|
|
@ -112,8 +112,8 @@ struct SnakeHookOperatorExecutor {
|
|||
|
||||
curves_sculpt_ = scene_->toolsettings->curves_sculpt;
|
||||
brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint);
|
||||
brush_radius_re_ = BKE_brush_size_get(scene_, brush_);
|
||||
brush_strength_ = BKE_brush_alpha_get(scene_, brush_);
|
||||
brush_radius_re_ = brush_radius_get(*scene_, *brush_, stroke_extension);
|
||||
brush_strength_ = brush_strength_get(*scene_, *brush_, stroke_extension);
|
||||
falloff_shape_ = static_cast<eBrushFalloffShape>(brush_->falloff_shape);
|
||||
|
||||
curves_to_world_mat_ = object_->obmat;
|
||||
|
|
Loading…
Reference in New Issue