GPencil: Fix unreported problems with Chisel brush

With the new sampling, the arc points were not using the angle of the brush and the line was with the same thickness in all orientations.
This commit is contained in:
Antonio Vazquez 2020-04-07 20:07:58 +02:00
parent 6b58571813
commit 7b4b07a7dd
1 changed files with 33 additions and 0 deletions

View File

@ -3127,6 +3127,34 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
return op->customdata;
}
/* Apply pressure change depending of the angle of the stroke for a segment. */
static void gp_brush_angle_segment(tGPsdata *p, tGPspoint *pt_prev, tGPspoint *pt)
{
Brush *brush = p->brush;
/* Sensitivity. */
const float sen = brush->gpencil_settings->draw_angle_factor;
/* Default angle of brush in radians */
const float angle = brush->gpencil_settings->draw_angle;
float mvec[2];
float fac;
float mpressure;
/* angle vector of the brush with full thickness */
float v0[2] = {cos(angle), sin(angle)};
mvec[0] = pt->x - pt_prev->x;
mvec[1] = pt->y - pt_prev->y;
normalize_v2(mvec);
fac = 1.0f - fabs(dot_v2v2(v0, mvec)); /* 0.0 to 1.0 */
/* interpolate with previous point for smoother transitions */
mpressure = interpf(pt->pressure - (sen * fac), pt_prev->pressure, 0.3f);
pt->pressure = mpressure;
CLAMP(pt->pressure, pt_prev->pressure * 0.5f, 1.0f);
}
/* Add arc points between two mouse events using the previous segment to determine the vertice of
* the arc.
* /+ CTL
@ -3209,6 +3237,11 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
pt->pressure = pt_prev->pressure;
pt->strength = pt_prev->strength;
/* Apply angle of stroke to brush size. */
if (brush_settings->draw_angle_factor != 0.0f) {
gp_brush_angle_segment(p, pt_prev, pt);
}
/* Apply randomness to pressure. */
if (brush_settings->draw_random_press > 0.0f) {
float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;