[Bf-blender-cvs] [c84eed2ab12] soc-2019-bevel-profiles: Progress on sampling the 2D coords along the curve's length. Sampling dysfunctional at the moment, debugging next. (Day 2)

Hans Goudey noreply at git.blender.org
Wed May 29 05:35:39 CEST 2019


Commit: c84eed2ab120d4f8fd0c36b22046e98c96516347
Author: Hans Goudey
Date:   Tue May 28 23:35:15 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rBc84eed2ab120d4f8fd0c36b22046e98c96516347

Progress on sampling the 2D coords along the curve's length. Sampling dysfunctional at the moment, debugging next. (Day 2)

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_colortools.h
M	source/blender/blenkernel/intern/colortools.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_color_types.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 0504271aed0..1a39c4c06f3 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_curve_mapping(md, "profile_curve")
+            layout.row().prop(md, "sample_points")
 
     def BOOLEAN(self, layout, _ob, md):
         split = layout.split()
diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h
index a6eb12c3708..42ab98bcc82 100644
--- a/source/blender/blenkernel/BKE_colortools.h
+++ b/source/blender/blenkernel/BKE_colortools.h
@@ -46,6 +46,18 @@ void curvemapping_set_black_white(struct CurveMapping *cumap,
                                   const float black[3],
                                   const float white[3]);
 
+
+/* Used for a path where the curve isn't necessarily a function. */
+/* Initialized with the number of segments to fill the table with */
+void curvemapping_path_initialize(struct CurveMapping *cumap, int nsegments); // HANS-TODO: Hmm, this assumes there is only one curve
+/* Evaluates along the length of the path rather than with X coord */
+void curvemapping_path_evaluate(const struct CurveMapping *cumap, int segment, float vecout[2]);
+
+void curvemap_path_evaluate(const struct CurveMap *cuma, float length_portion, float vecout[2]);
+
+float curvemap_path_total_length(const struct CurveMap *cuma);
+
+
 enum {
   CURVEMAP_SLOPE_NEGATIVE = 0,
   CURVEMAP_SLOPE_POSITIVE = 1,
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index 45cb5e817d2..44684f2a013 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -1211,6 +1211,120 @@ void curvemapping_table_RGBA(const CurveMapping *cumap, float **array, int *size
   }
 }
 
+
+
+
+
+/* *********** Curvemapping for paths /non-functions (Bevel) *************/
+
+/* HANS-TODO: Maybe this should check index out of bound */
+/* HANS-TODO: This falls back to linear interpolation for all points for now */
+/* This might be a little less efficient because it has to get fetch x and y rather than carrying them over from the last */
+float curvemap_path_distance_to_next_point(const struct CurveMap *cuma, int i) {
+  float x = cuma->curve[i].x;
+  float y = cuma->curve[i].y;
+  float x_next = cuma->curve[i+1].x;
+  float y_next = cuma->curve[i+1].y;
+
+  return sqrtf(powf(y_next - y, 2) + powf(x_next - x, 2));
+}
+
+
+/* Calculate the total length of the path (between all of the nodes and the ends at 0 and 1 */
+float curvemap_path_total_length(const struct CurveMap *cuma) {
+  float total_length = 0;
+  /*printf("Here are the locations of all of %d points in the list:\n", cuma->totpoint);
+  for (int i = 0; i < cuma->totpoint; i++) {
+    printf("(%f, %f)\n", cuma->curve[i].x, cuma->curve[i].y);
+  }*/
+
+  for (int i = 0; i < cuma->totpoint - 1; i++) {
+    total_length += curvemap_path_distance_to_next_point(cuma, i);
+  }
+
+  return total_length;
+}
+
+static inline float lerp(float a, float b, float f) {
+  return a + (b - a) * f;
+}
+
+void curvemap_path_evaluate(const struct CurveMap *cuma, float length_portion, float vecout[2]) {
+  /* HANS-TODO: For now I'm skipping the table and doing the evaluation here, */
+  /* but it should be moved later on so I don't have to travel down node list twice for every call */
+  float total_length = curvemap_path_total_length(cuma);
+  printf("Total length of the curve is: %f\n", (double)total_length);
+
+  /* Find the last point along the path with a lower length portion than the input */
+  int i = 0;
+  float length_travelled = 0.0f;
+  while (length_travelled < length_portion) {
+    /* Check if we reached the last point before the final one */
+    if (i == cuma->totpoint - 2) {
+      break;
+    }
+    float new_length = curvemap_path_distance_to_next_point(cuma, i) / total_length;
+    if (length_travelled + new_length >= length_portion) {
+      break;
+    }
+    length_travelled += new_length;
+    i++;
+  }
+
+  /* Now travel the rest of the length portion down the path to the next point and find the location there */
+  float distance_to_next_point = curvemap_path_distance_to_next_point(cuma, i);
+  float lerp_factor = (length_portion - length_travelled) / distance_to_next_point;
+
+
+  // PRINT OUT THE LOCATIONS OF THE POINTS IT'S LERPING BETWEEN TO DEBUG THIS
+
+
+  vecout[0] = lerp(cuma->curve[i].x, cuma->curve[i+1].x, lerp_factor);
+  vecout[1] = lerp(cuma->curve[i].y, cuma->curve[i+1].y, lerp_factor);
+}
+
+static void curvemap_path_make_table(const struct CurveMap *cuma) {
+  /* Fill a table with values for the position of the graph at each of the segments */
+}
+
+/* Used for a path where the curve isn't necessarily a function. */
+/* Initialized with the number of segments to fill the table with */
+void curvemapping_path_initialize(struct CurveMapping *cumap, int nsegments) {
+  cumap->cm[0].nsegments = nsegments;
+  /* Fill a table with the position at nssegments steps along the total length of the path */
+  curvemap_path_make_table(cumap->cm);
+}
+
+
+
+/* Evaluates along the length of the path rather than with X coord */
+/* Must initialize the table with the right amount of segments first! */
+void curvemapping_path_evaluate(const struct CurveMapping *cumap, int segment, float position_out[2]) {
+  /* Return the location in the table of the input segment */
+
+  const CurveMap *cuma = cumap->cm;
+  curvemap_path_evaluate(cuma, segment / cuma->nsegments, position_out);
+
+  /* Clip down to 0 to 1 range for both coords */
+  if (cumap->flag & CUMA_DO_CLIP) {
+    if (position_out[0] < cumap->curr.xmin) {
+      position_out[0] = cumap->curr.xmin;
+    }
+    else if (position_out[0] > cumap->curr.xmax) {
+      position_out[0] = cumap->curr.xmax;
+    }
+    if (position_out[1] < cumap->curr.ymin) {
+      position_out[1] = cumap->curr.ymin;
+    }
+    else if (position_out[1] > cumap->curr.ymax) {
+      position_out[1] = cumap->curr.ymax;
+    }
+  }
+}
+
+
+
+
 /* ***************** Histogram **************** */
 
 #define INV_255 (1.f / 255.f)
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index b93b01acd92..832fe524941 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1776,7 +1776,8 @@ static BMOpDefine bmo_bevel_def = {
    {"spread", BMO_OP_SLOT_FLT},           /* amount to offset beveled edge */
    {"smoothresh", BMO_OP_SLOT_FLT},       /* for passing mesh's smoothresh, used in hardening */
    {"use_custom_profiles", BMO_OP_SLOT_BOOL}, /* Whether to use custom profile feature */
-   {"profile_curve", BMO_OP_SLOT_INT}, /* the CurveMapping struct thing for the profile shape */ // HANS-TODO: figure out how to get the struct through here
+   {"profile_curve", BMO_OP_SLOT_INT},    /* the CurveMapping struct thing for the profile shape */ // HANS-TODO: figure out how to get the struct through here
+   {"sample_points", BMO_OP_SLOT_BOOL},   /* only sample points on plot */
    {{'\0'}},
   },
   /* slots_out */
