diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-02-22 17:22:44 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-02-22 17:22:44 +0300 |
commit | 4ee3d7e3ac359dd04f80af88a46c5f3b14f49708 (patch) | |
tree | 33ed7ecc447a19b634a65d46eda3cb046f0dab8f /source/blender/bmesh | |
parent | 5aff002f7b3ad52f6a88dc0a3c2eac482b57da3e (diff) | |
parent | 0eee776e454f6b78ffa33b2ed8b19c747d8193ec (diff) |
Merge branch 'master' into blender2.8
Conflicts:
source/blender/bmesh/intern/bmesh_mesh.c
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.c | 56 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.h | 2 |
2 files changed, 40 insertions, 18 deletions
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 8533083af22..d178b48ab60 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -524,18 +524,16 @@ void BM_verts_calc_normal_vcos(BMesh *bm, const float (*fnos)[3], const float (* * Helpers for #BM_mesh_loop_normals_update and #BM_loops_calc_normals_vnos */ static void bm_mesh_edges_sharp_tag( - BMesh *bm, const float (*vnos)[3], const float (*fnos)[3], float split_angle, - float (*r_lnos)[3]) + BMesh *bm, + const float (*vnos)[3], const float (*fnos)[3], float (*r_lnos)[3], + const float split_angle, const bool do_sharp_edges_tag) { BMIter eiter; BMEdge *e; int i; const bool check_angle = (split_angle < (float)M_PI); - - if (check_angle) { - split_angle = cosf(split_angle); - } + const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f; { char htype = BM_VERT | BM_LOOP; @@ -560,7 +558,7 @@ static void bm_mesh_edges_sharp_tag( if (check_angle) { const float *no_a = fnos ? fnos[BM_elem_index_get(l_a->f)] : l_a->f->no; const float *no_b = fnos ? fnos[BM_elem_index_get(l_b->f)] : l_b->f->no; - is_angle_smooth = (dot_v3v3(no_a, no_b) >= split_angle); + is_angle_smooth = (dot_v3v3(no_a, no_b) >= split_angle_cos); } /* We only tag edges that are *really* smooth: @@ -570,20 +568,28 @@ static void bm_mesh_edges_sharp_tag( * and both its faces have compatible (non-flipped) normals, * i.e. both loops on the same edge do not share the same vertex. */ - if (is_angle_smooth && - BM_elem_flag_test(e, BM_ELEM_SMOOTH) && + if (BM_elem_flag_test(e, BM_ELEM_SMOOTH) && BM_elem_flag_test(l_a->f, BM_ELEM_SMOOTH) && BM_elem_flag_test(l_b->f, BM_ELEM_SMOOTH) && l_a->v != l_b->v) { - const float *no; - BM_elem_flag_enable(e, BM_ELEM_TAG); - - /* linked vertices might be fully smooth, copy their normals to loop ones. */ - no = vnos ? vnos[BM_elem_index_get(l_a->v)] : l_a->v->no; - copy_v3_v3(r_lnos[BM_elem_index_get(l_a)], no); - no = vnos ? vnos[BM_elem_index_get(l_b->v)] : l_b->v->no; - copy_v3_v3(r_lnos[BM_elem_index_get(l_b)], no); + if (is_angle_smooth) { + const float *no; + BM_elem_flag_enable(e, BM_ELEM_TAG); + + /* linked vertices might be fully smooth, copy their normals to loop ones. */ + if (r_lnos) { + no = vnos ? vnos[BM_elem_index_get(l_a->v)] : l_a->v->no; + copy_v3_v3(r_lnos[BM_elem_index_get(l_a)], no); + no = vnos ? vnos[BM_elem_index_get(l_b->v)] : l_b->v->no; + copy_v3_v3(r_lnos[BM_elem_index_get(l_b)], no); + } + } + else if (do_sharp_edges_tag) { + /* Note that we do not care about the other sharp-edge cases (sharp poly, non-manifold edge, etc.), + * only tag edge as sharp when it is due to angle threashold. */ + BM_elem_flag_disable(e, BM_ELEM_SMOOTH); + } } } } @@ -1008,7 +1014,7 @@ void BM_loops_calc_normal_vcos( if (use_split_normals) { /* Tag smooth edges and set lnos from vnos when they might be completely smooth... * When using custom loop normals, disable the angle feature! */ - bm_mesh_edges_sharp_tag(bm, vnos, fnos, has_clnors ? (float)M_PI : split_angle, r_lnos); + bm_mesh_edges_sharp_tag(bm, vnos, fnos, r_lnos, has_clnors ? (float)M_PI : split_angle, false); /* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */ bm_mesh_loops_calc_normals(bm, vcos, fnos, r_lnos, r_lnors_spacearr, clnors_data, cd_loop_clnors_offset); @@ -1019,6 +1025,20 @@ void BM_loops_calc_normal_vcos( } } +/** Define sharp edges as needed to mimic 'autosmooth' from angle threshold. + * + * Used when defining an empty custom loop normals data layer, to keep same shading as with autosmooth! + */ +void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle) +{ + if (split_angle >= (float)M_PI) { + /* Nothing to do! */ + return; + } + + bm_mesh_edges_sharp_tag(bm, NULL, NULL, NULL, split_angle, true); +} + static void UNUSED_FUNCTION(bm_mdisps_space_set)( Object *ob, BMesh *bm, int from, int to, eObjectMode object_mode) { diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h index 01f11f6f942..8326e82af00 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.h +++ b/source/blender/bmesh/intern/bmesh_mesh.h @@ -52,6 +52,8 @@ void BM_loops_calc_normal_vcos( const bool use_split_normals, const float split_angle, float (*r_lnos)[3], struct MLoopNorSpaceArray *r_lnors_spacearr, short (*clnors_data)[2], const int cd_loop_clnors_offset); +void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle); + void bmesh_edit_begin(BMesh *bm, const BMOpTypeFlag type_flag); void bmesh_edit_end(BMesh *bm, const BMOpTypeFlag type_flag); |