diff options
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_mesh_normals.c')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_normals.c | 78 |
1 files changed, 18 insertions, 60 deletions
diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.c b/source/blender/bmesh/intern/bmesh_mesh_normals.c index 186c85abe58..34c07b4f310 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_normals.c +++ b/source/blender/bmesh/intern/bmesh_mesh_normals.c @@ -247,11 +247,6 @@ static void bm_face_calc_normals_cb(void *UNUSED(userdata), BM_face_calc_normal(f, f->no); } -/** - * \brief BMesh Compute Normals - * - * Updates the normals of a mesh. - */ void BM_mesh_normals_update_ex(BMesh *bm, const struct BMeshNormalsUpdate_Params *params) { if (params->face_normals) { @@ -295,10 +290,6 @@ static void bm_partial_verts_parallel_range_calc_normal_cb( bm_vert_calc_normals_impl(v); } -/** - * A version of #BM_mesh_normals_update that updates a subset of geometry, - * used to avoid the overhead of updating everything. - */ void BM_mesh_normals_update_with_partial_ex(BMesh *UNUSED(bm), const BMPartialUpdate *bmpinfo, const struct BMeshNormalsUpdate_Params *params) @@ -343,12 +334,6 @@ void BM_mesh_normals_update_with_partial(BMesh *bm, const BMPartialUpdate *bmpin /** \name Update Vertex & Face Normals (Custom Coords) * \{ */ -/** - * \brief BMesh Compute Normals from/to external data. - * - * Computes the vertex normals of a mesh into vnos, - * using given vertex coordinates (vcos) and polygon normals (fnos). - */ void BM_verts_calc_normal_vcos(BMesh *bm, const float (*fnos)[3], const float (*vcos)[3], @@ -404,16 +389,13 @@ void BM_normals_loops_edges_tag(BMesh *bm, const bool do_edges) */ static void bm_mesh_edges_sharp_tag(BMesh *bm, const float (*fnos)[3], - const float split_angle, + float split_angle_cos, const bool do_sharp_edges_tag) { BMIter eiter; BMEdge *e; int i; - const bool check_angle = (split_angle < (float)M_PI); - const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f; - if (fnos) { BM_mesh_elem_index_ensure(bm, BM_FACE); } @@ -438,12 +420,6 @@ static void bm_mesh_edges_sharp_tag(BMesh *bm, bm->elem_index_dirty &= ~BM_EDGE; } -/** - * 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 auto-smooth! - */ void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle) { if (split_angle >= (float)M_PI) { @@ -451,7 +427,7 @@ void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle) return; } - bm_mesh_edges_sharp_tag(bm, NULL, split_angle, true); + bm_mesh_edges_sharp_tag(bm, NULL, cosf(split_angle), true); } /** \} */ @@ -460,11 +436,6 @@ void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle) /** \name Loop Normals Calculation API * \{ */ -/** - * Check whether given loop is part of an unknown-so-far cyclic smooth fan, or not. - * Needed because cyclic smooth fans have no obvious 'entry point', - * and yet we need to walk them once, and only once. - */ bool BM_loop_check_cyclic_smooth_fan(BMLoop *l_curr) { BMLoop *lfan_pivot_next = l_curr; @@ -523,7 +494,8 @@ static int bm_mesh_loops_calc_normals_for_loop(BMesh *bm, float (*r_lnos)[3], MLoopNorSpaceArray *r_lnors_spacearr) { - BLI_assert((bm->elem_index_dirty & (BM_FACE | BM_LOOP)) == 0); + BLI_assert((bm->elem_index_dirty & BM_LOOP) == 0); + BLI_assert((fnos == NULL) || ((bm->elem_index_dirty & BM_FACE) == 0)); BLI_assert((vcos == NULL) || ((bm->elem_index_dirty & BM_VERT) == 0)); UNUSED_VARS_NDEBUG(bm); @@ -1110,11 +1082,13 @@ static void bm_mesh_loops_calc_normals__single_threaded(BMesh *bm, const short (*clnors_data)[2], const int cd_loop_clnors_offset, const bool do_rebuild, - const float split_angle) + const float split_angle_cos) { BMIter fiter; BMFace *f_curr; const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1); + /* When false the caller must have already tagged the edges. */ + const bool do_edge_tag = (split_angle_cos != EDGE_TAG_FROM_SPLIT_ANGLE_BYPASS); MLoopNorSpaceArray _lnors_spacearr = {NULL}; @@ -1155,7 +1129,9 @@ static void bm_mesh_loops_calc_normals__single_threaded(BMesh *bm, /* Always tag edges based on winding & sharp edge flag * (even when the auto-smooth angle doesn't need to be calculated). */ - bm_mesh_edges_sharp_tag(bm, fnos, has_clnors ? (float)M_PI : split_angle, false); + if (do_edge_tag) { + bm_mesh_edges_sharp_tag(bm, fnos, has_clnors ? -1.0f : split_angle_cos, false); + } /* We now know edges that can be smoothed (they are tagged), * and edges that will be hard (they aren't). @@ -1308,12 +1284,9 @@ static void bm_mesh_loops_calc_normals__multi_threaded(BMesh *bm, const short (*clnors_data)[2], const int cd_loop_clnors_offset, const bool do_rebuild, - const float split_angle) + const float split_angle_cos) { const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1); - const bool check_angle = (split_angle < (float)M_PI); - const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f; - MLoopNorSpaceArray _lnors_spacearr = {NULL}; { @@ -1387,7 +1360,7 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, const short (*clnors_data)[2], const int cd_loop_clnors_offset, const bool do_rebuild, - const float split_angle) + const float split_angle_cos) { if (bm->totloop < BM_OMP_LIMIT) { bm_mesh_loops_calc_normals__single_threaded(bm, @@ -1398,7 +1371,7 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, clnors_data, cd_loop_clnors_offset, do_rebuild, - split_angle); + split_angle_cos); } else { bm_mesh_loops_calc_normals__multi_threaded(bm, @@ -1409,7 +1382,7 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, clnors_data, cd_loop_clnors_offset, do_rebuild, - split_angle); + split_angle_cos); } } @@ -1620,7 +1593,7 @@ static void bm_mesh_loops_custom_normals_set(BMesh *bm, /* 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, fnos, (float)M_PI, false); + bm_mesh_edges_sharp_tag(bm, fnos, -1.0f, false); /* Finish computing lnos by accumulating face normals * in each fan of faces defined by sharp edges. */ @@ -1721,13 +1694,6 @@ static void bm_mesh_loops_calc_normals_no_autosmooth(BMesh *bm, } } -/** - * \brief BMesh Compute Loop Normals from/to external data. - * - * Compute split normals, i.e. vertex normals associated with each poly (hence 'loop normals'). - * Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry - * (splitting edges). - */ void BM_loops_calc_normal_vcos(BMesh *bm, const float (*vcos)[3], const float (*vnos)[3], @@ -1751,7 +1717,7 @@ void BM_loops_calc_normal_vcos(BMesh *bm, clnors_data, cd_loop_clnors_offset, do_rebuild, - has_clnors ? (float)M_PI : split_angle); + has_clnors ? -1.0f : cosf(split_angle)); } else { BLI_assert(!r_lnors_spacearr); @@ -1934,10 +1900,6 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor) #endif } -/** - * \warning This function sets #BM_ELEM_TAG on loops & edges via #bm_mesh_loops_calc_normals, - * take care to run this before setting up tags. - */ void BM_lnorspace_update(BMesh *bm) { if (bm->lnor_spacearr == NULL) { @@ -2251,10 +2213,6 @@ void BM_loop_normal_editdata_array_free(BMLoopNorEditDataArray *lnors_ed_arr) /** \name Custom Normals / Vector Layer Conversion * \{ */ -/** - * \warning This function sets #BM_ELEM_TAG on loops & edges via #bm_mesh_loops_calc_normals, - * take care to run this before setting up tags. - */ bool BM_custom_loop_normals_to_vector_layer(BMesh *bm) { BMFace *f; @@ -2266,7 +2224,6 @@ bool BM_custom_loop_normals_to_vector_layer(BMesh *bm) } BM_lnorspace_update(bm); - BM_mesh_elem_index_ensure(bm, BM_LOOP); /* Create a loop normal layer. */ if (!CustomData_has_layer(&bm->ldata, CD_NORMAL)) { @@ -2278,14 +2235,15 @@ bool BM_custom_loop_normals_to_vector_layer(BMesh *bm) const int cd_custom_normal_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL); const int cd_normal_offset = CustomData_get_offset(&bm->ldata, CD_NORMAL); + int l_index = 0; BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - const int l_index = BM_elem_index_get(l); const short *clnors_data = BM_ELEM_CD_GET_VOID_P(l, cd_custom_normal_offset); float *normal = BM_ELEM_CD_GET_VOID_P(l, cd_normal_offset); BKE_lnor_space_custom_data_to_normal( bm->lnor_spacearr->lspacearr[l_index], clnors_data, normal); + l_index += 1; } } |