[Bf-blender-cvs] [e3217f47afa] soc-2019-bevel-profiles: ProfileWidget sampling and display: 1. Added the ability to sample fewer segments from the profile path than the number of control points. 2. Added a display for the sampled segment positions in the widget's display. This isn't an essential feature, but it helps visualize where the segments will be sampled while keeping the focus on the widget itself.

Hans Goudey noreply at git.blender.org
Fri Jul 26 23:26:47 CEST 2019


Commit: e3217f47afab4e5ed17ef3aff9ed9f910434fa6d
Author: Hans Goudey
Date:   Fri Jul 26 16:50:36 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rBe3217f47afab4e5ed17ef3aff9ed9f910434fa6d

ProfileWidget sampling and display:
 1. Added the ability to sample fewer segments from the profile path than
    the number of control points.
 2. Added a display for the sampled segment positions in the widget's display.
    This isn't an essential feature, but it helps visualize where the segments
    will be sampled while keeping the focus on the widget itself.

This commit also includes various smaller changes:
 1. Resolving / deleting various TODO comments without affecting functionality
    in each file.
 2. Rewording and clarifying comments throughout the code.
 3. Renaming variable names for better code readability.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_profile_widget.h
M	source/blender/blenkernel/intern/profile_widget.c
M	source/blender/bmesh/tools/bmesh_bevel.c
M	source/blender/editors/interface/interface_draw.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 9c1211cd262..66dd99ffabb 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -176,6 +176,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         layout.row().prop(md, "use_custom_profile")
         if md.use_custom_profile:
             layout.template_profilewidget(md, "prwdgt")
+            # For drawing the sampled segment positions in the profile widget itself. This has to
+            # be done here before the ProfileWidget that the bevel code uses is copied from the
+            # original
+            md.prwdgt.initialize(md.segments)
 
     def BOOLEAN(self, layout, _ob, md):
         split = layout.split()
