Commit: 7b9a739b5b09d75cd3eb7256dc9557760387659d Author: Hans Goudey Date: Tue Aug 6 13:50:57 2019 -0400 Branches: soc-2019-bevel-profiles https://developer.blender.org/rB7b9a739b5b09d75cd3eb7256dc9557760387659d
Profile Widget: Sampling function returns ProfilePoint array This enables two things: - Memory savings, because no temporary array is needed to change data formats anymore and because the results can be reused more easily - Also returning information about which sampled points came from control points with vector handles, which will be useful for hardening normals of custom profile bevels. =================================================================== M source/blender/blenkernel/BKE_profile_widget.h M source/blender/blenkernel/intern/profile_widget.c M source/blender/blenloader/intern/readfile.c M source/blender/bmesh/tools/bmesh_bevel.c M source/blender/editors/interface/interface_draw.c M source/blender/editors/interface/interface_handlers.c M source/blender/editors/interface/interface_templates.c M source/blender/makesdna/DNA_profilewidget_types.h M source/blender/makesrna/intern/rna_profile.c =================================================================== diff --git a/source/blender/blenkernel/BKE_profile_widget.h b/source/blender/blenkernel/BKE_profile_widget.h index 3574ed67cef..480afe804a7 100644 --- a/source/blender/blenkernel/BKE_profile_widget.h +++ b/source/blender/blenkernel/BKE_profile_widget.h @@ -27,6 +27,9 @@ struct ProfileWidget; struct ProfilePoint; +/* HANS-QUESTION: Should I add the BKE_ to the front of these functions? The CurveMapping widget + * doesn't have them but it's mentioned in the style guide that public functions should have it */ + void profilewidget_set_defaults(struct ProfileWidget *prwdgt); struct ProfileWidget *profilewidget_add(int preset); @@ -51,10 +54,10 @@ void profilewidget_reverse(struct ProfileWidget *prwdgt); void profilewidget_reset(struct ProfileWidget *prwdgt); -void profilewidget_create_samples(const struct ProfileWidget *prwdgt, - float *locations, +void profilewidget_create_samples(struct ProfileWidget *prwdgt, int n_segments, - bool sample_straight_edges); + bool sample_straight_edges, + struct ProfilePoint *r_samples); void profilewidget_initialize(struct ProfileWidget *prwdgt, short nsegments); @@ -68,8 +71,8 @@ float profilewidget_distance_to_next_point(const struct ProfileWidget *prwdgt, i float profilewidget_total_length(const struct ProfileWidget *prwdgt); void profilewidget_create_samples_even_spacing(const struct ProfileWidget *prwdgt, - double *x_table_out, - double *y_table_out); + double *x_table_out, + double *y_table_out); /* Length portion is the fraction of the total path length where we want the location */ void profilewidget_evaluate_portion(const struct ProfileWidget *prwdgt, diff --git a/source/blender/blenkernel/intern/profile_widget.c b/source/blender/blenkernel/intern/profile_widget.c index dbac816dea6..fa8a180611a 100644 --- a/source/blender/blenkernel/intern/profile_widget.c +++ b/source/blender/blenkernel/intern/profile_widget.c @@ -42,16 +42,16 @@ #include "BKE_fcurve.h" #define DEBUG_PRWDGT 0 -#define DEBUG_PRWDGT_TABLE 0 +#define DEBUG_PRWDGT_TABLE 1 #define DEBUG_PRWDGT_EVALUATE 0 #define DEBUG_PRWDGT_REVERSE 0 -void profilewidget_set_defaults(ProfileWidget *prwdgt) +void BKE_profilewidget_set_defaults(ProfileWidget *prwdgt) { #if DEBUG_PRWDGT printf("PROFILEWIDGET SET DEFAULTS\n"); #endif - prwdgt->flag = PROF_DO_CLIP; + prwdgt->flag = PROF_USE_CLIP; BLI_rctf_init(&prwdgt->view_rect, 0.0f, 1.0f, 0.0f, 1.0f); prwdgt->clip_rect = prwdgt->view_rect; @@ -67,22 +67,6 @@ void profilewidget_set_defaults(ProfileWidget *prwdgt) prwdgt->changed_timestamp = 0; } -struct ProfileWidget *profilewidget_add(int preset) -{ -#if DEBUG_PRWDGT - printf("PROFILEWIDGET ADD\n"); -#endif - - ProfileWidget *prwdgt = MEM_callocN(sizeof(ProfileWidget), "new profile widget"); - - profilewidget_set_defaults(prwdgt); - prwdgt->preset = preset; - profilewidget_reset(prwdgt); - profilewidget_changed(prwdgt, false); - - return prwdgt; -} - void profilewidget_free_data(ProfileWidget *prwdgt) { #if DEBUG_PRWDGT @@ -99,9 +83,9 @@ void profilewidget_free_data(ProfileWidget *prwdgt) MEM_freeN(prwdgt->table); prwdgt->table = NULL; } - if (prwdgt->samples) { - MEM_freeN(prwdgt->samples); - prwdgt->samples = NULL; + if (prwdgt->segments) { + MEM_freeN(prwdgt->segments); + prwdgt->segments = NULL; } } @@ -129,8 +113,8 @@ void profilewidget_copy_data(ProfileWidget *target, const ProfileWidget *prwdgt) if (prwdgt->table) { target->table = MEM_dupallocN(prwdgt->table); } - if (prwdgt->samples) { - target->samples = MEM_dupallocN(prwdgt->samples); + if (prwdgt->segments) { + target->segments = MEM_dupallocN(prwdgt->segments); } } @@ -568,15 +552,18 @@ static int compare_curvature_bezt_edge_i(const BezTriple *bezt, const int i_a, c /** Used for sampling curves along the profile's path. Any points more than the number of user- * defined points will be evenly distributed among the curved edges. Then the remainders will be * distributed to the most curved edges. - * \param locations: An array of points to put the sampled positions. Must have length n_segments. * \param n_segments: The number of segments to sample along the path. It must be higher than the * number of points used to define the profile (prwdgt->totpoint). * \param sample_straight_edges: Whether to sample points between vector handle control points. If - this is true and there are only vector edges the straight edges will still be sampled. */ -void profilewidget_create_samples(const ProfileWidget *prwdgt, - float *locations, + * this is true and there are only vector edges the straight edges will still be sampled. + * \param r_samples: An array of points to put the sampled positions. Must have length n_segments. + * \return r_samples: Fill the array with the sampled locations and if the point corresponds + * to a control point, its handle type */ +/* HANS-TODO: This is getting called way too much: when the mouse moves over the bevel modifier UI */ +void profilewidget_create_samples(ProfileWidget *prwdgt, int n_segments, - bool sample_straight_edges) + bool sample_straight_edges, + ProfilePoint *r_samples) { #if DEBUG_PRWDGT printf("PROFILEWIDGET CREATE SAMPLES\n"); @@ -586,21 +573,22 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt, } #endif BezTriple *bezt; - int i, i_insert, n_left, n_common, i_segment, n_curved_edges; - int *i_curve_sorted, *n_points; - int totedges = prwdgt->totpoint - 1; + int i, i_insert, n_left, n_common, i_sample, n_curved_edges; + int *i_curve_sorted, *n_samples; int totpoints = prwdgt->totpoint; + int totedges = totpoints - 1; +// n_segments--; BLI_assert(n_segments > 0); - /* Create Bezier points for calculating the higher resolution path */ + /* Create Bezier points for calculating the higher resolution path. */ bezt = MEM_callocN((size_t)totpoints * sizeof(BezTriple), "beztarr"); for (i = 0; i < totpoints; i++) { bezt[i].vec[1][0] = prwdgt->path[i].x; bezt[i].vec[1][1] = prwdgt->path[i].y; bezt[i].h1 = bezt[i].h2 = (prwdgt->path[i].flag & PROF_HANDLE_VECTOR) ? HD_VECT : HD_AUTO; } - /* Get handle positions for the bezier points */ + /* Get handle positions for the bezier points. */ calchandle_profile(&bezt[0], NULL, &bezt[1]); for (i = 1; i < totpoints - 1; i++) { calchandle_profile(&bezt[i], &bezt[i - 1], &bezt[i + 1]); @@ -610,7 +598,7 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt, /* Sort a list of indexes by the curvature at each point*/ i_curve_sorted = MEM_callocN((size_t)totedges * sizeof(int), "i curve sorted"); for (i = 0; i < totedges; i++) { /* Insertion sort for now */ - /* Place the new index (i) at the first spot where its edge has less curvature */ + /* Place the new index i at the first spot where its edge has less curvature. */ for (i_insert = 0; i_insert < i; i_insert++) { if (!compare_curvature_bezt_edge_i(bezt, i, i_curve_sorted[i_insert])) { break; @@ -620,7 +608,7 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt, } /* Assign sampled points to each edge. */ - n_points = MEM_callocN((size_t)totedges * sizeof(int), "create samples numbers"); + n_samples = MEM_callocN((size_t)totedges * sizeof(int), "create samples numbers"); int n_added = 0; if (n_segments >= totedges) { if (sample_straight_edges) { @@ -629,10 +617,10 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt, n_common = n_segments / totedges; n_left = n_segments % totedges; - /* Assign the points that fill fit evenly to the edges */ + /* Assign the points that fill fit evenly to the edges. */ if (n_common > 0) { for (i = 0; i < totedges; i++) { - n_points[i] = n_common; + n_samples[i] = n_common; n_added += n_common; } } @@ -645,22 +633,20 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt, n_curved_edges++; } } - /* Just sample all of the edges if there are no curved edges */ - if (n_curved_edges == 0) { - n_curved_edges = totedges; - } + /* Just sample all of the edges if there are no curved edges. */ + n_curved_edges = (n_curved_edges == 0) ? totedges : n_curved_edges; - /* Give all of the curved edges the same number of points and straight edges one point */ - n_left = n_segments - (totedges - n_curved_edges); /* After one for each straight edge */ - n_common = n_left / n_curved_edges; /* Number assigned to every curved edge */ + /* Give all of the curved edges the same number of points and straight edges one point. */ + n_left = n_segments - (totedges - n_curved_edges); /* Left after 1 for each straight edge */ + n_common = n_left / n_curved_edges; /* Number assigned to all curved edges */ if (n_common > 0) { for (i = 0; i < totedges; i++) { if (is_curved_edge(bezt, i)) { - n_points[i] += n_common; + n_samples[i] += n_common; n_added += n_common; } else { - n_points[i] = 1; + n_samples[i] = 1; n_added++; } } @@ -668,46 +654,63 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt, n_left -= n_common * n_curved_edges; } } else { - /* Not enough segments to give one to each edge, so just give them to the most curved edges */ + /* Not enough segments to give one to each edge, so just give them to the most curved edges. */ n_left = n_segments; } - /* Assign the remainder of the points that @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs