Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_brush.c
| Context not available. | |||||
| GP_EditBrush_Data *brush = gso->brush; | GP_EditBrush_Data *brush = gso->brush; | ||||
| bGPDspoint *pt = &gps->points[i]; | bGPDspoint *pt = &gps->points[i]; | ||||
| float inf = gp_brush_influence_calc(gso, radius, co); | float inf = gp_brush_influence_calc(gso, radius, co); | ||||
| float pressure = 0.0f; | |||||
| float sco[3] = {0.0f}; | |||||
| /* Do nothing if not enough points to smooth out */ | /* perform smoothing */ | ||||
| if (gps->totpoints <= 2) { | return gp_smooth_stroke(gps, i, inf); | ||||
| return false; | |||||
| } | |||||
| /* Only affect endpoints by a fraction of the normal strength, | |||||
| * to prevent the stroke from shrinking too much | |||||
| */ | |||||
| if ((i == 0) || (i == gps->totpoints - 1)) { | |||||
| inf *= 0.1f; | |||||
| } | |||||
| /* Compute smoothed coordinate by taking the ones nearby */ | |||||
| /* XXX: This is potentially slow, and suffers from accumulation error as earlier points are handled before later ones */ | |||||
| { | |||||
| // XXX: this is hardcoded to look at 2 points on either side of the current one (i.e. 5 items total) | |||||
| const int steps = 2; | |||||
| const float average_fac = 1.0f / (float)(steps * 2 + 1); | |||||
| int step; | |||||
| /* add the point itself */ | |||||
| madd_v3_v3fl(sco, &pt->x, average_fac); | |||||
| if (brush->flag & GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE) { | |||||
| pressure += pt->pressure * average_fac; | |||||
| } | |||||
| /* n-steps before/after current point */ | |||||
| // XXX: review how the endpoints are treated by this algorithm | |||||
| // XXX: falloff measures should also introduce some weighting variations, so that further-out points get less weight | |||||
| for (step = 1; step <= steps; step++) { | |||||
| bGPDspoint *pt1, *pt2; | |||||
| int before = i - step; | |||||
| int after = i + step; | |||||
| CLAMP_MIN(before, 0); | |||||
| CLAMP_MAX(after, gps->totpoints - 1); | |||||
| pt1 = &gps->points[before]; | |||||
| pt2 = &gps->points[after]; | |||||
| /* add both these points to the average-sum (s += p[i]/n) */ | |||||
| madd_v3_v3fl(sco, &pt1->x, average_fac); | |||||
| madd_v3_v3fl(sco, &pt2->x, average_fac); | |||||
| /* do pressure too? */ | |||||
| if (brush->flag & GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE) { | |||||
| pressure += pt1->pressure * average_fac; | |||||
| pressure += pt2->pressure * average_fac; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* Based on influence factor, blend between original and optimal smoothed coordinate */ | |||||
| interp_v3_v3v3(&pt->x, &pt->x, sco, inf); | |||||
| if (brush->flag & GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE) { | |||||
| pt->pressure = pressure; | |||||
| } | |||||
| return true; | |||||
| } | } | ||||
| /* ----------------------------------------------- */ | /* ----------------------------------------------- */ | ||||
| Context not available. | |||||