fix for own bad mistake using alloca in a loop, also knife project wasnt selecting correctly.

This commit is contained in:
Campbell Barton 2013-03-15 13:18:35 +00:00
parent 03f02019f2
commit 87919be4f6
2 changed files with 24 additions and 18 deletions

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

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