=bmesh= brought back fill faces, alt-f

This commit is contained in:
Joseph Eagar
2011-04-23 00:05:13 +00:00
parent 133a1c2699
commit c2b670030d
5 changed files with 105 additions and 15 deletions

View File

@@ -869,7 +869,7 @@ int BLI_edgefill(int mat_nr)
if( compare_v3v3(v2, eve->co, COMPLIMIT)==0) {
float inner = angle_v3v3v3(v1, v2, eve->co);
if (fabs(inner-M_PI) < 0.05 || fabs(inner) < 0.05) {
if (fabs(inner-M_PI) < FLT_EPSILON*200 || fabs(inner) < FLT_EPSILON*200) {
eve = eve->next;
continue;
}

View File

@@ -946,7 +946,7 @@ BMOpDefine def_bevel = {
Makes triangle a bit nicer
*/
BMOpDefine def_beautify_fill = {
"beautify_fill",
"beautify_fill",
{{BMOP_OPSLOT_ELEMENT_BUF, "faces"}, /* input faces */
{BMOP_OPSLOT_ELEMENT_BUF, "constrain_edges"}, /* edges that can't be flipped */
{BMOP_OPSLOT_ELEMENT_BUF, "geomout"}, /* new flipped faces and edges */
@@ -955,6 +955,20 @@ BMOpDefine def_beautify_fill = {
BMOP_UNTAN_MULTIRES
};
/*
Triangle Fill
Fill edges with triangles
*/
BMOpDefine def_triangle_fill = {
"triangle_fill",
{{BMOP_OPSLOT_ELEMENT_BUF, "edges"}, /* input edges */
{BMOP_OPSLOT_ELEMENT_BUF, "geomout"}, /* new faces and edges */
{0} /*null-terminating sentinel*/},
bmesh_triangle_fill_exec,
BMOP_UNTAN_MULTIRES
};
BMOpDefine *opdefines[] = {
&def_splitop,
&def_dupeop,
@@ -1016,6 +1030,7 @@ BMOpDefine *opdefines[] = {
&def_join_triangles,
&def_bevel,
&def_beautify_fill,
&def_triangle_fill,
};
int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));

View File

@@ -70,5 +70,6 @@ void bmesh_create_cube_exec(BMesh *bm, BMOperator *op);
void bmesh_jointriangles_exec(BMesh *bm, BMOperator *op);
void bmesh_bevel_exec(BMesh *bm, BMOperator *op);
void bmesh_beautify_fill_exec(BMesh *bm, BMOperator *op);
void bmesh_triangle_fill_exec(BMesh *bm, BMOperator *op);
#endif

View File

@@ -1,15 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BKE_utildefines.h"
#include "bmesh.h"
#include "bmesh_private.h"
#include "BLI_scanfill.h"
#include "BLI_math.h"
#include "BLI_array.h"
#include "BLI_editVert.h"
#include "BLI_smallhash.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bmesh.h"
#include "bmesh_private.h"
#define EDGE_NEW 1
#define FACE_NEW 1
@@ -128,3 +132,65 @@ void bmesh_beautify_fill_exec(BMesh *bm, BMOperator *op)
BMO_Flag_To_Slot(bm, op, "geomout", ELE_NEW, BM_EDGE|BM_FACE);
}
void bmesh_triangle_fill_exec(BMesh *bm, BMOperator *op)
{
BMOIter siter;
BMEdge *e;
BMOperator bmop;
EditEdge *eed;
EditVert *eve, *v1, *v2;
EditFace *efa;
SmallHash hash;
BLI_smallhash_init(&hash);
BLI_begin_edgefill();
BMO_ITER(e, &siter, bm, op, "edges", BM_EDGE) {
BMO_SetFlag(bm, e, EDGE_MARK);
if (!BLI_smallhash_haskey(&hash, (uintptr_t)e->v1)) {
eve = BLI_addfillvert(e->v1->co);
eve->tmp.p = e->v1;
BLI_smallhash_insert(&hash, (uintptr_t)e->v1, eve);
}
if (!BLI_smallhash_haskey(&hash, (uintptr_t)e->v2)) {
eve = BLI_addfillvert(e->v2->co);
eve->tmp.p = e->v2;
BLI_smallhash_insert(&hash, (uintptr_t)e->v2, eve);
}
v1 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v1);
v2 = BLI_smallhash_lookup(&hash, (uintptr_t)e->v2);
eed = BLI_addfilledge(v1, v2);
eed->tmp.p = e;
}
BLI_edgefill(0);
for (efa=fillfacebase.first; efa; efa=efa->next) {
BMFace *f = BM_Make_QuadTri(bm, efa->v1->tmp.p, efa->v2->tmp.p, efa->v3->tmp.p, NULL, NULL, 1);
BMLoop *l;
BMIter liter;
BMO_SetFlag(bm, f, ELE_NEW);
BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
if (!BMO_TestFlag(bm, l->e, EDGE_MARK)) {
BMO_SetFlag(bm, l->e, ELE_NEW);
}
}
}
BLI_end_edgefill();
BLI_smallhash_release(&hash);
/*clean up fill*/
BMO_InitOpf(bm, &bmop, "beautify_fill faces=%ff constrain_edges=%fe", ELE_NEW, EDGE_MARK);
BMO_Exec_Op(bm, &bmop);
BMO_Flag_Buffer(bm, &bmop, "geomout", ELE_NEW, BM_FACE|BM_EDGE);
BMO_Finish_Op(bm, &bmop);
BMO_Flag_To_Slot(bm, op, "geomout", ELE_NEW, BM_EDGE|BM_FACE);
}

View File

@@ -3855,17 +3855,24 @@ void MESH_OT_separate(wmOperatorType *ot)
static int fill_mesh_exec(bContext *C, wmOperator *op)
{
#if 0
Object *obedit= CTX_data_edit_object(C);
EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
fill_mesh(em);
BKE_mesh_end_editmesh(obedit->data, em);
BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
BMOperator bmop;
if (!EDBM_InitOpf(em, &bmop, op, "triangle_fill edges=%he", BM_SELECT))
return OPERATOR_CANCELLED;
BMO_Exec_Op(em->bm, &bmop);
/*select new geometry*/
BMO_HeaderFlag_Buffer(em->bm, &bmop, "geomout", BM_SELECT, BM_FACE|BM_EDGE);
if (!EDBM_FinishOp(em, &bmop, op, 1))
return OPERATOR_CANCELLED;
DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
#endif
return OPERATOR_FINISHED;
}
@@ -3894,6 +3901,7 @@ static int beautify_fill_exec(bContext *C, wmOperator *op)
DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
return OPERATOR_FINISHED;
}