forked from bartvdbraak/blender
2 new bevel options for the operator and the modifier.
* even offset, uses same shell distance method as solidify to give even with beveled faces. * distance offset, this is mostly for compatibility with the modifier in trunk which uses the bevel width as a distance rather then a percentage. at the moment this is awkward for the operator since it makes percent act differently where the 0-1 range doesnt make sense. still need to bring back more options from trunks bevel modifier.
This commit is contained in:
parent
143a654e6f
commit
6254cc1c70
@ -126,6 +126,12 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
|
||||
split.prop(md, "width")
|
||||
split.prop(md, "use_only_vertices")
|
||||
|
||||
# BMESH_BRANCH ONLY
|
||||
split = layout.split()
|
||||
split.prop(md, "use_even_offset")
|
||||
split.prop(md, "use_distance_offset")
|
||||
# END BMESH_BRANCH ONLY
|
||||
|
||||
layout.label(text="Limit Method:")
|
||||
layout.row().prop(md, "limit_method", expand=True)
|
||||
if md.limit_method == 'ANGLE':
|
||||
|
@ -209,6 +209,10 @@ int BME_loop_reverse(struct BME_Mesh *bm, struct BME_Poly *f);
|
||||
#define BME_BEVEL_RUNNING (1<<9)
|
||||
#define BME_BEVEL_RES (1<<10)
|
||||
|
||||
#define BME_BEVEL_EVEN (1<<11) /* this is a new setting not related to old (trunk bmesh bevel code) but adding
|
||||
* here because they are mixed - campbell */
|
||||
#define BME_BEVEL_DIST (1<<12) /* same as above */
|
||||
|
||||
typedef struct BME_TransData {
|
||||
BME_Mesh *bm; /* the bmesh the vert belongs to */
|
||||
BME_Vert *v; /* pointer to the vert this tdata applies to */
|
||||
|
@ -1012,7 +1012,10 @@ static BMOpDefine def_bevel = {
|
||||
{{BMOP_OPSLOT_ELEMENT_BUF, "geom"}, /* input edges and vertices */
|
||||
{BMOP_OPSLOT_ELEMENT_BUF, "face_spans"}, /* new geometry */
|
||||
{BMOP_OPSLOT_ELEMENT_BUF, "face_holes"}, /* new geometry */
|
||||
{BMOP_OPSLOT_INT, "uselengths"}, /* grab edge lengths from a PROP_FLT customdata layer*/
|
||||
{BMOP_OPSLOT_INT, "use_lengths"}, /* grab edge lengths from a PROP_FLT customdata layer*/
|
||||
{BMOP_OPSLOT_INT, "use_even"}, /* corner vert placement: use shell/angle calculations */
|
||||
{BMOP_OPSLOT_INT, "use_dist"}, /* corner vert placement: evaluate percent as a distance,
|
||||
* modifier uses this. We could do this as another float setting */
|
||||
{BMOP_OPSLOT_INT, "lengthlayer"}, /* which PROP_FLT layer to use*/
|
||||
{BMOP_OPSLOT_FLT, "percent"}, /* percentage to expand bevelled edges*/
|
||||
{0} /*null-terminating sentinel*/},
|
||||
|
@ -30,11 +30,12 @@ typedef struct EdgeTag {
|
||||
BMVert *newv1, *newv2;
|
||||
} EdgeTag;
|
||||
|
||||
static void calc_corner_co(BMesh *bm, BMLoop *l, const float fac, float r_co[3])
|
||||
static void calc_corner_co(BMesh *bm, BMLoop *l, const float fac, float r_co[3], const short do_dist, const short do_even)
|
||||
{
|
||||
float no[3], l_vec_prev[3], l_vec_next[3], l_co_prev[3], l_co[3], l_co_next[3];
|
||||
float no[3], l_vec_prev[3], l_vec_next[3], l_co_prev[3], l_co[3], l_co_next[3], co_ofs[3];
|
||||
int is_concave;
|
||||
|
||||
/* first get the prev/next verts */
|
||||
if (l->f->len > 2) {
|
||||
copy_v3_v3(l_co_prev, l->prev->v->co);
|
||||
copy_v3_v3(l_co, l->v->co);
|
||||
@ -73,56 +74,68 @@ static void calc_corner_co(BMesh *bm, BMLoop *l, const float fac, float r_co[3])
|
||||
is_concave = dot_v3v3(no, up) < 0.0f;
|
||||
}
|
||||
|
||||
if (1) {
|
||||
/*simple percentage method */
|
||||
|
||||
/* now calculate the new location */
|
||||
if (do_dist) { /* treat 'fac' as distance */
|
||||
|
||||
normalize_v3(l_vec_prev);
|
||||
normalize_v3(l_vec_next);
|
||||
|
||||
add_v3_v3v3(co_ofs, l_vec_prev,l_vec_next);
|
||||
normalize_v3(co_ofs);
|
||||
|
||||
if (do_even) {
|
||||
negate_v3(l_vec_next);
|
||||
mul_v3_fl(co_ofs, fac * shell_angle_to_dist(0.5f * angle_normalized_v3v3(l_vec_prev, l_vec_next)));
|
||||
/* negate_v3(l_vec_next); */ /* no need unless we use again */
|
||||
}
|
||||
else {
|
||||
mul_v3_fl(co_ofs, fac);
|
||||
}
|
||||
}
|
||||
else { /* treat as 'fac' as a factor (0 - 1) */
|
||||
|
||||
/* not strictly necessary, balance vectors
|
||||
* so the longer edge doesn't skew the result,
|
||||
* gives nicer, move even output */
|
||||
float medium= (normalize_v3(l_vec_prev) + normalize_v3(l_vec_next)) / 2.0f;
|
||||
float angle= do_even ? angle_normalized_v3v3(l_vec_prev, l_vec_next) : 0.0f; /* get angle while normalized */
|
||||
|
||||
mul_v3_fl(l_vec_prev, medium);
|
||||
mul_v3_fl(l_vec_next, medium);
|
||||
|
||||
add_v3_v3v3(co_ofs, l_vec_prev, l_vec_next);
|
||||
|
||||
/* done */
|
||||
|
||||
|
||||
add_v3_v3(l_vec_prev, l_vec_next);
|
||||
mul_v3_fl(l_vec_prev, fac * 0.5);
|
||||
|
||||
if (is_concave)
|
||||
negate_v3(l_vec_prev);
|
||||
|
||||
add_v3_v3v3(r_co, l_vec_prev, l->v->co);
|
||||
if (do_even) {
|
||||
negate_v3(l_vec_next);
|
||||
mul_v3_fl(co_ofs, (fac * 0.5) * shell_angle_to_dist(0.5f * angle));
|
||||
/* negate_v3(l_vec_next); */ /* no need unless we use again */
|
||||
}
|
||||
else {
|
||||
mul_v3_fl(co_ofs, fac * 0.5);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* distance based */
|
||||
float tvec[3];
|
||||
float dist;
|
||||
|
||||
normalize_v3(l_vec_prev);
|
||||
normalize_v3(l_vec_next);
|
||||
/* apply delta vec */
|
||||
if (is_concave)
|
||||
negate_v3(co_ofs);
|
||||
|
||||
/* get the medium normalized direction */
|
||||
add_v3_v3v3(tvec, l_vec_prev,l_vec_next);
|
||||
normalize_v3(tvec);
|
||||
|
||||
/* for angle calculation */
|
||||
negate_v3(l_vec_next);
|
||||
|
||||
dist= shell_angle_to_dist(angle_normalized_v3v3(l_vec_prev, l_vec_next) * 0.5);
|
||||
|
||||
mul_v3_fl(tvec, fac * dist);
|
||||
|
||||
if (is_concave)
|
||||
negate_v3(tvec);
|
||||
|
||||
add_v3_v3v3(r_co, tvec, l->v->co);
|
||||
|
||||
}
|
||||
add_v3_v3v3(r_co, co_ofs, l->v->co);
|
||||
}
|
||||
|
||||
#define ETAG_SET(e, v, nv) (v) == (e)->v1 ? (etags[BM_GetIndex((e))].newv1 = (nv)) : (etags[BM_GetIndex((e))].newv2 = (nv))
|
||||
#define ETAG_GET(e, v) ((v) == (e)->v1 ? (etags[BM_GetIndex((e))].newv1) : (etags[BM_GetIndex((e))].newv2))
|
||||
|
||||
#define ETAG_SET(e, v, nv) ( \
|
||||
(v) == (e)->v1 ? \
|
||||
(etags[BM_GetIndex((e))].newv1 = (nv)) : \
|
||||
(etags[BM_GetIndex((e))].newv2 = (nv)) \
|
||||
)
|
||||
|
||||
#define ETAG_GET(e, v) ( \
|
||||
(v) == (e)->v1 ? \
|
||||
(etags[BM_GetIndex((e))].newv1) : \
|
||||
(etags[BM_GetIndex((e))].newv2) \
|
||||
)
|
||||
|
||||
void bmesh_bevel_exec(BMesh *bm, BMOperator *op)
|
||||
{
|
||||
@ -142,9 +155,11 @@ void bmesh_bevel_exec(BMesh *bm, BMOperator *op)
|
||||
BLI_array_declare(edges);
|
||||
SmallHash hash;
|
||||
float fac = BMO_Get_Float(op, "percent");
|
||||
const short do_even = BMO_Get_Int(op, "use_even");
|
||||
const short do_dist = BMO_Get_Int(op, "use_dist");
|
||||
int i, li, has_elens, HasMDisps = CustomData_has_layer(&bm->ldata, CD_MDISPS);
|
||||
|
||||
has_elens = CustomData_has_layer(&bm->edata, CD_PROP_FLT) && BMO_Get_Int(op, "uselengths");
|
||||
has_elens = CustomData_has_layer(&bm->edata, CD_PROP_FLT) && BMO_Get_Int(op, "use_lengths");
|
||||
if (has_elens) {
|
||||
li = BMO_Get_Int(op, "lengthlayer");
|
||||
}
|
||||
@ -314,7 +329,7 @@ void bmesh_bevel_exec(BMesh *bm, BMOperator *op)
|
||||
if (BMO_TestFlag(bm, l->prev->e, BEVEL_FLAG))
|
||||
{
|
||||
tag = tags + BM_GetIndex(l);
|
||||
calc_corner_co(bm, l, fac, co);
|
||||
calc_corner_co(bm, l, fac, co, do_dist, do_even);
|
||||
tag->newv = BM_Make_Vert(bm, co, l->v);
|
||||
} else {
|
||||
tag = tags + BM_GetIndex(l);
|
||||
|
@ -4461,11 +4461,9 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op)
|
||||
BMEdge *eed;
|
||||
BMOperator bmop;
|
||||
float factor= RNA_float_get(op->ptr, "percent"), fac=factor /*, dfac */ /* UNUSED */, df, s;
|
||||
/*float p2 = RNA_float_get(op->ptr, "param2");
|
||||
float p3 = RNA_float_get(op->ptr, "param3");
|
||||
float p4 = RNA_float_get(op->ptr, "param4");
|
||||
float p5 = RNA_float_get(op->ptr, "param5");*/
|
||||
int i, recursion = RNA_int_get(op->ptr, "recursion");
|
||||
const int use_even= RNA_boolean_get(op->ptr, "use_even");
|
||||
const int use_dist= RNA_boolean_get(op->ptr, "use_dist");
|
||||
float *w = NULL, ftot;
|
||||
int li;
|
||||
BLI_array_declare(w);
|
||||
@ -4500,7 +4498,7 @@ static int mesh_bevel_exec(bContext *C, wmOperator *op)
|
||||
for (i=0; i<BLI_array_count(w); i++) {
|
||||
fac = w[BLI_array_count(w)-i-1]*factor;
|
||||
|
||||
if (!EDBM_InitOpf(em, &bmop, op, "bevel geom=%hev percent=%f lengthlayer=%i uselengths=%i", BM_SELECT, fac, li, 1))
|
||||
if (!EDBM_InitOpf(em, &bmop, op, "bevel geom=%hev percent=%f lengthlayer=%i use_lengths=%i use_even=%i use_dist=%i", BM_SELECT, fac, li, 1, use_even, use_dist))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
BMO_Exec_Op(em->bm, &bmop);
|
||||
@ -4535,10 +4533,10 @@ void MESH_OT_bevel(wmOperatorType *ot)
|
||||
|
||||
RNA_def_float(ot->srna, "percent", 0.5f, -FLT_MAX, FLT_MAX, "Percentage", "", 0.0f, 1.0f);
|
||||
RNA_def_int(ot->srna, "recursion", 1, 1, 50, "Recursion Level", "Recursion Level", 1, 8);
|
||||
//RNA_def_float(ot->srna, "param2", 1.0f, -FLT_MAX, FLT_MAX, "Parameter 2", "", -1000.0f, 1000.0f);
|
||||
//RNA_def_float(ot->srna, "param3", 0.5f, -FLT_MAX, FLT_MAX, "Parameter 3", "", -1000.0f, 1000.0f);
|
||||
//RNA_def_float(ot->srna, "param4", 0.5f, -FLT_MAX, FLT_MAX, "Parameter 4", "", -1000.0f, 1000.0f);
|
||||
//RNA_def_float(ot->srna, "param5", 0.5f, -FLT_MAX, FLT_MAX, "Parameter 5", "", -1000.0f, 1000.0f);
|
||||
|
||||
RNA_def_boolean(ot->srna, "use_even", FALSE, "Even", "Calculate evenly spaced bevel");
|
||||
RNA_def_boolean(ot->srna, "use_dist", FALSE, "Distance", "Interpret the percent in blender units");
|
||||
|
||||
}
|
||||
|
||||
static int mesh_export_obj_exec(bContext *C, wmOperator *op)
|
||||
|
@ -2170,6 +2170,19 @@ static void rna_def_modifier_bevel(BlenderRNA *brna)
|
||||
#endif
|
||||
RNA_def_property_ui_text(prop, "Angle", "Angle above which to bevel edges");
|
||||
RNA_def_property_update(prop, 0, "rna_Modifier_update");
|
||||
|
||||
/* BMESH_BRANCH ONLY */
|
||||
prop= RNA_def_property(srna, "use_even_offset", PROP_BOOLEAN, PROP_NONE); /* name matches solidify */
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", BME_BEVEL_EVEN);
|
||||
RNA_def_property_ui_text(prop, "Even", "Use even bevel distance correction");
|
||||
RNA_def_property_update(prop, 0, "rna_Modifier_update");
|
||||
/* BMESH_BRANCH ONLY */
|
||||
prop= RNA_def_property(srna, "use_distance_offset", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", BME_BEVEL_DIST);
|
||||
RNA_def_property_ui_text(prop, "Distance", "Use the width as a distance in rather then a factor of the face size");
|
||||
RNA_def_property_update(prop, 0, "rna_Modifier_update");
|
||||
/* END BMESH_BRANCH ONLY */
|
||||
|
||||
}
|
||||
|
||||
static void rna_def_modifier_shrinkwrap(BlenderRNA *brna)
|
||||
|
@ -149,7 +149,8 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob,
|
||||
}
|
||||
}
|
||||
|
||||
BMO_CallOpf(bm, "bevel geom=%fe percent=%f", EDGE_MARK, bmd->value);
|
||||
BMO_CallOpf(bm, "bevel geom=%fe percent=%f use_even=%i use_dist=%i",
|
||||
EDGE_MARK, bmd->value, (bmd->flags & BME_BEVEL_EVEN)!=0, (bmd->flags & BME_BEVEL_DIST)!=0);
|
||||
BMO_pop(bm);
|
||||
BMEdit_RecalcTesselation(em);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user