Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_paint.c
| Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | typedef struct tGPsdata { | ||||
| short shift; | short shift; | ||||
| /** size in pixels for uv calculation */ | /** size in pixels for uv calculation */ | ||||
| float totpixlen; | float totpixlen; | ||||
| /* guide */ | /* guide */ | ||||
| tGPguide guide; | tGPguide guide; | ||||
| ReportList *reports; | ReportList *reports; | ||||
| /** Random settings by stroke */ | |||||
| GpRandomSettings random_settings; | |||||
| } tGPsdata; | } tGPsdata; | ||||
| /* ------ */ | /* ------ */ | ||||
| #define STROKE_HORIZONTAL 1 | #define STROKE_HORIZONTAL 1 | ||||
| #define STROKE_VERTICAL 2 | #define STROKE_VERTICAL 2 | ||||
| /* Macros for accessing sensitivity thresholds... */ | /* Macros for accessing sensitivity thresholds... */ | ||||
| ▲ Show 20 Lines • Show All 419 Lines • ▼ Show 20 Lines | for (int i = from_idx; i < to_idx + 1; i++) { | ||||
| /* Interpolate pressure. */ | /* Interpolate pressure. */ | ||||
| ptc->pressure = interpf(ptc->pressure, pressure, inf); | ptc->pressure = interpf(ptc->pressure, pressure, inf); | ||||
| /* Interpolate strength. */ | /* Interpolate strength. */ | ||||
| ptc->strength = interpf(ptc->strength, strength, inf); | ptc->strength = interpf(ptc->strength, strength, inf); | ||||
| } | } | ||||
| } | } | ||||
| static void gp_apply_randomness(tGPsdata *p, | |||||
| BrushGpencilSettings *brush_settings, | |||||
| tGPspoint *pt, | |||||
| const bool press, | |||||
| const bool strength, | |||||
| const bool uv) | |||||
| { | |||||
| bGPdata *gpd = p->gpd; | |||||
| GpRandomSettings random_settings = p->random_settings; | |||||
| float value = 0.0f; | |||||
| /* Apply randomness to pressure. */ | |||||
| if ((brush_settings->draw_random_press > 0.0f) && (press)) { | |||||
| if ((brush_settings->flag2 & GP_BRUSH_USE_PRESS_AT_STROKE) == 0) { | |||||
| float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | |||||
| value = 1.0 + rand * 2.0 * brush_settings->draw_random_press; | |||||
| } | |||||
| else { | |||||
| value = 1.0 + random_settings.pressure * brush_settings->draw_random_press; | |||||
| } | |||||
| /* Apply random curve. */ | |||||
| if (brush_settings->flag2 & GP_BRUSH_USE_PRESSURE_RAND_PRESS) { | |||||
| value *= BKE_curvemapping_evaluateF( | |||||
| brush_settings->curve_rand_pressure, 0, random_settings.pen_press); | |||||
| } | |||||
| pt->pressure *= value; | |||||
| CLAMP(pt->pressure, 0.1f, 1.0f); | |||||
| } | |||||
| /* Apply randomness to color strength. */ | |||||
| if ((brush_settings->draw_random_strength) && (strength)) { | |||||
| if ((brush_settings->flag2 & GP_BRUSH_USE_STRENGTH_AT_STROKE) == 0) { | |||||
| float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | |||||
| value = 1.0 + rand * brush_settings->draw_random_strength; | |||||
| } | |||||
| else { | |||||
| value = 1.0 + random_settings.strength * brush_settings->draw_random_strength; | |||||
| } | |||||
| /* Apply random curve. */ | |||||
| if (brush_settings->flag2 & GP_BRUSH_USE_STRENGTH_RAND_PRESS) { | |||||
| value *= BKE_curvemapping_evaluateF( | |||||
| brush_settings->curve_rand_pressure, 0, random_settings.pen_press); | |||||
| } | |||||
| pt->strength *= value; | |||||
| CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | |||||
| } | |||||
| /* Apply randomness to uv texture rotation. */ | |||||
| if ((brush_settings->uv_random > 0.0f) && (uv)) { | |||||
| if ((brush_settings->flag2 & GP_BRUSH_USE_UV_AT_STROKE) == 0) { | |||||
| float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) * 2.0f - | |||||
| 1.0f; | |||||
| value = rand * M_PI_2 * brush_settings->uv_random; | |||||
| } | |||||
| else { | |||||
| value = random_settings.uv * M_PI_2 * brush_settings->uv_random; | |||||
| } | |||||
| /* Apply random curve. */ | |||||
| if (brush_settings->flag2 & GP_BRUSH_USE_UV_RAND_PRESS) { | |||||
| value *= BKE_curvemapping_evaluateF( | |||||
| brush_settings->curve_rand_uv, 0, random_settings.pen_press); | |||||
| } | |||||
| pt->uv_rot += value; | |||||
| CLAMP(pt->uv_rot, -M_PI_2, M_PI_2); | |||||
| } | |||||
| } | |||||
| /* add current stroke-point to buffer (returns whether point was successfully added) */ | /* add current stroke-point to buffer (returns whether point was successfully added) */ | ||||
| static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure, double curtime) | static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure, double curtime) | ||||
| { | { | ||||
| bGPdata *gpd = p->gpd; | bGPdata *gpd = p->gpd; | ||||
| Brush *brush = p->brush; | Brush *brush = p->brush; | ||||
| BrushGpencilSettings *brush_settings = p->brush->gpencil_settings; | BrushGpencilSettings *brush_settings = p->brush->gpencil_settings; | ||||
| tGPspoint *pt; | tGPspoint *pt; | ||||
| Object *obact = (Object *)p->ownerPtr.data; | Object *obact = (Object *)p->ownerPtr.data; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */ | ||||
| gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( | gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( | ||||
| gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false); | gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false); | ||||
| /* Check the buffer was created. */ | /* Check the buffer was created. */ | ||||
| if (gpd->runtime.sbuffer == NULL) { | if (gpd->runtime.sbuffer == NULL) { | ||||
| return GP_STROKEADD_INVALID; | return GP_STROKEADD_INVALID; | ||||
| } | } | ||||
| /* Set vertex colors for buffer. */ | |||||
| ED_gpencil_sbuffer_vertex_color_set( | |||||
| p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material); | |||||
| /* get pointer to destination point */ | /* get pointer to destination point */ | ||||
| pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used); | pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used); | ||||
| /* store settings */ | /* store settings */ | ||||
| pt->strength = brush_settings->draw_strength; | pt->strength = brush_settings->draw_strength; | ||||
| pt->pressure = 1.0f; | pt->pressure = 1.0f; | ||||
| pt->uv_rot = 0.0f; | pt->uv_rot = 0.0f; | ||||
| copy_v2_v2(&pt->x, mval); | copy_v2_v2(&pt->x, mval); | ||||
| /* pressure */ | /* pressure */ | ||||
| if (brush_settings->flag & GP_BRUSH_USE_PRESSURE) { | if (brush_settings->flag & GP_BRUSH_USE_PRESSURE) { | ||||
| pt->pressure *= BKE_curvemapping_evaluateF(brush_settings->curve_sensitivity, 0, pressure); | pt->pressure *= BKE_curvemapping_evaluateF(brush_settings->curve_sensitivity, 0, pressure); | ||||
| } | } | ||||
| /* color strength */ | /* color strength */ | ||||
| if (brush_settings->flag & GP_BRUSH_USE_STENGTH_PRESSURE) { | if (brush_settings->flag & GP_BRUSH_USE_STENGTH_PRESSURE) { | ||||
| pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); | pt->strength *= BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, pressure); | ||||
| CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| } | } | ||||
| /* Set vertex colors for buffer. */ | |||||
| ED_gpencil_sbuffer_vertex_color_set(p->depsgraph, | |||||
| p->ob, | |||||
| p->scene->toolsettings, | |||||
| p->brush, | |||||
| p->material, | |||||
| p->random_settings.hsv, | |||||
| p->random_settings.pen_press); | |||||
| if (brush_settings->flag & GP_BRUSH_GROUP_RANDOM) { | if (brush_settings->flag & GP_BRUSH_GROUP_RANDOM) { | ||||
| /* Apply jitter to position */ | /* Apply jitter to position */ | ||||
| if (brush_settings->draw_jitter > 0.0f) { | if (brush_settings->draw_jitter > 0.0f) { | ||||
| float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | ||||
| float jitpress = 1.0f; | float jitpress = 1.0f; | ||||
| if (brush_settings->flag & GP_BRUSH_USE_JITTER_PRESSURE) { | if (brush_settings->flag & GP_BRUSH_USE_JITTER_PRESSURE) { | ||||
| jitpress = BKE_curvemapping_evaluateF(brush_settings->curve_jitter, 0, pressure); | jitpress = BKE_curvemapping_evaluateF(brush_settings->curve_jitter, 0, pressure); | ||||
| } | } | ||||
| /* FIXME the +2 means minimum jitter is 4 which is a bit strange for UX. */ | /* FIXME the +2 means minimum jitter is 4 which is a bit strange for UX. */ | ||||
| const float exp_factor = brush_settings->draw_jitter + 2.0f; | const float exp_factor = brush_settings->draw_jitter + 2.0f; | ||||
| const float fac = rand * square_f(exp_factor) * jitpress; | const float fac = rand * square_f(exp_factor) * jitpress; | ||||
| gp_brush_jitter(gpd, pt, fac); | gp_brush_jitter(gpd, pt, fac); | ||||
| } | } | ||||
| /* apply randomness to pressure */ | |||||
| if (brush_settings->draw_random_press > 0.0f) { | /* Apply other randomness. */ | ||||
| float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | gp_apply_randomness(p, brush_settings, pt, true, true, true); | ||||
| pt->pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press; | |||||
| CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f); | |||||
| } | |||||
| /* apply randomness to uv texture rotation */ | |||||
| if (brush_settings->uv_random > 0.0f) { | |||||
| float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) * | |||||
| 2.0f - | |||||
| 1.0f; | |||||
| pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random; | |||||
| CLAMP(pt->uv_rot, -M_PI_2, M_PI_2); | |||||
| } | |||||
| /* apply randomness to color strength */ | |||||
| if (brush_settings->draw_random_strength) { | |||||
| float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | |||||
| pt->strength *= 1.0 + rand * brush_settings->draw_random_strength; | |||||
| CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | |||||
| } | |||||
| } | } | ||||
| /* apply angle of stroke to brush size */ | /* apply angle of stroke to brush size */ | ||||
| if (brush_settings->draw_angle_factor != 0.0f) { | if (brush_settings->draw_angle_factor != 0.0f) { | ||||
| gp_brush_angle(gpd, brush, pt, mval); | gp_brush_angle(gpd, brush, pt, mval); | ||||
| } | } | ||||
| /* point time */ | /* point time */ | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | /* straight lines only -> only endpoints */ | ||||
| ptc = gpd->runtime.sbuffer; | ptc = gpd->runtime.sbuffer; | ||||
| /* convert screen-coordinates to appropriate coordinates (and store them) */ | /* convert screen-coordinates to appropriate coordinates (and store them) */ | ||||
| gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL); | gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL); | ||||
| /* copy pressure and time */ | /* copy pressure and time */ | ||||
| pt->pressure = ptc->pressure; | pt->pressure = ptc->pressure; | ||||
| pt->strength = ptc->strength; | pt->strength = ptc->strength; | ||||
| CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| copy_v4_v4(pt->vert_color, ptc->vert_color); | |||||
| pt->time = ptc->time; | pt->time = ptc->time; | ||||
| /* Apply the vertex color to point. */ | /* Apply the vertex color to point. */ | ||||
| ED_gpencil_point_vertex_color_set(ts, brush, pt); | ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); | ||||
| pt++; | pt++; | ||||
| if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) { | if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) { | ||||
| BKE_gpencil_dvert_ensure(gps); | BKE_gpencil_dvert_ensure(gps); | ||||
| MDeformWeight *dw = BKE_defvert_ensure_index(dvert, def_nr); | MDeformWeight *dw = BKE_defvert_ensure_index(dvert, def_nr); | ||||
| if (dw) { | if (dw) { | ||||
| dw->weight = ts->vgroup_weight; | dw->weight = ts->vgroup_weight; | ||||
| Show All 16 Lines | if (totelem == 2) { | ||||
| /* convert screen-coordinates to appropriate coordinates (and store them) */ | /* convert screen-coordinates to appropriate coordinates (and store them) */ | ||||
| gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL); | gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL); | ||||
| /* copy pressure and time */ | /* copy pressure and time */ | ||||
| pt->pressure = ptc->pressure; | pt->pressure = ptc->pressure; | ||||
| pt->strength = ptc->strength; | pt->strength = ptc->strength; | ||||
| CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| pt->time = ptc->time; | pt->time = ptc->time; | ||||
| /* Apply the vertex color to point. */ | /* Apply the vertex color to point. */ | ||||
| ED_gpencil_point_vertex_color_set(ts, brush, pt); | ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); | ||||
| if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) { | if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) { | ||||
| BKE_gpencil_dvert_ensure(gps); | BKE_gpencil_dvert_ensure(gps); | ||||
| MDeformWeight *dw = BKE_defvert_ensure_index(dvert, def_nr); | MDeformWeight *dw = BKE_defvert_ensure_index(dvert, def_nr); | ||||
| if (dw) { | if (dw) { | ||||
| dw->weight = ts->vgroup_weight; | dw->weight = ts->vgroup_weight; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc; | ||||
| i++, ptc++, pt++) { | i++, ptc++, pt++) { | ||||
| /* convert screen-coordinates to appropriate coordinates (and store them) */ | /* convert screen-coordinates to appropriate coordinates (and store them) */ | ||||
| gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL); | gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL); | ||||
| /* copy pressure and time */ | /* copy pressure and time */ | ||||
| pt->pressure = ptc->pressure; | pt->pressure = ptc->pressure; | ||||
| pt->strength = ptc->strength; | pt->strength = ptc->strength; | ||||
| CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| copy_v4_v4(pt->vert_color, ptc->vert_color); | |||||
| pt->time = ptc->time; | pt->time = ptc->time; | ||||
| pt->uv_fac = ptc->uv_fac; | pt->uv_fac = ptc->uv_fac; | ||||
| pt->uv_rot = ptc->uv_rot; | pt->uv_rot = ptc->uv_rot; | ||||
| /* Apply the vertex color to point. */ | /* Apply the vertex color to point. */ | ||||
| ED_gpencil_point_vertex_color_set(ts, brush, pt); | ED_gpencil_point_vertex_color_set(ts, brush, pt, ptc); | ||||
| if (dvert != NULL) { | if (dvert != NULL) { | ||||
| dvert->totweight = 0; | dvert->totweight = 0; | ||||
| dvert->dw = NULL; | dvert->dw = NULL; | ||||
| dvert++; | dvert++; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 617 Lines • ▼ Show 20 Lines | static void gp_init_drawing_brush(bContext *C, tGPsdata *p) | ||||
| Paint *paint = &ts->gp_paint->paint; | Paint *paint = &ts->gp_paint->paint; | ||||
| bool changed = false; | bool changed = false; | ||||
| /* if not exist, create a new one */ | /* if not exist, create a new one */ | ||||
| if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) { | if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) { | ||||
| /* create new brushes */ | /* create new brushes */ | ||||
| BKE_brush_gpencil_paint_presets(bmain, ts); | BKE_brush_gpencil_paint_presets(bmain, ts); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| /* be sure curves are initializated */ | /* Be sure curves are initializated. */ | ||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_sensitivity); | BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_sensitivity); | ||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_strength); | BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_strength); | ||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_jitter); | BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_jitter); | ||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_pressure); | |||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_strength); | |||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_uv); | |||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_hue); | |||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_saturation); | |||||
| BKE_curvemapping_initialize(paint->brush->gpencil_settings->curve_rand_value); | |||||
| /* assign to temp tGPsdata */ | /* assign to temp tGPsdata */ | ||||
| p->brush = paint->brush; | p->brush = paint->brush; | ||||
| if (paint->brush->gpencil_tool != GPAINT_TOOL_ERASE) { | if (paint->brush->gpencil_tool != GPAINT_TOOL_ERASE) { | ||||
| p->eraser = gp_get_default_eraser(p->bmain, ts); | p->eraser = gp_get_default_eraser(p->bmain, ts); | ||||
| } | } | ||||
| else { | else { | ||||
| p->eraser = paint->brush; | p->eraser = paint->brush; | ||||
| ▲ Show 20 Lines • Show All 929 Lines • ▼ Show 20 Lines | if (p->straight == 0) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| p->curtime = PIL_check_seconds_timer(); | p->curtime = PIL_check_seconds_timer(); | ||||
| /* handle pressure sensitivity (which is supplied by tablets or otherwise 1.0) */ | /* handle pressure sensitivity (which is supplied by tablets or otherwise 1.0) */ | ||||
| p->pressure = event->tablet.pressure; | p->pressure = event->tablet.pressure; | ||||
| /* By default use pen pressure for random curves but attenuated. */ | |||||
| p->random_settings.pen_press = pow(p->pressure, 3.0f); | |||||
| /* Hack for pressure sensitive eraser on D+RMB when using a tablet: | /* Hack for pressure sensitive eraser on D+RMB when using a tablet: | ||||
| * The pen has to float over the tablet surface, resulting in | * The pen has to float over the tablet surface, resulting in | ||||
| * zero pressure (T47101). Ignore pressure values if floating | * zero pressure (T47101). Ignore pressure values if floating | ||||
| * (i.e. "effectively zero" pressure), and only when the "active" | * (i.e. "effectively zero" pressure), and only when the "active" | ||||
| * end is the stylus (i.e. the default when not eraser) | * end is the stylus (i.e. the default when not eraser) | ||||
| */ | */ | ||||
| if (p->paintmode == GP_PAINTMODE_ERASER) { | if (p->paintmode == GP_PAINTMODE_ERASER) { | ||||
| ▲ Show 20 Lines • Show All 336 Lines • ▼ Show 20 Lines | if (!gpencil_draw_init(C, op, event)) { | ||||
| if (G.debug & G_DEBUG) { | if (G.debug & G_DEBUG) { | ||||
| printf("\tGP - no valid data\n"); | printf("\tGP - no valid data\n"); | ||||
| } | } | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else { | else { | ||||
| p = op->customdata; | p = op->customdata; | ||||
| } | } | ||||
| /* Init random settings. */ | |||||
| ED_gpencil_init_random_settings(p->brush, event->mval, &p->random_settings); | |||||
| /* TODO: set any additional settings that we can take from the events? | /* TODO: set any additional settings that we can take from the events? | ||||
| * if eraser is on, draw radial aid */ | * if eraser is on, draw radial aid */ | ||||
| if (p->paintmode == GP_PAINTMODE_ERASER) { | if (p->paintmode == GP_PAINTMODE_ERASER) { | ||||
| gpencil_draw_toggle_eraser_cursor(C, p, true); | gpencil_draw_toggle_eraser_cursor(C, p, true); | ||||
| } | } | ||||
| else { | else { | ||||
| ED_gpencil_toggle_brush_cursor(C, true, NULL); | ED_gpencil_toggle_brush_cursor(C, true, NULL); | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
| * / | * / | ||||
| * / | * / | ||||
| * + PtA - 1 | * + PtA - 1 | ||||
| * / | * / | ||||
| * CTL is the vertice of the triangle created between PtA and PtB */ | * CTL is the vertice of the triangle created between PtA and PtB */ | ||||
| static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments) | static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments) | ||||
| { | { | ||||
| bGPdata *gpd = p->gpd; | bGPdata *gpd = p->gpd; | ||||
| BrushGpencilSettings *brush_settings = p->brush->gpencil_settings; | |||||
| if (gpd->runtime.sbuffer_used < 3) { | if (gpd->runtime.sbuffer_used < 3) { | ||||
| tGPspoint *points = (tGPspoint *)gpd->runtime.sbuffer; | |||||
| /* Apply other randomness to first points. */ | |||||
| for (int i = 0; i < gpd->runtime.sbuffer_used; i++) { | |||||
| tGPspoint *pt = &points[i]; | |||||
| gp_apply_randomness(p, brush_settings, pt, false, false, true); | |||||
| } | |||||
| return; | return; | ||||
| } | } | ||||
| BrushGpencilSettings *brush_settings = p->brush->gpencil_settings; | |||||
| int idx_prev = gpd->runtime.sbuffer_used; | int idx_prev = gpd->runtime.sbuffer_used; | ||||
| /* Add space for new arc points. */ | /* Add space for new arc points. */ | ||||
| gpd->runtime.sbuffer_used += segments - 1; | gpd->runtime.sbuffer_used += segments - 1; | ||||
| /* Check if still room in buffer or add more. */ | /* Check if still room in buffer or add more. */ | ||||
| gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( | gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( | ||||
| gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false); | gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false); | ||||
| Show All 38 Lines | static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments) | ||||
| float midpoint[2], start[2], end[2], cp1[2], corner[2]; | float midpoint[2], start[2], end[2], cp1[2], corner[2]; | ||||
| mid_v2_v2v2(midpoint, &pt_prev->x, mval); | mid_v2_v2v2(midpoint, &pt_prev->x, mval); | ||||
| copy_v2_v2(start, &pt_prev->x); | copy_v2_v2(start, &pt_prev->x); | ||||
| copy_v2_v2(end, mval); | copy_v2_v2(end, mval); | ||||
| copy_v2_v2(cp1, ctl); | copy_v2_v2(cp1, ctl); | ||||
| corner[0] = midpoint[0] - (cp1[0] - midpoint[0]); | corner[0] = midpoint[0] - (cp1[0] - midpoint[0]); | ||||
| corner[1] = midpoint[1] - (cp1[1] - midpoint[1]); | corner[1] = midpoint[1] - (cp1[1] - midpoint[1]); | ||||
| float stepcolor = 1.0f / segments; | |||||
| for (int i = 0; i < segments; i++) { | for (int i = 0; i < segments; i++) { | ||||
| pt = &points[idx_prev + i - 1]; | pt = &points[idx_prev + i - 1]; | ||||
| pt->x = corner[0] + (end[0] - corner[0]) * sinf(a) + (start[0] - corner[0]) * cosf(a); | pt->x = corner[0] + (end[0] - corner[0]) * sinf(a) + (start[0] - corner[0]) * cosf(a); | ||||
| pt->y = corner[1] + (end[1] - corner[1]) * sinf(a) + (start[1] - corner[1]) * cosf(a); | pt->y = corner[1] + (end[1] - corner[1]) * sinf(a) + (start[1] - corner[1]) * cosf(a); | ||||
| /* Set pressure and strength equals to previous. It will be smoothed later. */ | /* Set pressure and strength equals to previous. It will be smoothed later. */ | ||||
| pt->pressure = pt_prev->pressure; | pt->pressure = pt_prev->pressure; | ||||
| pt->strength = pt_prev->strength; | pt->strength = pt_prev->strength; | ||||
| /* Interpolate vertex color. */ | |||||
| interp_v4_v4v4( | |||||
| pt->vert_color, pt_before->vert_color, pt_prev->vert_color, stepcolor * (i + 1)); | |||||
| /* Apply angle of stroke to brush size. */ | /* Apply angle of stroke to brush size. */ | ||||
| if (brush_settings->draw_angle_factor != 0.0f) { | if (brush_settings->draw_angle_factor != 0.0f) { | ||||
| gp_brush_angle_segment(p, pt_prev, pt); | gp_brush_angle_segment(p, pt_prev, pt); | ||||
| } | } | ||||
| /* Apply randomness to pressure. */ | /* Apply other randomness. */ | ||||
| if (brush_settings->draw_random_press > 0.0f) { | gp_apply_randomness(p, brush_settings, pt, false, false, true); | ||||
| float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | |||||
| pt->pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press; | |||||
| CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f); | |||||
| } | |||||
| /* Apply randomness to color strength. */ | |||||
| if (brush_settings->draw_random_strength) { | |||||
| float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f; | |||||
| pt->strength *= 1.0 + rand * brush_settings->draw_random_strength; | |||||
| CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f); | |||||
| } | |||||
| /* Apply randomness to uv texture rotation. */ | |||||
| if (brush_settings->uv_random > 0.0f) { | |||||
| float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used + i)) * | |||||
| 2.0f - | |||||
| 1.0f; | |||||
| pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random; | |||||
| CLAMP(pt->uv_rot, -M_PI_2, M_PI_2); | |||||
| } | |||||
| a += step; | a += step; | ||||
| } | } | ||||
| } | } | ||||
| static void gpencil_add_guide_points(const tGPsdata *p, | static void gpencil_add_guide_points(const tGPsdata *p, | ||||
| const GP_Sculpt_Guide *guide, | const GP_Sculpt_Guide *guide, | ||||
| const float start[2], | const float start[2], | ||||
| Show All 35 Lines | for (int i = 0; i < segments; i++) { | ||||
| gp_rotate_v2_v2v2fl(&pt->x, start, p->guide.origin, -a); | gp_rotate_v2_v2v2fl(&pt->x, start, p->guide.origin, -a); | ||||
| gpencil_snap_to_guide(p, guide, &pt->x); | gpencil_snap_to_guide(p, guide, &pt->x); | ||||
| a += step; | a += step; | ||||
| /* Set pressure and strength equals to previous. It will be smoothed later. */ | /* Set pressure and strength equals to previous. It will be smoothed later. */ | ||||
| pt->pressure = pt_before->pressure; | pt->pressure = pt_before->pressure; | ||||
| pt->strength = pt_before->strength; | pt->strength = pt_before->strength; | ||||
| copy_v4_v4(pt->vert_color, pt_before->vert_color); | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| float step = 1.0f / (float)(segments + 1); | float step = 1.0f / (float)(segments + 1); | ||||
| float a = step; | float a = step; | ||||
| for (int i = 0; i < segments; i++) { | for (int i = 0; i < segments; i++) { | ||||
| pt = &points[idx_prev + i - 1]; | pt = &points[idx_prev + i - 1]; | ||||
| interp_v2_v2v2(&pt->x, start, end, a); | interp_v2_v2v2(&pt->x, start, end, a); | ||||
| gpencil_snap_to_guide(p, guide, &pt->x); | gpencil_snap_to_guide(p, guide, &pt->x); | ||||
| a += step; | a += step; | ||||
| /* Set pressure and strength equals to previous. It will be smoothed later. */ | /* Set pressure and strength equals to previous. It will be smoothed later. */ | ||||
| pt->pressure = pt_before->pressure; | pt->pressure = pt_before->pressure; | ||||
| pt->strength = pt_before->strength; | pt->strength = pt_before->strength; | ||||
| copy_v4_v4(pt->vert_color, pt_before->vert_color); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Add fake points for missing mouse movements when the artist draw very fast creating an arc | * Add fake points for missing mouse movements when the artist draw very fast creating an arc | ||||
| * with the vertex in the middle of the segment and using the angle of the previous segment. | * with the vertex in the middle of the segment and using the angle of the previous segment. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 505 Lines • Show Last 20 Lines | |||||