[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18602] branches/bmesh/blender/source/ blender: got triangulator to work, and made it a bmesh operator.

Joseph Eagar joeedh at gmail.com
Wed Jan 21 08:03:40 CET 2009


Revision: 18602
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18602
Author:   joeedh
Date:     2009-01-21 08:03:39 +0100 (Wed, 21 Jan 2009)

Log Message:
-----------
got triangulator to work, and made it a bmesh operator.  also added dissolve faces operator, with no implementation (need to discuss with Geoffry how best to do this).  the bmesh test operator, jkey, now maps to the triangulator.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_private.h
    branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c

Added Paths:
-----------
    branches/bmesh/blender/source/blender/bmesh/operators/dissolvefacesop.c
    branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-01-21 07:01:20 UTC (rev 18601)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-01-21 07:03:39 UTC (rev 18602)
@@ -137,8 +137,22 @@
 #define BMOP_ESUBDIVIDE_EDGES	0
 #define BMOP_ESUBDIVIDE_TOTSLOT	1
 
+/*triangulate*/
+#define BMOP_TRIANGULATE		6
+
+#define BMOP_TRIANG_FACEIN		0
+#define BMOP_NEW_EDGES			1
+#define BMOP_NEW_FACES			2
+#define BMOP_TRIANG_TOTSLOT		3
+
+/*dissolve faces*/
+#define BMOP_DISSOLVE_FACES		7
+
+#define BMOP_DISFACES_FACEIN	0
+#define BMOP_DISFACES_TOTSLOT	1
+
 /*keep this updated!*/
-#define BMOP_TOTAL_OPS				6
+#define BMOP_TOTAL_OPS			8
 /*-------------------------------end operator defines-------------------------------*/
 
 extern BMOpDefine *opdefines[];

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-01-21 07:01:20 UTC (rev 18601)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-01-21 07:03:39 UTC (rev 18602)
@@ -3,6 +3,22 @@
 
 #include <stdio.h>
 
+BMOpDefine def_dissolvefacesop = {
+	{BMOP_OPSLOT_PNT_BUF},
+	dissolvefaces_exec,
+	BMOP_DISFACES_TOTSLOT,
+	0
+};
+
+BMOpDefine def_triangop = {
+	{BMOP_OPSLOT_PNT_BUF, 
+	 BMOP_OPSLOT_PNT_BUF,
+	 BMOP_OPSLOT_PNT_BUF},
+	triangulate_exec,
+	BMOP_TRIANG_TOTSLOT,
+	0
+};
+
 BMOpDefine def_subdop = {
 	{BMOP_OPSLOT_PNT_BUF},
 	esubdivide_exec,
@@ -52,6 +68,8 @@
 	&def_edit2bmesh,
 	&def_bmesh2edit,
 	&def_subdop,
+	&def_triangop,
+	&def_dissolvefacesop,
 };
 
 int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-01-21 07:01:20 UTC (rev 18601)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-01-21 07:03:39 UTC (rev 18602)
@@ -318,9 +318,9 @@
 
 /*
  *
- * BMO_FLAG_TO_SLOT
+ * BMO_HEADERFLAG_TO_SLOT
  *
- * Copies elements of a certain type, which have a certain flag set 
+ * Copies elements of a certain type, which have a certain header flag set 
  * into an output slot for an operator.
  *
 */
@@ -366,6 +366,14 @@
 	}
 }
 
