[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18244] branches/bmesh/bmesh: -> Moved some stuff out of dupeops into API

Geoffrey Bantle hairbat at yahoo.com
Fri Jan 2 05:08:05 CET 2009


Revision: 18244
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18244
Author:   briggs
Date:     2009-01-02 05:08:02 +0100 (Fri, 02 Jan 2009)

Log Message:
-----------
-> Moved some stuff out of dupeops into API

-BM_Select selects an element regardless of it's type
-BM_Is_Selected tests whether or not an element is selected
regardless of it's type.
-BM_Copy_Attributes copies custom data/flags/material indices/ect.

The individual select functions should be made static and in future
any additions to structures will require changes to BM_Copy_Attributes.
Operator writers should always use this function instead of copying such
data directly.

Todo:
BM_Copy_Attributes could optionally accept a bitflag defining what
types of data should be copied. ie:

BMESH_CUSTOMDATA|BMESH_HIDE|BMESH_SHARP, ect.

Note to joe:

I think this is the best way to deal with it in the API from now on.
It strikes good balance between keeping implementation details wrapped
up in the API while not having to worry about building some complex
attribute system.

So I suppose this makes the additions you made to bmesh_marking.h redundant?

Modified Paths:
--------------
    branches/bmesh/bmesh/bmesh.h
    branches/bmesh/bmesh/bmesh_marking.h
    branches/bmesh/bmesh/intern/bmesh_construct.c
    branches/bmesh/bmesh/intern/bmesh_marking.c
    branches/bmesh/bmesh/operators/bmesh_dupeops.c

Modified: branches/bmesh/bmesh/bmesh.h
===================================================================
--- branches/bmesh/bmesh/bmesh.h	2009-01-02 03:42:16 UTC (rev 18243)
+++ branches/bmesh/bmesh/bmesh.h	2009-01-02 04:08:02 UTC (rev 18244)
@@ -124,7 +124,6 @@
 	struct BLI_mempool *epool;
 	struct BLI_mempool *lpool;
 	struct BLI_mempool *ppool;
-	struct BMOperator *currentop;
 	struct BMVert **vtar;
 	struct BMEdge **edar;
 	struct BMLoop **lpar;
@@ -193,6 +192,7 @@
 struct BMEdge *BM_Make_Edge(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMEdge *example, int nodouble);
 struct BMFace *BM_Make_Quadtriangle(struct BMesh *bm, struct BMVert **verts, BMEdge **edges, int len, struct BMFace *example, int nodouble);
 struct BMFace *BM_Make_Ngon(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMEdge **edges, int len, int nodouble);
+void BM_Copy_Attributes(struct BMesh *source_mesh, struct BMesh *target_mesh, void *source, void *target);
 void BM_Delete_Face(struct BMesh *bm, struct BMFace *f);
 void BM_Delete_Edge(struct BMesh *bm, struct BMVert *v);
 void BM_Delete_Vert(struct BMesh *bm, struct BMVert *v);

Modified: branches/bmesh/bmesh/bmesh_marking.h
===================================================================
--- branches/bmesh/bmesh/bmesh_marking.h	2009-01-02 03:42:16 UTC (rev 18243)
+++ branches/bmesh/bmesh/bmesh_marking.h	2009-01-02 04:08:02 UTC (rev 18244)
@@ -7,6 +7,9 @@
 void BM_Select_Face(struct BMesh *bm, struct BMFace *f, int select);
 void BM_Selectmode_Set(struct BMesh *bm, int selectmode);
 
