Fixes for 2d painting:
* Jittering accounts for zoom * Smooth stroke accounts for zoom * Expose smooth stroke in image paint editor.
This commit is contained in:
parent
85b6299747
commit
b961fda0b1
@ -758,20 +758,33 @@ class IMAGE_PT_paint_stroke(BrushButtonsPanel, Panel):
|
||||
toolsettings = context.tool_settings.image_paint
|
||||
brush = toolsettings.brush
|
||||
|
||||
layout.prop(toolsettings, "input_samples")
|
||||
col = layout.column()
|
||||
col.prop(toolsettings, "input_samples")
|
||||
|
||||
layout.prop(brush, "use_airbrush")
|
||||
row = layout.row()
|
||||
col.prop(brush, "use_airbrush")
|
||||
row = col.row()
|
||||
row.active = brush.use_airbrush
|
||||
row.prop(brush, "rate", slider=True)
|
||||
|
||||
layout.prop(brush, "use_space")
|
||||
row = layout.row(align=True)
|
||||
col.separator()
|
||||
|
||||
col.prop(brush, "use_smooth_stroke")
|
||||
|
||||
col = layout.column()
|
||||
col.active = brush.use_smooth_stroke
|
||||
col.prop(brush, "smooth_stroke_radius", text="Radius", slider=True)
|
||||
col.prop(brush, "smooth_stroke_factor", text="Factor", slider=True)
|
||||
|
||||
col.separator()
|
||||
|
||||
col = layout.column()
|
||||
col.prop(brush, "use_space")
|
||||
row = col.row(align=True)
|
||||
row.active = brush.use_space
|
||||
row.prop(brush, "spacing", text="Distance", slider=True)
|
||||
row.prop(brush, "use_pressure_spacing", toggle=True, text="")
|
||||
|
||||
layout.prop(brush, "use_wrap")
|
||||
col.prop(brush, "use_wrap")
|
||||
|
||||
|
||||
class IMAGE_PT_paint_curve(BrushButtonsPanel, Panel):
|
||||
|
@ -96,6 +96,8 @@ typedef struct PaintStroke {
|
||||
float initial_mouse[2];
|
||||
float cached_pressure;
|
||||
|
||||
float zoom_2d;
|
||||
|
||||
StrokeGetLocation get_location;
|
||||
StrokeTestStart test_start;
|
||||
StrokeUpdateStep update_step;
|
||||
@ -275,15 +277,19 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const wmEve
|
||||
* separation will go away */
|
||||
if (paint_supports_jitter(mode)) {
|
||||
float delta[2];
|
||||
float factor = stroke->zoom_2d;
|
||||
|
||||
if (brush->flag & BRUSH_JITTER_PRESSURE)
|
||||
factor *= pressure;
|
||||
|
||||
BKE_brush_jitter_pos(scene, brush, mouse_in, mouse_out);
|
||||
|
||||
/* XXX: meh, this is round about because
|
||||
* BKE_brush_jitter_pos isn't written in the best way to
|
||||
* be reused here */
|
||||
if (brush->flag & BRUSH_JITTER_PRESSURE) {
|
||||
if(factor != 1.0) {
|
||||
sub_v2_v2v2(delta, mouse_out, mouse_in);
|
||||
mul_v2_fl(delta, pressure);
|
||||
mul_v2_fl(delta, factor);
|
||||
add_v2_v2v2(mouse_out, mouse_in, delta);
|
||||
}
|
||||
}
|
||||
@ -318,13 +324,14 @@ static int paint_smooth_stroke(PaintStroke *stroke, float output[2],
|
||||
output[1] = sample->mouse[1];
|
||||
|
||||
if (paint_supports_smooth_stroke(stroke->brush, mode)) {
|
||||
float radius = stroke->brush->smooth_stroke_radius*stroke->zoom_2d;
|
||||
float u = stroke->brush->smooth_stroke_factor, v = 1.0f - u;
|
||||
float dx = stroke->last_mouse_position[0] - sample->mouse[0];
|
||||
float dy = stroke->last_mouse_position[1] - sample->mouse[1];
|
||||
|
||||
/* If the mouse is moving within the radius of the last move,
|
||||
* don't update the mouse position. This allows sharp turns. */
|
||||
if (dx * dx + dy * dy < stroke->brush->smooth_stroke_radius * stroke->brush->smooth_stroke_radius)
|
||||
if (dx * dx + dy * dy < radius * radius)
|
||||
return 0;
|
||||
|
||||
output[0] = sample->mouse[0] * v + stroke->last_mouse_position[0] * u;
|
||||
@ -365,7 +372,6 @@ static int paint_space_stroke(bContext *C, wmOperator *op, const wmEvent *event,
|
||||
size_pressure = pressure;
|
||||
|
||||
if (size_pressure > FLT_EPSILON) {
|
||||
float zoomx, zoomy;
|
||||
/* brushes can have a minimum size of 1.0 but with pressure it can be smaller then a pixel
|
||||
* causing very high step sizes, hanging blender [#32381] */
|
||||
const float size_clamp = max_ff(1.0f, BKE_brush_size_get(scene, stroke->brush) * size_pressure);
|
||||
@ -373,12 +379,11 @@ static int paint_space_stroke(bContext *C, wmOperator *op, const wmEvent *event,
|
||||
|
||||
/* stroke system is used for 2d paint too, so we need to account for
|
||||
* the fact that brush can be scaled there. */
|
||||
get_imapaint_zoom(C, &zoomx, &zoomy);
|
||||
|
||||
if (stroke->brush->flag & BRUSH_SPACING_PRESSURE)
|
||||
spacing = max_ff(1.0f, spacing * (1.5f - pressure));
|
||||
|
||||
spacing *= max_ff(zoomx, zoomy);
|
||||
spacing *= stroke->zoom_2d;
|
||||
|
||||
scale = (size_clamp * spacing / 50.0f) / length;
|
||||
if (scale > FLT_EPSILON) {
|
||||
@ -594,10 +599,14 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
PaintSample sample_average;
|
||||
float mouse[2];
|
||||
int first = 0;
|
||||
float zoomx, zoomy;
|
||||
|
||||
paint_stroke_add_sample(p, stroke, event->mval[0], event->mval[1]);
|
||||
paint_stroke_sample_average(stroke, &sample_average);
|
||||
|
||||
get_imapaint_zoom(C, &zoomx, &zoomy);
|
||||
stroke->zoom_2d = max_ff(zoomx, zoomy);
|
||||
|
||||
/* let NDOF motion pass through to the 3D view so we can paint and rotate simultaneously!
|
||||
* this isn't perfect... even when an extra MOUSEMOVE is spoofed, the stroke discards it
|
||||
* since the 2D deltas are zero -- code in this file needs to be updated to use the
|
||||
|
Loading…
Reference in New Issue
Block a user