diff options
author | Rohan Rathi <rohanrathi08@gmail.com> | 2018-07-19 16:57:45 +0300 |
---|---|---|
committer | Rohan Rathi <rohanrathi08@gmail.com> | 2018-07-19 16:57:45 +0300 |
commit | b6b185691f018f6b175ffb58c65418991cda75f2 (patch) | |
tree | 2c24c02a2e63eeec4c8668fa7d652f88996722be | |
parent | 43ac0f38d72a33cf6721909f3f671ac2dac6ffe3 (diff) |
Code cleanup and fixes
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bevel.c | 44 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_bevel.c | 10 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 1 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_bevel.c | 40 |
4 files changed, 48 insertions, 47 deletions
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 8a72ffc775f..bcf44ad4384 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -152,7 +152,7 @@ typedef struct BoundVert { Profile profile; /* edge profile between this and next BoundVert */ bool any_seam; /* are any of the edges attached here seams? */ bool visited; /* used during delta adjust pass */ - int add_seam; + int seam_len; int sharp_len; // int _pad; } BoundVert; @@ -1532,18 +1532,18 @@ static void snap_to_superellipsoid(float co[3], const float super_r, bool midlin co[2] = z; } -#define EDGE_DATA_CHECK(eh, flag) (BM_elem_flag_test(eh->e, flag)) +#define BEV_EXTEND_EDGE_DATA_CHECK(eh, flag) (BM_elem_flag_test(eh->e, flag)) static void check_edge_data_seam_sharp_edges(BevVert *bv, int flag, bool neg) { EdgeHalf *e = &bv->edges[0], *efirst = &bv->edges[0]; - while ((!neg && !EDGE_DATA_CHECK(e, flag) || (neg && EDGE_DATA_CHECK(e, flag)))) { + while ((!neg && !BEV_EXTEND_EDGE_DATA_CHECK(e, flag) || (neg && BEV_EXTEND_EDGE_DATA_CHECK(e, flag)))) { e = e->next; if (e == efirst) break; } - if ((!neg && !EDGE_DATA_CHECK(e, flag) || (neg && EDGE_DATA_CHECK(e, flag)))) + if ((!neg && !BEV_EXTEND_EDGE_DATA_CHECK(e, flag) || (neg && BEV_EXTEND_EDGE_DATA_CHECK(e, flag)))) return; efirst = e; @@ -1551,17 +1551,17 @@ static void check_edge_data_seam_sharp_edges(BevVert *bv, int flag, bool neg) int flag_count = 0; EdgeHalf *ne = e->next; - while ((!neg && !EDGE_DATA_CHECK(ne, flag) || (neg && EDGE_DATA_CHECK(ne, flag))) && ne != efirst) { + while ((!neg && !BEV_EXTEND_EDGE_DATA_CHECK(ne, flag) || (neg && BEV_EXTEND_EDGE_DATA_CHECK(ne, flag))) && ne != efirst) { if (ne->is_bev) flag_count++; ne = ne->next; } - if (ne == e || (ne == efirst && (!neg && !EDGE_DATA_CHECK(efirst, flag) || - (neg && EDGE_DATA_CHECK(efirst, flag))))) { + if (ne == e || (ne == efirst && (!neg && !BEV_EXTEND_EDGE_DATA_CHECK(efirst, flag) || + (neg && BEV_EXTEND_EDGE_DATA_CHECK(efirst, flag))))) { break; } if (flag == BM_ELEM_SEAM) - e->rightv->add_seam = flag_count; + e->rightv->seam_len = flag_count; else if (flag == BM_ELEM_SMOOTH) e->rightv->sharp_len = flag_count; e = ne; @@ -1576,11 +1576,11 @@ static void bevel_extend_edge_data(BevVert *bv) BoundVert *bcur = bv->vmesh->boundstart, *start = bcur; do { - if (bcur->add_seam) { - if (!bv->vmesh->boundstart->add_seam && start == bv->vmesh->boundstart) + if (bcur->seam_len) { + if (!bv->vmesh->boundstart->seam_len && start == bv->vmesh->boundstart) start = bcur; - int idxlen = bcur->index + bcur->add_seam; + int idxlen = bcur->index + bcur->seam_len; for (int i = bcur->index; i < idxlen; i++) { BMVert *v1 = mesh_vert(vm, i % vm->count, 0, 0)->v, *v2; BMEdge *e; @@ -1659,7 +1659,6 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B { if (bp->hnmode == BEVEL_HN_NONE) return; - int mode = 1; VMesh *vm = bv->vmesh; BoundVert *bcur = vm->boundstart, *bstart = bcur; @@ -1672,7 +1671,7 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B float n_final[3] = { 0.0f, 0.0f, 0.0f }; if (bp->hnmode == BEVEL_HN_FACE) { - GHash *faceHash = BLI_ghash_int_new(__func__); + GHash *tempfaceHash = BLI_ghash_int_new(__func__); BM_ITER_ELEM(e, &eiter, bv->v, BM_EDGES_OF_VERT) { if (BM_elem_flag_test(e, BM_ELEM_TAG)) { @@ -1680,25 +1679,25 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B BMFace *f_a, *f_b; BM_edge_face_pair(e, &f_a, &f_b); - if(f_a && !BLI_ghash_haskey(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_a)))) { + if(f_a && !BLI_ghash_haskey(tempfaceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_a)))) { int f_area = BM_face_calc_area(f_a); float f_no[3]; copy_v3_v3(f_no, f_a->no); mul_v3_fl(f_no, f_area); add_v3_v3(n_final, f_no); - BLI_ghash_insert(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_a)), NULL); + BLI_ghash_insert(tempfaceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_a)), NULL); } - if(f_b && !BLI_ghash_haskey(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_b)))) { + if(f_b && !BLI_ghash_haskey(tempfaceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_b)))) { int f_area = BM_face_calc_area(f_b); float f_no[3]; copy_v3_v3(f_no, f_b->no); mul_v3_fl(f_no, f_area); add_v3_v3(n_final, f_no); - BLI_ghash_insert(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_b)), NULL); + BLI_ghash_insert(tempfaceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_b)), NULL); } } } - BLI_ghash_free(faceHash, NULL, NULL); + BLI_ghash_free(tempfaceHash, NULL, NULL); normalize_v3(n_final); } else if (bp->hnmode == BEVEL_HN_ADJ) { @@ -1718,11 +1717,11 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B do { if (BMO_slot_map_contains(nslot, bcur->nv.v) != true) { - float(*custom_normal) = MEM_callocN(sizeof(*custom_normal) * 3, __func__); - add_v3_v3(custom_normal, n_final); - normalize_v3(custom_normal); + float(*vert_normal) = MEM_callocN(sizeof(*vert_normal) * 3, __func__); + add_v3_v3(vert_normal, n_final); + normalize_v3(vert_normal); - BMO_slot_map_insert(op, nslot, bcur->nv.v, custom_normal); + BMO_slot_map_insert(op, nslot, bcur->nv.v, vert_normal); } bcur = bcur->next; } while (bcur != bstart); @@ -5662,6 +5661,7 @@ void BM_mesh_bevel( BLI_memarena_use_calloc(bp.mem_arena); set_profile_spacing(&bp); + /* Stores BMOp if executed through tool else stores BevelModNorEditData */ if (bm->use_toolflags) op = mod_bmop_customdata; else { diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c index f6b69beac71..83da84357dc 100644 --- a/source/blender/editors/mesh/editmesh_bevel.c +++ b/source/blender/editors/mesh/editmesh_bevel.c @@ -140,7 +140,7 @@ static void bevel_harden_normals(BMEditMesh *em, BMOperator *bmop, float face_st { BKE_editmesh_lnorspace_update(em); BM_normals_loops_edges_tag(em->bm, true); - int cd_clnors_offset = CustomData_get_offset(&em->bm->ldata, CD_CUSTOMLOOPNORMAL); + const int cd_clnors_offset = CustomData_get_offset(&em->bm->ldata, CD_CUSTOMLOOPNORMAL); BMesh *bm = em->bm; BMFace *f; @@ -181,10 +181,12 @@ static void bevel_harden_normals(BMEditMesh *em, BMOperator *bmop, float face_st else { e_next = (lfan_pivot->e == e_next) ? lfan_pivot->prev->e : lfan_pivot->e; } + BLI_SMALLSTACK_PUSH(loops, lfan_pivot); float cur[3]; mul_v3_v3fl(cur, lfan_pivot->f->no, BM_face_calc_area(lfan_pivot->f)); add_v3_v3(cn_wght, cur); + if(BM_elem_flag_test(lfan_pivot->f, BM_ELEM_SELECT)) add_v3_v3(cn_unwght, cur); @@ -310,7 +312,7 @@ static bool edbm_bevel_calc(wmOperator *op) 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 float strength = RNA_float_get(op->ptr, "strength"); + const float hn_strength = RNA_float_get(op->ptr, "strength"); const int hnmode = RNA_enum_get(op->ptr, "hnmode"); @@ -330,7 +332,7 @@ static bool edbm_bevel_calc(wmOperator *op) "bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i profile=%f clamp_overlap=%b " "material=%i loop_slide=%b mark_seam=%b mark_sharp=%b strength=%f hnmode=%i", BM_ELEM_SELECT, offset, segments, vertex_only, offset_type, profile, - clamp_overlap, material, loop_slide, mark_seam, mark_sharp, strength, hnmode); + clamp_overlap, material, loop_slide, mark_seam, mark_sharp, hn_strength, hnmode); BMO_op_exec(em->bm, &bmop); @@ -342,7 +344,7 @@ static bool edbm_bevel_calc(wmOperator *op) } if(hnmode != BEVEL_HN_NONE) - bevel_harden_normals(em, &bmop, strength, hnmode); + bevel_harden_normals(em, &bmop, hn_strength, hnmode); /* no need to de-select existing geometry */ if (!EDBM_op_finish(em, &bmop, op, true)) { diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 5e8ead09d91..fec73c267ce 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -318,7 +318,6 @@ enum { typedef struct BevelModNorEditData { struct GHash *faceHash; - struct GHash *vert_hash; } BevelModNorEditData; typedef struct BevelModifierData { diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 06c4f8c57fd..1ada8b215c5 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -108,9 +108,9 @@ static void bevel_set_weighted_normal_face_strength(BMesh *bm, Scene *scene) } } -static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, float hn_strength, int hnmode, MDeformVert *dvert, int vgroup) +static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, const float hn_strength, const int hnmode, MDeformVert *dvert, int vgroup) { - if (bmd->res > 20) + if (bmd->res > 20 || bmd->value == 0) return; BM_mesh_normals_update(bm); @@ -118,8 +118,8 @@ static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, float hn BM_normals_loops_edges_tag(bm, true); const bool vertex_only = (bmd->flags & MOD_BEVEL_VERT) != 0; - int cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL); - bool do_normal_to_recon = (hn_strength == 1.0f); + const int cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL); + const bool do_normal_to_recon = (hn_strength == 1.0f); BMFace *f; BMLoop *l, *l_cur, *l_first; @@ -127,9 +127,7 @@ static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, float hn GHash *faceHash = bmd->clnordata.faceHash; BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) { - if (!BLI_ghash_haskey(faceHash, f)) { - BM_elem_flag_set(f, BM_ELEM_HIDDEN, true); - } + l_cur = l_first = BM_FACE_FIRST_LOOP(f); do { if ((!BM_elem_flag_test(l_cur->e, BM_ELEM_TAG) || (!BM_elem_flag_test(l_cur, BM_ELEM_TAG) && @@ -234,6 +232,10 @@ static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, float hn static void bevel_fix_normal_shading_continuity(BevelModifierData *bmd, BMesh *bm) { + const bool vertex_only = (bmd->flags & MOD_BEVEL_VERT) != 0; + if (bmd->value == 0 || bmd->clnordata.faceHash == NULL && vertex_only) + return; + BM_mesh_normals_update(bm); BM_lnorspace_update(bm); @@ -242,7 +244,7 @@ static void bevel_fix_normal_shading_continuity(BevelModifierData *bmd, BMesh *b BMLoop *l; BMIter liter, eiter; - int cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL); + const int cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL); const float hn_strength = bmd->hn_strength; float ref = 10.0f; @@ -250,12 +252,12 @@ static void bevel_fix_normal_shading_continuity(BevelModifierData *bmd, BMesh *b BMFace *f_a, *f_b; BM_edge_face_pair(e, &f_a, &f_b); - bool _f_a = false, _f_b = false; + bool has_f_a = false, has_f_b = false; if (f_a) - _f_a = BLI_ghash_haskey(faceHash, f_a); + has_f_a = BLI_ghash_haskey(faceHash, f_a); if (f_b) - _f_b = BLI_ghash_haskey(faceHash, f_b); - if (_f_a ^ _f_b) { + has_f_b = BLI_ghash_haskey(faceHash, f_b); + if (has_f_a ^ has_f_b) { for (int i = 0; i < 2; i++) { BMVert *v = (i == 0) ? e->v1 : e->v2; @@ -269,7 +271,7 @@ static void bevel_fix_normal_shading_continuity(BevelModifierData *bmd, BMesh *b zero_v3(n_final); copy_v3_v3(pow_a, f_a->no); copy_v3_v3(pow_b, f_b->no); - if (_f_a) { + if (has_f_a) { mul_v3_fl(pow_a, bmd->res / ref); mul_v3_fl(pow_b, ref / bmd->res); } @@ -286,7 +288,7 @@ static void bevel_fix_normal_shading_continuity(BevelModifierData *bmd, BMesh *b } } } - else if(_f_a == true && _f_b == true) { + else if(has_f_a == true && has_f_b == true) { for (int i = 0; i < 2; i++) { BMVert *v = (i == 0) ? e->v1 : e->v2; BM_ITER_ELEM(l, &liter, v, BM_LOOPS_OF_VERT) { @@ -409,13 +411,11 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes vertex_only, bmd->lim_flags & MOD_BEVEL_WEIGHT, do_clamp, dvert, vgroup, mat, loop_slide, mark_seam, mark_sharp, bmd->hnmode, &bmd->clnordata); - if (bmd->value > 0 && bmd->hnmode != MOD_BEVEL_HN_NONE) { - if (bmd->hnmode != BEVEL_HN_FIX_SHA) - bevel_mod_harden_normals(bmd, bm, bmd->hn_strength, bmd->hnmode, dvert, vgroup); - else if(bmd->clnordata.faceHash && !vertex_only) - bevel_fix_normal_shading_continuity(bmd, bm); + if (bmd->hnmode != BEVEL_HN_FIX_SHA && bmd->hnmode != MOD_BEVEL_HN_NONE) { + bevel_mod_harden_normals(bmd, bm, bmd->hn_strength, bmd->hnmode, dvert, vgroup); } - + if(bmd->hnmode == BEVEL_HN_FIX_SHA) + bevel_fix_normal_shading_continuity(bmd, bm); if(set_wn_strength) bevel_set_weighted_normal_face_strength(bm, scene); |