diff options
author | Rohan Rathi <rohanrathi08@gmail.com> | 2018-06-04 12:43:54 +0300 |
---|---|---|
committer | Rohan Rathi <rohanrathi08@gmail.com> | 2018-06-04 12:43:54 +0300 |
commit | 2903146826a3e88bb9f001c7ce6678057fb7b1f3 (patch) | |
tree | 657feff62fffeb4a098e2b3d4215fba836732dc5 | |
parent | 79c0ac7c78878434aa01b54edbca9c7db6527831 (diff) |
Added UI support for seams and sharp edges and cleanup
-rw-r--r-- | release/scripts/startup/bl_ui/properties_data_modifier.py | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_bevel.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bevel.c | 31 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bevel.h | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_bevel.c | 28 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 8 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 10 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_bevel.c | 5 |
9 files changed, 72 insertions, 20 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index abdf1ed2db1..45dda12f39b 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -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) diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index b5e6fe168e5..e6a66372274 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -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 */ diff --git a/source/blender/bmesh/operators/bmo_bevel.c b/source/blender/bmesh/operators/bmo_bevel.c index 2ae87b64286..cf063f7b0a8 100644 --- a/source/blender/bmesh/operators/bmo_bevel.c +++ b/source/blender/bmesh/operators/bmo_bevel.c @@ -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); diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 102d563c90c..8a2a022852d 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -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; diff --git a/source/blender/bmesh/tools/bmesh_bevel.h b/source/blender/bmesh/tools/bmesh_bevel.h index 386dc8a1fce..d932ac381a6 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.h +++ b/source/blender/bmesh/tools/bmesh_bevel.h @@ -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__ */ diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c index e75b133b5bd..86aff48615c 100644 --- a/source/blender/editors/mesh/editmesh_bevel.c +++ b/source/blender/editors/mesh/editmesh_bevel.c @@ -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); } diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 1d7d1b34f6b..433d75706bb 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -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; diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index c665442a82f..a9bf7b18f73 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -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) diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 81a4e94386f..61ecc5c734e 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -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}); |