diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-20 13:42:18 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-20 13:42:18 +0400 |
commit | 017392d603de71c7df626a29f63cf945eb833cff (patch) | |
tree | f2addc54c9deeed962810de2f2de318ca4ac0663 /source/blender/blenkernel/intern | |
parent | 38338a51c92e3f47601199689c294da8a20bec18 (diff) |
fix/workaround [#36519] Origin to Center of Mass" failes when faces have an area of zero
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 79388dbb152..a6a85e82a4a 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -3667,7 +3667,7 @@ void BKE_mesh_flush_select_from_verts(Mesh *me) /* basic vertex data functions */ -int BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3]) +bool BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3]) { int i = me->totvert; MVert *mvert; @@ -3678,7 +3678,7 @@ int BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3]) return (me->totvert != 0); } -int BKE_mesh_center_median(Mesh *me, float cent[3]) +bool BKE_mesh_center_median(Mesh *me, float cent[3]) { int i = me->totvert; MVert *mvert; @@ -3694,19 +3694,19 @@ int BKE_mesh_center_median(Mesh *me, float cent[3]) return (me->totvert != 0); } -int BKE_mesh_center_bounds(Mesh *me, float cent[3]) +bool BKE_mesh_center_bounds(Mesh *me, float cent[3]) { float min[3], max[3]; INIT_MINMAX(min, max); if (BKE_mesh_minmax(me, min, max)) { mid_v3_v3v3(cent, min, max); - return 1; + return true; } - return 0; + return false; } -int BKE_mesh_center_centroid(Mesh *me, float cent[3]) +bool BKE_mesh_center_centroid(Mesh *me, float cent[3]) { int i = me->totpoly; MPoly *mpoly; @@ -3728,6 +3728,11 @@ int BKE_mesh_center_centroid(Mesh *me, float cent[3]) mul_v3_fl(cent, 1.0f / total_area); } + /* zero area faces cause this, fallback to median */ + if (UNLIKELY(!is_finite_v3(cent))) { + return BKE_mesh_center_median(me, cent); + } + return (me->totpoly != 0); } |