+/*
+ *
+ * BMO_FLAG_TO_SLOT
+ *
+ * Copies elements of a certain type, which have a certain flag set 
+ * into an output slot for an operator.
+ *
+*/
 void BMO_Flag_To_Slot(BMesh *bm, BMOperator *op, int slotcode, int flag, int type)
 {
 	BMIter elements;

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2009-01-21 07:01:20 UTC (rev 18601)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2009-01-21 07:03:39 UTC (rev 18602)
@@ -13,5 +13,7 @@
 void esubdivide_exec(BMesh *bmesh, BMOperator *op);
 void edit2bmesh_exec(BMesh *bmesh, BMOperator *op);
 void bmesh2edit_exec(BMesh *bmesh, BMOperator *op);
+void triangulate_exec(BMesh *bmesh, BMOperator *op);
+void dissolvefaces_exec(BMesh *bmesh, BMOperator *op);
 
 #endif

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c	2009-01-21 07:01:20 UTC (rev 18601)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c	2009-01-21 07:03:39 UTC (rev 18602)
@@ -364,10 +364,10 @@
  * -Modify this to try and find ears that will not create a non-manifold face after conversion back to editmesh
  *
 */
-void BM_Triangulate_Face(BMesh *bm, BMFace *f, float (*projectverts)[3])
+void BM_Triangulate_Face(BMesh *bm, BMFace *f, float (*projectverts)[3], int newedgeflag, int newfaceflag)
 {
 	int i, done;
-	BMLoop *l, *nextloop;
+	BMLoop *l, *newl, *nextloop;
 
 	/*copy vertex coordinates to vertspace array*/
 	i = 0;
@@ -386,9 +386,11 @@
 	while(!done){
 		done = 1;
 		l = find_ear(f, projectverts);
-		if(l){
+		if(l && l->head.prev != l->head.next && f->len > 3){
 			done = 0;
-			f = bmesh_sfme(bm, f, ((BMLoop*)(l->head.prev))->v, ((BMLoop*)(l->head.next))->v, 0);
+			f = bmesh_sfme(bm, f, ((BMLoop*)(l->head.prev))->v, ((BMLoop*)(l->head.next))->v, &newl);
+			BMO_SetFlag(bm, newl->e, newedgeflag);
+			BMO_SetFlag(bm, f, newfaceflag);
 		}
 	}
 
@@ -396,7 +398,9 @@
 		l = f->loopbase;
 		while (l->f->len > 3){
 			nextloop = ((BMLoop*)(l->head.next->next->next));
-			bmesh_sfme(bm, l->f, l->v,nextloop->v, 0);
+			bmesh_sfme(bm, l->f, l->v,nextloop->v, &newl);
+			BMO_SetFlag(bm, newl->e, newedgeflag);
+			BMO_SetFlag(bm, f, newfaceflag);
 			l = nextloop;
 		}
 	}

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_private.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_private.h	2009-01-21 07:01:20 UTC (rev 18601)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_private.h	2009-01-21 07:03:39 UTC (rev 18602)
@@ -59,7 +59,8 @@
 int bmesh_test_sysflag(struct BMHeader *element, int flag);
 
 /*Polygon Utilities ? FIXME... where do these each go?*/
-void bmesh_triangulate_face(struct BMesh *bm, struct BMFace *f, float (*projectverts)[3]);
+/*newedgeflag sets a flag layer flag, obviously not the header flag.*/
+void BM_Triangulate_Face(BMesh *bm, BMFace *f, float (*projectverts)[3], int newedgeflag, int newfaceflag);
 void bmesh_update_face_normal(struct BMesh *bm, struct BMFace *f, float (*projectverts)[3]);
 void compute_poly_plane(float (*verts)[3], int nverts);
 void poly_rotate_plane(float normal[3], float (*verts)[3], int nverts);

Added: branches/bmesh/blender/source/blender/bmesh/operators/dissolvefacesop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/dissolvefacesop.c	                        (rev 0)
+++ branches/bmesh/blender/source/blender/bmesh/operators/dissolvefacesop.c	2009-01-21 07:03:39 UTC (rev 18602)
@@ -0,0 +1,26 @@
+#include "MEM_guardedalloc.h"
+
+#include "BKE_utildefines.h"
+
+#include "bmesh.h"
+#include "bmesh_private.h"
+#include "BLI_arithb.h"
+
+#include <stdio.h>
+
+#define FACE_MARK	1
+void dissolvefaces_exec(BMesh *bmesh, BMOperator *op)
+{
+	BMOpSlot *finput;
+	BMFace *face;
+	float projectverts[400][3];
+	void *projverts;
+	int i, count = 0;
+	
+	BMO_Flag_Buffer(bmesh, op, BMOP_DISFACES_FACEIN, FACE_MARK);
+
+	/*TODO: need to discuss with Briggs how best to implement this, seems this would be
+	  a great time to use the walker api, get it up to snuff.  perhaps have a walker
+	  that goes over inner vertices of a contiguously-flagged region?  then you
+	  could just use dissolve disk on them.*/
+}
\ No newline at end of file

Added: branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c	                        (rev 0)
+++ branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c	2009-01-21 07:03:39 UTC (rev 18602)
@@ -0,0 +1,38 @@
+#include "MEM_guardedalloc.h"
+
+#include "BKE_utildefines.h"
+
+#include "bmesh.h"
+#include "bmesh_private.h"
+#include "BLI_arithb.h"
+
+#include <stdio.h>
+
+#define EDGE_NEW	1
+#define FACE_NEW	1
+void triangulate_exec(BMesh *bmesh, BMOperator *op)
+{
+	BMOpSlot *finput;
+	BMFace *face;
+	float projectverts[400][3];
+	void *projverts;
+	int i, count = 0;
+	
+	finput = BMO_GetSlot(op, BMOP_ESUBDIVIDE_EDGES);
+
+	for (i=0; i<finput->len; i++) {
+		face = ((BMFace**)finput->data.p)[i];
+
+		/*HACK! need to discuss with Briggs why the function takes an 
+		  externally-allocated array of vert coordinates in the first place.*/
+		if (face->len > 400) projverts = MEM_callocN(sizeof(float)*3*face->len, "projverts");
+		else projverts = projectverts;
+		
+		BM_Triangulate_Face(bmesh, face, projectverts, EDGE_NEW, FACE_NEW);
+		
+		if (projverts != projectverts) MEM_freeN(projverts);
+	}
+	
+	BMO_Flag_To_Slot(bmesh, op, BMOP_NEW_EDGES, EDGE_NEW, BM_EDGE);
+	BMO_Flag_To_Slot(bmesh, op, BMOP_NEW_FACES, FACE_NEW, BM_FACE);
+}
\ No newline at end of file

Modified: branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c	2009-01-21 07:01:20 UTC (rev 18601)
+++ branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c	2009-01-21 07:03:39 UTC (rev 18602)
@@ -3334,8 +3334,8 @@
 	{
 			BMOperator op;
 
-			BMO_Init_Op(&op, BMOP_ESUBDIVIDE);
-			BMO_HeaderFlag_To_Slot(bm, &op, BMOP_ESUBDIVIDE_EDGES, BM_SELECT, BM_EDGE);
+			BMO_Init_Op(&op, BMOP_TRIANGULATE);
+			BMO_HeaderFlag_To_Slot(bm, &op, BMOP_TRIANG_FACEIN, BM_SELECT, BM_FACE);
 
 			BMO_Exec_Op(bm, &op);
 			BMO_Finish_Op(bm, &op);





More information about the Bf-blender-cvs mailing list