[Bf-blender-cvs] [635d5ac54f9] soc-2019-bevel-profiles: Progress on ProfileWidget UI, and the profile's fill Start of better ProfilePoint insertion algorithm

Hans Goudey noreply at git.blender.org
Sat Jun 22 08:23:04 CEST 2019


Commit: 635d5ac54f9ba6f07bf5edf12dc9ce0d2322271d
Author: Hans Goudey
Date:   Sat Jun 22 02:22:39 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rB635d5ac54f9ba6f07bf5edf12dc9ce0d2322271d

Progress on ProfileWidget UI, and the profile's fill
Start of better ProfilePoint insertion algorithm

===================================================================

M	source/blender/blenkernel/BKE_profile_path.h
M	source/blender/blenkernel/intern/profile_path.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_profilepath_types.h
M	source/blender/makesrna/intern/rna_profile.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_profile_path.h b/source/blender/blenkernel/BKE_profile_path.h
index b472c6b7277..972f05a911f 100644
--- a/source/blender/blenkernel/BKE_profile_path.h
+++ b/source/blender/blenkernel/BKE_profile_path.h
@@ -28,6 +28,8 @@ struct ProfileWidget;
 struct ProfilePath;
 struct ProfilePoint;
 
+/* HANS-TODO: Organize */
+
 void profilewidget_set_defaults(struct ProfileWidget *prwdgt);
 
 struct ProfileWidget *profilewidget_add(int preset);
@@ -75,8 +77,4 @@ void profilewidget_changed(struct ProfileWidget *prwdgt, const bool rem_doubles)
 /* call before _all_ evaluation functions */
 void profilewidget_initialize(struct ProfileWidget *prwdgt, int nsegments);
 
-/* HANS-TODO: Remove these, they only sample in 1D, so they won't be useful */
-/* single curve, no table check */
-float profilepath_evaluateF(const struct ProfilePath *prpath, float value);
-
 #endif
diff --git a/source/blender/blenkernel/intern/profile_path.c b/source/blender/blenkernel/intern/profile_path.c
index 364545bfc41..ab3e518da42 100644
--- a/source/blender/blenkernel/intern/profile_path.c
+++ b/source/blender/blenkernel/intern/profile_path.c
@@ -41,7 +41,7 @@
 #include "BKE_curve.h"
 #include "BKE_fcurve.h"
 
-#define DEBUG_PRWDGT 0
+#define DEBUG_PRWDGT 1
 
 void profilewidget_set_defaults(ProfileWidget *prwdgt)
 {
@@ -75,6 +75,7 @@ struct ProfileWidget *profilewidget_add(int preset)
 
   profilewidget_set_defaults(prwdgt);
   profilepath_reset(prwdgt->profile, preset);
+  profilewidget_changed(prwdgt, false);
 
   return prwdgt;
 }
@@ -232,18 +233,9 @@ ProfilePoint *profilepath_insert(ProfilePath *prpath, float x, float y)
 
 #if DEBUG_PRWDGT
   printf("PROFILEPATH INSERT");
-  printf("(begin total points = %d)", prpath->total_points);
+  printf("(begin total points = %d)", prpath->totpoint);
 #endif
 
-  /* HANS-TODO: New insertion algorithm. Find closest points in 2D and then insert them in the
-   * middle of those. Maybe just lengthen the size of the array instead of allocating a new one
-   * too, but that probbaly doesn't matter so much.
-   *
-   * New algorithm would probably be: Sort the points by their proximity to the new location. Then
-   * find the two points closest to the new position that are ordered one after the next in the
-   * original array of points (this will probably be the two closest points, but for more
-   * complicated profiles it could be points on opposite sides of the profile). Then insert the new
-   * point between the two we just found. */
   /* insert fragments of the old one and the new point to the new curve */
   prpath->totpoint++;
   for (a = 0, b = 0; a < prpath->totpoint; a++) {
@@ -266,8 +258,7 @@ ProfilePoint *profilepath_insert(ProfilePath *prpath, float x, float y)
     }
   }
 #if DEBUG_PRWDGT
