diff options
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_evaluate.c')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_evaluate.c | 245 |
1 files changed, 133 insertions, 112 deletions
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 38e0d79d78c..ac935bb7f81 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -96,10 +96,10 @@ void BKE_mesh_calc_normals_mapping_simple(struct Mesh *mesh) const bool only_face_normals = CustomData_is_referenced_layer(&mesh->vdata, CD_MVERT); BKE_mesh_calc_normals_mapping_ex( - mesh->mvert, mesh->totvert, - mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, - mesh->mface, mesh->totface, NULL, NULL, - only_face_normals); + mesh->mvert, mesh->totvert, + mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, + mesh->mface, mesh->totface, NULL, NULL, + only_face_normals); } /* Calculate vertex and face normals, face normals are returned in *r_faceNors if non-NULL @@ -360,9 +360,10 @@ void BKE_mesh_calc_normals(Mesh *mesh) #ifdef DEBUG_TIME TIMEIT_START_AVERAGED(BKE_mesh_calc_normals); #endif - BKE_mesh_calc_normals_poly(mesh->mvert, NULL, mesh->totvert, - mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, - NULL, false); + BKE_mesh_calc_normals_poly( + mesh->mvert, NULL, mesh->totvert, + mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, + NULL, false); #ifdef DEBUG_TIME TIMEIT_END_AVERAGED(BKE_mesh_calc_normals); #endif @@ -511,8 +512,9 @@ MLoopNorSpace *BKE_lnor_space_create(MLoopNorSpaceArray *lnors_spacearr) * Beware, this modifies ref_vec and other_vec in place! * In case no valid space can be generated, ref_alpha and ref_beta are set to zero (which means 'use auto lnors'). */ -void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], - float vec_ref[3], float vec_other[3], BLI_Stack *edge_vectors) +void BKE_lnor_space_define( + MLoopNorSpace *lnor_space, const float lnor[3], + float vec_ref[3], float vec_other[3], BLI_Stack *edge_vectors) { const float pi2 = (float)M_PI * 2.0f; float tvec[3], dtp; @@ -794,8 +796,9 @@ static void mesh_edges_sharp_tag( e2l[1] = (mp->flag & ME_SMOOTH) ? INDEX_UNSET : INDEX_INVALID; } else if (e2l[1] == INDEX_UNSET) { - const bool is_angle_sharp = (check_angle && - dot_v3v3(polynors[loop_to_poly[e2l[0]]], polynors[mp_index]) < split_angle_cos); + const bool is_angle_sharp = ( + check_angle && + dot_v3v3(polynors[loop_to_poly[e2l[0]]], polynors[mp_index]) < split_angle_cos); /* Second loop using this edge, time to test its sharpness. * An edge is sharp if it is tagged as such, or its face is not smooth, @@ -1128,8 +1131,8 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli /* Find next loop of the smooth fan. */ BKE_mesh_loop_manifold_fan_around_vert_next( - mloops, mpolys, loop_to_poly, e2lfan_curr, mv_pivot_index, - &mlfan_curr, &mlfan_curr_index, &mlfan_vert_index, &mpfan_curr_index); + mloops, mpolys, loop_to_poly, e2lfan_curr, mv_pivot_index, + &mlfan_curr, &mlfan_curr_index, &mlfan_vert_index, &mpfan_curr_index); e2lfan_curr = edge_to_loops[mlfan_curr->e]; } @@ -1265,8 +1268,8 @@ static bool loop_split_generator_check_cyclic_smooth_fan( while (true) { /* Find next loop of the smooth fan. */ BKE_mesh_loop_manifold_fan_around_vert_next( - mloops, mpolys, loop_to_poly, e2lfan_curr, mv_pivot_index, - &mlfan_curr, &mlfan_curr_index, &mlfan_vert_index, &mpfan_curr_index); + mloops, mpolys, loop_to_poly, e2lfan_curr, mv_pivot_index, + &mlfan_curr, &mlfan_curr_index, &mlfan_vert_index, &mpfan_curr_index); e2lfan_curr = edge_to_loops[mlfan_curr->e]; @@ -1615,9 +1618,10 @@ static void mesh_normals_loop_custom_set( BLI_SMALLSTACK_DECLARE(clnors_data, short *); /* Compute current lnor spacearr. */ - BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops, - mpolys, polynors, numPolys, use_split_normals, split_angle, - &lnors_spacearr, NULL, loop_to_poly); + BKE_mesh_normals_loop_split( + mverts, numVerts, medges, numEdges, mloops, lnors, numLoops, + mpolys, polynors, numPolys, use_split_normals, split_angle, + &lnors_spacearr, NULL, loop_to_poly); /* Set all given zero vectors to their default value. */ if (use_vertices) { @@ -1725,9 +1729,10 @@ static void mesh_normals_loop_custom_set( /* And now, recompute our new auto lnors and lnor spacearr! */ BKE_lnor_spacearr_clear(&lnors_spacearr); - BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops, - mpolys, polynors, numPolys, use_split_normals, split_angle, - &lnors_spacearr, NULL, loop_to_poly); + BKE_mesh_normals_loop_split( + mverts, numVerts, medges, numEdges, mloops, lnors, numLoops, + mpolys, polynors, numPolys, use_split_normals, split_angle, + &lnors_spacearr, NULL, loop_to_poly); } else { BLI_BITMAP_SET_ALL(done_loops, true, (size_t)numLoops); @@ -1799,8 +1804,9 @@ void BKE_mesh_normals_loop_custom_set( MPoly *mpolys, const float (*polynors)[3], const int numPolys, short (*r_clnors_data)[2]) { - mesh_normals_loop_custom_set(mverts, numVerts, medges, numEdges, mloops, r_custom_loopnors, numLoops, - mpolys, polynors, numPolys, r_clnors_data, false); + mesh_normals_loop_custom_set( + mverts, numVerts, medges, numEdges, mloops, r_custom_loopnors, numLoops, + mpolys, polynors, numPolys, r_clnors_data, false); } void BKE_mesh_normals_loop_custom_from_vertices_set( @@ -1809,8 +1815,9 @@ void BKE_mesh_normals_loop_custom_from_vertices_set( MPoly *mpolys, const float (*polynors)[3], const int numPolys, short (*r_clnors_data)[2]) { - mesh_normals_loop_custom_set(mverts, numVerts, medges, numEdges, mloops, r_custom_vertnors, numLoops, - mpolys, polynors, numPolys, r_clnors_data, true); + mesh_normals_loop_custom_set( + mverts, numVerts, medges, numEdges, mloops, r_custom_vertnors, numLoops, + mpolys, polynors, numPolys, r_clnors_data, true); } /** @@ -1894,19 +1901,19 @@ void BKE_mesh_calc_poly_normal( mesh_calc_ngon_normal(mpoly, loopstart, mvarray, r_no); } else if (mpoly->totloop == 3) { - normal_tri_v3(r_no, - mvarray[loopstart[0].v].co, - mvarray[loopstart[1].v].co, - mvarray[loopstart[2].v].co - ); + normal_tri_v3( + r_no, + mvarray[loopstart[0].v].co, + mvarray[loopstart[1].v].co, + mvarray[loopstart[2].v].co); } else if (mpoly->totloop == 4) { - normal_quad_v3(r_no, - mvarray[loopstart[0].v].co, - mvarray[loopstart[1].v].co, - mvarray[loopstart[2].v].co, - mvarray[loopstart[3].v].co - ); + normal_quad_v3( + r_no, + mvarray[loopstart[0].v].co, + mvarray[loopstart[1].v].co, + mvarray[loopstart[2].v].co, + mvarray[loopstart[3].v].co); } else { /* horrible, two sided face! */ r_no[0] = 0.0; @@ -1946,19 +1953,19 @@ void BKE_mesh_calc_poly_normal_coords( mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, r_no); } else if (mpoly->totloop == 3) { - normal_tri_v3(r_no, - vertex_coords[loopstart[0].v], - vertex_coords[loopstart[1].v], - vertex_coords[loopstart[2].v] - ); + normal_tri_v3( + r_no, + vertex_coords[loopstart[0].v], + vertex_coords[loopstart[1].v], + vertex_coords[loopstart[2].v]); } else if (mpoly->totloop == 4) { - normal_quad_v3(r_no, - vertex_coords[loopstart[0].v], - vertex_coords[loopstart[1].v], - vertex_coords[loopstart[2].v], - vertex_coords[loopstart[3].v] - ); + normal_quad_v3( + r_no, + vertex_coords[loopstart[0].v], + vertex_coords[loopstart[1].v], + vertex_coords[loopstart[2].v], + vertex_coords[loopstart[3].v]); } else { /* horrible, two sided face! */ r_no[0] = 0.0; @@ -1986,19 +1993,19 @@ void BKE_mesh_calc_poly_center( const MVert *mvarray, float r_cent[3]) { if (mpoly->totloop == 3) { - mid_v3_v3v3v3(r_cent, - mvarray[loopstart[0].v].co, - mvarray[loopstart[1].v].co, - mvarray[loopstart[2].v].co - ); + mid_v3_v3v3v3( + r_cent, + mvarray[loopstart[0].v].co, + mvarray[loopstart[1].v].co, + mvarray[loopstart[2].v].co); } else if (mpoly->totloop == 4) { - mid_v3_v3v3v3v3(r_cent, - mvarray[loopstart[0].v].co, - mvarray[loopstart[1].v].co, - mvarray[loopstart[2].v].co, - mvarray[loopstart[3].v].co - ); + mid_v3_v3v3v3v3( + r_cent, + mvarray[loopstart[0].v].co, + mvarray[loopstart[1].v].co, + mvarray[loopstart[2].v].co, + mvarray[loopstart[3].v].co); } else { mesh_calc_ngon_center(mpoly, loopstart, mvarray, r_cent); @@ -2011,10 +2018,10 @@ float BKE_mesh_calc_poly_area( const MVert *mvarray) { if (mpoly->totloop == 3) { - return area_tri_v3(mvarray[loopstart[0].v].co, - mvarray[loopstart[1].v].co, - mvarray[loopstart[2].v].co - ); + return area_tri_v3( + mvarray[loopstart[0].v].co, + mvarray[loopstart[1].v].co, + mvarray[loopstart[2].v].co); } else { int i; @@ -2125,8 +2132,9 @@ static float mesh_calc_poly_area_centroid( } #if 0 /* slow version of the function below */ -void BKE_mesh_calc_poly_angles(MPoly *mpoly, MLoop *loopstart, - MVert *mvarray, float angles[]) +void BKE_mesh_calc_poly_angles( + MPoly *mpoly, MLoop *loopstart, + MVert *mvarray, float angles[]) { MLoop *ml; MLoop *mloop = &loopstart[-mpoly->loopstart]; @@ -2494,8 +2502,9 @@ void BKE_mesh_loops_to_mface_corners( * * \note when mface is not NULL, mface[face_index].v4 is used to test quads, else, loopindices[face_index][3] is used. */ -void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, MFace *mface, - int *polyindices, unsigned int (*loopindices)[4], const int num_faces) +void BKE_mesh_loops_to_tessdata( + CustomData *fdata, CustomData *ldata, MFace *mface, + int *polyindices, unsigned int (*loopindices)[4], const int num_faces) { /* Note: performances are sub-optimal when we get a NULL mface, we could be ~25% quicker with dedicated code... * Issue is, unless having two different functions with nearly the same code, there's not much ways to solve @@ -3088,8 +3097,9 @@ static void bm_corners_to_loops_ex( if (CustomData_external_test(fdata, CD_MDISPS)) { if (id && fdata->external) { - CustomData_external_add(ldata, id, CD_MDISPS, - totloop, fdata->external->filename); + CustomData_external_add( + ldata, id, CD_MDISPS, + totloop, fdata->external->filename); } } @@ -3127,10 +3137,11 @@ static void bm_corners_to_loops_ex( void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) { - BKE_mesh_convert_mfaces_to_mpolys_ex(&mesh->id, &mesh->fdata, &mesh->ldata, &mesh->pdata, - mesh->totedge, mesh->totface, mesh->totloop, mesh->totpoly, - mesh->medge, mesh->mface, - &mesh->totloop, &mesh->totpoly, &mesh->mloop, &mesh->mpoly); + BKE_mesh_convert_mfaces_to_mpolys_ex( + &mesh->id, &mesh->fdata, &mesh->ldata, &mesh->pdata, + mesh->totedge, mesh->totface, mesh->totloop, mesh->totpoly, + mesh->medge, mesh->mface, + &mesh->totloop, &mesh->totpoly, &mesh->mloop, &mesh->mpoly); BKE_mesh_update_customdata_pointers(mesh, true); } @@ -3147,21 +3158,23 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) */ void BKE_mesh_do_versions_convert_mfaces_to_mpolys(Mesh *mesh) { - BKE_mesh_convert_mfaces_to_mpolys_ex(&mesh->id, &mesh->fdata, &mesh->ldata, &mesh->pdata, - mesh->totedge, mesh->totface, mesh->totloop, mesh->totpoly, - mesh->medge, mesh->mface, - &mesh->totloop, &mesh->totpoly, &mesh->mloop, &mesh->mpoly); + BKE_mesh_convert_mfaces_to_mpolys_ex( + &mesh->id, &mesh->fdata, &mesh->ldata, &mesh->pdata, + mesh->totedge, mesh->totface, mesh->totloop, mesh->totpoly, + mesh->medge, mesh->mface, + &mesh->totloop, &mesh->totpoly, &mesh->mloop, &mesh->mpoly); CustomData_bmesh_do_versions_update_active_layers(&mesh->fdata, &mesh->ldata); BKE_mesh_update_customdata_pointers(mesh, true); } -void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id, CustomData *fdata, CustomData *ldata, CustomData *pdata, - int totedge_i, int totface_i, int totloop_i, int totpoly_i, - MEdge *medge, MFace *mface, - int *r_totloop, int *r_totpoly, - MLoop **r_mloop, MPoly **r_mpoly) +void BKE_mesh_convert_mfaces_to_mpolys_ex( + ID *id, CustomData *fdata, CustomData *ldata, CustomData *pdata, + int totedge_i, int totface_i, int totloop_i, int totpoly_i, + MEdge *medge, MFace *mface, + int *r_totloop, int *r_totpoly, + MLoop **r_mloop, MPoly **r_mpoly) { MFace *mf; MLoop *ml, *mloop; @@ -3385,10 +3398,11 @@ void BKE_mesh_polygons_flip( /* update the hide flag for edges and faces from the corresponding * flag in verts */ -void BKE_mesh_flush_hidden_from_verts_ex(const MVert *mvert, - const MLoop *mloop, - MEdge *medge, const int totedge, - MPoly *mpoly, const int totpoly) +void BKE_mesh_flush_hidden_from_verts_ex( + const MVert *mvert, + const MLoop *mloop, + MEdge *medge, const int totedge, + MPoly *mpoly, const int totpoly) { int i, j; @@ -3414,15 +3428,17 @@ void BKE_mesh_flush_hidden_from_verts_ex(const MVert *mvert, } void BKE_mesh_flush_hidden_from_verts(Mesh *me) { - BKE_mesh_flush_hidden_from_verts_ex(me->mvert, me->mloop, - me->medge, me->totedge, - me->mpoly, me->totpoly); + BKE_mesh_flush_hidden_from_verts_ex( + me->mvert, me->mloop, + me->medge, me->totedge, + me->mpoly, me->totpoly); } -void BKE_mesh_flush_hidden_from_polys_ex(MVert *mvert, - const MLoop *mloop, - MEdge *medge, const int UNUSED(totedge), - const MPoly *mpoly, const int totpoly) +void BKE_mesh_flush_hidden_from_polys_ex( + MVert *mvert, + const MLoop *mloop, + MEdge *medge, const int UNUSED(totedge), + const MPoly *mpoly, const int totpoly) { const MPoly *mp; int i; @@ -3455,18 +3471,20 @@ void BKE_mesh_flush_hidden_from_polys_ex(MVert *mvert, } void BKE_mesh_flush_hidden_from_polys(Mesh *me) { - BKE_mesh_flush_hidden_from_polys_ex(me->mvert, me->mloop, - me->medge, me->totedge, - me->mpoly, me->totpoly); + BKE_mesh_flush_hidden_from_polys_ex( + me->mvert, me->mloop, + me->medge, me->totedge, + me->mpoly, me->totpoly); } /** * simple poly -> vert/edge selection. */ -void BKE_mesh_flush_select_from_polys_ex(MVert *mvert, const int totvert, - const MLoop *mloop, - MEdge *medge, const int totedge, - const MPoly *mpoly, const int totpoly) +void BKE_mesh_flush_select_from_polys_ex( + MVert *mvert, const int totvert, + const MLoop *mloop, + MEdge *medge, const int totedge, + const MPoly *mpoly, const int totpoly) { MVert *mv; MEdge *med; @@ -3500,16 +3518,18 @@ void BKE_mesh_flush_select_from_polys_ex(MVert *mvert, const int totvert, } void BKE_mesh_flush_select_from_polys(Mesh *me) { - BKE_mesh_flush_select_from_polys_ex(me->mvert, me->totvert, - me->mloop, - me->medge, me->totedge, - me->mpoly, me->totpoly); + BKE_mesh_flush_select_from_polys_ex( + me->mvert, me->totvert, + me->mloop, + me->medge, me->totedge, + me->mpoly, me->totpoly); } -void BKE_mesh_flush_select_from_verts_ex(const MVert *mvert, const int UNUSED(totvert), - const MLoop *mloop, - MEdge *medge, const int totedge, - MPoly *mpoly, const int totpoly) +void BKE_mesh_flush_select_from_verts_ex( + const MVert *mvert, const int UNUSED(totvert), + const MLoop *mloop, + MEdge *medge, const int totedge, + MPoly *mpoly, const int totpoly) { MEdge *med; MPoly *mp; @@ -3554,10 +3574,11 @@ void BKE_mesh_flush_select_from_verts_ex(const MVert *mvert, const int UNUSED(to } void BKE_mesh_flush_select_from_verts(Mesh *me) { - BKE_mesh_flush_select_from_verts_ex(me->mvert, me->totvert, - me->mloop, - me->medge, me->totedge, - me->mpoly, me->totpoly); + BKE_mesh_flush_select_from_verts_ex( + me->mvert, me->totvert, + me->mloop, + me->medge, me->totedge, + me->mpoly, me->totpoly); } /** \} */ @@ -3585,7 +3606,7 @@ void BKE_mesh_calc_relative_deform( const float (*vert_cos_dst)[3], const float (*vert_cos_org)[3], - float (*vert_cos_new)[3]) + float (*vert_cos_new)[3]) { const MPoly *mp; int i; |