diff --git a/source/blender/blenkernel/BKE_profile_widget.h b/source/blender/blenkernel/BKE_profile_widget.h
index 0048b0bba09..3574ed67cef 100644
--- a/source/blender/blenkernel/BKE_profile_widget.h
+++ b/source/blender/blenkernel/BKE_profile_widget.h
@@ -67,7 +67,7 @@ float profilewidget_distance_to_next_point(const struct ProfileWidget *prwdgt, i
 /* Need to find the total length of the curve to sample a portion of it */
 float profilewidget_total_length(const struct ProfileWidget *prwdgt);
 
-void profilewidget_fill_segment_table(const struct ProfileWidget *prwdgt,
+void profilewidget_create_samples_even_spacing(const struct ProfileWidget *prwdgt,
                                       double *x_table_out,
                                       double *y_table_out);
 
diff --git a/source/blender/blenkernel/intern/profile_widget.c b/source/blender/blenkernel/intern/profile_widget.c
index 07492631998..6580ea907a3 100644
--- a/source/blender/blenkernel/intern/profile_widget.c
+++ b/source/blender/blenkernel/intern/profile_widget.c
@@ -45,7 +45,6 @@
 #define DEBUG_PRWDGT_TABLE 0
 #define DEBUG_PRWDGT_EVALUATE 0
 #define DEBUG_PRWDGT_REVERSE 0
-/* HANS-TODO: Remove debugging code */
 
 void profilewidget_set_defaults(ProfileWidget *prwdgt)
 {
@@ -84,6 +83,7 @@ struct ProfileWidget *profilewidget_add(int preset)
   return prwdgt;
 }
 
+/* HANS-TODO: Double free error here with the prwdgt->table */
 void profilewidget_free_data(ProfileWidget *prwdgt)
 {
 #if DEBUG_PRWDGT
@@ -167,7 +167,7 @@ bool profilewidget_remove_point(ProfileWidget *prwdgt, ProfilePoint *point)
 
   pts = MEM_mallocN((size_t)prwdgt->totpoint * sizeof(ProfilePoint), "path points");
 
-  /* well, lets keep the two outer points! */
+  /* Keep the two outer points */
   for (a = 0, b = 0; a < prwdgt->totpoint; a++) {
     if (&prwdgt->path[a] != point) {
       pts[b] = prwdgt->path[a];
@@ -309,17 +309,11 @@ void profilewidget_reverse(ProfileWidget *prwdgt)
   ProfilePoint *new_pts = MEM_mallocN(((size_t)prwdgt->totpoint) * sizeof(ProfilePoint),
                                       "path points");
   /* Mirror the new points across the y = x line */
-  for (int i = 1; i < prwdgt->totpoint - 1; i++) {
+  for (int i = 0; i < prwdgt->totpoint; i++) {
     new_pts[prwdgt->totpoint - i - 1].x = prwdgt->path[i].y;
     new_pts[prwdgt->totpoint - i - 1].y = prwdgt->path[i].x;
     new_pts[prwdgt->totpoint - i - 1].flag = prwdgt->path[i].flag;
   }
-  /* Set the location of the first and last points */
-  /* HANS-TODO: Bring this into the loop */
-  new_pts[0].x = 1.0;
-  new_pts[0].y = 0.0;
-  new_pts[prwdgt->totpoint - 1].x = 0.0;
-  new_pts[prwdgt->totpoint - 1].y = 1.0;
 
 #if DEBUG_PRWDGT_REVERSE
   printf("Locations before:\n");
@@ -375,6 +369,7 @@ void profilewidget_reset(ProfileWidget *prwdgt)
     case PROF_PRESET_SUPPORTS:
       prwdgt->path[0].x = 1.0;
       prwdgt->path[0].y = 0.0;
+      prwdgt->path[0].flag = PROF_HANDLE_VECTOR;
       prwdgt->path[1].x = 1.0;
       prwdgt->path[1].y = 0.5;
       for (int i = 1; i < 10; i++) {
@@ -385,6 +380,7 @@ void profilewidget_reset(ProfileWidget *prwdgt)
       prwdgt->path[10].y = 1.0;
       prwdgt->path[11].x = 0.0;
       prwdgt->path[11].y = 1.0;
+      prwdgt->path[11].flag = PROF_HANDLE_VECTOR;
       break;
     case PROF_PRESET_EXAMPLE1: /* HANS-TODO: Don't worry, this is just temporary */
       prwdgt->path[0].x = 1.0f;
@@ -442,7 +438,7 @@ void profilewidget_reset(ProfileWidget *prwdgt)
   }
 }
 
-/** Helper for profile_widget_create samples. Returns whether both handles that make up the edge
+/** Helper for 'profile_widget_create' samples. Returns whether both handles that make up the edge
  * are vector handles */
 static bool is_curved_edge(BezTriple * bezt, int i)
 {
@@ -450,6 +446,9 @@ static bool is_curved_edge(BezTriple * bezt, int i)
 }
 
 /** Used in the sample creation process. Reduced copy of #calchandleNurb_intern code in curve.c */
+/* HANS-TODO: Depending on the orientation of a profile the location of the bezier handles are
+ * different, which means there is some different dependence on X vs Y, but it should be direction
+ * agnostic */
 static void calchandle_profile(BezTriple *bezt, const BezTriple *prev, const BezTriple *next)
 {
 #define p2_handle1 ((p2)-3)
@@ -640,7 +639,7 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt,
   int totedges = prwdgt->totpoint - 1;
   int totpoints = prwdgt->totpoint;
 
-  BLI_assert(n_segments >= totpoints);
+  BLI_assert(n_segments > 0);
 
   /* Create Bezier points for calculating the higher resolution path */
   bezt = MEM_callocN((size_t)totpoints * sizeof(BezTriple), "beztarr");
@@ -649,12 +648,14 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt,
     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_ANIM;
   }
+  /* 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]);
   }
   calchandle_profile(&bezt[totpoints - 1], &bezt[totpoints - 2], NULL);
 
+  /* HANS-TODO: Figure out if this 'correction' to the end points' handles is actually helpful */
   if (prwdgt->totpoint > 2) {
     float hlen, nlen, vec[3];
 
@@ -675,7 +676,7 @@ void profilewidget_create_samples(const ProfileWidget *prwdgt,
         sub_v3_v3v3(bezt[0].vec[0], bezt[0].vec[1], vec);
       }
     }
-    i = prwdgt->totpoint - 1;
+    i = totpoints - 1;
     if (bezt[i].h2 == HD_AUTO) {
 
       hlen = len_v3v3(bezt[i].vec[1], bezt[i].vec[0]); /* original handle length */
@@ -697,9 +698,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");
-  /* (Insertion sort for now. It's probably fast enough though) */
-  /* HANS-TODO: Test the sorting */
-  for (i = 0; i < totedges; i++) {
+  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 */
     for (i_insert = 0; i_insert < i; i_insert++) {
       if (!compare_curvature_bezt_edge_i(bezt, i, i_curve_sorted[i_insert])) {
@@ -712,49 +711,54 @@ 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");
   int n_added = 0;
-  if (sample_straight_edges) {
-    /* Assign an even number to each edge if it’s possible, then add the remainder of sampled
-     * points starting with the most curved edges. */
-    n_common = n_segments / totedges;
-    n_left = n_segments % totedges;
-
-    /* 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_added += n_common;
-      }
-    }
-  }
-  else {
-    /* Count the number of curved edges */
-    n_curved_edges = 0;
-    for (i = 0; i < totedges; i++) {
-      if (is_curved_edge(bezt, i)) {
-        n_curved_edges++;
+  if (n_segments >= totedges) {
+    if (sample_straight_edges) {
+      /* Assign an even number to each edge if it’s possible, then add the remainder of sampled
+       * points starting with the most curved edges. */
+      n_common = n_segments / totedges;
+      n_left = n_segments % totedges;
+
+      /* 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_added += n_common;
+        }
       }
     }
-    /* Just sample all of the edges if there are no curved edges */
-    if (n_curved_edges == 0) {
-      n_curved_edges = totedges;
-    }
-
-    /* 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 one for each straight edge */
-    n_common = n_left / n_curved_edges; /* Number assigned to every curved edge */
-    if (n_common > 0) {
+    else {
+      /* Count the number of curved edges */
+      n_curved_edges = 0;
       for (i = 0; i < totedges; i++) {
         if (is_curved_edge(bezt, i)) {
-          n_points[i] += n_common;
-          n_added += n_common;
+          n_curved_edges++;
         }
-        else {
-          n_points[i] = 1;
-          n_added++;
+      }
+      /* Just sample all of the edges if there are no curved edges */
+      if (n_curved_edges == 0) {
+        n_curved_edges = totedges;
+      }
+
+      /* 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 */
+      if (n_common > 0) {
+        for (i = 0; i < totedges; i++) {
+          if (is_curved_edge(bezt, i)) {
+            n_points[i] += n_common;
+            n_added += n_common;
+          }
+          else {
+            n_points[i] = 1;
+            n_added++;
+          }
         }
       }
+      n_left -= n_common * n_curved_edges;
     }
-    n_left -= n_common * n_curved_edges;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list