-  printf("PROFILEPATH INSERT");
-  printf("(end total points = %d)\n", prpath->total_points);
+  printf("(end total points = %d)\n", prpath->totpoint);
 #endif
 
   /* free old path and replace it with the new one */
@@ -277,6 +268,39 @@ ProfilePoint *profilepath_insert(ProfilePath *prpath, float x, float y)
   return newpt;
 }
 
+/* HANS-TODO: New insertion algorithm. Find closest points in 2D and then insert them in the
+ * middle of those. Maybe just lengthen the size of the array instead of allocating a new one
+ * too, but that probbaly doesn't matter so much.
+ *
+ * New algorithm would probably be: Sort the points by their proximity to the new location. Then
+ * find the two points closest to the new position that are ordered one after the next in the
+ * original array of points (this will probably be the two closest points, but for more
+ * complicated profiles it could be points on opposite sides of the profile). Then insert the new
+ * point between the two we just found. */
+ProfilePoint *profilepath_insert2(ProfilePath *prpath, float x, float y)
+{
+  ProfilePoint *new_pts = MEM_callocN(((size_t)prpath->totpoint + 1) * sizeof(ProfilePoint),
+                                  "path points");
+  ProfilePoint *new_pt = NULL;
+  int a, b;
+  bool foundloc = false;
+  int *sorted_indices = MEM_callocN((size_t)prpath->totpoint * sizeof(int), "points sorted i");
+
+
+
+
+
+  /* free old path and replace it with the new one */
+  MEM_freeN(prpath->path);
+  prpath->path = new_pts;
+
+  MEM_freeN(sorted_indices);
+
+  return new_pt;
+}
+
+/* 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)
 {
 #if DEBUG_PRWDGT
@@ -291,6 +315,9 @@ void profilepath_reset(ProfilePath *prpath, int preset)
     case PROF_PRESET_LINE:
       prpath->totpoint = 2;
       break;
+    case PROF_PRESET_SUPPORTS:
+      prpath->totpoint = 4;
+      break;
   }
 
   prpath->path = MEM_callocN((size_t)prpath->totpoint * sizeof(ProfilePoint), "path points");
@@ -302,6 +329,17 @@ void profilepath_reset(ProfilePath *prpath, int preset)
       prpath->path[1].x = 1.0;
       prpath->path[1].y = 1.0;
       break;
+    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;
+      break;
   }
 
   if (prpath->table) {
@@ -474,17 +512,14 @@ static void profilepath_make_table(ProfilePath *prpath, const rctf *clipr)
 
 #if DEBUG_PRWDGT
   printf("PROFILEPATH MAKE TABLE\n");
-#endif
-
   if (prpath->path == NULL) {
-    printf("ProfilePath's path is NULL\n"); /* HANS-TODO: Remove */
+    printf("(path is NULL)\n");
     return;
   }
+#endif
 
-  /* HANS-TODO: Remove */
-//  prpath->table = prpath->path;
-
-  /* default rect also is table range */
+  /* Evaluate table inside the clip range */
+  /* HANS-TODO: Not good, this only uses X */
   prpath->mintable = clipr->xmin;
   prpath->maxtable = clipr->xmax;
 
@@ -634,7 +669,7 @@ void profilewidget_changed(ProfileWidget *prwdgt, const bool rem_doubles)
 
 #if DEBUG_PRWDGT
   printf("PROFILEWIDGET CHANGED\n");
