diff options
author | Falk David <falkdavid@gmx.de> | 2020-09-12 13:17:47 +0300 |
---|---|---|
committer | Falk David <falkdavid@gmx.de> | 2020-09-12 13:17:47 +0300 |
commit | c00523aca49d7e6d3aadf1e4a230ae8fb67044cc (patch) | |
tree | 5e5cb8fd566b75726241a20bf229f989e6f46367 /source/blender/editors/gpencil | |
parent | 8156e948042a464ca40ca78c946874340a8421f4 (diff) | |
parent | 269ceb666b01b8cddbfb5babddf38546a41eba39 (diff) |
Merge branch 'greasepencil-edit-curve' into soc-2020-greasepencil-curvesoc-2020-greasepencil-curve
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r-- | source/blender/editors/gpencil/annotate_paint.c | 5 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_convert.c | 26 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 6 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_merge.c | 11 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_mesh.c | 5 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 42 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_primitive.c | 8 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_sculpt_paint.c | 5 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_vertex_ops.c | 3 |
9 files changed, 60 insertions, 51 deletions
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index c29244c37f7..481a038fde1 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -1119,7 +1119,6 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, bGPDspoint *pt1, *pt2; int pc1[2] = {0}; int pc2[2] = {0}; - int i; int mval_i[2]; round_v2i_v2fl(mval_i, mval); @@ -1152,7 +1151,7 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, * we don't miss anything, though things will be * slightly slower as a result */ - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { bGPDspoint *pt = &gps->points[i]; pt->flag &= ~GP_SPOINT_TAG; } @@ -1161,7 +1160,7 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, * 1) Thin out parts of the stroke under the brush * 2) Tag "too thin" parts for removal (in second pass) */ - for (i = 0; (i + 1) < gps->totpoints; i++) { + for (int i = 0; (i + 1) < gps->totpoints; i++) { /* get points to work with */ pt1 = gps->points + i; pt2 = gps->points + i + 1; diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index 05c37567c55..b9234ac3ae7 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -371,10 +371,9 @@ static void gpencil_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd, int *nbr_gaps, float *tot_gaps_time) { - int i; float delta_time = 0.0f; - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { if (gtd->times[i] < 0 && i) { (*nbr_gaps)++; gtd->times[i] = -gtd->times[i] - delta_time; @@ -420,14 +419,11 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, float delta_time = 0.0f, next_delta_time = 0.0f; int nbr_done_gaps = 0; - int i; - float cfra; - /* This is a bit tricky, as: * - We can't add arbitrarily close points on FCurve (in time). * - We *must* have all "caps" points of all strokes in FCurve, as much as possible! */ - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { /* If new stroke... */ if (i > end_stroke_idx) { start_stroke_idx = i; @@ -442,7 +438,7 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, /* Simple proportional stuff... */ cu->ctime = gtd->dists[i] / gtd->tot_dist * cu->pathlen; - cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range); + float cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range); /* And now, the checks about timing... */ if (i == start_stroke_idx) { @@ -527,7 +523,7 @@ static void gpencil_stroke_path_animation(bContext *C, FCurve *fcu; PointerRNA ptr; PropertyRNA *prop = NULL; - int nbr_gaps = 0, i; + int nbr_gaps = 0; if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) { return; @@ -551,7 +547,7 @@ static void gpencil_stroke_path_animation(bContext *C, if (G.debug & G_DEBUG) { printf("%s: tot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]); } } @@ -628,7 +624,7 @@ static void gpencil_stroke_path_animation(bContext *C, if (G.debug & G_DEBUG) { printf("%s: \ntot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]); } printf("\n\n"); @@ -1251,12 +1247,10 @@ static void gpencil_stroke_finalize_curve_endpoints(Curve *cu) static void gpencil_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2]) { - Nurb *nu; const float delta = minmax_weights[0]; - float fac; - int i; /* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */ + float fac; if (IS_EQF(delta, minmax_weights[1])) { fac = 1.0f; } @@ -1264,16 +1258,16 @@ static void gpencil_stroke_norm_curve_weights(Curve *cu, const float minmax_weig fac = 1.0f / (minmax_weights[1] - delta); } - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (i = 0; i < nu->pntsu; i++, bezt++) { + for (int i = 0; i < nu->pntsu; i++, bezt++) { bezt->weight = (bezt->weight - delta) * fac; } } else if (nu->bp) { BPoint *bp = nu->bp; - for (i = 0; i < nu->pntsu; i++, bp++) { + for (int i = 0; i < nu->pntsu; i++, bp++) { bp->weight = (bp->weight - delta) * fac; } } diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 1994792e61a..9f0271c2aa4 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -5510,7 +5510,6 @@ static int gpencil_cutter_lasso_select(bContext *C, const float scale = ts->gp_sculpt.isect_threshold; bGPDspoint *pt; - int i; GP_SpaceConversion gsc = {NULL}; bool changed = false; @@ -5526,6 +5525,7 @@ static int gpencil_cutter_lasso_select(bContext *C, /* deselect all strokes first */ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { pt->flag &= ~GP_SPOINT_SELECT; } @@ -5538,7 +5538,7 @@ static int gpencil_cutter_lasso_select(bContext *C, GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { int tot_inside = 0; const int oldtot = gps->totpoints; - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { pt = &gps->points[i]; if ((pt->flag & GP_SPOINT_SELECT) || (pt->flag & GP_SPOINT_TAG)) { continue; @@ -5562,7 +5562,7 @@ static int gpencil_cutter_lasso_select(bContext *C, } /* if mark all points inside lasso set to remove all stroke */ if ((tot_inside == oldtot) || ((tot_inside == 1) && (oldtot == 2))) { - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { pt = &gps->points[i]; pt->flag |= GP_SPOINT_SELECT; } diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index 2713e6b0f54..70478d9b7d0 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -203,7 +203,6 @@ static void gpencil_calc_points_factor(bContext *C, tGPencilPointCache *src_array) { bGPDspoint *pt; - int i; int idx = 0; /* create selected point array an fill it */ @@ -217,6 +216,7 @@ static void gpencil_calc_points_factor(bContext *C, } LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (gps->flag & GP_STROKE_SELECT) { + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { if (clear_stroke) { pt->flag |= GP_SPOINT_TAG; @@ -255,7 +255,7 @@ static void gpencil_calc_points_factor(bContext *C, /* calc center */ float center[2] = {0.0f, 0.0f}; - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { center[0] += points2d[i][0]; center[1] += points2d[i][1]; } @@ -264,7 +264,7 @@ static void gpencil_calc_points_factor(bContext *C, /* calc angle and distance to center for each point */ const float axis[2] = {1.0f, 0.0f}; float v1[3]; - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { float ln = len_v2v2(center, points2d[i]); sub_v2_v2v2(v1, points2d[i], center); float angle = angle_signed_v2v2(axis, v1); @@ -340,10 +340,9 @@ static void gpencil_get_extremes( tGPencilPointCache *src_array, int totpoints, bGPDstroke *gps_filter, float *start, float *end) { tGPencilPointCache *array_pt = NULL; - int i; /* find first point */ - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { array_pt = &src_array[i]; if (gps_filter == array_pt->gps) { copy_v3_v3(start, &array_pt->x); @@ -351,7 +350,7 @@ static void gpencil_get_extremes( } } /* find last point */ - for (i = totpoints - 1; i >= 0; i--) { + for (int i = totpoints - 1; i >= 0; i--) { array_pt = &src_array[i]; if (gps_filter == array_pt->gps) { copy_v3_v3(end, &array_pt->x); diff --git a/source/blender/editors/gpencil/gpencil_mesh.c b/source/blender/editors/gpencil/gpencil_mesh.c index f4e40c2670f..e4862617d12 100644 --- a/source/blender/editors/gpencil/gpencil_mesh.c +++ b/source/blender/editors/gpencil/gpencil_mesh.c @@ -162,7 +162,7 @@ static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op) Object *ob_gpencil = NULL; ListBase list = {NULL, NULL}; - const bool simple_material = gpencil_bake_ob_list(C, depsgraph, scene, &list); + gpencil_bake_ob_list(C, depsgraph, scene, &list); /* Cannot check this in poll because the active object changes. */ if (list.first == NULL) { @@ -264,8 +264,7 @@ static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op) ob_eval->obmat, frame_offset, use_seams, - use_faces, - simple_material); + use_faces); /* Reproject all untaged created strokes. */ if (project_type != GP_REPROJECT_KEEP) { diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 1036f86fa2b..3cdb7682af2 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -941,7 +941,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) const 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) && (rv3d->persp == RV3D_CAMOB) && (!is_depth); - int i, totelem; + int totelem; /* For very low pressure at the end, truncate stroke. */ if (p->paintmode == GP_PAINTMODE_DRAW) { @@ -1079,7 +1079,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* reproject to plane (only in 3d space) */ gpencil_reproject_toplane(p, gps); pt = gps->points; - for (i = 0; i < gps->totpoints; i++, pt++) { + for (int i = 0; i < gps->totpoints; i++, pt++) { /* if parented change position relative to parent object */ gpencil_apply_parent_point(depsgraph, obact, gpl, pt); } @@ -1099,7 +1099,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) int found_depth = 0; depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points"); - + int i; for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) { round_v2i_v2fl(mval_i, &ptc->x); @@ -1169,6 +1169,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) dvert = gps->dvert; /* convert all points (normal behavior) */ + int i; for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc; i++, ptc++, pt++) { /* convert screen-coordinates to appropriate coordinates (and store them) */ @@ -1266,7 +1267,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* add weights */ if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) { BKE_gpencil_dvert_ensure(gps); - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { MDeformVert *ve = &gps->dvert[i]; MDeformWeight *dw = BKE_defvert_ensure_index(ve, def_nr); if (dw) { @@ -1524,6 +1525,9 @@ static void gpencil_stroke_eraser_dostroke(tGPsdata *p, pt1 = gps->points + i; pt2 = gps->points + i + 1; + float inf1 = 0.0f; + float inf2 = 0.0f; + /* only process if it hasn't been masked out... */ if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) { continue; @@ -1602,22 +1606,36 @@ static void gpencil_stroke_eraser_dostroke(tGPsdata *p, pt2->flag |= GP_SPOINT_TAG; do_cull = true; } + + inf1 = 1.0f; + inf2 = 1.0f; } else { - pt1->pressure -= gpencil_stroke_eraser_calc_influence(p, mval, radius, pc1) * - strength; - pt2->pressure -= gpencil_stroke_eraser_calc_influence(p, mval, radius, pc2) * - strength * 0.5f; + /* Erase point. Only erase if the eraser is on top of the point. */ + inf1 = gpencil_stroke_eraser_calc_influence(p, mval, radius, pc1); + if (inf1 > 0.0f) { + pt1->pressure = 0.0f; + pt1->flag |= GP_SPOINT_TAG; + do_cull = true; + } + inf2 = gpencil_stroke_eraser_calc_influence(p, mval, radius, pc2); + if (inf2 > 0.0f) { + pt2->pressure = 0.0f; + pt2->flag |= GP_SPOINT_TAG; + do_cull = true; + } } /* 2) Tag any point with overly low influence for removal in the next pass */ - if ((pt1->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || - (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)) { + if ((inf1 > 0.0f) && + (((pt1->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || + (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)))) { pt1->flag |= GP_SPOINT_TAG; do_cull = true; } - if ((pt2->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || - (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)) { + if ((inf1 > 2.0f) && + (((pt2->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || + (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)))) { pt2->flag |= GP_SPOINT_TAG; do_cull = true; } diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 5084f5090a1..b48fc1cb975 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -773,7 +773,6 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) /* get an array of depths, far depths are blended */ float *depth_arr = NULL; if (is_depth) { - int i; int mval_i[2], mval_prev[2] = {0}; bool interp_depth = false; bool found_depth = false; @@ -787,7 +786,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) depth_arr = MEM_mallocN(sizeof(float) * gps->totpoints, "depth_points"); tGPspoint *ptc = &points2D[0]; - for (i = 0; i < gps->totpoints; i++, ptc++) { + for (int i = 0; i < gps->totpoints; i++, ptc++) { round_v2i_v2fl(mval_i, &ptc->x); if ((ED_view3d_autodist_depth(tgpi->region, mval_i, depth_margin, depth_arr + i) == 0) && (i && (ED_view3d_autodist_depth_seg( @@ -801,14 +800,14 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) } if (!found_depth) { - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { depth_arr[i] = 0.9999f; } } else { /* if all depth are too high disable */ bool valid_depth = false; - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { if (depth_arr[i] < 0.9999f) { valid_depth = true; break; @@ -826,6 +825,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) int last_valid = 0; /* find first valid contact point */ + int i; for (i = 0; i < gps->totpoints; i++) { if (depth_arr[i] != FLT_MAX) { break; diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c index 6e16aee2573..fd150f1e20f 100644 --- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c +++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c @@ -546,12 +546,11 @@ static void gpencil_brush_grab_apply_cached(tGP_BrushEditData *gso, return; } - int i; float inverse_diff_mat[4][4]; invert_m4_m4(inverse_diff_mat, diff_mat); /* Apply dvec to all of the stored points */ - for (i = 0; i < data->size; i++) { + for (int i = 0; i < data->size; i++) { bGPDspoint *pt = &gps->points[data->points[i]]; float delta[3] = {0.0f}; @@ -1106,7 +1105,7 @@ static bool gpencil_sculpt_brush_apply_clone(bContext *C, tGP_BrushEditData *gso gpencil_brush_clone_adjust(gso); } else { - /* Continuous - Just keep pasting everytime we move */ + /* Continuous - Just keep pasting every time we move. */ /* TODO: The spacing of repeat should be controlled using a * "stepsize" or similar property? */ gpencil_brush_clone_add(C, gso); diff --git a/source/blender/editors/gpencil/gpencil_vertex_ops.c b/source/blender/editors/gpencil/gpencil_vertex_ops.c index 36ce7d3dc47..69e50beb66e 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_ops.c +++ b/source/blender/editors/gpencil/gpencil_vertex_ops.c @@ -682,7 +682,6 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) char name[32] = ""; Material *ma = NULL; GPMatArray *mat_elm = NULL; - int i; bool changed = false; @@ -744,6 +743,7 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) /* Check if material exist. */ bool found = false; + int i; for (i = 0; i < totmat; i++) { mat_elm = &mat_table[i]; if (mat_elm->ma == NULL) { @@ -796,6 +796,7 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) /* Update all points. */ bGPDspoint *pt; + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { copy_v3_v3(pt->vert_color, gp_style->stroke_rgba); pt->vert_color[3] = 1.0f; |