Added UI support for seams and sharp edges and cleanup

This commit is contained in:
Rohan Rathi 2018-06-04 15:13:54 +05:30
parent 79c0ac7c78
commit 2903146826
Notes: blender-bot 2023-03-06 21:31:04 +01:00
Referenced by issue #69184, bevel modifier -- mark seems
Referenced by issue #105429, Misleading Mark Seams/Sharp tooltips in bevel operation
9 changed files with 72 additions and 20 deletions

View File

@ -140,6 +140,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.prop(md, "use_only_vertices")
col.prop(md, "use_clamp_overlap")
col.prop(md, "loop_slide")
col.prop(md, "mark_seam")
col.prop(md, "mark_sharp")
layout.label(text="Limit Method:")
layout.row().prop(md, "limit_method", expand=True)

View File

@ -1736,6 +1736,8 @@ static BMOpDefine bmo_bevel_def = {
{"clamp_overlap", BMO_OP_SLOT_BOOL}, /* do not allow beveled edges/vertices to overlap each other */
{"material", BMO_OP_SLOT_INT}, /* material for bevel faces, -1 means get from adjacent faces */
{"loop_slide", BMO_OP_SLOT_BOOL}, /* prefer to slide along edges to having even widths */
{"mark_seam", BMO_OP_SLOT_BOOL},
{"mark_sharp", BMO_OP_SLOT_BOOL},
{{'\0'}},
},
/* slots_out */

View File

@ -43,6 +43,8 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
const bool clamp_overlap = BMO_slot_bool_get(op->slots_in, "clamp_overlap");
const int material = BMO_slot_int_get(op->slots_in, "material");
const bool loop_slide = BMO_slot_bool_get(op->slots_in, "loop_slide");
const bool mark_seam = BMO_slot_bool_get(op->slots_in, "mark_seam");
const bool mark_sharp = BMO_slot_bool_get(op->slots_in, "mark_sharp");
if (offset > 0) {
BMOIter siter;
@ -63,7 +65,7 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
}
}
BM_mesh_bevel(bm, offset, offset_type, seg, profile, vonly, false, clamp_overlap, NULL, -1, material, loop_slide);
BM_mesh_bevel(bm, offset, offset_type, seg, profile, vonly, false, clamp_overlap, NULL, -1, material, loop_slide, mark_seam, mark_sharp);
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);

View File

