BKE_mesh: add a utility to get edge indices from looptri.

Not all three sides of a tesselated mesh triangle are guaranteed
to be original mesh edges, so a somewhat complicated check is
required to detect which ones are real. It seems that until now
there was no utility function for that, only some example code.
This commit is contained in:
Alexander Gavrilov 2018-10-20 21:02:52 +03:00
parent 84fa806491
commit 0709fac41e
3 changed files with 18 additions and 0 deletions

View File

@ -105,6 +105,7 @@ int poly_get_adj_loops_from_vert(
unsigned int r_adj[2]);
int BKE_mesh_edge_other_vert(const struct MEdge *e, int v);
void BKE_mesh_looptri_get_real_edges(const struct Mesh *mesh, const struct MLoopTri *looptri, int r_edges[3]);
void BKE_mesh_free(struct Mesh *me);
void BKE_mesh_init(struct Mesh *me);

View File

@ -1270,6 +1270,21 @@ int BKE_mesh_edge_other_vert(const MEdge *e, int v)
return -1;
}
/**
* Sets each output array element to the edge index if it is a real edge, or -1.
*/
void BKE_mesh_looptri_get_real_edges(const Mesh *mesh, const MLoopTri *looptri, int r_edges[3])
{
for (int i = 2, i_next = 0; i_next < 3; i = i_next++) {
const MLoop *l1 = &mesh->mloop[looptri->tri[i]], *l2 = &mesh->mloop[looptri->tri[i_next]];
const MEdge *e = &mesh->medge[l1->e];
bool is_real = (l1->v == e->v1 && l2->v == e->v2) || (l1->v == e->v2 && l2->v == e->v1);
r_edges[i] = is_real ? l1->e : -1;
}
}
/* basic vertex data functions */
bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3])
{

View File

@ -172,6 +172,8 @@ typedef struct MLoop {
* }
* \endcode
*
* See #BKE_mesh_looptri_get_real_edges for a utility that does this.
*
* \note A #MLoopTri may be in the middle of an ngon and not reference **any** edges.
*/
typedef struct MLoopTri {