[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18305] branches/bmesh/bmesh: The conversions functions are now operator-afied.

Joseph Eagar joeedh at gmail.com
Sun Jan 4 03:25:11 CET 2009


Revision: 18305
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18305
Author:   joeedh
Date:     2009-01-04 03:25:10 +0100 (Sun, 04 Jan 2009)

Log Message:
-----------
The conversions functions are now operator-afied.

Also tried to make the flags play nice with each other
again, since that was messing things up.  I'm a
little confused on the design; I thought that flags
from the Edit****->f variables would go in
header->flag, along with the flags that live in
other variables.

I made the two temp flags (flag layer flag, not
header->flag) be at the 15th and 16th bit, since
otherwise they could probably interfere with
operator flags.  I also reverted the change of
header->flag to a short, and the changes of the
bmesh-specific flags.

Modified Paths:
--------------
    branches/bmesh/bmesh/bmesh.h
    branches/bmesh/bmesh/bmesh_operators.h
    branches/bmesh/bmesh/editmesh_tools.c
    branches/bmesh/bmesh/intern/bmesh_opdefines.c
    branches/bmesh/bmesh/intern/bmesh_operators_private.h
    branches/bmesh/bmesh/intern/bmesh_structure.c
    branches/bmesh/bmesh/intern/bmesh_to_editmesh.c
    branches/bmesh/bmesh/intern/editmesh_to_bmesh.c
    branches/bmesh/bmesh/operators/subdivideop.c

Modified: branches/bmesh/bmesh/bmesh.h
===================================================================
--- branches/bmesh/bmesh/bmesh.h	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/bmesh.h	2009-01-04 02:25:10 UTC (rev 18305)
@@ -62,38 +62,37 @@
 */
 
 /*BMHeader->type*/
-#define BM_VERT 					1
-#define BM_EDGE 					2
-#define BM_FACE 					4
-#define BM_LOOP 					8
-#define BM_ALL					BM_VERT | BM_EDGE | BM_FACE | BM_LOOP
+#define BM_VERT 	1
+#define BM_EDGE 	2
+#define BM_FACE 	4
+#define BM_LOOP 	8
+#define BM_ALL		BM_VERT | BM_EDGE | BM_FACE | BM_LOOP
 
 /*BMHeader->flag*/
 #define BM_SELECT	(1<<0)
-#define BM_SEAM		(1<<1)
-#define BM_FGON		(1<<2)
-#define BM_HIDDEN	(1<<3)
-#define BM_SHARP	(1<<4)
-#define BM_SMOOTH	(1<<5)
 