-  if (prwdgt->profile->total_points < 0) {
+  if (prwdgt->profile->totpoint < 0) {
     printf("Someone screwed up the totpoint\n");
   }
 #endif
@@ -752,7 +787,7 @@ void profilepath_evaluate(const struct ProfilePath *prpath,
 {
 #if DEBUG_PRWDGT
   printf("PROFILEPATH EVALUATE\n");
-  if (prpath->total_points < 0) {
+  if (prpath->totpoint < 0) {
     printf("Someone screwed up the totpoint\n");
   }
 #endif
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index af11bc8dd03..e674d55f6d8 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -57,7 +57,7 @@
 #define BEVEL_MAX_AUTO_ADJUST_PCT 300.0f
 #define BEVEL_MATCH_SPEC_WEIGHT 0.2
 
-#define DEBUG_CUSTOM_PROFILE_SAMPLE 1
+#define DEBUG_CUSTOM_PROFILE_SAMPLE 0
 #define DEBUG_CUSTOM_PROFILE 0
 #define DEBUG_CUSTOM_PROFILE_WELD 0
 #define DEBUG_CUSTOM_PROFILE_ORIENTATION 0
@@ -2415,6 +2415,9 @@ static void build_boundary_vertex_only(BevelParams *bp, BevVert *bv, bool constr
  * The 'width adjust' part of build_boundary has been done already,
  * and \a efirst is the first beveled edge at vertex \a bv.
  */
+/* HANS-TODO: In the TRI_FAN fill case, check if the third point is planar with the other two
+ * boundverts. If it is, then use polyfill operation on the face instead of a TRI_FAN. When they
+ * are planar the overlapping geometry used to fill the profile if it overlaps itself looks bad */
 static void build_boundary_terminal_edge(BevelParams *bp,
                                          BevVert *bv,
                                          EdgeHalf *efirst,
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 0f8987f9a81..351de7b7b95 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -33,6 +33,7 @@
 #include "BLI_rect.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
+#include "BLI_polyfill_2d.h"
 
 #include "BKE_colorband.h"
 #include "BKE_colortools.h"
@@ -2101,12 +2102,22 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, cons
   immUnbindProgram();
 }
 
+
+#define DEBUG_PROFILE_DRAW 1
+
 /** Simplified version of ui_draw_but_CURVE, used to draw bevel ProfileWidget. */
 /* HANS-TODO: Add the ability to lengthen the height of the UI to keep the grid square */
 void ui_draw_but_PROFILE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, const rcti *rect)
 {
   ProfileWidget *prwidget;
 
+#if DEBUG_PROFILE_DRAW
+  printf("UI DRAW BUT PROFILE");
+  if ((int)but->a1 == UI_GRAD_H) {
+    printf("(UI_GRAD_H mode for some reason)");
+  }
+#endif
+
   if (but->editprwdgt) { /* HANS-TODO: Maybe don't reuse this? */
     prwidget = but->editprwdgt;
   }
@@ -2168,34 +2179,22 @@ void ui_draw_but_PROFILE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, co
   /* backdrop */
   float color_backdrop[4] = {0, 0, 0, 1};
 
-  /* HANS-TODO: Probably get rid of the first case here */
-  if (but->a1 == UI_GRAD_H) {
-    /* grid, hsv uses different grid */
-    GPU_blend(true);
-    GPU_blend_set_func_separate(
-        GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
-    ARRAY_SET_ITEMS(color_backdrop, 0, 0, 0, 48.0 / 255.0);
-    immUniformColor4fv(color_backdrop);
-    ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.1666666f);
-    GPU_blend(false);
+  if (prwidget->flag & PROF_DO_CLIP) {
+    gl_shaded_color_get_fl((uchar *)wcol->inner, -20, color_backdrop);
+    immUniformColor3fv(color_backdrop);
+    immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+    immUniformColor3ubv((uchar *)wcol->inner);
+    immRectf(pos,
+             rect->xmin + zoomx * (prwidget->clipr.xmin - offsx),
+             rect->ymin + zoomy * (prwidget->clipr.ymin - offsy),
+             rect->xmin + zoomx * (prwidget->clipr.xmax - offsx),
+             rect->ymin + zoomy * (prwidget->clipr.ymax - offsy));
   }
   else {
-    if (prwi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list