@ -202,6 +202,8 @@ typedef struct BevelParams {
bool loop_slide; /* should bevel prefer to slide along edges rather than keep widths spec? */
bool limit_offset; /* should offsets be limited by collisions? */
bool offset_adjust; /* should offsets be adjusted to try to get even widths? */
bool mark_seam;
bool mark_sharp;
const struct MDeformVert *dvert; /* vertex group array, maybe set if vertex_only */
int vertex_group; /* vertex group index, maybe set if vertex_only */
int mat_nr; /* if >= 0, material number for bevel; else material comes from adjacent faces */
@ -1526,7 +1528,7 @@ static void snap_to_superellipsoid(float co[3], const float super_r, bool midlin
#define EDGE_DATA_CHECK(eh, flag) (BM_elem_flag_test(eh->e, flag))
static void check_edge_data(BevVert *bv, int flag, bool neg)
static void check_edge_data_seam_sharp_edges(BevVert *bv, int flag, bool neg)
{
EdgeHalf *e = &bv->edges[0], *efirst = &bv->edges[0];
@ -1560,12 +1562,6 @@ static void check_edge_data(BevVert *bv, int flag, bool neg)
}
static void set_bound_vert_extend_seam_sharp_edges(BevVert *bv)
{
check_edge_data(bv, BM_ELEM_SEAM, false);
check_edge_data(bv, BM_ELEM_SMOOTH, true);
}
static void bevel_extend_edge_data(BevVert *bv)
{
VMesh *vm = bv->vmesh;
@ -1653,7 +1649,7 @@ static void bevel_extend_edge_data(BevVert *bv)
}
/* Set the any_seam property for a BevVert and all its BoundVerts */
static void set_bound_vert_seams(BevVert *bv)
static void set_bound_vert_seams(BevVert *bv, bool mark_seam, bool mark_sharp)
{
BoundVert *v;
EdgeHalf *e;
@ -1670,7 +1666,12 @@ static void set_bound_vert_seams(BevVert *bv)
bv->any_seam |= v->any_seam;
} while ((v = v->next) != bv->vmesh->boundstart);
set_bound_vert_extend_seam_sharp_edges(bv);
if (mark_seam) {
check_edge_data_seam_sharp_edges(bv, BM_ELEM_SEAM, false);
}
if (mark_sharp) {
check_edge_data_seam_sharp_edges(bv, BM_ELEM_SMOOTH, true);
}
}
static int count_bound_vert_seams(BevVert *bv)
@ -1741,7 +1742,7 @@ static void build_boundary_vertex_only(BevelParams *bp, BevVert *bv, bool constr
calculate_vm_profiles(bp, bv, vm);
if (construct) {
set_bound_vert_seams(bv);
set_bound_vert_seams(bv, bp->mark_seam, bp->mark_sharp);
if (vm->count == 2)
vm->mesh_kind = M_NONE;
else if (bp->seg == 1)
@ -1796,7 +1797,7 @@ static void build_boundary_terminal_edge(BevelParams *bp, BevVert *bv, EdgeHalf
e->next->leftv = e->next->rightv = v;
/* could use M_POLY too, but tri-fan looks nicer)*/
vm->mesh_kind = M_TRI_FAN;
set_bound_vert_seams(bv);
set_bound_vert_seams(bv, bp->mark_seam, bp->mark_sharp);
}
else {
adjust_bound_vert(e->next->leftv, co);
@ -1855,7 +1856,7 @@ static void build_boundary_terminal_edge(BevelParams *bp, BevVert *bv, EdgeHalf
}
if (construct) {
set_bound_vert_seams(bv);
set_bound_vert_seams(bv, bp->mark_seam, bp->mark_sharp);
if (vm->count == 2 && bv->edgecount == 3) {
vm->mesh_kind = M_NONE;
@ -1997,7 +1998,7 @@ static void build_boundary(BevelParams *bp, BevVert *bv, bool construct)
calculate_vm_profiles(bp, bv, vm);
if (construct) {
set_bound_vert_seams(bv);
set_bound_vert_seams(bv, bp->mark_seam, bp->mark_sharp);
if (vm->count == 2) {
vm->mesh_kind = M_NONE;
@ -5481,7 +5482,7 @@ void BM_mesh_bevel(
const float segments, const float profile,
const bool vertex_only, const bool use_weights, const bool limit_offset,
const struct MDeformVert *dvert, const int vertex_group, const int mat,
const bool loop_slide)
const bool loop_slide, const bool mark_seam, const bool mark_sharp)
{
BMIter iter;
BMVert *v, *v_next;
@ -5502,6 +5503,8 @@ void BM_mesh_bevel(
bp.dvert = dvert;
bp.vertex_group = vertex_group;
bp.mat_nr = mat;
bp.mark_seam = mark_seam;
bp.mark_sharp = mark_sharp;
if (profile >= 0.999f) { /* r ~ 692, so PRO_SQUARE_R is 1e4 */
bp.pro_super_r = PRO_SQUARE_R;

View File

@ -33,6 +33,6 @@ void BM_mesh_bevel(
BMesh *bm, const float offset, const int offset_type, const float segments,
const float profile, const bool vertex_only, const bool use_weights,
const bool limit_offset, const struct MDeformVert *dvert, const int vertex_group,
const int mat, const bool loop_slide);
const int mat, const bool loop_slide, const bool mark_seam, const bool mark_sharp);
#endif /* __BMESH_BEVEL_H__ */

View File

@ -224,6 +224,8 @@ static bool edbm_bevel_calc(wmOperator *op)
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");
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
@ -240,9 +242,9 @@ static bool edbm_bevel_calc(wmOperator *op)
EDBM_op_init(em, &bmop, op,
"bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i profile=%f clamp_overlap=%b "
"material=%i loop_slide=%b",
"material=%i loop_slide=%b mark_seam=%b mark_sharp=%b",
BM_ELEM_SELECT, offset, segments, vertex_only, offset_type, profile,
clamp_overlap, material, loop_slide);
clamp_overlap, material, loop_slide, mark_seam, mark_sharp);
BMO_op_exec(em->bm, &bmop);
@ -603,6 +605,26 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
edbm_bevel_update_header(C, op);
handled = true;
break;
case UKEY:
if (event->val == KM_RELEASE)
break;
else {
bool mark_seam = RNA_boolean_get(op->ptr, "mark_seam");
RNA_boolean_set(op->ptr, "mark_seam", !mark_seam);
edbm_bevel_calc(op);
handled = true;
break;
}
case KKEY:
if (event->val == KM_RELEASE)
break;
else {
bool mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp");
RNA_boolean_set(op->ptr, "mark_sharp", !mark_sharp);
edbm_bevel_calc(op);
handled = true;
break;
}
}
@ -666,6 +688,8 @@ void MESH_OT_bevel(wmOperatorType *ot)
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);
}

View File

@ -328,7 +328,7 @@ typedef struct BevelModifierData {
short lim_flags; /* flags to tell the tool how to limit the bevel */
short e_flags; /* flags to direct how edge weights are applied to verts */
short mat; /* material index if >= 0, else material inherited from surrounding faces */
short pad;
short edge_flags;
int pad2;
float profile; /* controls profile shape (0->1, .5 is round) */
/* if the MOD_BEVEL_ANGLE is set, this will be how "sharp" an edge must be before it gets beveled */
@ -365,6 +365,12 @@ enum {
MOD_BEVEL_AMT_PERCENT = 3,
};
/* BevelModifierData->edge_flags */
enum {
MOD_BEVEL_MARK_SEAM = (1 << 0),
MOD_BEVEL_MARK_SHARP = (1 << 1),
};
typedef struct SmokeModifierData {
ModifierData modifier;

View File

@ -3104,6 +3104,16 @@ static void rna_def_modifier_bevel(BlenderRNA *brna)
RNA_def_property_boolean_negative_sdna(prop, NULL, "flags", MOD_BEVEL_EVEN_WIDTHS);
RNA_def_property_ui_text(prop, "Loop Slide", "Prefer sliding along edges to having even widths");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "mark_seam", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "edge_flags", MOD_BEVEL_MARK_SEAM);
RNA_def_property_ui_text(prop, "Mark Seams", "Mark Seams along beveled edges");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "mark_sharp", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "edge_flags", MOD_BEVEL_MARK_SHARP);
RNA_def_property_ui_text(prop, "Mark Sharp", "Mark beveled edges as sharp");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
static void rna_def_modifier_shrinkwrap(BlenderRNA *brna)

View File

@ -59,6 +59,7 @@ static void initData(ModifierData *md)
bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
bmd->lim_flags = 0;
bmd->e_flags = 0;
bmd->edge_flags = 0;
bmd->mat = -1;
bmd->profile = 0.5f;
bmd->bevel_angle = DEG2RADF(30.0f);
@ -96,6 +97,8 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
const int offset_type = bmd->val_flags;
const int mat = CLAMPIS(bmd->mat, -1, ctx->object->totcol - 1);
const bool loop_slide = (bmd->flags & MOD_BEVEL_EVEN_WIDTHS) == 0;
const bool mark_seam = (bmd->edge_flags & MOD_BEVEL_MARK_SEAM);
const bool mark_sharp = (bmd->edge_flags & MOD_BEVEL_MARK_SHARP);
bm = BKE_mesh_to_bmesh_ex(
mesh,
@ -166,7 +169,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
BM_mesh_bevel(bm, bmd->value, offset_type, bmd->res, bmd->profile,
vertex_only, bmd->lim_flags & MOD_BEVEL_WEIGHT, do_clamp,
dvert, vgroup, mat, loop_slide);
dvert, vgroup, mat, loop_slide, mark_seam, mark_sharp);
result = BKE_bmesh_to_mesh_nomain(bm, &(struct BMeshToMeshParams){0});