a81add7a86edc0e4f8a50d92f85cc2b48ed919ed
[blender.git] / source / blender / editors / mesh / editmesh_bevel.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Joseph Eagar, Howard Trickey, Campbell Barton
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/editors/mesh/editmesh_bevel.c
24  *  \ingroup edmesh
25  */
26
27 #include "MEM_guardedalloc.h"
28
29 #include "DNA_object_types.h"
30
31 #include "BLI_string.h"
32 #include "BLI_math.h"
33
34 #include "BLT_translation.h"
35
36 #include "BKE_context.h"
37 #include "BKE_global.h"
38 #include "BKE_editmesh.h"
39 #include "BKE_unit.h"
40
41 #include "RNA_define.h"
42 #include "RNA_access.h"
43
44 #include "WM_api.h"
45 #include "WM_types.h"
46
47 #include "UI_interface.h"
48
49 #include "ED_mesh.h"
50 #include "ED_numinput.h"
51 #include "ED_screen.h"
52 #include "ED_space_api.h"
53 #include "ED_transform.h"
54 #include "ED_view3d.h"
55
56 #include "mesh_intern.h"  /* own include */
57
58
59 #define MVAL_PIXEL_MARGIN  5.0f
60
61 /* until implement profile = 0 case, need to clamp somewhat above zero */
62 #define PROFILE_HARD_MIN 0.15f
63
64 #define SEGMENTS_HARD_MAX 1000
65
66 /* which value is mouse movement and numeric input controlling? */
67 #define OFFSET_VALUE 0
68 #define OFFSET_VALUE_PERCENT 1
69 #define PROFILE_VALUE 2
70 #define SEGMENTS_VALUE 3
71 #define NUM_VALUE_KINDS 4
72
73 static const char *value_rna_name[NUM_VALUE_KINDS] = {"offset", "offset", "profile", "segments"};
74 static const float value_clamp_min[NUM_VALUE_KINDS] = {0.0f, 0.0f, PROFILE_HARD_MIN, 1.0f};
75 static const float value_clamp_max[NUM_VALUE_KINDS] = {1e6, 100.0f, 1.0f, SEGMENTS_HARD_MAX};
76 static const float value_start[NUM_VALUE_KINDS] = {0.0f, 0.0f, 0.5f, 1.0f};
77 static const float value_scale_per_inch[NUM_VALUE_KINDS] = { 0.0f, 100.0f, 1.0f, 4.0f};
78
79 typedef struct {
80         BMEditMesh *em;
81         float initial_length[NUM_VALUE_KINDS];
82         float scale[NUM_VALUE_KINDS];
83         NumInput num_input[NUM_VALUE_KINDS]; 
84         float shift_value[NUM_VALUE_KINDS]; /* The current value when shift is pressed. Negative when shift not active. */
85         bool is_modal;
86
87         /* modal only */
88         float mcenter[2];
89         BMBackup mesh_backup;
90         void *draw_handle_pixel;
91         short twtype;
92         short value_mode;  /* Which value does mouse movement and numeric input affect? */
93         float segments;     /* Segments as float so smooth mouse pan works in small increments */
94 } BevelData;
95
96 static void edbm_bevel_update_header(bContext *C, wmOperator *op)
97 {
98         const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Mode: %s (M), Clamp Overlap: %s (C), "
99                                  "Vertex Only: %s (V), Profile Control: %s (P), Offset: %s, Segments: %d, Profile: %.3f");
100
101         char msg[UI_MAX_DRAW_STR];
102         ScrArea *sa = CTX_wm_area(C);
103         Scene *sce = CTX_data_scene(C);
104
105         if (sa) {
106                 BevelData *opdata = op->customdata;
107                 char offset_str[NUM_STR_REP_LEN];
108                 const char *type_str;
109                 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");
110
111                 if (hasNumInput(&opdata->num_input[OFFSET_VALUE])) {
112                         outputNumInput(&opdata->num_input[OFFSET_VALUE], offset_str, &sce->unit);
113                 }
114                 else {
115                         BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset"));
116                 }
117
118                 RNA_property_enum_name_gettexted(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &type_str);
119
120                 BLI_snprintf(msg, sizeof(msg), str, type_str,
121                              WM_bool_as_string(RNA_boolean_get(op->ptr, "clamp_overlap")),
122                              WM_bool_as_string(RNA_boolean_get(op->ptr, "vertex_only")),
123                              WM_bool_as_string(opdata->value_mode == PROFILE_VALUE),
124                              offset_str, RNA_int_get(op->ptr, "segments"), RNA_float_get(op->ptr, "profile"));
125
126                 ED_area_headerprint(sa, msg);
127         }
128 }
129
130 static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
131 {
132         Object *obedit = CTX_data_edit_object(C);
133         Scene *scene = CTX_data_scene(C);
134         BMEditMesh *em = BKE_editmesh_from_object(obedit);
135         BevelData *opdata;
136         float pixels_per_inch;
137         int i;
138
139         if (em->bm->totvertsel == 0) {
140                 return false;
141         }
142
143         op->customdata = opdata = MEM_mallocN(sizeof(BevelData), "beveldata_mesh_operator");
144
145         opdata->em = em;
146         opdata->is_modal = is_modal;
147         opdata->value_mode = OFFSET_VALUE;
148         opdata->segments = (float) RNA_int_get(op->ptr, "segments");
149         pixels_per_inch = U.dpi * U.pixelsize;
150
151         for (i = 0; i < NUM_VALUE_KINDS; i++) {
152                 opdata->shift_value[i] = -1.0f;
153                 /* note: scale for OFFSET_VALUE will get overwritten in edbm_bevel_invoke */
154                 opdata->scale[i] = value_scale_per_inch[i] / pixels_per_inch; 
155
156                 initNumInput(&opdata->num_input[i]);
157                 opdata->num_input[i].idx_max = 0;
158                 opdata->num_input[i].val_flag[0] |= NUM_NO_NEGATIVE;
159                 if (i == SEGMENTS_VALUE) {
160                         opdata->num_input[i].val_flag[0] |= NUM_NO_FRACTION | NUM_NO_ZERO;
161                 }
162                 if (i == OFFSET_VALUE) {
163                         opdata->num_input[i].unit_sys = scene->unit.system;
164                 }
165                 opdata->num_input[i].unit_type[0] = B_UNIT_NONE;  /* Not sure this is a factor or a unit? */
166         }
167
168         /* avoid the cost of allocating a bm copy */
169         if (is_modal) {
170                 View3D *v3d = CTX_wm_view3d(C);
171                 ARegion *ar = CTX_wm_region(C);
172
173                 opdata->mesh_backup = EDBM_redo_state_store(em);
174                 opdata->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ED_region_draw_mouse_line_cb,
175                         opdata->mcenter, REGION_DRAW_POST_PIXEL);
176                 G.moving = G_TRANSFORM_EDIT;
177
178                 if (v3d) {
179                         opdata->twtype = v3d->twtype;
180                         v3d->twtype = 0;
181                 }
182         }
183
184         return true;
185 }
186
187 static bool edbm_bevel_calc(wmOperator *op)
188 {
189         BevelData *opdata = op->customdata;
190         BMEditMesh *em = opdata->em;
191         BMOperator bmop;
192         const float offset = RNA_float_get(op->ptr, "offset");
193         const int offset_type = RNA_enum_get(op->ptr, "offset_type");
194         const int segments = RNA_int_get(op->ptr, "segments");
195         const float profile = RNA_float_get(op->ptr, "profile");
196         const bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only");
197         const bool clamp_overlap = RNA_boolean_get(op->ptr, "clamp_overlap");
198         int material = RNA_int_get(op->ptr, "material");
199         const bool loop_slide = RNA_boolean_get(op->ptr, "loop_slide");
200
201         /* revert to original mesh */
202         if (opdata->is_modal) {
203                 EDBM_redo_state_restore(opdata->mesh_backup, em, false);
204         }
205
206         if (em->ob) {
207                 material = CLAMPIS(material, -1, em->ob->totcol - 1);
208         }
209
210         EDBM_op_init(em, &bmop, op,
211                      "bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i profile=%f clamp_overlap=%b "
212                      "material=%i loop_slide=%b",
213                      BM_ELEM_SELECT, offset, segments, vertex_only, offset_type, profile,
214                      clamp_overlap, material, loop_slide);
215
216         BMO_op_exec(em->bm, &bmop);
217
218         if (offset != 0.0f) {
219                 /* not essential, but we may have some loose geometry that
220                  * won't get bevel'd and better not leave it selected */
221                 EDBM_flag_disable_all(em, BM_ELEM_SELECT);
222                 BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
223         }
224
225         /* no need to de-select existing geometry */
226         if (!EDBM_op_finish(em, &bmop, op, true)) {
227                 return false;
228         }
229
230         EDBM_mesh_normals_update(opdata->em);
231
232         EDBM_update_generic(opdata->em, true, true);
233
234         return true;
235 }
236
237 static void edbm_bevel_exit(bContext *C, wmOperator *op)
238 {
239         BevelData *opdata = op->customdata;
240
241         ScrArea *sa = CTX_wm_area(C);
242
243         if (sa) {
244                 ED_area_headerprint(sa, NULL);
245         }
246
247         if (opdata->is_modal) {
248                 View3D *v3d = CTX_wm_view3d(C);
249                 ARegion *ar = CTX_wm_region(C);
250                 EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
251                 ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
252                 if (v3d) {
253                         v3d->twtype = opdata->twtype;
254                 }
255                 G.moving = 0;
256         }
257         MEM_freeN(opdata);
258         op->customdata = NULL;
259 }
260
261 static void edbm_bevel_cancel(bContext *C, wmOperator *op)
262 {
263         BevelData *opdata = op->customdata;
264         if (opdata->is_modal) {
265                 EDBM_redo_state_free(&opdata->mesh_backup, opdata->em, true);
266                 EDBM_update_generic(opdata->em, false, true);
267         }
268
269         edbm_bevel_exit(C, op);
270
271         /* need to force redisplay or we may still view the modified result */
272         ED_region_tag_redraw(CTX_wm_region(C));
273 }
274
275 /* bevel! yay!!*/
276 static int edbm_bevel_exec(bContext *C, wmOperator *op)
277 {
278         if (!edbm_bevel_init(C, op, false)) {
279                 return OPERATOR_CANCELLED;
280         }
281
282         if (!edbm_bevel_calc(op)) {
283                 edbm_bevel_cancel(C, op);
284                 return OPERATOR_CANCELLED;
285         }
286
287         edbm_bevel_exit(C, op);
288
289         return OPERATOR_FINISHED;
290 }
291
292 static void edbm_bevel_calc_initial_length(wmOperator *op, const wmEvent *event, bool mode_changed)
293 {
294         BevelData *opdata;
295         float mlen[2], len, value, sc, st;
296         int vmode;
297
298         opdata = op->customdata;
299         mlen[0] = opdata->mcenter[0] - event->mval[0];
300         mlen[1] = opdata->mcenter[1] - event->mval[1];
301         len = len_v2(mlen);
302         vmode = opdata->value_mode;
303         if (mode_changed) {
304                 /* If current value is not default start value, adjust len so that 
305                  * the scaling and offset in edbm_bevel_mouse_set_value will
306                  * start at current value */
307                 value = (vmode == SEGMENTS_VALUE) ?
308                         opdata->segments : RNA_float_get(op->ptr, value_rna_name[vmode]);
309                 sc = opdata->scale[vmode];
310                 st = value_start[vmode];
311                 if (value != value_start[vmode]) {
312                         len = (st + sc * (len - MVAL_PIXEL_MARGIN) - value) / sc;
313                 }
314         }
315         opdata->initial_length[opdata->value_mode] = len;
316 }
317
318 static int edbm_bevel_invoke(bContext *C, wmOperator *op, const wmEvent *event)
319 {
320         /* TODO make modal keymap (see fly mode) */
321         RegionView3D *rv3d = CTX_wm_region_view3d(C);
322         BevelData *opdata;
323         float center_3d[3];
324
325         if (!edbm_bevel_init(C, op, true)) {
326                 return OPERATOR_CANCELLED;
327         }
328
329         opdata = op->customdata;
330
331         /* initialize mouse values */
332         if (!calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, center_3d, opdata->mcenter)) {
333                 /* in this case the tool will likely do nothing,
334                  * ideally this will never happen and should be checked for above */
335                 opdata->mcenter[0] = opdata->mcenter[1] = 0;
336         }
337         edbm_bevel_calc_initial_length(op, event, false);
338
339         /* for OFFSET_VALUE only, the scale is the size of a pixel under the mouse in 3d space */
340         opdata->scale[OFFSET_VALUE] = rv3d ? ED_view3d_pixel_size(rv3d, center_3d) : 1.0f;
341
342         edbm_bevel_update_header(C, op);
343
344         if (!edbm_bevel_calc(op)) {
345                 edbm_bevel_cancel(C, op);
346                 return OPERATOR_CANCELLED;
347         }
348
349         WM_event_add_modal_handler(C, op);
350
351         return OPERATOR_RUNNING_MODAL;
352 }
353
354 static void edbm_bevel_mouse_set_value(wmOperator *op, const wmEvent *event)
355 {
356         BevelData *opdata = op->customdata;
357         int vmode = opdata->value_mode;
358         float mdiff[2];
359         float value;
360
361         mdiff[0] = opdata->mcenter[0] - event->mval[0];
362         mdiff[1] = opdata->mcenter[1] - event->mval[1];
363
364         value = ((len_v2(mdiff) - MVAL_PIXEL_MARGIN) - opdata->initial_length[vmode]);
365
366         /* Scale according to value mode */
367         value = value_start[vmode] + value * opdata->scale[vmode];
368
369         /* Fake shift-transform... */
370         if (event->shift) {
371                 if (opdata->shift_value[vmode] < 0.0f) {
372                         opdata->shift_value[vmode] = (vmode == SEGMENTS_VALUE) ?
373                                 opdata->segments : RNA_float_get(op->ptr, value_rna_name[vmode]);
374                 }
375                 value = (value - opdata->shift_value[vmode]) * 0.1f + opdata->shift_value[vmode];
376         }
377         else if (opdata->shift_value[vmode] >= 0.0f) {
378                 opdata->shift_value[vmode] = -1.0f;
379         }
380
381         /* clamp accordingto value mode, and store value back */
382         CLAMP(value, value_clamp_min[vmode], value_clamp_max[vmode]);
383         if (vmode == SEGMENTS_VALUE) {
384                 opdata->segments = value;
385                 RNA_int_set(op->ptr, "segments", (int)(value + 0.5f));
386         }
387         else {
388                 RNA_float_set(op->ptr, value_rna_name[vmode], value);
389         }
390 }
391
392 static void edbm_bevel_numinput_set_value(wmOperator *op)
393 {
394         BevelData *opdata = op->customdata;
395         float value;
396         int vmode;
397
398         vmode = opdata->value_mode;
399         value = (vmode == SEGMENTS_VALUE) ?
400                 opdata->segments : RNA_float_get(op->ptr, value_rna_name[vmode]);
401         applyNumInput(&opdata->num_input[vmode], &value);
402         CLAMP(value, value_clamp_min[vmode], value_clamp_max[vmode]);
403         if (vmode == SEGMENTS_VALUE) {
404                 opdata->segments = value;
405                 RNA_int_set(op->ptr, "segments", (int)value);
406         }
407         else {
408                 RNA_float_set(op->ptr, value_rna_name[vmode], value);
409         }
410 }
411
412 static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
413 {
414         BevelData *opdata = op->customdata;
415         const bool has_numinput = hasNumInput(&opdata->num_input[opdata->value_mode]);
416
417         /* Modal numinput active, try to handle numeric inputs first... */
418         if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
419                 edbm_bevel_numinput_set_value(op);
420                 edbm_bevel_calc(op);
421                 edbm_bevel_update_header(C, op);
422                 return OPERATOR_RUNNING_MODAL;
423         }
424         else {
425                 bool handled = false;
426                 switch (event->type) {
427                         case ESCKEY:
428                         case RIGHTMOUSE:
429                                 edbm_bevel_cancel(C, op);
430                                 return OPERATOR_CANCELLED;
431
432                         case MOUSEMOVE:
433                                 if (!has_numinput) {
434                                         edbm_bevel_mouse_set_value(op, event);
435                                         edbm_bevel_calc(op);
436                                         edbm_bevel_update_header(C, op);
437                                         handled = true;
438                                 }
439                                 break;
440
441                         case LEFTMOUSE:
442                         case PADENTER:
443                         case RETKEY:
444                                 if (event->val == KM_PRESS) {
445                                         edbm_bevel_calc(op);
446                                         edbm_bevel_exit(C, op);
447                                         return OPERATOR_FINISHED;
448                                 }
449                                 break;
450
451                         case MOUSEPAN: {
452                                 float delta = 0.02f * (event->y - event->prevy);
453                                 if (opdata->segments >= 1 && opdata->segments + delta < 1)
454                                         opdata->segments = 1;
455                                 else
456                                         opdata->segments += delta;
457                                 RNA_int_set(op->ptr, "segments", (int)opdata->segments);
458                                 edbm_bevel_calc(op);
459                                 edbm_bevel_update_header(C, op);
460                                 handled = true;
461                                 break;
462                         }
463
464                         /* Note this will prevent padplus and padminus to ever activate modal numinput.
465                          * This is not really an issue though, as we only expect positive values here...
466                          * Else we could force them to only modify segments number when shift is pressed, or so.
467                          */
468
469                         case WHEELUPMOUSE:  /* change number of segments */
470                         case PADPLUSKEY:
471                                 if (event->val == KM_RELEASE)
472                                         break;
473
474                                 opdata->segments = opdata->segments + 1;
475                                 RNA_int_set(op->ptr, "segments", (int)opdata->segments);
476                                 edbm_bevel_calc(op);
477                                 edbm_bevel_update_header(C, op);
478                                 handled = true;
479                                 break;
480
481                         case WHEELDOWNMOUSE:  /* change number of segments */
482                         case PADMINUS:
483                                 if (event->val == KM_RELEASE)
484                                         break;
485
486                                 opdata->segments = max_ff(opdata->segments - 1, 1);
487                                 RNA_int_set(op->ptr, "segments", (int)opdata->segments);
488                                 edbm_bevel_calc(op);
489                                 edbm_bevel_update_header(C, op);
490                                 handled = true;
491                                 break;
492
493                         case MKEY:
494                                 if (event->val == KM_RELEASE)
495                                         break;
496
497                                 {
498                                         PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");
499                                         int type = RNA_property_enum_get(op->ptr, prop);
500                                         type++;
501                                         if (type > BEVEL_AMT_PERCENT) {
502                                                 type = BEVEL_AMT_OFFSET;
503                                         }
504                                         if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT)
505                                                 opdata->value_mode = OFFSET_VALUE_PERCENT;
506                                         else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT)
507                                                 opdata->value_mode = OFFSET_VALUE;
508                                         RNA_property_enum_set(op->ptr, prop, type);
509                                 }
510                                 /* Update offset accordingly to new offset_type. */
511                                 if (!has_numinput &&
512                                     (opdata->value_mode == OFFSET_VALUE || opdata->value_mode == OFFSET_VALUE_PERCENT))
513                                 {
514                                         edbm_bevel_mouse_set_value(op, event);
515                                 }               
516                                 edbm_bevel_calc(op);
517                                 edbm_bevel_update_header(C, op);
518                                 handled = true;
519                                 break;
520                         case CKEY:
521                                 if (event->val == KM_RELEASE)
522                                         break;
523
524                                 {
525                                         PropertyRNA *prop = RNA_struct_find_property(op->ptr, "clamp_overlap");
526                                         RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
527                                 }
528                                 edbm_bevel_calc(op);
529                                 edbm_bevel_update_header(C, op);
530                                 handled = true;
531                                 break;
532                         case PKEY:
533                                 if (event->val == KM_RELEASE)
534                                         break;
535                                 if (opdata->value_mode == PROFILE_VALUE) {
536                                         opdata->value_mode = OFFSET_VALUE;
537                                 }
538                                 else {
539                                         opdata->value_mode = PROFILE_VALUE;
540                                 }
541                                 edbm_bevel_calc_initial_length(op, event, true);
542                                 break;
543                         case SKEY:
544                                 if (event->val == KM_RELEASE)
545                                         break;
546                                 if (opdata->value_mode == SEGMENTS_VALUE) {
547                                         opdata->value_mode = OFFSET_VALUE;
548                                 }
549                                 else {
550                                         opdata->value_mode = SEGMENTS_VALUE;
551                                 }
552                                 edbm_bevel_calc_initial_length(op, event, true);
553                                 break;
554                         case VKEY:
555                                 if (event->val == KM_RELEASE)
556                                         break;
557                                 
558                                 {
559                                         PropertyRNA *prop = RNA_struct_find_property(op->ptr, "vertex_only");
560                                         RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
561                                 }
562                                 edbm_bevel_calc(op);
563                                 edbm_bevel_update_header(C, op);
564                                 handled = true;
565                                 break;
566                                 
567                 }
568
569                 /* Modal numinput inactive, try to handle numeric inputs last... */
570                 if (!handled && event->val == KM_PRESS && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
571                         edbm_bevel_numinput_set_value(op);
572                         edbm_bevel_calc(op);
573                         edbm_bevel_update_header(C, op);
574                         return OPERATOR_RUNNING_MODAL;
575                 }
576         }
577
578         return OPERATOR_RUNNING_MODAL;
579 }
580
581 static void mesh_ot_bevel_offset_range_func(PointerRNA *ptr, PropertyRNA *UNUSED(prop),
582                                             float *min, float *max, float *softmin, float *softmax)
583 {
584         const int offset_type = RNA_enum_get(ptr, "offset_type");
585
586         *min = -FLT_MAX;
587         *max = FLT_MAX;
588         *softmin = 0.0f;
589         *softmax = (offset_type == BEVEL_AMT_PERCENT) ? 100.0f : 1.0f;
590 }
591
592 void MESH_OT_bevel(wmOperatorType *ot)
593 {
594         PropertyRNA *prop;
595
596         static EnumPropertyItem offset_type_items[] = {
597                 {BEVEL_AMT_OFFSET, "OFFSET", 0, "Offset", "Amount is offset of new edges from original"},
598                 {BEVEL_AMT_WIDTH, "WIDTH", 0, "Width", "Amount is width of new face"},
599                 {BEVEL_AMT_DEPTH, "DEPTH", 0, "Depth", "Amount is perpendicular distance from original edge to bevel face"},
600                 {BEVEL_AMT_PERCENT, "PERCENT", 0, "Percent", "Amount is percent of adjacent edge length"},
601                 {0, NULL, 0, NULL, NULL},
602         };
603
604         /* identifiers */
605         ot->name = "Bevel";
606         ot->description = "Edge Bevel";
607         ot->idname = "MESH_OT_bevel";
608
609         /* api callbacks */
610         ot->exec = edbm_bevel_exec;
611         ot->invoke = edbm_bevel_invoke;
612         ot->modal = edbm_bevel_modal;
613         ot->cancel = edbm_bevel_cancel;
614         ot->poll = ED_operator_editmesh;
615
616         /* flags */
617         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR | OPTYPE_BLOCKING;
618
619         RNA_def_enum(ot->srna, "offset_type", offset_type_items, 0, "Amount Type", "What distance Amount measures");
620         prop = RNA_def_float(ot->srna, "offset", 0.0f, -1e6f, 1e6f, "Amount", "", 0.0f, 1.0f);
621         RNA_def_property_float_array_funcs_runtime(prop, NULL, NULL, mesh_ot_bevel_offset_range_func);
622         RNA_def_int(ot->srna, "segments", 1, 1, SEGMENTS_HARD_MAX, "Segments", "Segments for curved edge", 1, 8);
623         RNA_def_float(ot->srna, "profile", 0.5f, PROFILE_HARD_MIN, 1.0f, "Profile",
624                 "Controls profile shape (0.5 = round)", PROFILE_HARD_MIN, 1.0f);
625         RNA_def_boolean(ot->srna, "vertex_only", false, "Vertex Only", "Bevel only vertices");
626         RNA_def_boolean(ot->srna, "clamp_overlap", false, "Clamp Overlap",
627                 "Do not allow beveled edges/vertices to overlap each other");
628         RNA_def_boolean(ot->srna, "loop_slide", true, "Loop Slide", "Prefer slide along edge to even widths");
629         RNA_def_int(ot->srna, "material", -1, -1, INT_MAX, "Material",
630                 "Material for bevel faces (-1 means use adjacent faces)", -1, 100);
631 }