Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_primitive.c
| Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | static void gp_session_validatebuffer(tGPDprimitive *p) | ||||
| 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, true); | gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, true); | ||||
| /* reset flags */ | /* reset flags */ | ||||
| gpd->runtime.sbuffer_sflag = 0; | gpd->runtime.sbuffer_sflag = 0; | ||||
| gpd->runtime.sbuffer_sflag |= GP_STROKE_3DSPACE; | gpd->runtime.sbuffer_sflag |= GP_STROKE_3DSPACE; | ||||
| /* Set vertex colors for buffer. */ | /* Set vertex colors for buffer. */ | ||||
| ED_gpencil_sbuffer_vertex_color_set( | ED_gpencil_sbuffer_vertex_color_set(p->depsgraph, | ||||
| p->depsgraph, p->ob, p->scene->toolsettings, p->brush, p->material); | p->ob, | ||||
| p->scene->toolsettings, | |||||
| p->brush, | |||||
| p->material, | |||||
| p->random_settings.hsv, | |||||
| 1.0f); | |||||
| if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) { | if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) { | ||||
| gpd->runtime.sbuffer_sflag |= GP_STROKE_CYCLIC; | gpd->runtime.sbuffer_sflag |= GP_STROKE_CYCLIC; | ||||
| } | } | ||||
| } | } | ||||
| static void gp_init_colors(tGPDprimitive *p) | static void gp_init_colors(tGPDprimitive *p) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 539 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* Helper: Update shape of the stroke */ | /* Helper: Update shape of the stroke */ | ||||
| static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) | static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) | ||||
| { | { | ||||
| ToolSettings *ts = tgpi->scene->toolsettings; | ToolSettings *ts = tgpi->scene->toolsettings; | ||||
| bGPdata *gpd = tgpi->gpd; | bGPdata *gpd = tgpi->gpd; | ||||
| Brush *brush = tgpi->brush; | Brush *brush = tgpi->brush; | ||||
| BrushGpencilSettings *brush_settings = brush->gpencil_settings; | |||||
| GpRandomSettings random_settings = tgpi->random_settings; | |||||
| bGPDstroke *gps = tgpi->gpf->strokes.first; | bGPDstroke *gps = tgpi->gpf->strokes.first; | ||||
| GP_Sculpt_Settings *gset = &ts->gp_sculpt; | GP_Sculpt_Settings *gset = &ts->gp_sculpt; | ||||
| int depth_margin = (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 4 : 0; | int depth_margin = (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 4 : 0; | ||||
| const char *align_flag = &ts->gpencil_v3d_align; | const char *align_flag = &ts->gpencil_v3d_align; | ||||
| bool is_depth = (bool)(*align_flag & (GP_PROJECT_DEPTH_VIEW | GP_PROJECT_DEPTH_STROKE)); | bool is_depth = (bool)(*align_flag & (GP_PROJECT_DEPTH_VIEW | GP_PROJECT_DEPTH_STROKE)); | ||||
| const bool is_camera = (bool)(ts->gp_sculpt.lock_axis == 0) && | const bool is_camera = (bool)(ts->gp_sculpt.lock_axis == 0) && | ||||
| (tgpi->rv3d->persp == RV3D_CAMOB) && (!is_depth); | (tgpi->rv3d->persp == RV3D_CAMOB) && (!is_depth); | ||||
| Show All 38 Lines | static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) | ||||
| } | } | ||||
| /* convert screen-coordinates to 3D coordinates */ | /* convert screen-coordinates to 3D coordinates */ | ||||
| gp_session_validatebuffer(tgpi); | gp_session_validatebuffer(tgpi); | ||||
| gp_init_colors(tgpi); | gp_init_colors(tgpi); | ||||
| if (gset->flag & GP_SCULPT_SETT_FLAG_PRIMITIVE_CURVE) { | if (gset->flag & GP_SCULPT_SETT_FLAG_PRIMITIVE_CURVE) { | ||||
| BKE_curvemapping_initialize(ts->gp_sculpt.cur_primitive); | BKE_curvemapping_initialize(ts->gp_sculpt.cur_primitive); | ||||
| } | } | ||||
| if (tgpi->brush->gpencil_settings->flag & GP_BRUSH_USE_JITTER_PRESSURE) { | if (brush_settings->flag & GP_BRUSH_USE_JITTER_PRESSURE) { | ||||
| BKE_curvemapping_initialize(tgpi->brush->gpencil_settings->curve_jitter); | BKE_curvemapping_initialize(brush_settings->curve_jitter); | ||||
| } | } | ||||
| if (tgpi->brush->gpencil_settings->flag & GP_BRUSH_USE_STENGTH_PRESSURE) { | if (brush_settings->flag & GP_BRUSH_USE_STENGTH_PRESSURE) { | ||||
| BKE_curvemapping_initialize(tgpi->brush->gpencil_settings->curve_strength); | BKE_curvemapping_initialize(brush_settings->curve_strength); | ||||
| } | } | ||||
| /* get an array of depths, far depths are blended */ | /* get an array of depths, far depths are blended */ | ||||
| float *depth_arr = NULL; | float *depth_arr = NULL; | ||||
| if (is_depth) { | if (is_depth) { | ||||
| int i; | int i; | ||||
| int mval_i[2], mval_prev[2] = {0}; | int mval_i[2], mval_prev[2] = {0}; | ||||
| bool interp_depth = false; | bool interp_depth = false; | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) | ||||
| } | } | ||||
| /* load stroke points and sbuffer */ | /* load stroke points and sbuffer */ | ||||
| for (int i = 0; i < gps->totpoints; i++) { | for (int i = 0; i < gps->totpoints; i++) { | ||||
| bGPDspoint *pt = &gps->points[i]; | bGPDspoint *pt = &gps->points[i]; | ||||
| tGPspoint *p2d = &points2D[i]; | tGPspoint *p2d = &points2D[i]; | ||||
| /* set rnd value for reuse */ | /* set rnd value for reuse */ | ||||
| if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && (p2d->rnd_dirty != true)) { | if ((brush_settings->flag & GP_BRUSH_GROUP_RANDOM) && (p2d->rnd_dirty != true)) { | ||||
| p2d->rnd[0] = BLI_rng_get_float(tgpi->rng); | p2d->rnd[0] = BLI_rng_get_float(tgpi->rng); | ||||
| p2d->rnd[1] = BLI_rng_get_float(tgpi->rng); | p2d->rnd[1] = BLI_rng_get_float(tgpi->rng); | ||||
| p2d->rnd[2] = BLI_rng_get_float(tgpi->rng); | |||||
| p2d->rnd_dirty = true; | p2d->rnd_dirty = true; | ||||
| } | } | ||||
| /* Copy points to buffer */ | /* Copy points to buffer */ | ||||
| tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used); | tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used); | ||||
| /* Store original points */ | /* Store original points */ | ||||
| float tmp_xyp[2]; | float tmp_xyp[2]; | ||||
| copy_v2_v2(tmp_xyp, &p2d->x); | copy_v2_v2(tmp_xyp, &p2d->x); | ||||
| /* calc pressure */ | /* calc pressure */ | ||||
| float curve_pressure = 1.0; | float curve_pressure = 1.0; | ||||
| float pressure = 1.0; | float pressure = 1.0; | ||||
| float strength = brush->gpencil_settings->draw_strength; | float strength = brush_settings->draw_strength; | ||||
| /* normalize value to evaluate curve */ | /* normalize value to evaluate curve */ | ||||
| if (gset->flag & GP_SCULPT_SETT_FLAG_PRIMITIVE_CURVE) { | if (gset->flag & GP_SCULPT_SETT_FLAG_PRIMITIVE_CURVE) { | ||||
| float value = (float)i / (gps->totpoints - 1); | float value = (float)i / (gps->totpoints - 1); | ||||
| curve_pressure = BKE_curvemapping_evaluateF(gset->cur_primitive, 0, value); | curve_pressure = BKE_curvemapping_evaluateF(gset->cur_primitive, 0, value); | ||||
| pressure = curve_pressure; | pressure = curve_pressure; | ||||
| } | } | ||||
| /* apply jitter to position */ | /* apply jitter to position */ | ||||
| if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && | if ((brush_settings->flag & GP_BRUSH_GROUP_RANDOM) && (brush_settings->draw_jitter > 0.0f)) { | ||||
| (brush->gpencil_settings->draw_jitter > 0.0f)) { | |||||
| float jitter; | float jitter; | ||||
| if (brush->gpencil_settings->flag & GP_BRUSH_USE_JITTER_PRESSURE) { | if (brush_settings->flag & GP_BRUSH_USE_JITTER_PRESSURE) { | ||||
| jitter = BKE_curvemapping_evaluateF( | jitter = BKE_curvemapping_evaluateF(brush_settings->curve_jitter, 0, curve_pressure); | ||||
| brush->gpencil_settings->curve_jitter, 0, curve_pressure); | |||||
| } | } | ||||
| else { | else { | ||||
| jitter = brush->gpencil_settings->draw_jitter; | jitter = brush_settings->draw_jitter; | ||||
| } | } | ||||
| /* exponential value */ | /* exponential value */ | ||||
| const float exfactor = square_f(brush->gpencil_settings->draw_jitter + 2.0f); | const float exfactor = square_f(brush_settings->draw_jitter + 2.0f); | ||||
| const float fac = p2d->rnd[0] * exfactor * jitter; | const float fac = p2d->rnd[0] * exfactor * jitter; | ||||
| /* vector */ | /* vector */ | ||||
| float mvec[2], svec[2]; | float mvec[2], svec[2]; | ||||
| if (i > 0) { | if (i > 0) { | ||||
| mvec[0] = (p2d->x - (p2d - 1)->x); | mvec[0] = (p2d->x - (p2d - 1)->x); | ||||
| mvec[1] = (p2d->y - (p2d - 1)->y); | mvec[1] = (p2d->y - (p2d - 1)->y); | ||||
| normalize_v2(mvec); | normalize_v2(mvec); | ||||
| } | } | ||||
| else { | else { | ||||
| zero_v2(mvec); | zero_v2(mvec); | ||||
| } | } | ||||
| svec[0] = -mvec[1]; | svec[0] = -mvec[1]; | ||||
| svec[1] = mvec[0]; | svec[1] = mvec[0]; | ||||
| if (p2d->rnd[1] > 0.5f) { | if (p2d->rnd[1] > 0.5f) { | ||||
| mul_v2_fl(svec, -fac); | mul_v2_fl(svec, -fac); | ||||
| } | } | ||||
| else { | else { | ||||
| mul_v2_fl(svec, fac); | mul_v2_fl(svec, fac); | ||||
| } | } | ||||
| add_v2_v2(&p2d->x, svec); | add_v2_v2(&p2d->x, svec); | ||||
| } | } | ||||
| /* apply randomness to pressure */ | /* color strength */ | ||||
| if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && | if (brush_settings->flag & GP_BRUSH_USE_STENGTH_PRESSURE) { | ||||
| (brush->gpencil_settings->draw_random_press > 0.0f)) { | float curvef = BKE_curvemapping_evaluateF(brush_settings->curve_strength, 0, curve_pressure); | ||||
| if (p2d->rnd[0] > 0.5f) { | strength *= curvef; | ||||
| pressure -= (brush->gpencil_settings->draw_random_press * 2.0f) * p2d->rnd[1]; | strength *= brush_settings->draw_strength; | ||||
| } | } | ||||
| else { | |||||
| pressure += (brush->gpencil_settings->draw_random_press * 2.0f) * p2d->rnd[2]; | CLAMP(strength, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| if (brush_settings->flag & GP_BRUSH_GROUP_RANDOM) { | |||||
| /* Apply randomness to pressure. */ | |||||
| if (brush_settings->draw_random_press > 0.0f) { | |||||
| if ((brush_settings->flag2 & GP_BRUSH_USE_PRESS_AT_STROKE) == 0) { | |||||
| float rand = BLI_rng_get_float(tgpi->rng) * 2.0f - 1.0f; | |||||
| pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press; | |||||
| } | } | ||||
| else { | |||||
| pressure *= 1.0 + random_settings.pressure * brush_settings->draw_random_press; | |||||
| } | } | ||||
| /* color strength */ | /* Apply random curve. */ | ||||
| if (brush->gpencil_settings->flag & GP_BRUSH_USE_STENGTH_PRESSURE) { | if (brush_settings->flag2 & GP_BRUSH_USE_PRESSURE_RAND_PRESS) { | ||||
| float curvef = BKE_curvemapping_evaluateF( | pressure *= BKE_curvemapping_evaluateF(brush_settings->curve_rand_pressure, 0, pressure); | ||||
| brush->gpencil_settings->curve_strength, 0, curve_pressure); | |||||
| strength *= curvef; | |||||
| strength *= brush->gpencil_settings->draw_strength; | |||||
| } | } | ||||
| CLAMP(strength, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(pressure, 0.1f, 1.0f); | ||||
| } | |||||
| /* apply randomness to color strength */ | /* Apply randomness to color strength. */ | ||||
| if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_RANDOM) && | if (brush_settings->draw_random_strength) { | ||||
| (brush->gpencil_settings->draw_random_strength > 0.0f)) { | if ((brush_settings->flag2 & GP_BRUSH_USE_STRENGTH_AT_STROKE) == 0) { | ||||
| if (p2d->rnd[2] > 0.5f) { | float rand = BLI_rng_get_float(tgpi->rng) * 2.0f - 1.0f; | ||||
| strength -= strength * brush->gpencil_settings->draw_random_strength * p2d->rnd[0]; | strength *= 1.0 + rand * brush_settings->draw_random_strength; | ||||
| } | } | ||||
| else { | else { | ||||
| strength += strength * brush->gpencil_settings->draw_random_strength * p2d->rnd[1]; | strength *= 1.0 + random_settings.strength * brush_settings->draw_random_strength; | ||||
| } | } | ||||
| /* Apply random curve. */ | |||||
| if (brush_settings->flag2 & GP_BRUSH_USE_STRENGTH_RAND_PRESS) { | |||||
| strength *= BKE_curvemapping_evaluateF(brush_settings->curve_rand_strength, 0, pressure); | |||||
| } | |||||
| CLAMP(strength, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(strength, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| } | } | ||||
| } | |||||
| copy_v2_v2(&tpt->x, &p2d->x); | copy_v2_v2(&tpt->x, &p2d->x); | ||||
| CLAMP_MIN(pressure, 0.1f); | |||||
| tpt->pressure = pressure; | tpt->pressure = pressure; | ||||
| tpt->strength = strength; | tpt->strength = strength; | ||||
| tpt->time = p2d->time; | tpt->time = p2d->time; | ||||
| /* Set vertex colors for buffer. */ | |||||
| ED_gpencil_sbuffer_vertex_color_set(tgpi->depsgraph, | |||||
| tgpi->ob, | |||||
| tgpi->scene->toolsettings, | |||||
| tgpi->brush, | |||||
| tgpi->material, | |||||
| tgpi->random_settings.hsv, | |||||
| strength); | |||||
| /* point uv */ | /* point uv */ | ||||
| if (gpd->runtime.sbuffer_used > 0) { | if (gpd->runtime.sbuffer_used > 0) { | ||||
| tGPspoint *tptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1; | tGPspoint *tptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1; | ||||
| bGPDspoint spt, spt2; | bGPDspoint spt, spt2; | ||||
| /* get origin to reproject point */ | /* get origin to reproject point */ | ||||
| float origin[3]; | float origin[3]; | ||||
| ED_gpencil_drawing_reference_get(tgpi->scene, tgpi->ob, ts->gpencil_v3d_align, origin); | ED_gpencil_drawing_reference_get(tgpi->scene, tgpi->ob, ts->gpencil_v3d_align, origin); | ||||
| Show All 31 Lines | for (int i = 0; i < gps->totpoints; i++) { | ||||
| gp_stroke_convertcoords_tpoint( | gp_stroke_convertcoords_tpoint( | ||||
| tgpi->scene, tgpi->region, tgpi->ob, p2d, depth_arr ? depth_arr + i : NULL, &pt->x); | tgpi->scene, tgpi->region, tgpi->ob, p2d, depth_arr ? depth_arr + i : NULL, &pt->x); | ||||
| pt->pressure = pressure; | pt->pressure = pressure; | ||||
| pt->strength = strength; | pt->strength = strength; | ||||
| pt->time = 0.0f; | pt->time = 0.0f; | ||||
| pt->flag = 0; | pt->flag = 0; | ||||
| pt->uv_fac = tpt->uv_fac; | pt->uv_fac = tpt->uv_fac; | ||||
| /* Apply the vertex color to point. */ | copy_v4_v4(pt->vert_color, tpt->vert_color); | ||||
| ED_gpencil_point_vertex_color_set(ts, brush, pt); | |||||
| if (gps->dvert != NULL) { | if (gps->dvert != NULL) { | ||||
| MDeformVert *dvert = &gps->dvert[i]; | MDeformVert *dvert = &gps->dvert[i]; | ||||
| dvert->totweight = 0; | dvert->totweight = 0; | ||||
| dvert->dw = NULL; | dvert->dw = NULL; | ||||
| } | } | ||||
| /* Restore original points */ | /* Restore original points */ | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | static void gpencil_primitive_init(bContext *C, wmOperator *op) | ||||
| /* if brush doesn't exist, create a new set (fix damaged files from old versions) */ | /* if brush doesn't exist, create a new set (fix damaged files from old versions) */ | ||||
| if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) { | if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) { | ||||
| BKE_brush_gpencil_paint_presets(bmain, ts); | BKE_brush_gpencil_paint_presets(bmain, ts); | ||||
| } | } | ||||
| /* Set Draw brush. */ | /* Set Draw brush. */ | ||||
| Brush *brush = BKE_paint_toolslots_brush_get(paint, 0); | Brush *brush = BKE_paint_toolslots_brush_get(paint, 0); | ||||
| BKE_brush_tool_set(brush, paint, 0); | BKE_brush_tool_set(brush, paint, 0); | ||||
| BKE_paint_brush_set(paint, brush); | BKE_paint_brush_set(paint, brush); | ||||
| tgpi->brush = brush; | tgpi->brush = brush; | ||||
| /* control points */ | /* control points */ | ||||
| tgpi->gpd->runtime.cp_points = MEM_callocN(sizeof(bGPDcontrolpoint) * MAX_CP, | tgpi->gpd->runtime.cp_points = MEM_callocN(sizeof(bGPDcontrolpoint) * MAX_CP, | ||||
| "gp primitive cpoint"); | "gp primitive cpoint"); | ||||
| tgpi->gpd->runtime.tot_cp_points = 0; | tgpi->gpd->runtime.tot_cp_points = 0; | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static int gpencil_primitive_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bGPdata *gpd = CTX_data_gpencil_data(C); | bGPdata *gpd = CTX_data_gpencil_data(C); | ||||
| tGPDprimitive *tgpi = NULL; | tGPDprimitive *tgpi = NULL; | ||||
| /* initialize operator runtime data */ | /* initialize operator runtime data */ | ||||
| gpencil_primitive_init(C, op); | gpencil_primitive_init(C, op); | ||||
| tgpi = op->customdata; | tgpi = op->customdata; | ||||
| /* Init random settings. */ | |||||
| ED_gpencil_init_random_settings(tgpi->brush, event->mval, &tgpi->random_settings); | |||||
| const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input"); | const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input"); | ||||
| if (!is_modal) { | if (!is_modal) { | ||||
| tgpi->flag = IN_PROGRESS; | tgpi->flag = IN_PROGRESS; | ||||
| gpencil_primitive_interaction_begin(tgpi, event); | gpencil_primitive_interaction_begin(tgpi, event); | ||||
| } | } | ||||
| /* if in tools region, wait till we get to the main (3d-space) | /* if in tools region, wait till we get to the main (3d-space) | ||||
| * region before allowing drawing to take place. | * region before allowing drawing to take place. | ||||
| Show All 20 Lines | static void gpencil_primitive_interaction_end(bContext *C, | ||||
| wmWindow *win, | wmWindow *win, | ||||
| tGPDprimitive *tgpi) | tGPDprimitive *tgpi) | ||||
| { | { | ||||
| bGPDframe *gpf; | bGPDframe *gpf; | ||||
| bGPDstroke *gps; | bGPDstroke *gps; | ||||
| ToolSettings *ts = tgpi->scene->toolsettings; | ToolSettings *ts = tgpi->scene->toolsettings; | ||||
| Brush *brush = tgpi->brush; | Brush *brush = tgpi->brush; | ||||
| BrushGpencilSettings *brush_settings = brush->gpencil_settings; | |||||
| const int def_nr = tgpi->ob->actdef - 1; | const int def_nr = tgpi->ob->actdef - 1; | ||||
| const bool have_weight = (bool)BLI_findlink(&tgpi->ob->defbase, def_nr); | const bool have_weight = (bool)BLI_findlink(&tgpi->ob->defbase, def_nr); | ||||
| /* return to normal cursor and header status */ | /* return to normal cursor and header status */ | ||||
| ED_workspace_status_text(C, NULL); | ED_workspace_status_text(C, NULL); | ||||
| WM_cursor_modal_restore(win); | WM_cursor_modal_restore(win); | ||||
| /* insert keyframes as required... */ | /* insert keyframes as required... */ | ||||
| short add_frame_mode; | short add_frame_mode; | ||||
| if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) { | if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) { | ||||
| add_frame_mode = GP_GETFRAME_ADD_COPY; | add_frame_mode = GP_GETFRAME_ADD_COPY; | ||||
| } | } | ||||
| else { | else { | ||||
| add_frame_mode = GP_GETFRAME_ADD_NEW; | add_frame_mode = GP_GETFRAME_ADD_NEW; | ||||
| } | } | ||||
| gpf = BKE_gpencil_layer_frame_get(tgpi->gpl, tgpi->cframe, add_frame_mode); | gpf = BKE_gpencil_layer_frame_get(tgpi->gpl, tgpi->cframe, add_frame_mode); | ||||
| /* prepare stroke to get transferred */ | /* prepare stroke to get transferred */ | ||||
| gps = tgpi->gpf->strokes.first; | gps = tgpi->gpf->strokes.first; | ||||
| if (gps) { | if (gps) { | ||||
| gps->thickness = brush->size; | gps->thickness = brush->size; | ||||
| gps->hardeness = brush->gpencil_settings->hardeness; | gps->hardeness = brush_settings->hardeness; | ||||
| copy_v2_v2(gps->aspect_ratio, brush->gpencil_settings->aspect_ratio); | copy_v2_v2(gps->aspect_ratio, brush_settings->aspect_ratio); | ||||
| /* Calc geometry data. */ | /* Calc geometry data. */ | ||||
| BKE_gpencil_stroke_geometry_update(gps); | BKE_gpencil_stroke_geometry_update(gps); | ||||
| } | } | ||||
| /* transfer stroke from temporary buffer to the actual frame */ | /* transfer stroke from temporary buffer to the actual frame */ | ||||
| if (ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) { | if (ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) { | ||||
| BLI_movelisttolist_reverse(&gpf->strokes, &tgpi->gpf->strokes); | BLI_movelisttolist_reverse(&gpf->strokes, &tgpi->gpf->strokes); | ||||
| ▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | switch (event->type) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* brush strength */ | /* brush strength */ | ||||
| static void gpencil_primitive_strength(tGPDprimitive *tgpi, bool reset) | static void gpencil_primitive_strength(tGPDprimitive *tgpi, bool reset) | ||||
| { | { | ||||
| Brush *brush = tgpi->brush; | Brush *brush = tgpi->brush; | ||||
| BrushGpencilSettings *brush_settings = brush->gpencil_settings; | |||||
| if (brush) { | if (brush) { | ||||
| if (reset) { | if (reset) { | ||||
| brush->gpencil_settings->draw_strength = tgpi->brush_strength; | brush_settings->draw_strength = tgpi->brush_strength; | ||||
| tgpi->brush_strength = 0.0f; | tgpi->brush_strength = 0.0f; | ||||
| } | } | ||||
| else { | else { | ||||
| if (tgpi->brush_strength == 0.0f) { | if (tgpi->brush_strength == 0.0f) { | ||||
| tgpi->brush_strength = brush->gpencil_settings->draw_strength; | tgpi->brush_strength = brush_settings->draw_strength; | ||||
| } | } | ||||
| float move[2]; | float move[2]; | ||||
| sub_v2_v2v2(move, tgpi->mval, tgpi->mvalo); | sub_v2_v2v2(move, tgpi->mval, tgpi->mvalo); | ||||
| float adjust = (move[1] > 0.0f) ? 0.01f : -0.01f; | float adjust = (move[1] > 0.0f) ? 0.01f : -0.01f; | ||||
| brush->gpencil_settings->draw_strength += adjust * fabsf(len_manhattan_v2(move)); | brush_settings->draw_strength += adjust * fabsf(len_manhattan_v2(move)); | ||||
| } | } | ||||
| /* limit low limit because below 0.2f the stroke is invisible */ | /* limit low limit because below 0.2f the stroke is invisible */ | ||||
| CLAMP(brush->gpencil_settings->draw_strength, 0.2f, 1.0f); | CLAMP(brush_settings->draw_strength, 0.2f, 1.0f); | ||||
| } | } | ||||
| } | } | ||||
| /* brush size */ | /* brush size */ | ||||
| static void gpencil_primitive_size(tGPDprimitive *tgpi, bool reset) | static void gpencil_primitive_size(tGPDprimitive *tgpi, bool reset) | ||||
| { | { | ||||
| Brush *brush = tgpi->brush; | Brush *brush = tgpi->brush; | ||||
| if (brush) { | if (brush) { | ||||
| ▲ Show 20 Lines • Show All 486 Lines • Show Last 20 Lines | |||||