[Bf-blender-cvs] [87c435004e7] soc-2019-bevel-profiles: Profilewidget: Added option to not sample straight (vector interpolated) edges.

Hans Goudey noreply at git.blender.org
Sun Jul 7 20:23:17 CEST 2019


Commit: 87c435004e76ca49f24626bf2b4e8ce49660b989
Author: Hans Goudey
Date:   Sun Jul 7 14:23:20 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rB87c435004e76ca49f24626bf2b4e8ce49660b989

Profilewidget: Added option to not sample straight (vector interpolated) edges.

The option is part of the bevel modifier for now, but I may move it to the profile widget.

Disabled by default.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_profile_widget.h
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/blenkernel/intern/profile_widget.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/bmesh/intern/bmesh_opdefines.c
M	source/blender/bmesh/operators/bmo_bevel.c
M	source/blender/bmesh/tools/bmesh_bevel.c
M	source/blender/bmesh/tools/bmesh_bevel.h
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_bevel.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 0636d69258a..5f11674b2b3 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -174,6 +174,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         layout.row().prop(md, "use_custom_profile")
         if md.use_custom_profile:
             layout.template_profilewidget(md, "prwdgt")
+            layout.row().prop(md, "sample_straight_edges")
 
     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 d0c8651d6f1..49b48124e38 100644
