2009-03-04 09:38:26 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "bmesh.h"
|
|
|
|
|
#include "mesh_intern.h"
|
|
|
|
|
#include "bmesh_private.h"
|
|
|
|
|
#include "BLI_arithb.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-03-14 13:16:35 +00:00
|
|
|
#include <string.h>
|
2009-03-04 09:38:26 +00:00
|
|
|
|
|
|
|
|
#define VERT_INPUT 1
|
|
|
|
|
#define EDGE_OUT 1
|
2009-03-14 13:16:35 +00:00
|
|
|
#define FACE_NEW 2
|
2009-03-04 09:38:26 +00:00
|
|
|
|
|
|
|
|
void connectverts_exec(BMesh *bm, BMOperator *op)
|
|
|
|
|
{
|
|
|
|
|
BMIter iter, liter;
|
|
|
|
|
BMFace *f, *nf;
|
2009-03-14 13:16:35 +00:00
|
|
|
BMLoop **loops = NULL, *lastl = NULL;
|
|
|
|
|
V_DECLARE(loops);
|
2009-03-13 13:11:50 +00:00
|
|
|
BMLoop *l, *nl;
|
2009-03-14 13:16:35 +00:00
|
|
|
BMVert *v1, *v2, **verts = NULL;
|
|
|
|
|
V_DECLARE(verts);
|
|
|
|
|
int i;
|
2009-03-04 09:38:26 +00:00
|
|
|
|
Brought Extrude all the way back. The contextual menu works,
as does only edges and individual faces extrude (individual vert
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator. I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well. To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
2009-08-11 07:49:35 +00:00
|
|
|
BMO_Flag_Buffer(bm, op, "verts", VERT_INPUT, BM_VERT);
|
2009-03-04 09:38:26 +00:00
|
|
|
|
2009-03-22 23:16:43 +00:00
|
|
|
for (f=BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL); f; f=BMIter_Step(&iter)){
|
2009-03-14 13:16:35 +00:00
|
|
|
V_RESET(loops);
|
|
|
|
|
V_RESET(verts);
|
|
|
|
|
|
|
|
|
|
if (BMO_TestFlag(bm, f, FACE_NEW)) continue;
|
|
|
|
|
|
2009-03-04 09:38:26 +00:00
|
|
|
l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f);
|
|
|
|
|
v1 = v2 = NULL;
|
2009-03-14 13:16:35 +00:00
|
|
|
lastl = NULL;
|
2009-03-04 09:38:26 +00:00
|
|
|
for (; l; l=BMIter_Step(&liter)) {
|
|
|
|
|
if (BMO_TestFlag(bm, l->v, VERT_INPUT)) {
|
2009-03-14 13:16:35 +00:00
|
|
|
if (!lastl) {
|
|
|
|
|
lastl = l;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lastl != l->head.prev && lastl !=
|
|
|
|
|
l->head.next)
|
|
|
|
|
{
|
|
|
|
|
V_GROW(loops);
|
|
|
|
|
loops[V_COUNT(loops)-1] = lastl;
|
|
|
|
|
|
|
|
|
|
V_GROW(loops);
|
|
|
|
|
loops[V_COUNT(loops)-1] = l;
|
|
|
|
|
|
|
|
|
|
}
|
2009-03-15 06:14:03 +00:00
|
|
|
lastl = l;
|
2009-03-04 09:38:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-14 13:16:35 +00:00
|
|
|
if (V_COUNT(loops) == 0) continue;
|
|
|
|
|
|
|
|
|
|
if (V_COUNT(loops) > 2) {
|
|
|
|
|
V_GROW(loops);
|
|
|
|
|
loops[V_COUNT(loops)-1] = loops[V_COUNT(loops)-2];
|
|
|
|
|
|
|
|
|
|
V_GROW(loops);
|
|
|
|
|
loops[V_COUNT(loops)-1] = loops[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BM_LegalSplits(bm, f, loops, V_COUNT(loops)/2);
|
|
|
|
|
|
|
|
|
|
for (i=0; i<V_COUNT(loops)/2; i++) {
|
|
|
|
|
if (loops[i*2]==NULL) continue;
|
2009-03-13 13:11:50 +00:00
|
|
|
|
2009-03-14 13:16:35 +00:00
|
|
|
V_GROW(verts);
|
|
|
|
|
verts[V_COUNT(verts)-1] = loops[i*2]->v;
|
|
|
|
|
|
|
|
|
|
V_GROW(verts);
|
|
|
|
|
verts[V_COUNT(verts)-1] = loops[i*2+1]->v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0; i<V_COUNT(verts)/2; i++) {
|
|
|
|
|
nf = BM_Split_Face(bm, f, verts[i*2],
|
|
|
|
|
verts[i*2+1], &nl, NULL);
|
|
|
|
|
f = nf;
|
2009-03-13 13:11:50 +00:00
|
|
|
|
|
|
|
|
if (!nl || !nf) {
|
2009-03-04 09:38:26 +00:00
|
|
|
BMO_RaiseError(bm, op,
|
|
|
|
|
BMERR_CONNECTVERT_FAILED, NULL);
|
2009-03-14 13:16:35 +00:00
|
|
|
V_FREE(loops);
|
|
|
|
|
return;;;
|
2009-03-04 09:38:26 +00:00
|
|
|
}
|
2009-03-14 13:16:35 +00:00
|
|
|
BMO_SetFlag(bm, nf, FACE_NEW);
|
2009-03-13 13:11:50 +00:00
|
|
|
BMO_SetFlag(bm, nl->e, EDGE_OUT);
|
2009-03-04 09:38:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-22 23:16:43 +00:00
|
|
|
BMO_Flag_To_Slot(bm, op, "edgeout", EDGE_OUT, BM_EDGE);
|
2009-03-14 13:16:35 +00:00
|
|
|
|
|
|
|
|
V_FREE(loops);
|
|
|
|
|
V_FREE(verts);
|
2009-03-04 09:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int BM_ConnectVerts(EditMesh *em, int flag)
|
|
|
|
|
{
|
|
|
|
|
EditMesh *em2;
|
|
|
|
|
BMesh *bm = editmesh_to_bmesh(em);
|
|
|
|
|
BMOperator op;
|
|
|
|
|
|
2009-03-22 23:16:43 +00:00
|
|
|
BMO_Init_Op(&op, "connectverts");
|
|
|
|
|
BMO_HeaderFlag_To_Slot(bm, &op, "verts", flag, BM_VERT);
|
2009-03-04 09:38:26 +00:00
|
|
|
BMO_Exec_Op(bm, &op);
|
|
|
|
|
BMO_Finish_Op(bm, &op);
|
|
|
|
|
|
2009-03-22 23:16:43 +00:00
|
|
|
if (BMO_GetSlot(&op, "edgeout")->len > 0 &&
|
2009-03-04 09:38:26 +00:00
|
|
|
BMO_GetError(bm, NULL, NULL)==0)
|
|
|
|
|
{
|
|
|
|
|
em2 = bmesh_to_editmesh(bm);
|
|
|
|
|
set_editMesh(em, em2);
|
|
|
|
|
MEM_freeN(em2);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|