BMesh: remove checks for tessellating 2 sided faces

2 sided faces aren't supported and will cause problems in many areas
of Blender's code.

Removing (implied) support for faces with fewer than 3 sides
means the total number of triangles is known ahead of time.

This simplifies adding support for multi-threading and partial updates
to an existing tessellation - as the face and loop indices can be used
to access the range of triangles associated with a face.

Also correct outdated comments.
This commit is contained in:
Campbell Barton 2021-06-01 12:49:22 +10:00
parent f8ce744c83
commit 5e7fb77dc4
7 changed files with 21 additions and 36 deletions

View File

@ -127,9 +127,10 @@ static void editmesh_tessface_calc_intern(BMEditMesh *em)
}
em->looptris = looptris;
em->tottri = looptris_tot;
/* after allocating the em->looptris, we're ready to tessellate */
BM_mesh_calc_tessellation(em->bm, em->looptris, &em->tottri);
BM_mesh_calc_tessellation(em->bm, em->looptris);
}
void BKE_editmesh_looptri_calc(BMEditMesh *em)

View File

@ -1530,14 +1530,11 @@ void BM_face_as_array_loop_quad(BMFace *f, BMLoop *r_loops[4])
*
* \note \a looptris Must be pre-allocated to at least the size of given by: poly_to_tri_count
*/
void BM_mesh_calc_tessellation(BMesh *bm, BMLoop *(*looptris)[3], int *r_looptris_tot)
void BM_mesh_calc_tessellation(BMesh *bm, BMLoop *(*looptris)[3])
{
/* use this to avoid locking pthread for _every_ polygon
* and calling the fill function */
/* Avoid polygon filling logic for 3-4 sided faces. */
#define USE_TESSFACE_SPEEDUP
/* this assumes all faces can be scan-filled, which isn't always true,
* worst case we over alloc a little which is acceptable */
#ifndef NDEBUG
const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
#endif
@ -1549,9 +1546,10 @@ void BM_mesh_calc_tessellation(BMesh *bm, BMLoop *(*looptris)[3], int *r_looptri
MemArena *arena = NULL;
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
BLI_assert(efa->len >= 3);
/* don't consider two-edged faces */
if (UNLIKELY(efa->len < 3)) {
/* do nothing */
if (0) {
/* do nothing (needed for else statements below) */
}
#ifdef USE_TESSFACE_SPEEDUP
@ -1664,8 +1662,6 @@ void BM_mesh_calc_tessellation(BMesh *bm, BMLoop *(*looptris)[3], int *r_looptri
arena = NULL;
}
*r_looptris_tot = i;
BLI_assert(i <= looptris_tot);
#undef USE_TESSFACE_SPEEDUP
@ -1674,10 +1670,8 @@ void BM_mesh_calc_tessellation(BMesh *bm, BMLoop *(*looptris)[3], int *r_looptri
/**
* A version of #BM_mesh_calc_tessellation that avoids degenerate triangles.
*/
void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3], int *r_looptris_tot)
void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3])
{
/* this assumes all faces can be scan-filled, which isn't always true,
* worst case we over alloc a little which is acceptable */
#ifndef NDEBUG
const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
#endif
@ -1692,11 +1686,9 @@ void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3], int *r_
Heap *pf_heap = NULL;
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
/* don't consider two-edged faces */
if (UNLIKELY(efa->len < 3)) {
/* do nothing */
}
else if (efa->len == 3) {
BLI_assert(efa->len >= 3);
if (efa->len == 3) {
BMLoop *l;
BMLoop **l_ptr = looptris[i++];
l_ptr[0] = l = BM_FACE_FIRST_LOOP(efa);
@ -1805,7 +1797,5 @@ void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3], int *r_
BLI_heap_free(pf_heap, NULL);
}
*r_looptris_tot = i;
BLI_assert(i <= looptris_tot);
}

View File

