diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-27 07:51:45 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-27 07:51:45 +0400 |
commit | 1d6c3ccf092c9c692db454f477435a814b81d30a (patch) | |
tree | 948dbbfbf7d9b55195dbde36bfffda037abd284e /source/blender/blenlib/intern/math_geom_inline.c | |
parent | 6586fd9c62784af5496c48e5eeebc9b128d1addd (diff) |
display the number of tri's in object mode status, often requested feature from users who model for realtime/game-engine output,
the total number of faces wasn't so useful and could be especially misleading with ngons.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom_inline.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c index ba9770e1bd1..9bb824be85e 100644 --- a/source/blender/blenlib/intern/math_geom_inline.c +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -158,4 +158,24 @@ MINLINE int min_axis_v3(const float vec[3]) ((y < z) ? 1 : 2)); } +/** + * Simple method to find how many tri's we need when we already know the corner+poly count. + * + * Formula is: + * + * tri = ((corner_count / poly_count) - 2) * poly_count; + * + * Use doubles since this is used for allocating and we + * don't want float precision to give incorrect results. + * + * \param poly_count The number of ngon's/tris (1-2 sided faces will give incorrect results) + * \param corner_count - also known as loops in BMesh/DNA + */ +MINLINE int poly_to_tri_count(const int poly_count, const int corner_count) +{ + const double poly_count_d = (double)poly_count; + const double corner_count_d = (double)corner_count; + return (int)((((corner_count_d / poly_count_d) - 2.0) * poly_count_d) + 0.5); +} + #endif /* __MATH_GEOM_INLINE_C__ */ |