diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-02-29 03:08:40 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-02-29 03:08:40 +0400 |
commit | 1ebb6e3360587fa673666a957538c8280b646f3c (patch) | |
tree | 888780693b11c3d5c7678cb3e9d6acabab8b74fe /source/blender/blenkernel/intern/mesh.c | |
parent | d279fb503d756262a1724da6084374f80589d0a3 (diff) |
Code cleanup for the neighbor_average() sculpt function.
Moved some of the code into a couple new mesh functions for searching
in poly loops to simplify the function, the rest is just cosmetic
changes.
Diffstat (limited to 'source/blender/blenkernel/intern/mesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index ef80c225482..c9b73376a3d 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -2833,6 +2833,42 @@ float mesh_calc_poly_area(MPoly *mpoly, MLoop *loopstart, } } +/* Find the index of the loop in 'poly' which references vertex, + returns -1 if not found */ +int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, + unsigned vert) +{ + int j; + for (j = 0; j < poly->totloop; j++, loopstart++) { + if (loopstart->v == vert) + return j; + } + + return -1; +} + +/* Fill 'adj_r' with the loop indices in 'poly' adjacent to the + vertex. Returns the index of the loop matching vertex, or -1 if the + vertex is not in 'poly' */ +int poly_get_adj_loops_from_vert(unsigned adj_r[3], const MPoly *poly, + const MLoop *mloop, unsigned vert) +{ + int corner = poly_find_loop_from_vert(poly, + &mloop[poly->loopstart], + vert); + + if(corner != -1) { + const MLoop *ml = &mloop[poly->loopstart + corner]; + + /* vertex was found */ + adj_r[0] = ME_POLY_LOOP_PREV(mloop, poly, corner)->v; + adj_r[1] = ml->v; + adj_r[2] = ME_POLY_LOOP_NEXT(mloop, poly, corner)->v; + } + + return corner; +} + /* basic vertex data functions */ int minmax_mesh(Mesh *me, float min[3], float max[3]) { |