diff --git a/source/blender/bmesh/operators/bmo_bevel.c b/source/blender/bmesh/operators/bmo_bevel.c
index fd586f1eaa6..5eac6c90636 100644
--- a/source/blender/bmesh/operators/bmo_bevel.c
+++ b/source/blender/bmesh/operators/bmo_bevel.c
@@ -47,7 +47,8 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
   const float spread = BMO_slot_float_get(op->slots_in, "spread");
   const float smoothresh = BMO_slot_float_get(op->slots_in, "smoothresh");
   const bool use_custom_profile = BMO_slot_bool_get(op->slots_in, "use_custom_profile");
-  const struct CurveMapping *profile_curve = NULL; // HANS-TODO: This probably shouldn't be NULL? More figuring out how to get this through
+  const struct CurveMapping *profile_curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); // HANS-TODO: This probably shouldn't be NULL? More figuring out how to get this through
+  const bool sample_points = BMO_slot_bool_get(op->slots_in, "sample_points");
 
   if (offset > 0) {
     BMOIter siter;
@@ -92,7 +93,8 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
                   spread,
                   smoothresh,
                   use_custom_profile,
-                  profile_curve);
+                  profile_curve,
+                  sample_points);
 
     BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
     BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_TAG);
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index fdf4da79657..b8b739d24e5 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -285,7 +285,9 @@ typedef struct BevelParams {
   /** Should we harden normals? */
   bool harden_normals;
   /** Should we use the custom profiles feature? */
-  bool use_custom_profiles;
+  bool use_custom_profile;
+  /** Should we just sample the points on the plot */
+  bool sample_points;
   /** The curve mapping struct used to store the custom profile*/
   const struct CurveMapping *profile_curve;
   /** Vertex group array, maybe set if vertex_only. */
@@ -6593,7 +6595,8 @@ void BM_mesh_bevel(BMesh *bm,
                    const float spread,
                    const float smoothresh,
                    const bool use_custom_profile,
-                   const struct CurveMapping *profile_curve)
+                   const struct CurveMapping *profile_curve,
+                   const bool sample_points)
 {
   BMIter iter, liter;
   BMVert *v, *v_next;
@@ -6625,8 +6628,21 @@ void BM_mesh_bevel(BMesh *bm,
   bp.spread = spread;
   bp.smoothresh = smoothresh;
   bp.face_hash = NULL;
-  bp.use_custom_profiles = use_custom_profile;
+  bp.use_custom_profile = use_custom_profile;
   bp.pr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list