[Bf-blender-cvs] [cb7e337bdef] soc-2019-bevel-profiles: Added new properties to operator / modifier and curve widget to UI. (Day 1)

Hans Goudey noreply at git.blender.org
Tue May 28 14:42:24 CEST 2019


Commit: cb7e337bdefd1373b6a88b5479b824fa26bafe69
Author: Hans Goudey
Date:   Tue May 28 08:42:11 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rBcb7e337bdefd1373b6a88b5479b824fa26bafe69

Added new properties to operator / modifier and curve widget to UI. (Day 1)

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
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 754cac25f3e..0504271aed0 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -171,6 +171,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         layout.row().prop(md, "miter_inner")
         layout.row().prop(md, "spread")
 
+        layout.row().prop(md, "use_custom_profile")
+        if md.use_custom_profile:
+            layout.template_curve_mapping(md, "profile_curve")
+
     def BOOLEAN(self, layout, _ob, md):
         split = layout.split()
 
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index 2114f9ebd3d..b93b01acd92 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1775,6 +1775,8 @@ static BMOpDefine bmo_bevel_def = {
     bmo_enum_bevel_miter_type},         /* outer miter kind */
    {"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
    {{'\0'}},
   },
   /* slots_out */
diff --git a/source/blender/bmesh/operators/bmo_bevel.c b/source/blender/bmesh/operators/bmo_bevel.c
index 33be9559db3..fd586f1eaa6 100644
--- a/source/blender/bmesh/operators/bmo_bevel.c
+++ b/source/blender/bmesh/operators/bmo_bevel.c
@@ -24,6 +24,7 @@
 
 #include "bmesh.h"
 #include "bmesh_tools.h"
+#include "BKE_colortools.h"
 
 #include "intern/bmesh_operators_private.h" /* own include */
 
@@ -45,6 +46,8 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
   const int miter_inner = BMO_slot_int_get(op->slots_in, "miter_inner");
   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
 
   if (offset > 0) {
     BMOIter siter;
@@ -87,7 +90,9 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
                   miter_outer,
                   miter_inner,
                   spread,
-                  smoothresh);
+                  smoothresh,
+                  use_custom_profile,
+                  profile_curve);
 
     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 2ef3f60e0a6..fdf4da79657 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -38,6 +38,8 @@
 
 #include "eigen_capi.h"
 
+#include "BKE_colortools.h"
+
 #include "bmesh.h"
 #include "bmesh_bevel.h" /* own include */
 
@@ -217,6 +219,30 @@ typedef enum {
   F_RECON,
 } FKind;
 
+
+
+
+/* THIS IS HOW I WOULD WANT TO HAVE THE DATA FOR THE CUSTOM CURVE STORED. WE'LL SEE HOW CLOSE CURVEMAPPING ACTUALLY IS TO THAT
+ * THIS IS MOSTLY JUST AN AID FOR ME SO I CAN KNOW THE KIND OF DATA I NEED TO FIND FROM THE CURVEMAPPING STRUCT */
+
+typedef struct ProfileCurve {
+  /** A list of all of the nodes that make up the curve */
+  struct ProfileNode *curve_nodes;
+} ProfileCurve;
+
+typedef struct ProfileNode {
+  /** X and Y locations of the node from 0f to 1f */
+  float x;
+  float y;
+  /** Whether the point is interpolated to with a curve or a straight line */
+  bool sharp;
+} ProfileNode;
+
+
+
+
+
+
 #if 0
 static const char* fkind_names[] = {"F_NONE", "F_ORIG", "F_VERT", "F_EDGE", "F_RECON"}; /* DEBUG */
 #endif