-typedef struct BMHeader
-{
+#define BM_SEAM		(1<<16)
+#define BM_FGON		(1<<17)
+#define BM_HIDDEN	(1<<18)
+#define BM_SHARP	(1<<19)
+#define BM_SMOOTH	(1<<20)
+
+typedef struct BMHeader {
 	struct BMHeader *next, *prev;
 	int 		EID;								/*Consider removing this/making it ifdeffed for debugging*/
-	short 		flag, type;								
+	int 		flag, type;
 	int			eflag1, eflag2;						/*Flags used by eulers. Try and get rid of/minimize some of these*/
 	struct BMFlagLayer *flags;						/*Dynamically allocated block of flag layers for operators to use*/
 } BMHeader;
 
-typedef struct BMFlagLayer{
+typedef struct BMFlagLayer {
 	int f1;
 	short mask, pflag;
-}BMFlagLayer;
+} BMFlagLayer;
 
-#define BM_OVERLAP		(1<<0)			/*used by bmesh_verts_in_face*/
-#define BM_EDGEVERT 	(1<<1) 			/*used by bmesh_make_ngon*/
+#define BM_OVERLAP		(1<<14)			/*used by bmesh_verts_in_face*/
+#define BM_EDGEVERT 	(1<<15) 		/*used by bmesh_make_ngon*/
 
-
 /*
  * BMNode
  *
@@ -103,14 +102,13 @@
  *
 */
 
-typedef struct BMNode{
+typedef struct BMNode {
 	struct BMNode *next, *prev;
 	void *data;
-}BMNode;
+} BMNode;
 
 
-typedef struct BMesh
-{
+typedef struct BMesh {
 	ListBase verts, edges, polys;
 	struct BLI_mempool *vpool;
 	struct BLI_mempool *epool;
@@ -128,10 +126,9 @@
 	struct BLI_mempool *flagpool;					/*memory pool for dynamically allocated flag layers*/
 	int stackdepth;									/*current depth of operator stack*/
 	int totflags, walkers;							/*total number of tool flag layers*/
-}BMesh;
+} BMesh;
 
-typedef struct BMVert
-{	
+typedef struct BMVert {	
 	struct BMHeader head;
 	float co[3];									
 	float no[3];									
@@ -141,35 +138,32 @@
 	float bweight;												/*please, someone just get rid of me...*/
 } BMVert;
 
-typedef struct BMEdge
-{
+typedef struct BMEdge {
 	struct BMHeader head;
 	struct BMVert *v1, *v2;
 	struct BMNode d1, d2;
 	struct BMLoop *loop;
 	void *data;
 	float crease, bweight;										/*make these custom data.... no really, please....*/
-}BMEdge;
+} BMEdge;
 
-typedef struct BMLoop 
-{	
+typedef struct BMLoop  {
 	struct BMHeader head;
 	struct BMNode radial;
 	struct BMVert *v;
 	struct BMEdge *e;
 	struct BMFace *f;	
 	void *data;
-}BMLoop;
+} BMLoop;
 
-typedef struct BMFace
-{
+typedef struct BMFace {
 	struct BMHeader head;
 	struct BMLoop *loopbase;
 	unsigned int len;
 	void *data;
 	float no[3];
 	unsigned short mat_nr;									/*custom data again, and get rid of the unsigned short nonsense...*/
-}BMFace;
+} BMFace;
 
 /*stub */
 void bmesh_error(void);

Modified: branches/bmesh/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/bmesh/bmesh_operators.h	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/bmesh_operators.h	2009-01-04 02:25:10 UTC (rev 18305)
@@ -110,13 +110,17 @@
 
 /*editmesh->bmesh op*/
 #define BMOP_FROM_EDITMESH		3
-#define BMOP_FROM_EDITMESH_EM	0
-#define BMOP_FROM_EDITMESH_TOTSLOT 1
+enum {
+	BMOP_FROM_EDITMESH_EM,
+	BMOP_FROM_EDITMESH_TOTSLOT,
+};
 
+#define BMOP_TO_EDITMESH		4
 /*bmesh->editmesh op*/
-#define BMOP_TO_EDITMESH		4
-#define BMOP_TO_EDITMESH_EM		0
-#define BMOP_TO_EDITMESH_TOTSLOT 1
+enum {
+	BMOP_TO_EDITMESH_EMOUT,
+	BMOP_TO_EDITMESH_TOTSLOT,
+};
 
 /*edge subdivide op*/
 #define BMOP_ESUBDIVIDE			5

Modified: branches/bmesh/bmesh/editmesh_tools.c
===================================================================
--- branches/bmesh/bmesh/editmesh_tools.c	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/editmesh_tools.c	2009-01-04 02:25:10 UTC (rev 18305)
@@ -2423,13 +2423,16 @@
 
 void esubdivideflag(int flag, float rad, int beauty, int numcuts, int seltype)
 {
-	BMesh *bm = editmesh_to_bmesh(G.editMesh);
-	BMOperator subdop;
+	BMesh *bm;
+	BMOperator subdop, conv;
 	EditMesh *em = G.editMesh;
 	BMEdge **list, *bed;
 	BMIter iter;
 	int tot;
 	
+	/*convert from editmesh*/
+	bm = editmesh_to_bmesh(G.editMesh);
+
 	BMO_Init_Op(&subdop, BMOP_ESUBDIVIDE);
 	for (tot=0, bed=BMIter_New(&iter, bm, BM_EDGES, NULL); bed; bed=BMIter_Step(&iter)) {
 		if (BM_Is_Selected(bm, bed)) tot++;

Modified: branches/bmesh/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/bmesh/intern/bmesh_opdefines.c	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/intern/bmesh_opdefines.c	2009-01-04 02:25:10 UTC (rev 18305)
@@ -12,14 +12,14 @@
 
 BMOpDefine def_edit2bmesh = {
 	{BMOP_OPSLOT_PNT},
-	NULL,
+	edit2bmesh_exec,
 	BMOP_TO_EDITMESH_TOTSLOT,
 	0
 };
 
 BMOpDefine def_bmesh2edit = {
 	{BMOP_OPSLOT_PNT},
-	NULL,
+	bmesh2edit_exec,
 	BMOP_FROM_EDITMESH_TOTSLOT,
 	0
 };

Modified: branches/bmesh/bmesh/intern/bmesh_operators_private.h
===================================================================
--- branches/bmesh/bmesh/intern/bmesh_operators_private.h	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/intern/bmesh_operators_private.h	2009-01-04 02:25:10 UTC (rev 18305)
@@ -11,5 +11,7 @@
 void dupeop_exec(struct BMesh *bm, struct BMOperator *op);
 void delop_exec(struct BMesh *bm, struct BMOperator *op);
 void esubdivide_exec(BMesh *bmesh, BMOperator *op);
+void edit2bmesh_exec(BMesh *bmesh, BMOperator *op);
+void bmesh2edit_exec(BMesh *bmesh, BMOperator *op);
 
 #endif

Modified: branches/bmesh/bmesh/intern/bmesh_structure.c
===================================================================
--- branches/bmesh/bmesh/intern/bmesh_structure.c	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/intern/bmesh_structure.c	2009-01-04 02:25:10 UTC (rev 18305)
@@ -89,7 +89,6 @@
 	v->head.next = v->head.prev = NULL;
 	v->head.EID = bm->nextv;
 	v->head.type = BM_VERT;
-	v->head.flag = BM_NEW;
 	v->co[0] = v->co[1] = v->co[2] = 0.0f;
 	v->no[0] = v->no[1] = v->no[2] = 0.0f;
 	v->edge = NULL;
@@ -116,7 +115,6 @@
 	e = BLI_mempool_alloc(bm->epool);
 	e->head.next = e->head.prev = NULL;
 	e->head.EID = bm->nexte;
-	e->head.flag = BM_NEW;
 	e->head.type = BM_EDGE;
 	e->v1 = v1;
 	e->v2 = v2;
@@ -144,7 +142,6 @@
 	BMLoop *l=NULL;
 	l = BLI_mempool_alloc(bm->lpool);
 	l->head.next = l->head.prev = NULL;
-	l->head.flag = BM_NEW;
 	l->head.EID = bm->nextl;
 	l->head.type = BM_LOOP;
 	l->radial.next = l->radial.prev = NULL;
@@ -168,7 +165,6 @@
 	BMFace *f = NULL;
 	f = BLI_mempool_alloc(bm->ppool);
 	f->head.next = f->head.prev = NULL;
-	f->head.flag = BM_NEW;
 	f->head.EID = bm->nextp;
 	f->head.type = BM_FACE;
 	f->loopbase = NULL;

Modified: branches/bmesh/bmesh/intern/bmesh_to_editmesh.c
===================================================================
--- branches/bmesh/bmesh/intern/bmesh_to_editmesh.c	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/intern/bmesh_to_editmesh.c	2009-01-04 02:25:10 UTC (rev 18305)
@@ -90,8 +90,11 @@
 	eve = addvertlist(v->co,NULL);
 	eve->keyindex = index;
 	evlist[index]= eve;
-	if(BM_Is_Selected(bm, v)) eve->f |= SELECT;
+	
+	/*copy flags*/
+	eve->f = v->head.flag & 255;
 	if(v->head.flag & BM_HIDDEN) eve->h = 1;
+
 	eve->bweight = v->bweight;
 	CustomData_em_copy_data(&bm->vdata, &em->vdata, v->data, &eve->data);
 	/*copy normal*/
@@ -174,7 +177,7 @@
 	return efa;
 }
 
-EditMesh *bmesh_to_editmesh(BMesh *bm) 
+EditMesh *bmesh_to_editmesh_intern(BMesh *bm) 
 {
 	BMVert *v;
 	BMEdge *e;
@@ -192,7 +195,7 @@
 	em = G.editMesh;
 
 	if (em == NULL) return NULL; //what?
-	em->act_face = NULL ;
+	em->act_face = NULL;
 
 	CustomData_copy(&bm->vdata, &em->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
 	CustomData_copy(&bm->edata, &em->edata, CD_MASK_BMESH, CD_CALLOC, 0);
@@ -219,4 +222,22 @@
 	MEM_freeN(evlist);
 	countall();
 	return em;
+}
+
+void bmesh2edit_exec(BMesh *bmesh, BMOperator *op)
+{
+	BMO_Set_Pnt(op, BMOP_TO_EDITMESH_EMOUT, bmesh_to_editmesh_intern(bmesh));
+}
+
+EditMesh *bmesh_to_editmesh(BMesh *bmesh)
+{
+	BMOperator conv;
+	EditMesh *em;
+
+	BMO_Init_Op(&conv, BMOP_TO_EDITMESH);
+	BMO_Exec_Op(bmesh, &conv);
+	em = conv.slots[BMOP_TO_EDITMESH_EMOUT].data.p;
+	BMO_Finish_Op(bmesh, &conv);
+
+	return em;
 }
\ No newline at end of file

Modified: branches/bmesh/bmesh/intern/editmesh_to_bmesh.c
===================================================================
--- branches/bmesh/bmesh/intern/editmesh_to_bmesh.c	2009-01-04 02:09:41 UTC (rev 18304)
+++ branches/bmesh/bmesh/intern/editmesh_to_bmesh.c	2009-01-04 02:25:10 UTC (rev 18305)
@@ -91,6 +91,8 @@
 		v = BM_Make_Vert(bm, eve->co, NULL);
 		
 		/*transfer flags*/
+		v->head.flag = eve->f;
+		v->head.flag |= eve->h ? BM_HIDDEN : 0;
 		if(eve->f & SELECT) BM_Select_Vert(bm, v, 1);
 		v->bweight = eve->bweight;
 
@@ -327,8 +329,7 @@
  *
 */
 
-BMesh *editmesh_to_bmesh(EditMesh *em) {
-	BMesh *bm;
+BMesh *editmesh_to_bmesh_intern(EditMesh *em, BMesh *bm) {
 	BMVert *v;
 	EditVert *eve;
 	EditEdge *eed;
@@ -338,9 +339,6 @@
 	/*make sure to update FGon flags*/
 	EM_fgon_flags();
 
-	/*allocate a bmesh*/
-	bm = BM_Make_Mesh(allocsize);
-
 	/*copy custom data layout*/
 	CustomData_copy(&em->vdata, &bm->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
 	CustomData_copy(&em->edata, &bm->edata, CD_MASK_BMESH, CD_CALLOC, 0);
@@ -389,4 +387,26 @@
 	}
 	//BM_end_edit(bm, BM_CALC_NORM);
 	return bm;
+}
+
+void edit2bmesh_exec(BMesh *bmesh, BMOperator *op)
+{
+	editmesh_to_bmesh_intern(op->slots[BMOP_FROM_EDITMESH_EM].data.p, bmesh);
+}
+
+BMesh *editmesh_to_bmesh(EditMesh *em)
+{
+	BMOperator conv;
+	BMesh *bm;
+	int allocsize[4] = {512,512,2048,512}, numTex, numCol;
+
+	/*allocate a bmesh*/
+	bm = BM_Make_Mesh(allocsize);
+
+	BMO_Init_Op(&conv, BMOP_FROM_EDITMESH);
+	BMO_Set_Pnt(&conv, BMOP_FROM_EDITMESH_EM, em);
+	BMO_Exec_Op(bm, &conv);
+	BMO_Finish_Op(bm, &conv);
+
+	return bm;
 }
\ No newline at end of file

Modified: branches/bmesh/bmesh/operators/subdivideop.c
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list