--- a/source/blender/blenkernel/BKE_profile_widget.h
+++ b/source/blender/blenkernel/BKE_profile_widget.h
@@ -41,7 +41,10 @@ void profilewidget_copy_data(struct ProfileWidget *target, const struct ProfileW
 
 struct ProfileWidget *profilewidget_copy(const struct ProfileWidget *prwdgt);
 
-void profilewidget_create_samples(const struct ProfileWidget *prwdgt, float *locations, int n_segments);
+void profilewidget_create_samples(const struct ProfileWidget *prwdgt,
+                                  float *locations,
+                                  int n_segments,
+                                  bool sample_straight_edges);
 
 /* Evaluates along the length of the path rather than with X coord */
 void profilewidget_evaluate(const struct ProfileWidget *prwdgt,
@@ -51,9 +54,9 @@ void profilewidget_evaluate(const struct ProfileWidget *prwdgt,
 
 /* Length portion is the fraction of the total path length where we want the location */
 void profilewidget_evaluate_portion(const struct ProfileWidget *prwdgt,
-                          float length_portion,
-                          float *x_out,
-                          float *y_out);
+                                    float length_portion,
+                                    float *x_out,
+                                    float *y_out);
 
 void profilewidget_initialize(struct ProfileWidget *prwdgt, short nsegments);
 
@@ -80,7 +83,7 @@ void profilewidget_handle_set(struct ProfileWidget *prwdgt, int type);
 void profilewidget_changed(struct ProfileWidget *prwdgt, const bool rem_doubles);
 
 void profilewidget_fill_segment_table(const struct ProfileWidget *prwdgt,
-                                    double *x_table_out,
-                                    double *y_table_out);
+                                      double *x_table_out,
+                                      double *y_table_out);
 
 #endif
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index a86085942bf..2254207e545 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -338,7 +338,6 @@ static void modifier_copy_data_id_us_cb(void *UNUSED(userData),
 
 void modifier_copyData_ex(ModifierData *md, ModifierData *target, const int flag)
 {
-  printf("MODIFIER COPYDATA EX\n");
   const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
   target->mode = md->mode;
diff --git a/source/blender/blenkernel/intern/profile_widget.c b/source/blender/blenkernel/intern/profile_widget.c
index aa15e80100c..b4577ca7b99 100644
--- a/source/blender/blenkernel/intern/profile_widget.c
+++ b/source/blender/blenkernel/intern/profile_widget.c
@@ -45,9 +45,7 @@
 #define DEBUG_PRWDGT_TABLE 0
 #define DEBUG_PRWDGT_EVALUATE 0
 #define DEBUG_PRWDGT_REVERSE 0
-
-/* HANS-TODO: Organize functions, especially by which need initialization and which don't */
-/* HANS-TODO: Make sure the stupid asserts I've used as sanity checks aren't making it to release builds */
+/* HANS-TODO: Remove debugging code */
 
 void profilewidget_set_defaults(ProfileWidget *prwdgt)
 {
@@ -151,9 +149,8 @@ ProfileWidget *profilewidget_copy(const ProfileWidget *prwdgt)
   return NULL;
 }
 
-/* ********** requires profilewidget_changed() call after ******** */
-
-/* remove specified point */
+/** Removes a specific point from the path of control points
+ * \note: Requiress profilewidget_changed call after */
 bool profilewidget_remove_point(ProfileWidget *prwdgt, ProfilePoint *point)
 {
   ProfilePoint *pts;
@@ -187,40 +184,42 @@ bool profilewidget_remove_point(ProfileWidget *prwdgt, ProfilePoint *point)
   return (removed != 0);
 }
 
-/* removes with flag set */
+/** Removes every point in the widget with the supplied flag set, except for the first and last.
+ * \param flag: ProfilePoint->flag
+ * \note: Requiress profilewidget_changed call after */
 void profilewidget_remove(ProfileWidget *prwdgt, const short flag)
 {
-  ProfilePoint *pts = MEM_mallocN(((size_t)prwdgt->totpoint) * sizeof(ProfilePoint),
-                                  "path points");
-  int a, b, removed = 0;
-
 #if DEBUG_PRWDGT
   printf("PROFILEPATH REMOVE\n");
 #endif
+  int i_old, i_new, n_removed = 0;
 
-  /* well, lets keep the two outer points! */
-  pts[0] = prwdgt->path[0];
-  for (a = 1, b = 1; a < prwdgt->totpoint - 1; a++) {
-    if (!(prwdgt->path[a].flag & flag)) {
-      pts[b] = prwdgt->path[a];
-      b++;
+  /* Copy every point without the flag into the new path */
+  ProfilePoint *new_pts = MEM_mallocN(((size_t)prwdgt->totpoint) * sizeof(ProfilePoint),
+                                  "path points");
+
+  /* Don't delete the starting and ending points */
+  new_pts[0] = prwdgt->path[0];
+  for (i_old = 1, i_new = 1; i_old < prwdgt->totpoint - 1; i_old++) {
+    if (!(prwdgt->path[i_old].flag & flag)) {
+      new_pts[i_new] = prwdgt->path[i_old];
+      i_new++;
     }
     else {
-      removed++;
+      n_removed++;
     }
   }
-  pts[b] = prwdgt->path[a];
+  new_pts[i_new] = prwdgt->path[i_old];
 
   MEM_freeN(prwdgt->path);
-  prwdgt->path = pts;
-  prwdgt->totpoint -= removed;
+  prwdgt->path = new_pts;
+  prwdgt->totpoint -= n_removed;
 }
 
-/* The choice for which points to place the new vertex between is more complex with a profile than
- * with a mapping function. We can't just find the new neighbors with X value comparisons. Instead
- * this function checks which line segment is closest to the new point with a handy pre-made
- * function.
-*/
+/** Adds a new point at the specified location. The choice for which points to place the new vertex
+ * between is more complex for a profile. We can't just find the new neighbors with X value
+ * comparisons. Instead this function checks which line segment is closest to the new point.
+ * \note: Requiress profilewidget_changed call after */
 ProfilePoint *profilewidget_insert(ProfileWidget *prwdgt, float x, float y)
 {
   ProfilePoint *new_pt = NULL;
@@ -254,7 +253,7 @@ ProfilePoint *profilewidget_insert(ProfileWidget *prwdgt, float x, float y)
                                       "path points");
   for (int i_new = 0, i_old = 0; i_new < prwdgt->totpoint; i_new++) {
     if (i_new != insert_i) {
-      /* Insert old point */
+      /* Insert old points */
       new_pts[i_new].x = prwdgt->path[i_old].x;
       new_pts[i_new].y = prwdgt->path[i_old].y;
       new_pts[i_new].flag = prwdgt->path[i_old].flag & ~PROF_SELECT; /* Deselect old points */
@@ -275,8 +274,29 @@ ProfilePoint *profilewidget_insert(ProfileWidget *prwdgt, float x, float y)
   return new_pt;
 }
 
-/* Requires ProfileWidget changed call afterwards */
-/* HANS-TODO: Or we could just reverse the table here and not require that? */
+/** Sets the handle type of the selected control points.
+ * \param type: Either HD_VECT or HD_AUTO_ANIM
+ * \note: Requiress profilewidget_changed call after. */
+void profilewidget_handle_set(ProfileWidget *prwdgt, int type)
+{
+#if DEBUG_PRWDGT
+  printf("PROFILEPATH HANDLE SET\n");
+#endif
+  for (int i = 0; i < prwdgt->totpoint; i++) {
+    if (prwdgt->path[i].flag & PROF_SELECT) {
+      prwdgt->path[i].flag &= ~(PROF_HANDLE_VECTOR | PROF_HANDLE_AUTO_ANIM);
+      if (type == HD_VECT) {
+        prwdgt->path[i].flag |= PROF_HANDLE_VECTOR;
+      }
+      else if (type == HD_AUTO_ANIM) {
+        prwdgt->path[i].flag |= PROF_HANDLE_AUTO_ANIM;
+      }
+    }
+  }
+}
+
+/** Flips the profile across the diagonal so that its orientation is reversed.
+ * \note: Requiress profilewidget_changed call after.  */
 void profilewidget_reverse(ProfileWidget *prwdgt)
 {
 #if DEBUG_PRWDGT
@@ -318,8 +338,8 @@ void profilewidget_reverse(ProfileWidget *prwdgt)
   prwdgt->path = new_pts;
 }
 
-/* Requires ProfileWidget changed call afterwards */
-/* HANS-TODO: Couldn't it just build the table at the end of this function here? */
+/** Resets the profile to the current preset.
+ * \note: Requiress profilewidget_changed call after */
 void profilewidget_reset(ProfileWidget *prwdgt)
 {
 #if DEBUG_PRWDGT
@@ -422,29 +442,14 @@ void profilewidget_reset(ProfileWidget *prwdgt)
   }
 }
 
-/** Sets the handle type of the selected control points.
-  *\param type: Either HD_VECT or HD_AUTO_ANIM */
-void profilewidget_handle_set(ProfileWidget *prwdgt, int type)
+/** 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)
 {
-#if DEBUG_PRWDGT
-  printf("PROFILEPATH HANDLE SET\n");
-#endif
-  for (int i = 0; i < prwdgt->totpoint; i++) {
-    if (prwdgt->path[i].flag & PROF_SELECT) {
-      prwdgt->path[i].flag &= ~(PROF_HANDLE_VECTOR | PROF_HANDLE_AUTO_ANIM);
-      if (type == HD_VECT) {
-        prwdgt->path[i].flag |= PROF_HANDLE_VECTOR;
-      }
-      else if (type == HD_AUTO_ANIM) {
-        prwdgt->path[i].flag |= PROF_HANDLE_AUTO_ANIM;
-      }
-    }
-  }
+  return (bezt[i].h2 != HD_VECT || bezt[i + 1].h1 != HD_VECT);
 }
 
-/* *********************** Making the tables and display ************** */
-
-/** Reduced copy of #calchandleNurb_intern code in curve.c */
+/** Used in the sample creation process. Reduced copy of #calchandleNurb_intern code in curve.c */
 static void calchandle_profile(BezTriple *bezt, const BezTriple *prev, const BezTriple *next)
 {
 #define p2_handle1 ((p2)-3)
@@ -565,9 +570,9 @@ static void calchandle_profile(BezTriple *bezt, const 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list