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.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2012-04-06 09:21:19 +00:00
|
|
|
/** \file blender/bmesh/operators/bmo_connect.c
|
|
|
|
* \ingroup bmesh
|
2013-03-30 08:54:50 +00:00
|
|
|
*
|
|
|
|
* Connect verts across faces (splits faces) and bridge tool.
|
2012-04-06 09:21:19 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_array.h"
|
2012-03-24 01:24:58 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
#include "bmesh.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-04-06 09:21:19 +00:00
|
|
|
#include "intern/bmesh_operators_private.h" /* own include */
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
#define VERT_INPUT 1
|
|
|
|
#define EDGE_OUT 1
|
|
|
|
#define FACE_NEW 2
|
|
|
|
|
2012-06-30 15:27:13 +00:00
|
|
|
void bmo_connect_verts_exec(BMesh *bm, BMOperator *op)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
BMIter iter, liter;
|
2013-03-09 16:19:07 +00:00
|
|
|
BMFace *f, *f_new;
|
2012-09-05 23:17:19 +00:00
|
|
|
BMLoop *(*loops_split)[2] = NULL;
|
|
|
|
BLI_array_declare(loops_split);
|
2013-03-09 16:19:07 +00:00
|
|
|
BMLoop *l, *l_new;
|
2012-09-05 23:17:19 +00:00
|
|
|
BMVert *(*verts_pair)[2] = NULL;
|
|
|
|
BLI_array_declare(verts_pair);
|
2012-02-19 18:31:04 +00:00
|
|
|
int i;
|
|
|
|
|
2012-11-19 14:58:31 +00:00
|
|
|
BMO_slot_buffer_flag_enable(bm, op->slots_in, "verts", BM_VERT, VERT_INPUT);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-11-27 06:53:26 +00:00
|
|
|
/* BMESH_TODO, loop over vert faces:
|
|
|
|
* faster then looping over all faces, then searching each for flagged verts*/
|
2013-03-09 16:19:07 +00:00
|
|
|
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
|
|
|
BMLoop *l_last;
|
2012-09-05 23:17:19 +00:00
|
|
|
BLI_array_empty(loops_split);
|
|
|
|
BLI_array_empty(verts_pair);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-03-01 13:13:08 +00:00
|
|
|
if (BMO_elem_flag_test(bm, f, FACE_NEW)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-03-09 16:19:07 +00:00
|
|
|
l_last = NULL;
|
|
|
|
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
|
2012-02-19 18:31:04 +00:00
|
|
|
if (BMO_elem_flag_test(bm, l->v, VERT_INPUT)) {
|
2013-03-09 16:19:07 +00:00
|
|
|
if (!l_last) {
|
|
|
|
l_last = l;
|
2012-02-19 18:31:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-09 16:19:07 +00:00
|
|
|
if (l_last != l->prev && l_last != l->next) {
|
2012-09-05 23:17:19 +00:00
|
|
|
BLI_array_grow_one(loops_split);
|
2013-03-09 16:19:07 +00:00
|
|
|
loops_split[BLI_array_count(loops_split) - 1][0] = l_last;
|
2012-09-05 23:17:19 +00:00
|
|
|
loops_split[BLI_array_count(loops_split) - 1][1] = l;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
}
|
2013-03-09 16:19:07 +00:00
|
|
|
l_last = l;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 23:17:19 +00:00
|
|
|
if (BLI_array_count(loops_split) == 0) {
|
2012-03-01 13:13:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-09-05 23:17:19 +00:00
|
|
|
if (BLI_array_count(loops_split) > 1) {
|
|
|
|
BLI_array_grow_one(loops_split);
|
|
|
|
loops_split[BLI_array_count(loops_split) - 1][0] = loops_split[BLI_array_count(loops_split) - 2][1];
|
|
|
|
loops_split[BLI_array_count(loops_split) - 1][1] = loops_split[0][0];
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 23:17:19 +00:00
|
|
|
BM_face_legal_splits(bm, f, loops_split, BLI_array_count(loops_split));
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-09-05 23:17:19 +00:00
|
|
|
for (i = 0; i < BLI_array_count(loops_split); i++) {
|
|
|
|
if (loops_split[i][0] == NULL) {
|
2012-03-01 13:13:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-09-05 23:17:19 +00:00
|
|
|
BLI_array_grow_one(verts_pair);
|
|
|
|
verts_pair[BLI_array_count(verts_pair) - 1][0] = loops_split[i][0]->v;
|
|
|
|
verts_pair[BLI_array_count(verts_pair) - 1][1] = loops_split[i][1]->v;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 23:17:19 +00:00
|
|
|
for (i = 0; i < BLI_array_count(verts_pair); i++) {
|
2013-03-09 16:19:07 +00:00
|
|
|
f_new = BM_face_split(bm, f, verts_pair[i][0], verts_pair[i][1], &l_new, NULL, false);
|
|
|
|
f = f_new;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-03-09 16:19:07 +00:00
|
|
|
if (!l_new || !f_new) {
|
2012-02-19 18:31:04 +00:00
|
|
|
BMO_error_raise(bm, op, BMERR_CONNECTVERT_FAILED, NULL);
|
2012-09-05 23:17:19 +00:00
|
|
|
BLI_array_free(loops_split);
|
2012-02-19 18:31:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-03-09 16:19:07 +00:00
|
|
|
BMO_elem_flag_enable(bm, f_new, FACE_NEW);
|
|
|
|
BMO_elem_flag_enable(bm, l_new->e, EDGE_OUT);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 05:50:19 +00:00
|
|
|
BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "edges.out", BM_EDGE, EDGE_OUT);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-09-05 23:17:19 +00:00
|
|
|
BLI_array_free(loops_split);
|
|
|
|
BLI_array_free(verts_pair);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|