+void BM_Select(struct BMesh *bm, void *element, int select);
+
+
 /* NOTE: unused, bad: 
 
   simple system to manipulate flags, coded here

Modified: branches/bmesh/bmesh/intern/bmesh_construct.c
===================================================================
--- branches/bmesh/bmesh/intern/bmesh_construct.c	2009-01-02 03:42:16 UTC (rev 18243)
+++ branches/bmesh/bmesh/intern/bmesh_construct.c	2009-01-02 04:08:02 UTC (rev 18244)
@@ -312,3 +312,53 @@
 		current = next;
 	}
 }
+
+static void bm_copy_vert_attributes(BMesh *source_mesh, BMesh *target_mesh, BMVert *source_vertex, BMVert *target_vertex)
+{
+	CustomData_bmesh_copy_data(&source_mesh->vdata, &target_mesh->vdata, source_vertex->data, &target_vertex->data);	
+	target_vertex->bweight = source_vertex->bweight;
+}
+
+static void bm_copy_edge_attributes(BMesh *source_mesh, BMesh *target_mesh, BMEdge *source_edge, BMEdge *target_edge)
+{
+	CustomData_bmesh_copy_data(&source_mesh->edata, &target_mesh->edata, source_edge->data, &target_edge->data);
+	target_edge->crease = source_edge->crease;
+	target_edge->bweight = source_edge->bweight;
+}
+
+static void bm_copy_loop_attributes(BMesh *source_mesh, BMesh *target_mesh, BMLoop *source_loop, BMLoop *target_loop)
+{
+	CustomData_bmesh_copy_data(&source_mesh->ldata, &target_mesh->ldata, source_loop->data, &target_loop->data);
+}
+
+static void bm_copy_face_attributes(BMesh *source_mesh, BMesh *target_mesh, BMFace *source_face, BMFace *target_face)
+{
+	CustomData_bmesh_copy_data(&source_mesh->pdata, &target_mesh->pdata, source_face->data, &target_face->data);	
+	target_face->mat_nr = source_face->mat_nr;
+}
+
+/*Todo: Special handling for hide flags?*/
+
+void BM_Copy_Attributes(BMesh *source_mesh, BMesh *target_mesh, void *source, void *target)
+{
+	BMHeader *sheader = source, *theader = target;
+	
+	if(sheader->type != theader->type)
+		return;
+
+	/*First we copy select*/
+	if(BM_Is_Selected(source_mesh, source)) BM_Select(target_mesh, target, 1);
+	
+	/*Now we copy flags*/
+	theader->flag = sheader->flag;
+	
+	/*Copy specific attributes*/
+	if(theader->type == BMESH_VERT)
+		bm_copy_vert_attributes(source_mesh, target_mesh, (BMVert*)source, (BMVert*)target);
+	else if(theader->type == BMESH_EDGE)
+		bm_copy_edge_attributes(source_mesh, target_mesh, (BMEdge*)source, (BMEdge*)target);
+	else if(theader->type == BMESH_LOOP)
+		bm_copy_loop_attributes(source_mesh, target_mesh, (BMLoop*)source, (BMLoop*)target);
+	else if(theader->type == BMESH_FACE)
+		bm_copy_face_attributes(source_mesh, target_mesh, (BMFace*)source, (BMFace*)target);
+}
\ No newline at end of file

Modified: branches/bmesh/bmesh/intern/bmesh_marking.c
===================================================================
--- branches/bmesh/bmesh/intern/bmesh_marking.c	2009-01-02 03:42:16 UTC (rev 18243)
+++ branches/bmesh/bmesh/intern/bmesh_marking.c	2009-01-02 04:08:02 UTC (rev 18244)
@@ -199,7 +199,18 @@
 	}
 }
 
-int BM_Is_Selected(BMesh *bm, BMHeader *h)
+
+void BM_Select(struct BMesh *bm, void *element, int select)
 {
-	return bmesh_test_sysflag(h, BMESH_SELECT);
+	BMHeader *head = element;
+
+	if(head->type == BMESH_VERT) BM_Select_Vert(bm, (BMVert*)element, select);
+	else if(head->type == BMESH_EDGE) BM_Select_Edge(bm, (BMEdge*)element, select);
+	else if(head->type == BMESH_FACE) BM_Select_Face(bm, (BMFace*)element, select);
 }
+
+int BM_Is_Selected(BMesh *bm, void *element)
+{
+	BMHeader *head = element;
+	return bmesh_test_sysflag(head, BMESH_SELECT);
+}
\ No newline at end of file

