2012-02-19 18:31:04 +00:00
|
|
|
/*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Joseph Eagar, Geoffrey Bantle, Campbell Barton
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/bmesh/intern/bmesh_queries.c
|
|
|
|
|
* \ingroup bmesh
|
|
|
|
|
*
|
|
|
|
|
* This file contains functions for answering common
|
|
|
|
|
* Topological and geometric queries about a mesh, such
|
|
|
|
|
* as, "What is the angle between these two faces?" or,
|
|
|
|
|
* "How many faces are incident upon this vertex?" Tool
|
|
|
|
|
* authors should use the functions in this file instead
|
|
|
|
|
* of inspecting the mesh structure directly.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-02-26 21:32:20 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_array.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
|
|
|
|
#include "bmesh.h"
|
2012-03-08 03:25:53 +00:00
|
|
|
#include "intern/bmesh_private.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
#define BM_OVERLAP (1 << 13)
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Returns whether or not a given vertex is
|
|
|
|
|
* is part of a given edge.
|
|
|
|
|
*/
|
|
|
|
|
int BM_vert_in_edge(BMEdge *e, BMVert *v)
|
|
|
|
|
{
|
|
|
|
|
return bmesh_vert_in_edge(e, v);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-03-06 16:17:55 +00:00
|
|
|
* \brief Other Loop in Face Sharing an Edge
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-03-03 12:35:37 +00:00
|
|
|
* Finds the other loop that shares \a v with \a e loop in \a f.
|
2012-03-06 16:17:55 +00:00
|
|
|
*
|
|
|
|
|
* +----------+
|
|
|
|
|
* | |
|
|
|
|
|
* | f |
|
|
|
|
|
* | |
|
|
|
|
|
* +----------+ <-- return the face loop of this vertex.
|
|
|
|
|
* v --> e
|
|
|
|
|
* ^ ^ <------- These vert args define direction
|
|
|
|
|
* in the face to check.
|
|
|
|
|
* The faces loop direction is ignored.
|
|
|
|
|
*
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-03-04 16:36:31 +00:00
|
|
|
BMLoop *BM_face_other_edge_loop(BMFace *f, BMEdge *e, BMVert *v)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
BMLoop *l_first;
|
|
|
|
|
|
2012-03-04 16:36:31 +00:00
|
|
|
/* we could loop around the face too, but turns out this uses a lot
|
|
|
|
|
* more iterations (approx double with quads, many more with 5+ ngons) */
|
|
|
|
|
l_iter = l_first = e->l;
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
do {
|
2012-03-04 16:36:31 +00:00
|
|
|
if (l_iter->e == e && l_iter->f == f) {
|
2012-02-19 18:31:04 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2012-03-04 16:36:31 +00:00
|
|
|
} while ((l_iter = l_iter->radial_next) != l_first);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
return l_iter->v == v ? l_iter->prev : l_iter->next;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-03 12:35:37 +00:00
|
|
|
/**
|
2012-03-06 16:17:55 +00:00
|
|
|
* \brief Other Loop in Face Sharing a Vertex
|
2012-03-03 12:35:37 +00:00
|
|
|
*
|
|
|
|
|
* Finds the other loop in a face.
|
|
|
|
|
*
|
2012-03-04 16:36:31 +00:00
|
|
|
* This function returns a loop in \a f that shares an edge with \a v
|
2012-03-03 12:35:37 +00:00
|
|
|
* The direction is defined by \a v_prev, where the return value is
|
|
|
|
|
* the loop of what would be 'v_next'
|
|
|
|
|
*
|
2012-03-04 16:01:02 +00:00
|
|
|
*
|
|
|
|
|
* +----------+ <-- return the face loop of this vertex.
|
|
|
|
|
* | |
|
|
|
|
|
* | f |
|
|
|
|
|
* | |
|
|
|
|
|
* +----------+
|
|
|
|
|
* v_prev --> v
|
2012-03-04 16:36:31 +00:00
|
|
|
* ^^^^^^ ^ <-- These vert args define direction
|
2012-03-04 16:01:02 +00:00
|
|
|
* in the face to check.
|
|
|
|
|
* The faces loop direction is ignored.
|
|
|
|
|
*
|
2012-03-03 12:35:37 +00:00
|
|
|
* \note \a v_prev and \a v _implicitly_ define an edge.
|
|
|
|
|
*/
|
2012-03-04 16:01:02 +00:00
|
|
|
BMLoop *BM_face_other_vert_loop(BMFace *f, BMVert *v_prev, BMVert *v)
|
2012-03-03 12:35:37 +00:00
|
|
|
{
|
|
|
|
|
BMIter liter;
|
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
|
|
|
|
|
BLI_assert(BM_edge_exists(v_prev, v) != NULL);
|
|
|
|
|
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (l_iter, &liter, v, BM_LOOPS_OF_VERT) {
|
2012-03-03 12:35:37 +00:00
|
|
|
if (l_iter->f == f) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (l_iter) {
|
|
|
|
|
if (l_iter->prev->v == v_prev) {
|
|
|
|
|
return l_iter->next;
|
|
|
|
|
}
|
|
|
|
|
else if (l_iter->next->v == v_prev) {
|
|
|
|
|
return l_iter->prev;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* invalid args */
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* invalid args */
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-25 14:44:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Other Loop in Face Sharing a Vert
|
|
|
|
|
*
|
|
|
|
|
* Finds the other loop that shares \a v with \a e loop in \a f.
|
|
|
|
|
*
|
|
|
|
|
* +----------+ <-- return the face loop of this vertex.
|
|
|
|
|
* | |
|
|
|
|
|
* | |
|
|
|
|
|
* | |
|
|
|
|
|
* +----------+ <-- This vertex defines the direction.
|
|
|
|
|
* l v
|
|
|
|
|
* ^ <------- This loop defines both the face to search
|
|
|
|
|
* and the edge, in combination with 'v'
|
|
|
|
|
* The faces loop direction is ignored.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
BMLoop *BM_loop_other_vert_loop(BMLoop *l, BMVert *v)
|
|
|
|
|
{
|
|
|
|
|
#if 0 /* works but slow */
|
|
|
|
|
return BM_face_other_vert_loop(l->f, BM_edge_other_vert(l->e, v), v);
|
|
|
|
|
#else
|
|
|
|
|
BMEdge *e = l->e;
|
|
|
|
|
BMVert *v_prev = BM_edge_other_vert(e, v);
|
|
|
|
|
if (l->v == v) {
|
|
|
|
|
if (l->prev->v == v_prev) {
|
|
|
|
|
return l->next;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(l->next->v == v_prev);
|
|
|
|
|
|
|
|
|
|
return l->prev;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(l->v == v_prev);
|
|
|
|
|
|
|
|
|
|
if (l->prev->v == v) {
|
|
|
|
|
return l->prev->prev;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(l->next->v == v);
|
|
|
|
|
return l->next->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Returns TRUE if the vertex is used in a given face.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int BM_vert_in_face(BMFace *f, BMVert *v)
|
|
|
|
|
{
|
2012-02-25 14:56:37 +00:00
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
|
|
|
|
|
#ifdef USE_BMESH_HOLES
|
|
|
|
|
BMLoopList *lst;
|
|
|
|
|
for (lst = f->loops.first; lst; lst = lst->next)
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
#ifdef USE_BMESH_HOLES
|
|
|
|
|
l_iter = l_first = lst->first;
|
|
|
|
|
#else
|
|
|
|
|
l_iter = l_first = f->l_first;
|
|
|
|
|
#endif
|
|
|
|
|
do {
|
|
|
|
|
if (l_iter->v == v) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Compares the number of vertices in an array
|
|
|
|
|
* that appear in a given face
|
|
|
|
|
*/
|
|
|
|
|
int BM_verts_in_face(BMesh *bm, BMFace *f, BMVert **varr, int len)
|
|
|
|
|
{
|
|
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
|
|
|
|
|
#ifdef USE_BMESH_HOLES
|
|
|
|
|
BMLoopList *lst;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int i, count = 0;
|
|
|
|
|
|
2012-02-25 19:43:51 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
BMO_elem_flag_enable(bm, varr[i], BM_OVERLAP);
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
#ifdef USE_BMESH_HOLES
|
|
|
|
|
for (lst = f->loops.first; lst; lst = lst->next)
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#ifdef USE_BMESH_HOLES
|
|
|
|
|
l_iter = l_first = lst->first;
|
|
|
|
|
#else
|
|
|
|
|
l_iter = l_first = f->l_first;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (BMO_elem_flag_test(bm, l_iter->v, BM_OVERLAP)) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) BMO_elem_flag_disable(bm, varr[i], BM_OVERLAP);
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Returns whether or not a given edge is is part of a given face.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
|
|
|
|
int BM_edge_in_face(BMFace *f, BMEdge *e)
|
|
|
|
|
{
|
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
BMLoop *l_first;
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (l_iter->e == e) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Returns whether or not two vertices are in
|
|
|
|
|
* a given edge
|
|
|
|
|
*/
|
|
|
|
|
int BM_verts_in_edge(BMVert *v1, BMVert *v2, BMEdge *e)
|
|
|
|
|
{
|
|
|
|
|
return bmesh_verts_in_edge(v1, v2, e);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Given a edge and one of its vertices, returns
|
|
|
|
|
* the other vertex.
|
|
|
|
|
*/
|
|
|
|
|
BMVert *BM_edge_other_vert(BMEdge *e, BMVert *v)
|
|
|
|
|
{
|
2012-02-27 13:47:53 +00:00
|
|
|
return bmesh_edge_other_vert_get(e, v);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-19 21:47:32 +00:00
|
|
|
/**
|
|
|
|
|
* The function takes a vertex at the center of a fan and returns the opposite edge in the fan.
|
|
|
|
|
* All edges in the fan must be manifold, otherwise return NULL.
|
|
|
|
|
*
|
|
|
|
|
* \note This could (probably) be done more effieiently.
|
|
|
|
|
*/
|
|
|
|
|
BMEdge *BM_vert_other_disk_edge(BMVert *v, BMEdge *e_first)
|
|
|
|
|
{
|
|
|
|
|
BMLoop *l_a;
|
|
|
|
|
int tot = 0;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BLI_assert(BM_vert_in_edge(e_first, v));
|
|
|
|
|
|
|
|
|
|
l_a = e_first->l;
|
|
|
|
|
do {
|
|
|
|
|
l_a = BM_loop_other_vert_loop(l_a, v);
|
|
|
|
|
l_a = BM_vert_in_edge(l_a->e, v) ? l_a : l_a->prev;
|
|
|
|
|
if (BM_edge_is_manifold(l_a->e)) {
|
|
|
|
|
l_a = l_a->radial_next;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tot++;
|
|
|
|
|
} while (l_a != e_first->l);
|
|
|
|
|
|
|
|
|
|
/* we know the total, now loop half way */
|
|
|
|
|
tot /= 2;
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
l_a = e_first->l;
|
|
|
|
|
do {
|
|
|
|
|
if (i == tot) {
|
|
|
|
|
l_a = BM_vert_in_edge(l_a->e, v) ? l_a : l_a->prev;
|
|
|
|
|
return l_a->e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l_a = BM_loop_other_vert_loop(l_a, v);
|
|
|
|
|
l_a = BM_vert_in_edge(l_a->e, v) ? l_a : l_a->prev;
|
|
|
|
|
if (BM_edge_is_manifold(l_a->e)) {
|
|
|
|
|
l_a = l_a->radial_next;
|
|
|
|
|
}
|
|
|
|
|
/* this wont have changed from the previous loop */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
} while (l_a != e_first->l);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 01:57:42 +00:00
|
|
|
/**
|
|
|
|
|
* Returms edge length
|
|
|
|
|
*/
|
2012-04-23 01:19:50 +00:00
|
|
|
float BM_edge_calc_length(BMEdge *e)
|
2012-03-19 01:57:42 +00:00
|
|
|
{
|
|
|
|
|
return len_v3v3(e->v1->co, e->v2->co);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-03 12:35:37 +00:00
|
|
|
/**
|
|
|
|
|
* Utility function, since enough times we have an edge
|
|
|
|
|
* and want to access 2 connected faces.
|
|
|
|
|
*
|
|
|
|
|
* \return TRUE when only 2 faces are found.
|
|
|
|
|
*/
|
|
|
|
|
int BM_edge_face_pair(BMEdge *e, BMFace **r_fa, BMFace **r_fb)
|
|
|
|
|
{
|
|
|
|
|
BMLoop *la, *lb;
|
|
|
|
|
|
|
|
|
|
if ((la = e->l) &&
|
|
|
|
|
(lb = la->radial_next) &&
|
|
|
|
|
(lb->radial_next == la))
|
|
|
|
|
{
|
|
|
|
|
*r_fa = la->f;
|
|
|
|
|
*r_fb = lb->f;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*r_fa = NULL;
|
|
|
|
|
*r_fb = NULL;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 01:57:42 +00:00
|
|
|
/**
|
|
|
|
|
* Utility function, since enough times we have an edge
|
|
|
|
|
* and want to access 2 connected loops.
|
|
|
|
|
*
|
|
|
|
|
* \return TRUE when only 2 faces are found.
|
|
|
|
|
*/
|
|
|
|
|
int BM_edge_loop_pair(BMEdge *e, BMLoop **r_la, BMLoop **r_lb)
|
|
|
|
|
{
|
|
|
|
|
BMLoop *la, *lb;
|
|
|
|
|
|
|
|
|
|
if ((la = e->l) &&
|
|
|
|
|
(lb = la->radial_next) &&
|
|
|
|
|
(lb->radial_next == la))
|
|
|
|
|
{
|
|
|
|
|
*r_la = la;
|
|
|
|
|
*r_lb = lb;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*r_la = NULL;
|
|
|
|
|
*r_lb = NULL;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Returns the number of edges around this vertex.
|
|
|
|
|
*/
|
|
|
|
|
int BM_vert_edge_count(BMVert *v)
|
|
|
|
|
{
|
|
|
|
|
return bmesh_disk_count(v);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-11 21:47:14 +00:00
|
|
|
int BM_vert_edge_count_nonwire(BMVert *v)
|
2012-03-11 20:45:58 +00:00
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
BMIter eiter;
|
|
|
|
|
BMEdge *edge;
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (edge, &eiter, v, BM_EDGES_OF_VERT) {
|
2012-03-20 04:27:14 +00:00
|
|
|
if (edge->l) {
|
2012-03-11 21:47:14 +00:00
|
|
|
count++;
|
2012-03-11 20:45:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Returns the number of faces around this edge
|
|
|
|
|
*/
|
|
|
|
|
int BM_edge_face_count(BMEdge *e)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
if (e->l) {
|
2012-03-01 17:13:02 +00:00
|
|
|
BMLoop *l_iter;
|
|
|
|
|
BMLoop *l_first;
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = e->l;
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
do {
|
|
|
|
|
count++;
|
2012-03-01 17:13:02 +00:00
|
|
|
} while ((l_iter = l_iter->radial_next) != l_first);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Returns the number of faces around this vert
|
|
|
|
|
*/
|
|
|
|
|
int BM_vert_face_count(BMVert *v)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
BMLoop *l;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
|
2012-02-19 18:31:04 +00:00
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
#if 0 //this code isn't working
|
|
|
|
|
BMEdge *curedge = NULL;
|
|
|
|
|
|
|
|
|
|
if (v->e) {
|
|
|
|
|
curedge = v->e;
|
|
|
|
|
do {
|
|
|
|
|
if (curedge->l) count += BM_edge_face_count(curedge);
|
2012-02-27 13:47:53 +00:00
|
|
|
curedge = bmesh_disk_edge_next(curedge, v);
|
2012-02-19 18:31:04 +00:00
|
|
|
} while (curedge != v->e);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Tests whether or not the vertex is part of a wire edge.
|
|
|
|
|
* (ie: has no faces attached to it)
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-03-22 07:53:11 +00:00
|
|
|
int BM_vert_is_wire(BMVert *v)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
BMEdge *curedge;
|
|
|
|
|
|
|
|
|
|
if (v->e == NULL) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curedge = v->e;
|
|
|
|
|
do {
|
|
|
|
|
if (curedge->l) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 19:30:44 +00:00
|
|
|
curedge = bmesh_disk_edge_next(curedge, v);
|
2012-02-19 18:31:04 +00:00
|
|
|
} while (curedge != v->e);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Tests whether or not the edge is part of a wire.
|
|
|
|
|
* (ie: has no faces attached to it)
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-03-22 07:53:11 +00:00
|
|
|
int BM_edge_is_wire(BMEdge *e)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
return (e->l) ? FALSE : TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* A vertex is non-manifold if it meets the following conditions:
|
2012-04-18 06:36:47 +00:00
|
|
|
* 1: Loose - (has no edges/faces incident upon it).
|
|
|
|
|
* 2: Joins two distinct regions - (two pyramids joined at the tip).
|
|
|
|
|
* 3: Is part of a an edge with more than 2 faces.
|
|
|
|
|
* 4: Is part of a wire edge.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-03-22 07:53:11 +00:00
|
|
|
int BM_vert_is_manifold(BMVert *v)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
BMEdge *e, *oe;
|
|
|
|
|
BMLoop *l;
|
|
|
|
|
int len, count, flag;
|
|
|
|
|
|
|
|
|
|
if (v->e == NULL) {
|
|
|
|
|
/* loose vert */
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* count edges while looking for non-manifold edges */
|
2012-04-18 06:36:47 +00:00
|
|
|
len = 0;
|
|
|
|
|
oe = e = v->e;
|
|
|
|
|
do {
|
|
|
|
|
/* loose edge or edge shared by more than two faces,
|
|
|
|
|
* edges with 1 face user are OK, otherwise we could
|
|
|
|
|
* use BM_edge_is_manifold() here */
|
|
|
|
|
if (e->l == NULL || bmesh_radial_length(e->l) > 2) {
|
2012-02-19 18:31:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2012-04-18 06:36:47 +00:00
|
|
|
len++;
|
2012-04-20 13:45:38 +00:00
|
|
|
} while ((e = bmesh_disk_edge_next(e, v)) != oe);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
|
flag = 1;
|
|
|
|
|
e = NULL;
|
|
|
|
|
oe = v->e;
|
|
|
|
|
l = oe->l;
|
|
|
|
|
while (e != oe) {
|
|
|
|
|
l = (l->v == v) ? l->prev : l->next;
|
|
|
|
|
e = l->e;
|
|
|
|
|
count++; /* count the edges */
|
|
|
|
|
|
|
|
|
|
if (flag && l->radial_next == l) {
|
|
|
|
|
/* we've hit the edge of an open mesh, reset once */
|
|
|
|
|
flag = 0;
|
|
|
|
|
count = 1;
|
|
|
|
|
oe = e;
|
|
|
|
|
e = NULL;
|
|
|
|
|
l = oe->l;
|
|
|
|
|
}
|
|
|
|
|
else if (l->radial_next == l) {
|
|
|
|
|
/* break the loop */
|
|
|
|
|
e = oe;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
l = l->radial_next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count < len) {
|
|
|
|
|
/* vert shared by multiple regions */
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Tests whether or not this edge is manifold.
|
2012-04-03 17:09:47 +00:00
|
|
|
* A manifold edge has exactly 2 faces attached to it.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-03-01 16:56:42 +00:00
|
|
|
|
|
|
|
|
#if 1 /* fast path for checking manifold */
|
2012-03-22 07:53:11 +00:00
|
|
|
int BM_edge_is_manifold(BMEdge *e)
|
2012-03-01 16:56:42 +00:00
|
|
|
{
|
|
|
|
|
const BMLoop *l = e->l;
|
2012-04-03 17:09:47 +00:00
|
|
|
return (l && (l->radial_next != l) && /* not 0 or 1 face users */
|
|
|
|
|
(l->radial_next->radial_next == l)); /* 2 face users */
|
2012-03-01 16:56:42 +00:00
|
|
|
}
|
|
|
|
|
#else
|
2012-03-22 07:53:11 +00:00
|
|
|
int BM_edge_is_manifold(BMEdge *e)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
int count = BM_edge_face_count(e);
|
2012-04-03 17:09:47 +00:00
|
|
|
if (count == 2) {
|
2012-03-01 16:56:42 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-02-19 18:31:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-01 16:56:42 +00:00
|
|
|
#endif
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Tests whether or not an edge is on the boundary
|
|
|
|
|
* of a shell (has one face associated with it)
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-03-01 16:56:42 +00:00
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
#if 1 /* fast path for checking boundary */
|
2012-03-01 16:56:42 +00:00
|
|
|
int BM_edge_is_boundary(BMEdge *e)
|
|
|
|
|
{
|
|
|
|
|
const BMLoop *l = e->l;
|
|
|
|
|
return (l && (l->radial_next == l));
|
|
|
|
|
}
|
|
|
|
|
#else
|
2012-02-24 06:44:04 +00:00
|
|
|
int BM_edge_is_boundary(BMEdge *e)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
int count = BM_edge_face_count(e);
|
|
|
|
|
if (count == 1) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2012-03-01 16:56:42 +00:00
|
|
|
else {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2012-03-01 16:56:42 +00:00
|
|
|
#endif
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-19 18:31:04 +00:00
|
|
|
* Counts the number of edges two faces share (if any)
|
|
|
|
|
*/
|
2012-02-26 19:46:12 +00:00
|
|
|
int BM_face_share_edge_count(BMFace *f1, BMFace *f2)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
BMLoop *l_first;
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f1);
|
|
|
|
|
do {
|
2012-02-27 13:47:53 +00:00
|
|
|
if (bmesh_radial_face_find(l_iter->e, f2)) {
|
2012-02-19 18:31:04 +00:00
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Test if e1 shares any faces with e2
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-02-26 19:46:12 +00:00
|
|
|
int BM_edge_share_face_count(BMEdge *e1, BMEdge *e2)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
BMLoop *l;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
|
|
|
|
|
if (e1->l && e2->l) {
|
|
|
|
|
l = e1->l;
|
|
|
|
|
do {
|
|
|
|
|
f = l->f;
|
2012-02-27 13:47:53 +00:00
|
|
|
if (bmesh_radial_face_find(e2, f)) {
|
2012-02-19 18:31:04 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
l = l->radial_next;
|
|
|
|
|
} while (l != e1->l);
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests to see if e1 shares a vertex with e2
|
|
|
|
|
*/
|
2012-02-28 19:30:44 +00:00
|
|
|
int BM_edge_share_vert_count(BMEdge *e1, BMEdge *e2)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
return (e1->v1 == e2->v1 ||
|
|
|
|
|
e1->v1 == e2->v2 ||
|
|
|
|
|
e1->v2 == e2->v1 ||
|
|
|
|
|
e1->v2 == e2->v2);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 21:32:20 +00:00
|
|
|
/**
|
|
|
|
|
* Return the shared vertex between the two edges or NULL
|
|
|
|
|
*/
|
2012-02-28 19:30:44 +00:00
|
|
|
BMVert *BM_edge_share_vert(BMEdge *e1, BMEdge *e2)
|
2012-02-26 21:32:20 +00:00
|
|
|
{
|
|
|
|
|
if (BM_vert_in_edge(e2, e1->v1)) {
|
|
|
|
|
return e1->v1;
|
|
|
|
|
}
|
|
|
|
|
else if (BM_vert_in_edge(e2, e1->v2)) {
|
|
|
|
|
return e1->v2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-08 20:00:37 +00:00
|
|
|
/**
|
2012-04-18 04:32:55 +00:00
|
|
|
* \brief Return the Loop Shared by Face and Vertex
|
2012-03-08 20:00:37 +00:00
|
|
|
*
|
|
|
|
|
* Finds the loop used which uses \a v in face loop \a l
|
|
|
|
|
*
|
|
|
|
|
* \note currenly this just uses simple loop in future may be speeded up
|
|
|
|
|
* using radial vars
|
|
|
|
|
*/
|
|
|
|
|
BMLoop *BM_face_vert_share_loop(BMFace *f, BMVert *v)
|
|
|
|
|
{
|
|
|
|
|
BMLoop *l_first;
|
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
|
do {
|
|
|
|
|
if (l_iter->v == v) {
|
|
|
|
|
return l_iter;
|
|
|
|
|
}
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 04:32:55 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Return the Loop Shared by Face and Edge
|
|
|
|
|
*
|
|
|
|
|
* Finds the loop used which uses \a e in face loop \a l
|
|
|
|
|
*
|
|
|
|
|
* \note currenly this just uses simple loop in future may be speeded up
|
|
|
|
|
* using radial vars
|
|
|
|
|
*/
|
|
|
|
|
BMLoop *BM_face_edge_share_loop(BMFace *f, BMEdge *e)
|
|
|
|
|
{
|
|
|
|
|
BMLoop *l_first;
|
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = e->l;
|
|
|
|
|
do {
|
|
|
|
|
if (l_iter->f == f) {
|
|
|
|
|
return l_iter;
|
|
|
|
|
}
|
|
|
|
|
} while ((l_iter = l_iter->radial_next) != l_first);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/**
|
2012-02-28 18:28:30 +00:00
|
|
|
* Returns the verts of an edge as used in a face
|
|
|
|
|
* if used in a face at all, otherwise just assign as used in the edge.
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-03-18 07:38:51 +00:00
|
|
|
* Useful to get a deterministic winding order when calling
|
2012-02-28 18:28:30 +00:00
|
|
|
* BM_face_create_ngon() on an arbitrary array of verts,
|
|
|
|
|
* though be sure to pick an edge which has a face.
|
2012-04-18 04:32:55 +00:00
|
|
|
*
|
2012-05-20 21:23:26 +00:00
|
|
|
* \note This is in fact quite a simple check, mainly include this function so the intent is more obvious.
|
2012-04-18 04:32:55 +00:00
|
|
|
* We know these 2 verts will _always_ make up the loops edge
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-03-19 01:57:42 +00:00
|
|
|
void BM_edge_ordered_verts_ex(BMEdge *edge, BMVert **r_v1, BMVert **r_v2,
|
|
|
|
|
BMLoop *edge_loop)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2012-03-19 01:57:42 +00:00
|
|
|
BLI_assert(edge_loop->e == edge);
|
2012-04-18 04:32:55 +00:00
|
|
|
*r_v1 = edge_loop->v;
|
|
|
|
|
*r_v2 = edge_loop->next->v;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-19 01:57:42 +00:00
|
|
|
void BM_edge_ordered_verts(BMEdge *edge, BMVert **r_v1, BMVert **r_v2)
|
|
|
|
|
{
|
|
|
|
|
BM_edge_ordered_verts_ex(edge, r_v1, r_v2, edge->l);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
|
* Calculates the angle between the previous and next loops
|
|
|
|
|
* (angle at this loops face corner).
|
2012-02-23 03:39:39 +00:00
|
|
|
*
|
2012-02-28 18:28:30 +00:00
|
|
|
* \return angle in radians
|
2012-02-23 03:39:39 +00:00
|
|
|
*/
|
2012-04-23 01:19:50 +00:00
|
|
|
float BM_loop_calc_face_angle(BMLoop *l)
|
2012-02-23 03:39:39 +00:00
|
|
|
{
|
|
|
|
|
return angle_v3v3v3(l->prev->v->co,
|
|
|
|
|
l->v->co,
|
|
|
|
|
l->next->v->co);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-11 05:58:22 +00:00
|
|
|
/**
|
2012-04-23 01:19:50 +00:00
|
|
|
* \brief BM_loop_calc_face_normal
|
2012-03-11 05:58:22 +00:00
|
|
|
*
|
|
|
|
|
* Calculate the normal at this loop corner or fallback to the face normal on straignt lines.
|
|
|
|
|
*
|
|
|
|
|
* \param bm The BMesh
|
|
|
|
|
* \param l The loop to calculate the normal at
|
|
|
|
|
* \param r_normal Resulting normal
|
|
|
|
|
*/
|
2012-04-23 01:19:50 +00:00
|
|
|
void BM_loop_calc_face_normal(BMLoop *l, float r_normal[3])
|
2012-03-11 05:58:22 +00:00
|
|
|
{
|
|
|
|
|
if (normal_tri_v3(r_normal,
|
|
|
|
|
l->prev->v->co,
|
|
|
|
|
l->v->co,
|
|
|
|
|
l->next->v->co) != 0.0f)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v3_v3(r_normal, l->f->no);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-23 01:19:50 +00:00
|
|
|
* \brief BM_loop_calc_face_tangent
|
2012-03-11 05:58:22 +00:00
|
|
|
*
|
|
|
|
|
* Calculate the tangent at this loop corner or fallback to the face normal on straignt lines.
|
|
|
|
|
* This vector always points inward into the face.
|
|
|
|
|
*
|
|
|
|
|
* \param bm The BMesh
|
|
|
|
|
* \param l The loop to calculate the tangent at
|
|
|
|
|
* \param r_tangent Resulting tangent
|
|
|
|
|
*/
|
2012-04-23 01:19:50 +00:00
|
|
|
void BM_loop_calc_face_tangent(BMLoop *l, float r_tangent[3])
|
2012-03-11 05:58:22 +00:00
|
|
|
{
|
|
|
|
|
float v_prev[3];
|
|
|
|
|
float v_next[3];
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(v_prev, l->prev->v->co, l->v->co);
|
|
|
|
|
sub_v3_v3v3(v_next, l->v->co, l->next->v->co);
|
|
|
|
|
|
|
|
|
|
normalize_v3(v_prev);
|
|
|
|
|
normalize_v3(v_next);
|
|
|
|
|
|
|
|
|
|
if (compare_v3v3(v_prev, v_next, FLT_EPSILON) == FALSE) {
|
|
|
|
|
float dir[3];
|
2012-04-07 12:37:15 +00:00
|
|
|
float nor[3]; /* for this purpose doesn't need to be normalized */
|
2012-03-11 05:58:22 +00:00
|
|
|
add_v3_v3v3(dir, v_prev, v_next);
|
|
|
|
|
cross_v3_v3v3(nor, v_prev, v_next);
|
|
|
|
|
cross_v3_v3v3(r_tangent, dir, nor);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-03-18 07:38:51 +00:00
|
|
|
/* prev/next are the same - compare with face normal since we don't have one */
|
2012-03-11 05:58:22 +00:00
|
|
|
cross_v3_v3v3(r_tangent, v_next, l->f->no);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
normalize_v3(r_tangent);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-29 06:55:10 +00:00
|
|
|
* \brief BMESH EDGE/FACE ANGLE
|
|
|
|
|
*
|
2012-02-19 18:31:04 +00:00
|
|
|
* Calculates the angle between two faces.
|
|
|
|
|
* Assumes the face normals are correct.
|
|
|
|
|
*
|
2012-02-28 18:28:30 +00:00
|
|
|
* \return angle in radians
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-04-23 01:19:50 +00:00
|
|
|
float BM_edge_calc_face_angle(BMEdge *e)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2012-04-18 06:44:48 +00:00
|
|
|
if (BM_edge_is_manifold(e)) {
|
2012-02-19 18:31:04 +00:00
|
|
|
BMLoop *l1 = e->l;
|
|
|
|
|
BMLoop *l2 = e->l->radial_next;
|
|
|
|
|
return angle_normalized_v3v3(l1->f->no, l2->f->no);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-02-25 14:56:37 +00:00
|
|
|
return DEG2RADF(90.0f);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 11:25:05 +00:00
|
|
|
/**
|
|
|
|
|
* \brief BMESH EDGE/FACE TANGENT
|
|
|
|
|
*
|
|
|
|
|
* Calculate the tangent at this loop corner or fallback to the face normal on straignt lines.
|
|
|
|
|
* This vector always points inward into the face.
|
|
|
|
|
*
|
2012-04-23 01:19:50 +00:00
|
|
|
* \brief BM_edge_calc_face_tangent
|
2012-04-19 11:25:05 +00:00
|
|
|
* \param e
|
|
|
|
|
* \param e_loop The loop to calculate the tangent at,
|
|
|
|
|
* used to get the face and winding direction.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-04-23 01:19:50 +00:00
|
|
|
void BM_edge_calc_face_tangent(BMEdge *e, BMLoop *e_loop, float r_tangent[3])
|
2012-04-19 11:25:05 +00:00
|
|
|
{
|
|
|
|
|
float tvec[3];
|
|
|
|
|
BMVert *v1, *v2;
|
|
|
|
|
BM_edge_ordered_verts_ex(e, &v1, &v2, e_loop);
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(tvec, v1->co, v2->co); /* use for temp storage */
|
|
|
|
|
/* note, we could average the tangents of both loops,
|
|
|
|
|
* for non flat ngons it will give a better direction */
|
|
|
|
|
cross_v3_v3v3(r_tangent, tvec, e_loop->f->no);
|
|
|
|
|
normalize_v3(r_tangent);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 07:42:48 +00:00
|
|
|
/**
|
2012-02-29 06:55:10 +00:00
|
|
|
* \brief BMESH VERT/EDGE ANGLE
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* Calculates the angle a verts 2 edges.
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-28 07:42:48 +00:00
|
|
|
* \returns the angle in radians
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-04-23 01:19:50 +00:00
|
|
|
float BM_vert_calc_edge_angle(BMVert *v)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
BMEdge *e1, *e2;
|
|
|
|
|
|
|
|
|
|
/* saves BM_vert_edge_count(v) and and edge iterator,
|
|
|
|
|
* get the edges and count them both at once */
|
|
|
|
|
|
|
|
|
|
if ((e1 = v->e) &&
|
2012-04-23 01:19:50 +00:00
|
|
|
(e2 = bmesh_disk_edge_next(e1, v)) &&
|
2012-02-19 18:31:04 +00:00
|
|
|
/* make sure we come full circle and only have 2 connected edges */
|
2012-04-23 01:19:50 +00:00
|
|
|
(e1 == bmesh_disk_edge_next(e2, v)))
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
BMVert *v1 = BM_edge_other_vert(e1, v);
|
|
|
|
|
BMVert *v2 = BM_edge_other_vert(e2, v);
|
|
|
|
|
|
2012-05-03 19:57:24 +00:00
|
|
|
return (float)M_PI - angle_v3v3v3(v1->co, v->co, v2->co);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-02-25 14:56:37 +00:00
|
|
|
return DEG2RADF(90.0f);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 19:03:15 +00:00
|
|
|
/**
|
|
|
|
|
* \note this isn't optimal to run on an array of verts,
|
|
|
|
|
* see 'solidify_add_thickness' for a function which runs on an array.
|
|
|
|
|
*/
|
2012-04-23 01:19:50 +00:00
|
|
|
float BM_vert_calc_shell_factor(BMVert *v)
|
2012-04-19 19:03:15 +00:00
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMLoop *l;
|
|
|
|
|
float accum_shell = 0.0f;
|
|
|
|
|
float accum_angle = 0.0f;
|
|
|
|
|
|
|
|
|
|
BM_ITER_ELEM (l, &iter, v, BM_LOOPS_OF_VERT) {
|
2012-04-23 01:19:50 +00:00
|
|
|
const float face_angle = BM_loop_calc_face_angle(l);
|
2012-04-19 19:03:15 +00:00
|
|
|
accum_shell += shell_angle_to_dist(angle_normalized_v3v3(v->no, l->f->no)) * face_angle;
|
|
|
|
|
accum_angle += face_angle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return accum_shell / accum_angle;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-29 10:44:00 +00:00
|
|
|
/**
|
|
|
|
|
* \note quite an obscure function.
|
|
|
|
|
* used in bmesh operators that have a relative scale options,
|
|
|
|
|
*/
|
|
|
|
|
float BM_vert_calc_mean_tagged_edge_length(BMVert *v)
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
int tot;
|
|
|
|
|
float length = 0.0f;
|
|
|
|
|
|
|
|
|
|
BM_ITER_ELEM_INDEX (e, &iter, v, BM_EDGES_OF_VERT, tot) {
|
|
|
|
|
BMVert *v_other = BM_edge_other_vert(e, v);
|
|
|
|
|
if (BM_elem_flag_test(v_other, BM_ELEM_TAG)) {
|
|
|
|
|
length += BM_edge_calc_length(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return length / (float)tot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-02-28 07:42:48 +00:00
|
|
|
/**
|
2012-02-28 18:28:30 +00:00
|
|
|
* Returns the edge existing between v1 and v2, or NULL if there isn't one.
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-28 18:28:30 +00:00
|
|
|
* \note multiple edges may exist between any two vertices, and therefore
|
|
|
|
|
* this function only returns the first one found.
|
|
|
|
|
*/
|
|
|
|
|
BMEdge *BM_edge_exists(BMVert *v1, BMVert *v2)
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (e, &iter, v1, BM_EDGES_OF_VERT) {
|
2012-02-28 18:28:30 +00:00
|
|
|
if (e->v1 == v2 || e->v2 == v2)
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-29 06:55:10 +00:00
|
|
|
* Given a set of vertices \a varr, find out if
|
2012-02-19 18:31:04 +00:00
|
|
|
* all those vertices overlap an existing face.
|
|
|
|
|
*
|
2012-02-28 08:17:53 +00:00
|
|
|
* \note Making a face here is valid but in some cases you wont want to
|
|
|
|
|
* make a face thats part of another.
|
|
|
|
|
*
|
2012-02-28 07:42:48 +00:00
|
|
|
* \returns TRUE for overlap
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2012-02-28 08:17:53 +00:00
|
|
|
int BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_overlapface)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2012-02-28 08:17:53 +00:00
|
|
|
BMIter viter;
|
2012-02-19 18:31:04 +00:00
|
|
|
BMFace *f;
|
|
|
|
|
int i, amount;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (f, &viter, varr[i], BM_FACES_OF_VERT) {
|
2012-02-19 18:31:04 +00:00
|
|
|
amount = BM_verts_in_face(bm, f, varr, len);
|
2012-02-28 08:17:53 +00:00
|
|
|
if (amount >= len) {
|
|
|
|
|
if (r_overlapface) {
|
|
|
|
|
*r_overlapface = f;
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-28 07:19:28 +00:00
|
|
|
|
|
|
|
|
if (r_overlapface) {
|
|
|
|
|
*r_overlapface = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-28 08:17:53 +00:00
|
|
|
* Given a set of vertices (varr), find out if
|
|
|
|
|
* there is a face with exactly those vertices
|
|
|
|
|
* (and only those vertices).
|
|
|
|
|
*/
|
|
|
|
|
int BM_face_exists(BMesh *bm, BMVert **varr, int len, BMFace **r_existface)
|
|
|
|
|
{
|
|
|
|
|
BMIter viter;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
int i, amount;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (f, &viter, varr[i], BM_FACES_OF_VERT) {
|
2012-02-28 08:17:53 +00:00
|
|
|
amount = BM_verts_in_face(bm, f, varr, len);
|
|
|
|
|
if (amount == len && amount == f->len) {
|
|
|
|
|
if (r_existface) {
|
|
|
|
|
*r_existface = f;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (r_existface) {
|
|
|
|
|
*r_existface = NULL;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-29 06:55:10 +00:00
|
|
|
* Given a set of vertices and edges (\a varr, \a earr), find out if
|
2012-02-26 21:32:20 +00:00
|
|
|
* all those vertices are filled in by existing faces that _only_ use those vertices.
|
|
|
|
|
*
|
|
|
|
|
* This is for use in cases where creating a face is possible but would result in
|
|
|
|
|
* many overlapping faces.
|
|
|
|
|
*
|
|
|
|
|
* An example of how this is used: when 2 tri's are selected that share an edge,
|
|
|
|
|
* pressing Fkey would make a new overlapping quad (without a check like this)
|
|
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* \a earr and \a varr can be in any order, however they _must_ form a closed loop.
|
2012-02-26 21:32:20 +00:00
|
|
|
*/
|
2012-04-19 14:38:09 +00:00
|
|
|
int BM_face_exists_multi(BMVert **varr, BMEdge **earr, int len)
|
2012-02-26 21:32:20 +00:00
|
|
|
{
|
|
|
|
|
BMFace *f;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
BMVert *v;
|
|
|
|
|
int ok;
|
|
|
|
|
int tot_tag;
|
|
|
|
|
|
|
|
|
|
BMIter fiter;
|
|
|
|
|
BMIter viter;
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
/* save some time by looping over edge faces rather then vert faces
|
|
|
|
|
* will still loop over some faces twice but not as many */
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (f, &fiter, earr[i], BM_FACES_OF_EDGE) {
|
2012-02-26 21:32:20 +00:00
|
|
|
BM_elem_flag_disable(f, BM_ELEM_INTERNAL_TAG);
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (v, &viter, f, BM_VERTS_OF_FACE) {
|
2012-02-26 21:32:20 +00:00
|
|
|
BM_elem_flag_disable(v, BM_ELEM_INTERNAL_TAG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* clear all edge tags */
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (e, &fiter, varr[i], BM_EDGES_OF_VERT) {
|
2012-02-26 21:32:20 +00:00
|
|
|
BM_elem_flag_disable(e, BM_ELEM_INTERNAL_TAG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* now tag all verts and edges in the boundary array as true so
|
2012-02-26 21:32:20 +00:00
|
|
|
* we can know if a face-vert is from our array */
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
BM_elem_flag_enable(varr[i], BM_ELEM_INTERNAL_TAG);
|
|
|
|
|
BM_elem_flag_enable(earr[i], BM_ELEM_INTERNAL_TAG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* so! boundary is tagged, everything else cleared */
|
2012-02-26 21:32:20 +00:00
|
|
|
|
|
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* 1) tag all faces connected to edges - if all their verts are boundary */
|
2012-02-26 21:32:20 +00:00
|
|
|
tot_tag = 0;
|
|
|
|
|
for (i = 0; i < len; i++) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (f, &fiter, earr[i], BM_FACES_OF_EDGE) {
|
2012-02-26 21:32:20 +00:00
|
|
|
if (!BM_elem_flag_test(f, BM_ELEM_INTERNAL_TAG)) {
|
|
|
|
|
ok = TRUE;
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (v, &viter, f, BM_VERTS_OF_FACE) {
|
2012-02-26 21:32:20 +00:00
|
|
|
if (!BM_elem_flag_test(v, BM_ELEM_INTERNAL_TAG)) {
|
|
|
|
|
ok = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok) {
|
2012-03-18 07:38:51 +00:00
|
|
|
/* we only use boundary verts */
|
2012-02-26 21:32:20 +00:00
|
|
|
BM_elem_flag_enable(f, BM_ELEM_INTERNAL_TAG);
|
|
|
|
|
tot_tag++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* we already found! */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tot_tag == 0) {
|
2012-03-18 07:38:51 +00:00
|
|
|
/* no faces use only boundary verts, quit early */
|
2012-02-26 21:32:20 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* 2) loop over non-boundary edges that use boundary verts,
|
2012-02-26 21:32:20 +00:00
|
|
|
* check each have 2 tagges faces connected (faces that only use 'varr' verts) */
|
|
|
|
|
ok = TRUE;
|
|
|
|
|
for (i = 0; i < len; i++) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (e, &fiter, varr[i], BM_EDGES_OF_VERT) {
|
2012-02-26 21:32:20 +00:00
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
if (/* non-boundary edge */
|
2012-02-26 21:32:20 +00:00
|
|
|
BM_elem_flag_test(e, BM_ELEM_INTERNAL_TAG) == FALSE &&
|
2012-03-18 07:38:51 +00:00
|
|
|
/* ...using boundary verts */
|
2012-02-26 21:32:20 +00:00
|
|
|
BM_elem_flag_test(e->v1, BM_ELEM_INTERNAL_TAG) == TRUE &&
|
|
|
|
|
BM_elem_flag_test(e->v2, BM_ELEM_INTERNAL_TAG) == TRUE)
|
|
|
|
|
{
|
|
|
|
|
int tot_face_tag = 0;
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (f, &fiter, e, BM_FACES_OF_EDGE) {
|
2012-02-26 21:32:20 +00:00
|
|
|
if (BM_elem_flag_test(f, BM_ELEM_INTERNAL_TAG)) {
|
|
|
|
|
tot_face_tag++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tot_face_tag != 2) {
|
|
|
|
|
ok = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok == FALSE) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* same as 'BM_face_exists_multi' but built vert array from edges */
|
2012-04-19 14:38:09 +00:00
|
|
|
int BM_face_exists_multi_edge(BMEdge **earr, int len)
|
2012-02-26 21:32:20 +00:00
|
|
|
{
|
|
|
|
|
BMVert **varr;
|
|
|
|
|
BLI_array_fixedstack_declare(varr, BM_NGON_STACK_SIZE, len, __func__);
|
|
|
|
|
|
|
|
|
|
int ok;
|
|
|
|
|
int i, i_next;
|
|
|
|
|
|
|
|
|
|
/* first check if verts have edges, if not we can bail out early */
|
|
|
|
|
ok = TRUE;
|
2012-02-26 22:38:49 +00:00
|
|
|
for (i = len - 1, i_next = 0; i_next < len; (i = i_next++)) {
|
2012-02-26 21:32:20 +00:00
|
|
|
if (!(varr[i] = BM_edge_share_vert(earr[i], earr[i_next]))) {
|
|
|
|
|
ok = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok == FALSE) {
|
|
|
|
|
BMESH_ASSERT(0);
|
|
|
|
|
BLI_array_fixedstack_free(varr);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:38:09 +00:00
|
|
|
ok = BM_face_exists_multi(varr, earr, len);
|
2012-02-26 21:32:20 +00:00
|
|
|
|
|
|
|
|
BLI_array_fixedstack_free(varr);
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|