@@ -258,6 +284,10 @@ typedef struct BevelParams {
   bool mark_sharp;
   /** Should we harden normals? */
   bool harden_normals;
+  /** Should we use the custom profiles feature? */
+  bool use_custom_profiles;
+  /** The curve mapping struct used to store the custom profile*/
+  const struct CurveMapping *profile_curve;
   /** Vertex group array, maybe set if vertex_only. */
   const struct MDeformVert *dvert;
   /** Vertex group index, maybe set if vertex_only. */
@@ -6561,7 +6591,9 @@ void BM_mesh_bevel(BMesh *bm,
                    const int miter_outer,
                    const int miter_inner,
                    const float spread,
-                   const float smoothresh)
+                   const float smoothresh,
+                   const bool use_custom_profile,
+                   const struct CurveMapping *profile_curve)
 {
   BMIter iter, liter;
   BMVert *v, *v_next;
@@ -6593,6 +6625,8 @@ void BM_mesh_bevel(BMesh *bm,
   bp.spread = spread;
   bp.smoothresh = smoothresh;
   bp.face_hash = NULL;
+  bp.use_custom_profiles = use_custom_profile;
+  bp.profile_curve = profile_curve;
 
   if (profile >= 0.950f) { /* r ~ 692, so PRO_SQUARE_R is 1e4 */
     bp.pro_super_r = PRO_SQUARE_R;
diff --git a/source/blender/bmesh/tools/bmesh_bevel.h b/source/blender/bmesh/tools/bmesh_bevel.h
index 496be9219b7..b7eab89bbe5 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.h
+++ b/source/blender/bmesh/tools/bmesh_bevel.h
@@ -21,6 +21,8 @@
  * \ingroup bmesh
  */
 
+#include "BKE_colortools.h"
+
 struct MDeformVert;
 
 void BM_mesh_bevel(BMesh *bm,
@@ -42,6 +44,8 @@ void BM_mesh_bevel(BMesh *bm,
                    const int miter_outer,
                    const int miter_inner,
                    const float spread,
-                   const float smoothresh);
+                   const float smoothresh,
+                   const bool use_custom_profile,
+                   const struct CurveMapping *profile_curve);
 
 #endif /* __BMESH_BEVEL_H__ */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 6a524e03b6e..d63eff17f39 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -392,6 +392,10 @@ typedef struct BevelModifierData {
   /** if the MOD_BEVEL_VWEIGHT option is set,
    * this will be the name of the vert group, MAX_VGROUP_NAME */
   char defgrp_name[64];
+
+  /** Curve info for the custom profile */
+  struct CurveMapping *profile_curve;
+
 } BevelModifierData;
 
 /* BevelModifierData->flags and BevelModifierData->lim_flags */
@@ -401,7 +405,7 @@ enum {
   MOD_BEVEL_ANGLE = (1 << 3),
   MOD_BEVEL_WEIGHT = (1 << 4),
   MOD_BEVEL_VGROUP = (1 << 5),
-  /*  unused                  = (1 << 7), */
+  MOD_BEVEL_CUSTOM_PROFILE = (1 << 7),
   /*  unused                  = (1 << 8), */
   /*  unused                  = (1 << 9), */
   /*  unused                  = (1 << 10), */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 2a09abe5f8d..0b205a40abd 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3644,6 +3644,16 @@ static void rna_def_modifier_bevel(BlenderRNA *brna)
   RNA_def_property_ui_range(prop, 0.0f, 100.0f, 0.1, 4);
   RNA_def_property_ui_text(prop, "Spread", "Spread distance for inner miter arcs");
   RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+  prop = RNA_def_property(srna, "use_custom_profile", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_BEVEL_CUSTOM_PROFILE);
+  RNA_def_property_ui_text(prop, "Custom Profile", "Whether to use a user inputed curve for the bevel's profile");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+  prop = RNA_def_property(srna, "profile_curve", PROP_POINTER, PROP_NONE);
+  RNA_def_property_pointer_sdna(prop, NULL, "profile_curve");
+  RNA_def_property_ui_text(prop, "Custom Profile Curve", "The curve for the custom profile if it is used");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update"); // Maybe actually "rna_Modifier_dependency_update", we'll see
 }
 
 static void rna_def_modifier_shrinkwrap(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c
index 26b45bbef0d..23180ce08c0 100644
--- a/source/blender/modifiers/intern/MOD_bevel.c
+++ b/source/blender/modifiers/intern/MOD_bevel.c
@@ -40,6 +40,7 @@
 
 #include "bmesh.h"
 #include "bmesh_tools.h"
+#include "BKE_colortools.h"
 
 #include "DEG_depsgraph_query.h"
 
@@ -62,6 +63,7 @@ static void initData(ModifierData *md)
   bmd->profile = 0.5f;
   bmd->bevel_angle = DEG2RADF(30.0f);
   bmd->defgrp_name[0] = '\0';
+  bmd->profile_curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
 }
 
 static void copyData(const ModifierData *md_src, ModifierData *md_dst, const int flag)
@@ -109,6 +111,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
   const int miter_outer = bmd->miter_outer;
   const int miter_inner = bmd->miter_inner;
   const float spread = bmd->spread;
+  const bool use_custom_profile = (bmd->flags & MOD_BEVEL_CUSTOM_PROFILE);
 
   bm = BKE_mesh_to_bmesh_ex(mesh,
                             &(struct BMeshCreateParams){0},
@@ -211,7 +214,9 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
                 miter_outer,
                 miter_inner,
                 spread,
-                mesh->smoothresh);
+                mesh->smoothresh,
+                use_custom_profile,
+                bmd->profile_curve);
 
   result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL);
 
@@ -221,6 +226,8 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
 
   result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
 
+  // HANS-TODO: Should the Curve be removed here or will it free itself elsewhere. I should test...
+
   return result;
 }



More information about the Bf-blender-cvs mailing list