editmesh_bevel.c: void MESH_OT_bevel(wmOperatorType *ot) { printf("MESH OT BEVEL\n"); PropertyRNA *prop; static const EnumPropertyItem offset_type_items[] = { {BEVEL_AMT_OFFSET, "OFFSET", 0, "Offset", "Amount is offset of new edges from original"}, {BEVEL_AMT_WIDTH, "WIDTH", 0, "Width", "Amount is width of new face"}, {BEVEL_AMT_DEPTH,"DEPTH", 0, "Depth", "Amount is perpendicular distance from original edge to bevel face"}, {BEVEL_AMT_PERCENT, "PERCENT", 0, "Percent", "Amount is percent of adjacent edge length"}, {0, NULL, 0, NULL, NULL}, }; static const EnumPropertyItem face_strength_mode_items[] = { {BEVEL_FACE_STRENGTH_NONE, "NONE", 0, "None", "Do not set face strength"}, {BEVEL_FACE_STRENGTH_NEW, "NEW", 0, "New", "Set face strength on new faces only"}, {BEVEL_FACE_STRENGTH_AFFECTED, "AFFECTED", 0, "Affected", "Set face strength on new and modified faces only"}, {BEVEL_FACE_STRENGTH_ALL, "ALL", 0, "All", "Set face strength on all faces"}, {0, NULL, 0, NULL, NULL}, }; static const EnumPropertyItem miter_outer_items[] = { {BEVEL_MITER_SHARP, "SHARP", 0, "Sharp", "Outside of miter is sharp"}, {BEVEL_MITER_PATCH, "PATCH", 0, "Patch", "Outside of miter is squared-off patch"}, {BEVEL_MITER_ARC, "ARC", 0, "Arc", "Outside of miter is arc"}, {0, NULL, 0, NULL, NULL}, }; static const EnumPropertyItem miter_inner_items[] = { {BEVEL_MITER_SHARP, "SHARP", 0, "Sharp", "Inside of miter is sharp"}, {BEVEL_MITER_ARC, "ARC", 0, "Arc", "Inside of miter is arc"}, {0, NULL, 0, NULL, NULL}, }; /* identifiers */ ot->name = "Bevel"; ot->description = "Cut into selected items at an angle to create bevel or chamfer"; ot->idname = "MESH_OT_bevel"; /* api callbacks */ ot->exec = edbm_bevel_exec; ot->invoke = edbm_bevel_invoke; ot->modal = edbm_bevel_modal; ot->cancel = edbm_bevel_cancel; ot->poll = ED_operator_editmesh; ot->poll_property = edbm_bevel_poll_property; ot->ui = edbm_bevel_ui; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR_XY | OPTYPE_BLOCKING; RNA_def_enum(ot->srna, "offset_type", offset_type_items, 0, "Width Type", "What distance Width measures"); prop = RNA_def_property(ot->srna, "offset", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_range(prop, 0.0, 1e6); RNA_def_property_ui_range(prop, 0.0f, 100.0, 1, 3); RNA_def_property_ui_text(prop, "Width", "Bevel amount"); prop = RNA_def_property(ot->srna, "offset_pct", PROP_FLOAT, PROP_PERCENTAGE); RNA_def_property_range(prop, 0.0, 100); RNA_def_property_ui_text(prop, "Width Percent", "Bevel amount for percentage method"); RNA_def_int(ot->srna, "segments", 1, 1, SEGMENTS_HARD_MAX, "Segments", "Segments for curved edge", 1, 100); RNA_def_float(ot->srna, "profile", 0.5f, PROFILE_HARD_MIN, 1.0f, "Profile", "Controls profile shape (0.5 = round)", PROFILE_HARD_MIN, 1.0f); RNA_def_boolean(ot->srna, "vertex_only", false, "Vertex Only", "Bevel only vertices"); RNA_def_boolean(ot->srna, "clamp_overlap", false, "Clamp Overlap", "Do not allow beveled edges/vertices to overlap each other"); RNA_def_boolean(ot->srna, "loop_slide", true, "Loop Slide", "Prefer slide along edge to even widths"); RNA_def_boolean(ot->srna, "mark_seam", false, "Mark Seams", "Mark Seams along beveled edges"); RNA_def_boolean(ot->srna, "mark_sharp", false, "Mark Sharp", "Mark beveled edges as sharp"); RNA_def_int(ot->srna, "material", -1, -1, INT_MAX, "Material", "Material for bevel faces (-1 means use adjacent faces)", -1, 100); RNA_def_boolean(ot->srna, "harden_normals", false, "Harden Normals", "Match normals of new faces to adjacent faces"); RNA_def_enum(ot->srna, "face_strength_mode", face_strength_mode_items, BEVEL_FACE_STRENGTH_NONE, "Face Strength Mode", "Whether to set face strength, and which faces to set face strength on"); RNA_def_enum(ot->srna, "miter_outer", miter_outer_items, BEVEL_MITER_SHARP, "Outer Miter", "Pattern to use for outside of miters"); RNA_def_enum(ot->srna, "miter_inner", miter_inner_items, BEVEL_MITER_SHARP, "Inner Miter", "Pattern to use for inside of miters"); RNA_def_float(ot->srna, "spread", 0.1f, 0.0f, 1e6f, "Spread", "Amount to spread arcs for arc inner miters", 0.0f, 100.0f); RNA_def_boolean(ot->srna, "use_custom_profile", false, "Custom Profile", "Define a custom profile for the bevel"); /* HANS-TODO: Add the profile widget here somehow */ RNA_def_pointer(ot->srna, "prwdgt", "ProfileWidget", "", "Widget for editing profile path"); RNA_def_boolean(ot->srna, "sample_straight_edges", false, "Custom Profile", "Define a custom profile for the bevel"); prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", ""); RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } static bool edbm_bevel_calc(wmOperator *op) { printf("EDBM BEVEL CALC\n"); BevelData *opdata = op->customdata; BMEditMesh *em; BMOperator bmop; bool changed = false; const float offset = get_bevel_offset(op); const int offset_type = RNA_enum_get(op->ptr, "offset_type"); const int segments = RNA_int_get(op->ptr, "segments"); const float profile = RNA_float_get(op->ptr, "profile"); const bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only"); const bool clamp_overlap = RNA_boolean_get(op->ptr, "clamp_overlap"); int material = RNA_int_get(op->ptr, "material"); const bool loop_slide = RNA_boolean_get(op->ptr, "loop_slide"); const bool mark_seam = RNA_boolean_get(op->ptr, "mark_seam"); const bool mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp"); const bool harden_normals = RNA_boolean_get(op->ptr, "harden_normals"); const int face_strength_mode = RNA_enum_get(op->ptr, "face_strength_mode"); const int miter_outer = RNA_enum_get(op->ptr, "miter_outer"); const int miter_inner = RNA_enum_get(op->ptr, "miter_inner"); const float spread = RNA_float_get(op->ptr, "spread"); const bool use_custom_profile = RNA_boolean_get(op->ptr, "use_custom_profile"); const PointerRNA prwdgt_ptr = RNA_pointer_get(op->ptr, "prwdgt"); const bool sample_straight_edges = RNA_boolean_get(op->ptr, "sample_straight_edges"); const ProfileWidget *prwdgt = prwdgt_ptr.data; rna_profile.c: static void rna_def_profilewidget_points_api(BlenderRNA *brna, PropertyRNA *cprop) { StructRNA *srna; PropertyRNA *parm; FunctionRNA *func; RNA_def_property_srna(cprop, "ProfilePoints"); srna = RNA_def_struct(brna, "ProfilePoints", NULL); RNA_def_struct_sdna(srna, "ProfileWidget"); RNA_def_struct_ui_text(srna, "Profile Point", "Collection of Profile Points"); func = RNA_def_function(srna, "new", "profilewidget_insert"); RNA_def_function_ui_description(func, "Add point to the profile widget"); parm = RNA_def_float(func, "x", 0.0f, -FLT_MAX, FLT_MAX, "X Position", "X Position for new point", -FLT_MAX, FLT_MAX); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); parm = RNA_def_float(func, "y", 0.0f, -FLT_MAX, FLT_MAX, "Y Position", "Y Position for new point", -FLT_MAX, FLT_MAX); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); parm = RNA_def_pointer(func, "point", "ProfilePoint", "", "New point"); RNA_def_function_return(func, parm); func = RNA_def_function(srna, "remove", "rna_ProfileWidget_remove_point"); RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Delete point from profile widget"); parm = RNA_def_pointer(func, "point", "ProfilePoint", "", "PointElement to remove"); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0); } DNA_profilewidget_types.h /** \file * \ingroup DNA */ #ifndef DNA_PROFILEPATH_TYPES_H #define DNA_PROFILEPATH_TYPES_H #include "DNA_vec_types.h" #define PROF_TABLE_SIZE 256 /* HANS-TODO: Switch to variable table size based on resolution and number of points #define PROF_N_TABLE(n_pts) (((n_pts) - 1) * PROF_RESOL) #define PROF_RESOL 2 */ typedef struct ProfilePoint { /** Location of the point */ float x, y; /** Flag for handle type and selection state */ short flag; char _pad[2]; } ProfilePoint; /** ProfilePoint->flag */ enum { PROF_SELECT = (1 << 0), PROF_HANDLE_VECTOR = (1 << 1), PROF_HANDLE_AUTO_ANIM = (1 << 2), }; typedef struct ProfileWidget { /** Number of user-added points that define the profile */ short totpoint; /** Number of sampled points */ short totsegments; /** Preset to use when reset */ int preset; /** Sequence of points defining the shape of the curve */ ProfilePoint *path; /** Display and evaluation table at higher resolution for curves */ ProfilePoint *table; /** The positions of the sampled points. Used to display a preview of where they will be */ ProfilePoint *samples; /** Cur; for buttons, to show active curve. */ int flag; /** Used for keeping track how many times the widget is changed */ int changed_timestamp; /** Current rect, clip rect (is default rect too). */ rctf view_rect, clip_rect; } ProfileWidget; /** ProfileWidget->flag */ enum { PROF_DO_CLIP = (1 << 0), PROF_USE_TABLE = (1 << 1), }; typedef enum eProfileWidgetPresets { PROF_PRESET_LINE = 0, /* Default simple line */ PROF_PRESET_SUPPORTS = 1, /* Support loops for a regular curved profile */ PROF_PRESET_EXAMPLE1 = 2, /* Molding type example of a supposed common use case */ } ProfileWiedgetPresets; #endif