diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-13 10:32:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-13 10:32:08 +0400 |
commit | 0488af00fe95d9af32215d38394994013f09bb2b (patch) | |
tree | 72de32d9b63f064e2a6760baba2100cebea967d5 /source/blender/bmesh/intern/bmesh_queries.c | |
parent | 56771becd0fefd1102795cb4c9c82b53f2ed7d2e (diff) |
fix for crash with laplacian smooth when unselected ngons were used, volume calculation assumed unselected face were not ngons.
- added convenience function BM_face_calc_tessellation() to get triangles from an ngon.
- expose volume function as BM_mesh_calc_volume().
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_queries.c')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_queries.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 70df0b56607..54950f2af82 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -1652,3 +1652,33 @@ bool BM_face_is_any_edge_flag_test(BMFace *f, const char hflag) } while ((l_iter = l_iter->next) != l_first); return false; } + +float BM_mesh_calc_volume(BMesh *bm) +{ + /* warning, calls own tessellation function, may be slow */ + float vol = 0.0f; + BMFace *f; + BMIter fiter; + + BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { + const int tottri = f->len - 2; + BMLoop **loops = BLI_array_alloca(loops, f->len); + int (*index)[3] = BLI_array_alloca(index, tottri); + int j; + + BM_face_calc_tessellation(f, loops, index); + + for (j = 0; j < tottri; j++) { + const float *p1 = loops[index[j][0]]->v->co; + const float *p2 = loops[index[j][1]]->v->co; + const float *p3 = loops[index[j][2]]->v->co; + + /* co1.dot(co2.cross(co3)) / 6.0 */ + float cross[3]; + cross_v3_v3v3(cross, p2, p3); + vol += (1.0f / 6.0f) * dot_v3v3(p1, cross); + } + } + + return fabsf(vol); +} |