Modified: branches/bmesh/bmesh/operators/bmesh_dupeops.c
===================================================================
--- branches/bmesh/bmesh/operators/bmesh_dupeops.c	2009-01-02 03:42:16 UTC (rev 18243)
+++ branches/bmesh/bmesh/operators/bmesh_dupeops.c	2009-01-02 04:08:02 UTC (rev 18244)
@@ -29,19 +29,16 @@
 {
 	BMVert *target_vertex = NULL;
 
-	/*create a new vertex*/
+	/*Create a new vertex*/
 	target_vertex = BM_Make_Vert(target_mesh, source_vertex->co,  NULL);
-
-	/*insert new vertex into the vert hash*/
+	
+	/*Insert new vertex into the vert hash*/
 	BLI_ghash_insert(vhash, source_vertex, target_vertex);	
 	
-	/*copy custom data in this function since we cannot be assured that byte layout is same between meshes*/
-	CustomData_bmesh_copy_data(&source_mesh->vdata, &target_mesh->vdata, source_vertex->data, &target_vertex->data);	
-
-	/*Copy Flags*/
-	if(source_vertex->head.flag & SELECT) BM_Select_Vert(target_mesh, target_vertex, 1);
-	target_vertex->head.flag |= source_vertex->head.flag;
-
+	/*Copy attributes*/
+	BM_Copy_Attributes(source_mesh, target_mesh, source_vertex, target_vertex);
+	
+	/*Set internal op flags*/
 	BMO_SetFlag(target_mesh, (BMHeader*)target_vertex, DUPE_NEW);
 	
 	return target_vertex;
@@ -58,22 +55,20 @@
 	BMEdge *target_edge = NULL;
 	BMVert *target_vert1, *target_vert2;
 	
-	/*lookup v1 and v2*/
+	/*Lookup v1 and v2*/
 	target_vert1 = BLI_ghash_lookup(vhash, source_edge->v1);
 	target_vert2 = BLI_ghash_lookup(vhash, source_edge->v2);
 	
-	/*create a new edge*/
+	/*Create a new edge*/
 	target_edge = BM_Make_Edge(target_mesh, target_vert1, target_vert2, NULL, 0);
 
-	/*insert new edge into the edge hash*/
+	/*Insert new edge into the edge hash*/
 	BLI_ghash_insert(ehash, source_edge, target_edge);	
 	
-	/*copy custom data in this function since we cannot be assured that byte layout is same between meshes*/	
-	CustomData_bmesh_copy_data(&source_mesh->edata, &target_mesh->edata, source_edge->data, &target_edge->data);
+	/*Copy attributes*/
+	BM_Copy_Attributes(source_mesh, target_mesh, source_edge, target_edge);
 	
-	/*copy flags*/
-	target_edge->head.flag = source_edge->head.flag;
-
+	/*Set internal op flags*/
 	BMO_SetFlag(target_mesh, (BMHeader*)target_edge, DUPE_NEW);
 	
 	return target_edge;
@@ -106,13 +101,8 @@
 	/*create new face*/
 	target_face = BM_Make_Ngon(target_mesh, target_vert1, target_vert2, edar, source_face->len, 0);	
 	
-	/*we copy custom data by hand, we cannot assume that customdata byte layout will be exactly the same....*/
-	CustomData_bmesh_copy_data(&source_mesh->pdata, &target_mesh->pdata, source_face->data, &target_face->data);	
+	BM_Copy_Attributes(source_mesh, target_mesh, source_face, target_face);
 
-	/*copy flags*/
-	target_face->head.flags = source_face->head.flags;
-	if(source_face->head.flag & SELECT) BM_Select_Face(target_mesh, target_face, 1);
-
 	/*mark the face for output*/
 	BMO_SetFlag(target_mesh, (BMHeader*)target_face, DUPE_NEW);
 	
@@ -121,8 +111,10 @@
 	  target_loop=BMIter_New(target_mesh, &iter2, BM_LOOPS_OF_FACE, target_face);
 	  source_loop && target_loop; source_loop=BMIter_Step(&iter), target_loop=BMIter_Step(&iter2),
 	  i++) {
-		CustomData_bmesh_copy_data(&source_mesh->ldata, &target_mesh->ldata, source_loop->data, &target_loop->data);		
-	}	
+		BM_Copy_Attributes(source_mesh, target_mesh, source_loop, target_loop);		
+	}
+
+
 	return target_face;
 }
 	/*





More information about the Bf-blender-cvs mailing list