@ -24,8 +24,8 @@ struct Heap;
#include "BLI_compiler_attrs.h"
void BM_mesh_calc_tessellation(BMesh *bm, BMLoop *(*looptris)[3], int *r_looptris_tot);
void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3], int *r_looptris_tot);
void BM_mesh_calc_tessellation(BMesh *bm, BMLoop *(*looptris)[3]);
void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3]);
void BM_face_calc_tessellation(const BMFace *f,
const bool use_fixed_quad,

View File

@ -1239,10 +1239,9 @@ static void sculpt_gesture_apply_trim(SculptGestureContext *sgcontext)
}));
const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
int tottri;
BMLoop *(*looptris)[3];
looptris = MEM_malloc_arrayN(looptris_tot, sizeof(*looptris), __func__);
BM_mesh_calc_tessellation_beauty(bm, looptris, &tottri);
BM_mesh_calc_tessellation_beauty(bm, looptris);
BMIter iter;
int i;
@ -1290,7 +1289,7 @@ static void sculpt_gesture_apply_trim(SculptGestureContext *sgcontext)
break;
}
BM_mesh_boolean(
bm, looptris, tottri, bm_face_isect_pair, NULL, 2, true, true, false, boolean_mode);
bm, looptris, looptris_tot, bm_face_isect_pair, NULL, 2, true, true, false, boolean_mode);
}
MEM_freeN(looptris);

View File

@ -283,11 +283,10 @@ static void BMD_mesh_intersection(BMesh *bm,
/* main bmesh intersection setup */
/* create tessface & intersect */
const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
int tottri;
BMLoop *(*looptris)[3] = (BMLoop * (*)[3])
MEM_malloc_arrayN(looptris_tot, sizeof(*looptris), __func__);
BM_mesh_calc_tessellation_beauty(bm, looptris, &tottri);
BM_mesh_calc_tessellation_beauty(bm, looptris);
/* postpone this until after tessellating
* so we can use the original normals before the vertex are moved */
@ -364,7 +363,7 @@ static void BMD_mesh_intersection(BMesh *bm,
BM_mesh_intersect(bm,
looptris,
tottri,
looptris_tot,
bm_face_isect_pair,
nullptr,
false,

View File

@ -1385,7 +1385,6 @@ static PyObject *bpy_bmesh_calc_loop_triangles(BPy_BMElem *self)
BMesh *bm;
int looptris_tot;
int tottri;
BMLoop *(*looptris)[3];
PyObject *ret;
@ -1398,10 +1397,10 @@ static PyObject *bpy_bmesh_calc_loop_triangles(BPy_BMElem *self)
looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
looptris = PyMem_MALLOC(sizeof(*looptris) * looptris_tot);
BM_mesh_calc_tessellation(bm, looptris, &tottri);
BM_mesh_calc_tessellation(bm, looptris);
ret = PyList_New(tottri);
for (i = 0; i < tottri; i++) {
ret = PyList_New(looptris_tot);
for (i = 0; i < looptris_tot; i++) {
PyList_SET_ITEM(ret, i, BPy_BMLoop_Array_As_Tuple(bm, looptris[i], 3));
}

View File

@ -961,8 +961,6 @@ static PyObject *C_BVHTree_FromBMesh(PyObject *UNUSED(cls), PyObject *args, PyOb
/* Get data for tessellation */
{
int tris_len_dummy;
coords_len = (uint)bm->totvert;
tris_len = (uint)poly_to_tri_count(bm->totface, bm->totloop);
@ -971,8 +969,7 @@ static PyObject *C_BVHTree_FromBMesh(PyObject *UNUSED(cls), PyObject *args, PyOb
looptris = MEM_mallocN(sizeof(*looptris) * (size_t)tris_len, __func__);
BM_mesh_calc_tessellation(bm, looptris, &tris_len_dummy);
BLI_assert(tris_len_dummy == (int)tris_len);
BM_mesh_calc_tessellation(bm, looptris);
}
{