BMesh: generalize logic for quad/ngon triangulate

Avoid having 2 different code-paths for face triangulation.
This commit is contained in:
Campbell Barton 2015-11-05 06:32:04 +11:00
parent 3152419e7e
commit ce49c70956

@ -796,8 +796,20 @@ void BM_face_triangulate(
/* ensure both are valid or NULL */
BLI_assert((r_faces_new == NULL) == (r_faces_new_tot == NULL));
BLI_assert(f->len > 3);
{
BMLoop **loops = BLI_array_alloca(loops, f->len);
unsigned int (*tris)[3] = BLI_array_alloca(tris, f->len);
const int totfilltri = f->len - 2;
const int last_tri = f->len - 3;
int i;
if (f->len == 4) {
/* even though we're not using BLI_polyfill, fill in 'tris' and 'loops'
* so we can share code to handle face creation afterwards. */
BMLoop *l_v1, *l_v2;
l_first = BM_FACE_FIRST_LOOP(f);
switch (quad_method) {
@ -858,30 +870,17 @@ void BM_face_triangulate(
}
}
f_new = BM_face_split(bm, f, l_v1, l_v2, &l_new, NULL, true);
copy_v3_v3(f_new->no, f->no);
loops[0] = l_v1;
loops[1] = l_v1->next;
loops[2] = l_v2;
loops[3] = l_v2->next;
if (use_tag) {
BM_elem_flag_enable(l_new->e, BM_ELEM_TAG);
BM_elem_flag_enable(f_new, BM_ELEM_TAG);
ARRAY_SET_ITEMS(tris[0], 0, 1, 2);
ARRAY_SET_ITEMS(tris[1], 0, 2, 3);
}
if (r_faces_new) {
r_faces_new[nf_i++] = f_new;
}
if (r_edges_new) {
r_edges_new[ne_i++] = l_new->e;
}
}
else if (f->len > 4) {
else {
float axis_mat[3][3];
float (*projverts)[2] = BLI_array_alloca(projverts, f->len);
BMLoop **loops = BLI_array_alloca(loops, f->len);
unsigned int (*tris)[3] = BLI_array_alloca(tris, f->len);
const int totfilltri = f->len - 2;
const int last_tri = f->len - 3;
int i;
axis_dominant_v3_to_m3_negate(axis_mat, f->no);
@ -900,6 +899,7 @@ void BM_face_triangulate(
}
BLI_memarena_clear(pf_arena);
}
/* loop over calculated triangles and create new geometry */
for (i = 0; i < totfilltri; i++) {