diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-14 20:10:46 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-14 20:10:46 +0400 |
commit | bb26d80ad88236800607bed0b0a72a5d14f67bb9 (patch) | |
tree | eb4882c30fa0bfc6c9a652631717ac740f5d6182 /source/blender/bmesh | |
parent | e5407ef8d9fc0973089b2ac69e418179b99bfa18 (diff) |
code cleanup and move alternate shell calculation method into its own function: BM_vert_calc_shell_factor_ex
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_queries.c | 34 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_queries.h | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 633c715f257..5f5c60dde3f 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -1113,6 +1113,40 @@ float BM_vert_calc_shell_factor(BMVert *v) return 1.0f; } } +/* alternate version of #BM_vert_calc_shell_factor which only + * uses 'hflag' faces, but falls back to all if none found. */ +float BM_vert_calc_shell_factor_ex(BMVert *v, const char hflag) +{ + BMIter iter; + BMLoop *l; + float accum_shell = 0.0f; + float accum_angle = 0.0f; + int tot_sel = 0, tot = 0; + + BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) { + if (BM_elem_flag_test(l->f, hflag)) { /* <-- main difference to BM_vert_calc_shell_factor! */ + const float face_angle = BM_loop_calc_face_angle(l); + accum_shell += shell_angle_to_dist(angle_normalized_v3v3(v->no, l->f->no)) * face_angle; + accum_angle += face_angle; + tot_sel++; + } + tot++; + } + + if (accum_angle != 0.0f) { + return accum_shell / accum_angle; + } + else { + /* other main difference from BM_vert_calc_shell_factor! */ + if (tot != 0 && tot_sel == 0) { + /* none selected, so use all */ + return BM_vert_calc_shell_factor(v); + } + else { + return 1.0f; + } + } +} /** * \note quite an obscure function. diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index 7a18f69371e..9af792417bf 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -69,6 +69,7 @@ void BM_edge_calc_face_tangent(BMEdge *e, BMLoop *e_loop, float r_tangent[3]) float BM_vert_calc_edge_angle(BMVert *v); float BM_vert_calc_shell_factor(BMVert *v); +float BM_vert_calc_shell_factor_ex(BMVert *v, const char hflag); float BM_vert_calc_mean_tagged_edge_length(BMVert *v); BMLoop *BM_face_find_shortest_loop(BMFace *f); |