[Bf-blender-cvs] [4520f4dc47d] soc-2019-bevel-profiles: ProfileWidget: Added preset selection and reverse button.
Hans Goudey
noreply at git.blender.org
Thu Jun 27 07:39:27 CEST 2019
Commit: 4520f4dc47db827eb0ed940a19612dd223573ae2
Author: Hans Goudey
Date: Thu Jun 27 01:30:25 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rB4520f4dc47db827eb0ed940a19612dd223573ae2
ProfileWidget: Added preset selection and reverse button.
The preset selection selects from a few examples currently which are just
defined in the C code manually for now. The preset selector is drawn as part
of the ProfileWidget rather than by the bevel modifier.
The reverse function flips all of the points across the y = 1 - x centerline.
It will act as the manual control over the orientation of the profile. It will
probably need a new icon eventually.
This commit also includes various other changes including variable name changes,
updated comments, and cleanup.
===================================================================
M source/blender/blenkernel/BKE_profile_path.h
M source/blender/blenkernel/intern/profile_path.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_profilepath_types.h
M source/blender/makesrna/RNA_enum_types.h
M source/blender/makesrna/intern/rna_profile.c
M source/blender/modifiers/intern/MOD_bevel.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_profile_path.h b/source/blender/blenkernel/BKE_profile_path.h
index 972f05a911f..affa5140ee7 100644
--- a/source/blender/blenkernel/BKE_profile_path.h
+++ b/source/blender/blenkernel/BKE_profile_path.h
@@ -69,12 +69,18 @@ bool profilepath_remove_point(struct ProfilePath *prpath, struct ProfilePoint *p
struct ProfilePoint *profilepath_insert(struct ProfilePath *prpath, float x, float y);
+void profilepath_reverse(struct ProfilePath *prpath);
+
void profilepath_handle_set(struct ProfilePath *prpath, int type);
/* Called for a complete update of the widget after modifications */
void profilewidget_changed(struct ProfileWidget *prwdgt, const bool rem_doubles);
-/* call before _all_ evaluation functions */
+/* call before all evaluation functions */
void profilewidget_initialize(struct ProfileWidget *prwdgt, int nsegments);
+void profilepath_fill_segment_table(const struct ProfilePath *prpath,
+ double *x_table_out,
+ double *y_table_out);
+
#endif
diff --git a/source/blender/blenkernel/intern/profile_path.c b/source/blender/blenkernel/intern/profile_path.c
index 4796966927f..ed01a75cf30 100644
--- a/source/blender/blenkernel/intern/profile_path.c
+++ b/source/blender/blenkernel/intern/profile_path.c
@@ -41,7 +41,12 @@
#include "BKE_curve.h"
#include "BKE_fcurve.h"
-#define DEBUG_PRWDGT 1
+#define DEBUG_PRWDGT 0
+#define DEBUG_PRWDGT_TABLE 1
+#define DEBUG_PRWDGT_EVALUATE 0
+#define DEBUG_PRWDGT_REVERSE 0
+
+/* HANS-TODO: Organize functions, especially by which need initialization and which don't */
void profilewidget_set_defaults(ProfileWidget *prwdgt)
{
@@ -50,8 +55,8 @@ void profilewidget_set_defaults(ProfileWidget *prwdgt)
#endif
prwdgt->flag = PROF_DO_CLIP;
- BLI_rctf_init(&prwdgt->curr, 0.0f, 1.0f, 0.0f, 1.0f);
- prwdgt->clipr = prwdgt->curr;
+ BLI_rctf_init(&prwdgt->view_rect, 0.0f, 1.0f, 0.0f, 1.0f);
+ prwdgt->clip_rect = prwdgt->view_rect;
prwdgt->profile->totpoint = 2;
prwdgt->profile->path = MEM_callocN(2 * sizeof(ProfilePoint), "path points");
@@ -99,14 +104,6 @@ void profilewidget_free_data(ProfileWidget *prwdgt)
MEM_freeN(prwdgt->profile->table);
prwdgt->profile->table = NULL;
}
- if (prwdgt->profile->x_segment_vals) {
- MEM_freeN(prwdgt->profile->x_segment_vals);
- prwdgt->profile->x_segment_vals = NULL;
- }
- if (prwdgt->profile->y_segment_vals) {
- MEM_freeN(prwdgt->profile->y_segment_vals);
- prwdgt->profile->y_segment_vals = NULL;
- }
MEM_freeN(prwdgt->profile);
}
@@ -135,12 +132,6 @@ void profilewidget_copy_data(ProfileWidget *target, const ProfileWidget *prwdgt)
if (prwdgt->profile->table) {
target->profile->table = MEM_dupallocN(prwdgt->profile->table);
}
- if (prwdgt->profile->x_segment_vals) {
- target->profile->x_segment_vals = MEM_dupallocN(prwdgt->profile->x_segment_vals);
- }
- if (prwdgt->profile->y_segment_vals) {
- target->profile ->y_segment_vals = MEM_dupallocN(prwdgt->profile->y_segment_vals);
- }
}
ProfileWidget *profilewidget_copy(const ProfileWidget *prwdgt)
@@ -157,7 +148,6 @@ ProfileWidget *profilewidget_copy(const ProfileWidget *prwdgt)
return NULL;
}
-
/* ********** requires profilewidget_changed() call after ******** */
/* remove specified point */
@@ -236,6 +226,7 @@ ProfilePoint *profilepath_insert(ProfilePath *prpath, float x, float y)
printf("PROFILEPATH INSERT\n");
#endif
+ /* Find the index at the line segment that's closest to the new position */
float distance;
float min_distance = FLT_MAX;
int insert_i;
@@ -277,6 +268,48 @@ ProfilePoint *profilepath_insert(ProfilePath *prpath, float x, float y)
return new_pt;
}
+/* Requires ProfilePath changed call afterwards */
+/* HANS-TODO: Or we could just reverse the table here and not require that? */
+void profilepath_reverse(ProfilePath *prpath)
+{
+#if DEBUG_PRWDGT
+ printf("PROFILEPATH INSERT\n");
+#endif
+ /* Quick fix for when there are only two points and reversing shouldn't do anything */
+ if (prpath->totpoint == 2) {
+ return;
+ }
+ ProfilePoint *new_pts = MEM_mallocN(((size_t)prpath->totpoint) * sizeof(ProfilePoint),
+ "path points");
+ /* Mirror the new points across the y = 1 - x line */
+ for (int i = 1; i < prpath->totpoint - 1; i++) {
+ new_pts[prpath->totpoint - i - 1].x = 1.0f - prpath->path[i].y;
+ new_pts[prpath->totpoint - i - 1].y = 1.0f - prpath->path[i].x;
+ new_pts[prpath->totpoint - i - 1].flag = prpath->path[i].flag;
+ }
+ /* Set the location of the first and last points */
+ new_pts[0].x = 0.0;
+ new_pts[0].y = 0.0;
+ new_pts[prpath->totpoint - 1].x = 1.0;
+ new_pts[prpath->totpoint - 1].y = 1.0;
+
+#if DEBUG_PRWDGT_REVERSE
+ printf("Locations before:\n");
+ for (int i = 0; i < prpath->totpoint; i++) {
+ printf("(%.2f, %.2f)", (double)prpath->path[i].x, (double)prpath->path[i].y);
+ }
+ printf("\nLocations after:\n");
+ for (int i = 0; i < prpath->totpoint; i++) {
+ printf("(%.2f, %.2f)", (double)new_pts[i].x, (double)new_pts[i].y);
+ }
+ printf("\n");
+#endif
+
+ /* Free the old points and use the new ones */
+ MEM_freeN(prpath->path);
+ prpath->path = new_pts;
+}
+
/* Requires ProfilePath changed call afterwards */
/* HANS-TODO: Couldn't it just build the table at the end of this function here? */
void profilepath_reset(ProfilePath *prpath, int preset)
@@ -294,7 +327,10 @@ void profilepath_reset(ProfilePath *prpath, int preset)
prpath->totpoint = 2;
break;
case PROF_PRESET_SUPPORTS:
- prpath->totpoint = 4;
+ prpath->totpoint = 12;
+ break;
+ case PROF_PRESET_EXAMPLE1:
+ prpath->totpoint = 23;
break;
}
@@ -310,14 +346,66 @@ void profilepath_reset(ProfilePath *prpath, int preset)
case PROF_PRESET_SUPPORTS:
prpath->path[0].x = 0.0;
prpath->path[0].y = 0.0;
- prpath->path[1].x = 0.5;
- prpath->path[1].y = 0.0;
- /* HANS-TODO: Add curve in middle */
- prpath->path[2].x = 0.5;
- prpath->path[2].y = 0.5;
- prpath->path[3].x = 1.0;
- prpath->path[3].y = 1.0;
+ prpath->path[1].x = 0.0;
+ prpath->path[1].y = 0.5;
+ for (int i = 1; i < 10; i++) {
+ prpath->path[i + 1].x = 0.5f * (1.0f - cosf((float)((i / 9.0) * M_PI_2)));
+ prpath->path[i + 1].y = 0.5f + 0.5f * sinf((float)((i / 9.0) * M_PI_2));
+ }
+ prpath->path[10].x = 0.5;
+ prpath->path[10].y = 1.0;
+ prpath->path[11].x = 1.0;
+ prpath->path[11].y = 1.0;
break;
+ case PROF_PRESET_EXAMPLE1: /* HANS-TODO: Don't worry, this is just temporary */
+ prpath->path[0].x = 0.0f;
+ prpath->path[0].y = 0.0f;
+ prpath->path[1].x = 0.0f;
+ prpath->path[1].y = 0.6f;
+ prpath->path[2].x = 0.1f;
+ prpath->path[2].y = 0.6f;
+ prpath->path[3].x = 0.1f;
+ prpath->path[3].y = 0.7f;
+ prpath->path[4].x = 0.195024f;
+ prpath->path[4].y = 0.709379f;
+ prpath->path[5].x = 0.294767f;
+ prpath->path[5].y = 0.735585f;
+ prpath->path[6].x = 0.369792f;
+ prpath->path[6].y = 0.775577f;
+ prpath->path[7].x = 0.43429f;
+ prpath->path[7].y = 0.831837f;
+ prpath->path[8].x = 0.500148f;
+ prpath->path[8].y = 0.884851f;
+ prpath->path[9].x = 0.565882f;
+ prpath->path[9].y = 0.91889f;
+ prpath->path[10].x = 0.633279f;
+ prpath->path[10].y = 0.935271f;
+ prpath->path[11].x = 0.697628f;
+ prpath->path[11].y = 0.937218f;
+ prpath->path[12].x = 0.75148f;
+ prpath->path[12].y = 0.924844f;
+ prpath->path[13].x = 0.791918f;
+ prpath->path[13].y = 0.904817f;
+ prpath->path[14].x = 0.822379f;
+ prpath->path[14].y = 0.873682f;
+ prpath->path[15].x = 0.842155f;
+ prpath->path[15].y = 0.83174f;
+ prpath->path[16].x = 0.85f;
+ prpath->path[16].y = 0.775f;
+ prpath->path[17].x = 0.929009f;
+ prpath->path[17].y = 0.775f;
+ prpath->path[18].x = 0.953861f;
+ prpath->path[18].y = 0.780265f;
+ prpath->path[19].x = 0.967919f;
+ prpath->path[19].y = 0.794104f;
+ prpath->path[20].x = 0.978458f;
+ prpath->path[20].y = 0.818784f;
+ prpath->path[21].x = 0.988467f;
+ prpath->path[21].y = 0.890742f;
+ prpath->path[22].x = 1.0f;
+ prpath->path[22].x = 1.0f;
+ break;
+
}
if (prpath->table) {
@@ -504,7 +592,6 @@ static void profilepath_make_table(ProfilePath *prpath, const rctf *clipr)
prpath->mintable = clipr->xmin;
prpath->maxtable = clipr->xmax;
- /* hrmf... we now rely on blender ipo beziers, these are more advanced */
bezt = MEM_callocN((size_t)prpath->totpoint * sizeof(BezTriple), "beztarr");
for (i = 0; i < prpath->totpoint; i++) {
@@ -603,7 +690,7 @@ static void profilepath_make_table(ProfilePath *prpath, const rctf *clipr)
range = PROF_TABLEDIV * (prpath->maxtable - prpath->mintable);
prpath->range = 1.0f / range;
- /* now make a table with CM_TABLE equal x distances */
+ /* now make a table with PROF_TABLE_SIZE equal distances */
fp = allpoints;
lastpoint = allpoints + 2 * (totpoint - 1);
point = MEM_callocN((PROF_TABLE_SIZE + 1) * sizeof(ProfilePoint), "dist table");
@@ -617,9 +704,10 @@ static void profilepath_make_table(ProfilePath *prpath, const rctf *clipr)
fp += 2;
}
if (fp == allpoints || (curf >= fp[0] && fp == lastpoint)) {
- /* HANS-TODO: Remove this case */
+ /* HANS-TODO: Remove this case. Why did I say this? */
}
else {
+ /* HANS-QUESTION: Why this factor stuff? */
float fac1 = fp[0] - fp[-2];
float fac2 = fp[0] - curf;
if (fac1 > FLT_EPSILON) {
@@ -641,7 +729,7 @@ void profilewidget_changed(ProfileWidget *prwdgt, const bool rem_doubles)
{
ProfilePath *prpath = prwdgt->profile;
ProfilePoint *points = prpath->path;
- rctf *clipr = &prwdgt->clipr;
+ rctf *clipr = &prwdgt->clip_rect;
float thresh = 0.01f * BLI_rctf_size_x(clipr);
float dx = 0.0f, dy = 0.0f;
int i;
@@ -682,13 +770,13 @@ void profilewidget_changed(ProfileWidget *prwdgt, const bool rem_doubles)
/* ensure zoom-level res
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list