From 87919be4f6f83900b03bb68bcc2b21455f8a00c9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 15 Mar 2013 13:18:35 +0000 Subject: fix for own bad mistake using alloca in a loop, also knife project wasnt selecting correctly. --- source/blender/bmesh/intern/bmesh_queries.c | 38 ++++++++++++---------- .../blender/editors/mesh/editmesh_knife_project.c | 4 ++- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'source') diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index c073f0f2793..0525337120f 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -1655,6 +1655,26 @@ bool BM_face_is_any_edge_flag_test(BMFace *f, const char hflag) return false; } +static void bm_mesh_calc_volume_face(BMFace *f, float *r_vol) +{ + 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); + *r_vol += (1.0f / 6.0f) * dot_v3v3(p1, cross); + } +} float BM_mesh_calc_volume(BMesh *bm) { /* warning, calls own tessellation function, may be slow */ @@ -1663,23 +1683,7 @@ float BM_mesh_calc_volume(BMesh *bm) 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); - } + bm_mesh_calc_volume_face(f, &vol); } return fabsf(vol); diff --git a/source/blender/editors/mesh/editmesh_knife_project.c b/source/blender/editors/mesh/editmesh_knife_project.c index 7bb7e362c98..d5291602080 100644 --- a/source/blender/editors/mesh/editmesh_knife_project.c +++ b/source/blender/editors/mesh/editmesh_knife_project.c @@ -133,9 +133,11 @@ static int knifeproject_exec(bContext *C, wmOperator *op) EDBM_mesh_knife(C, polys, true); /* select only tagged faces */ - BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false); + BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false); BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, true, BM_ELEM_TAG); + BM_mesh_select_mode_flush(em->bm); + BLI_linklist_freeN(polys); return OPERATOR_FINISHED; -- cgit v1.2.3