fix/workaround [#36519] Origin to Center of Mass" failes when faces have an area of zero

This commit is contained in:
Campbell Barton
2013-08-20 09:42:18 +00:00
parent 38338a51c9
commit 017392d603
2 changed files with 15 additions and 10 deletions

View File

@@ -332,10 +332,10 @@ void BKE_mesh_edge_poly_map_create(MeshElemMap **r_map, int **r_mem,
/* vertex level transformations & checks (no derived mesh) */
int BKE_mesh_minmax(struct Mesh *me, float r_min[3], float r_max[3]);
int BKE_mesh_center_median(struct Mesh *me, float cent[3]);
int BKE_mesh_center_bounds(struct Mesh *me, float cent[3]);
int BKE_mesh_center_centroid(struct Mesh *me, float cent[3]);
bool BKE_mesh_minmax(struct Mesh *me, float r_min[3], float r_max[3]);
bool BKE_mesh_center_median(struct Mesh *me, float cent[3]);
bool BKE_mesh_center_bounds(struct Mesh *me, float cent[3]);
bool BKE_mesh_center_centroid(struct Mesh *me, float cent[3]);
void BKE_mesh_translate(struct Mesh *me, const float offset[3], const bool do_keys);
/* mesh_validate.c */

View File

@@ -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);
}