[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21659] branches/bmesh/blender/source/ blender: moved the selection history stuff within bmesh itself, to avoid memory access problems.

Joseph Eagar joeedh at gmail.com
Fri Jul 17 12:54:00 CEST 2009


Revision: 21659
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21659
Author:   joeedh
Date:     2009-07-17 12:54:00 +0200 (Fri, 17 Jul 2009)

Log Message:
-----------
moved the selection history stuff within bmesh itself, to avoid memory access problems.  also committing some playing around I did with the edge subdivide code, which isn't doesn't really completely work.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/BKE_tessmesh.h
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/bmesh_marking.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_structure.c
    branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
    branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_select.c
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_selecthistory.c
    branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c
    branches/bmesh/blender/source/blender/editors/space_view3d/drawobject.c
    branches/bmesh/blender/source/blender/editors/transform/transform_conversions.c

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_tessmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_tessmesh.h	2009-07-17 10:42:32 UTC (rev 21658)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_tessmesh.h	2009-07-17 10:54:00 UTC (rev 21659)
@@ -11,13 +11,6 @@
     the BMEditMesh structure.
 */
 
-typedef struct BMEditSelection
-{
-	struct BMEditSelection *next, *prev;
-	short type;
-	void *data;
-} BMEditSelection;
-
 /*this structure replaces EditMesh.
  
   through this, you get access to both the edit bmesh,
@@ -25,7 +18,7 @@
   struct itself.
   
   the entire derivedmesh and modifier system works with this structure,
-  and not BMesh.  Mesh->editbmesh will store a pointer to this structure.*/
+  and not BMesh.  Mesh->edit_bmesh stores a pointer to this structure.*/
 typedef struct BMEditMesh {
 	struct BMesh *bm;
 
@@ -50,9 +43,6 @@
 	struct BMVert **vert_index;
 	struct BMEdge **edge_index;
 	struct BMFace **face_index;
-	
-	/*selection order list*/
-	ListBase selected;
 
 	/*selection mode*/
 	int selectmode;

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h	2009-07-17 10:42:32 UTC (rev 21658)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h	2009-07-17 10:54:00 UTC (rev 21659)
@@ -170,6 +170,9 @@
 	int totflags, walkers;							/*total number of tool flag layers*/
 	ListBase errorstack;
 
+	/*selection order list*/
+	ListBase selected;
+
 	/*active face pointer*/
 	struct BMFace *act_face;
 } BMesh;

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_marking.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_marking.h	2009-07-17 10:42:32 UTC (rev 21658)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_marking.h	2009-07-17 10:54:00 UTC (rev 21659)
@@ -1,6 +1,13 @@
 #ifndef BM_MARKING_H
 #define BM_MARKING_H
 
+typedef struct BMEditSelection
+{
+	struct BMEditSelection *next, *prev;
+	short type;
+	void *data;
+} BMEditSelection;
+
 /*Selection code*/
 void BM_Select_Vert(struct BMesh *bm, struct BMVert *v, int select);
 void BM_Select_Edge(struct BMesh *bm, struct BMEdge *e, int select);
@@ -13,4 +20,12 @@
 void BM_Select(struct BMesh *bm, void *element, int select);
 int BM_Is_Selected(BMesh *bm, void *element);
 
+/*edit selection stuff*/
+void BM_editselection_center(BMesh *bm, float *center, BMEditSelection *ese);
+void BM_editselection_normal(float *normal, BMEditSelection *ese);
+void BM_editselection_plane(BMesh *bm, float *plane, BMEditSelection *ese);
+void BM_remove_selection(BMesh *bm, void *data);
+void BM_store_selection(BMesh *bm, void *data);
+void BM_validate_selections(BMesh *bm);
+
 #endif

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c	2009-07-17 10:42:32 UTC (rev 21658)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c	2009-07-17 10:54:00 UTC (rev 21659)
@@ -418,11 +418,12 @@
 	V_DECLARE(etable);
 	BMLoop *l, *l2, **loops = NULL;
 	V_DECLARE(loops);
-	BMFace *f, *f2;
-
+	BMFace *f, *f2, **ftable = NULL;
+	V_DECLARE(ftable);
+	BMEditSelection *ese;
 	BMIter iter, liter;
 	int allocsize[4] = {512,512,2048,512}, numTex, numCol;
-	int i;
+	int i, j;
 
 	/*allocate a bmesh*/
 	bm = BM_Make_Mesh(allocsize);
@@ -468,15 +469,15 @@
 	}
 	
 	f = BMIter_New(&iter, bmold, BM_FACES_OF_MESH, NULL);
-	for (; f; f=BMIter_Step(&iter)) {
+	for (i=0; f; f=BMIter_Step(&iter), i++) {
 		V_RESET(loops);
 		V_RESET(edges);
 		l = BMIter_New(&liter, bmold, BM_LOOPS_OF_FACE, f);
-		for (i=0; i<f->len; i++, l = BMIter_Step(&liter)) {
+		for (j=0; j<f->len; j++, l = BMIter_Step(&liter)) {
 			V_GROW(loops);
 			V_GROW(edges);
-			loops[i] = l;
-			edges[i] = etable[BMINDEX_GET(l->e)];
+			loops[j] = l;
+			edges[j] = etable[BMINDEX_GET(l->e)];
 		}
 
 		v = vtable[BMINDEX_GET(loops[0]->v)];
@@ -488,19 +489,41 @@
 		}
 
 		f2 = BM_Make_Ngon(bm, v, v2, edges, f->len, 0);
+		
+		BMINDEX_SET(f, i);
+		V_GROW(ftable);
+		ftable[i] = f2;
+
 		BM_Copy_Attributes(bmold, bm, f, f2);
 		VECCOPY(f2->no, f->no);
 
 		l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f2);
-		for (i=0; i<f->len; i++, l = BMIter_Step(&liter)) {
-			BM_Copy_Attributes(bmold, bm, loops[i], l);
+		for (j=0; j<f->len; j++, l = BMIter_Step(&liter)) {
+			BM_Copy_Attributes(bmold, bm, loops[j], l);
 		}
 
 		if (f == bmold->act_face) bm->act_face = f2;
 	}
-	
+
+	/*copy over edit selection history*/
+	for (ese=bmold->selected.first; ese; ese=ese->next) {
+		void *ele;
+
+		if (ese->type == BM_VERT)
+			ele = vtable[BMINDEX_GET(ese->data)];
+		else if (ese->type == BM_EDGE)
+			ele = etable[BMINDEX_GET(ese->data)];
+		else if (ese->type == BM_FACE) {
+			ele = ftable[BMINDEX_GET(ese->data)];
+		}
+
+		BM_store_selection(bm, ele);
+	}
+
 	V_FREE(etable);
 	V_FREE(vtable);
+	V_FREE(ftable);
+
 	V_FREE(loops);
 	V_FREE(edges);
 

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c	2009-07-17 10:42:32 UTC (rev 21658)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c	2009-07-17 10:54:00 UTC (rev 21659)
@@ -1,7 +1,14 @@
-#include <string.h>
+#include "MEM_guardedalloc.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+
 #include "bmesh.h"
 #include "bmesh_private.h"
 
+#include <string.h>
 
 /*
  * BM_MARK.C
@@ -304,4 +311,182 @@
 {
 	BMHeader *head = element;
 	return BM_TestHFlag(head, BM_SELECT);
-}
\ No newline at end of file
+}
+
+
+/* generic way to get data from an EditSelection type 
+These functions were written to be used by the Modifier widget when in Rotate about active mode,
+but can be used anywhere.
+EM_editselection_center
+EM_editselection_normal
+EM_editselection_plane
+*/
+void BM_editselection_center(BMesh *em, float *center, BMEditSelection *ese)
+{
+	if (ese->type==BM_VERT) {
+		BMVert *eve= ese->data;
+		VecCopyf(center, eve->co);
+	} else if (ese->type==BM_EDGE) {
+		BMEdge *eed= ese->data;
+		VecAddf(center, eed->v1->co, eed->v2->co);
+		VecMulf(center, 0.5);
+	} else if (ese->type==BM_FACE) {
+		BMFace *efa= ese->data;
+		BM_Compute_Face_Center(em, efa, center);
+	}
+}
+
+void BM_editselection_normal(float *normal, BMEditSelection *ese)
+{
+	if (ese->type==BM_VERT) {
+		BMVert *eve= ese->data;
+		VecCopyf(normal, eve->no);
+	} else if (ese->type==BM_EDGE) {
+		BMEdge *eed= ese->data;
+		float plane[3]; /* need a plane to correct the normal */
+		float vec[3]; /* temp vec storage */
+		
+		VecAddf(normal, eed->v1->no, eed->v2->no);
+		VecSubf(plane, eed->v2->co, eed->v1->co);
+		
+		/* the 2 vertex normals will be close but not at rightangles to the edge
+		for rotate about edge we want them to be at right angles, so we need to
+		do some extra colculation to correct the vert normals,
+		we need the plane for this */
+		Crossf(vec, normal, plane);
+		Crossf(normal, plane, vec); 
+		Normalize(normal);
+		
+	} else if (ese->type==BM_FACE) {
+		BMFace *efa= ese->data;
+		VecCopyf(normal, efa->no);
+	}
+}
+
+/* Calculate a plane that is rightangles to the edge/vert/faces normal
+also make the plane run allong an axis that is related to the geometry,
+because this is used for the manipulators Y axis.*/
+void BM_editselection_plane(BMesh *em, float *plane, BMEditSelection *ese)
+{
+	if (ese->type==BM_VERT) {
+		BMVert *eve= ese->data;
+		float vec[3]={0,0,0};
+		
+		if (ese->prev) { /*use previously selected data to make a usefull vertex plane */
+			BM_editselection_center(em, vec, ese->prev);
+			VecSubf(plane, vec, eve->co);
+		} else {
+			/* make a fake  plane thats at rightangles to the normal
+			we cant make a crossvec from a vec thats the same as the vec
+			unlikely but possible, so make sure if the normal is (0,0,1)
+			that vec isnt the same or in the same direction even.*/
+			if (eve->no[0]<0.5)		vec[0]=1;
+			else if (eve->no[1]<0.5)	vec[1]=1;
+			else				vec[2]=1;
+			Crossf(plane, eve->no, vec);
+		}
+	} else if (ese->type==BM_EDGE) {
+		BMEdge *eed= ese->data;
+
+		/*the plane is simple, it runs allong the edge
+		however selecting different edges can swap the direction of the y axis.
+		this makes it less likely for the y axis of the manipulator
+		(running along the edge).. to flip less often.
+		at least its more pradictable */
+		if (eed->v2->co[1] > eed->v1->co[1]) /*check which to do first */
+			VecSubf(plane, eed->v2->co, eed->v1->co);
+		else
+			VecSubf(plane, eed->v1->co, eed->v2->co);
+		
+	} else if (ese->type==BM_FACE) {
+		BMFace *efa= ese->data;
+		float vec[3] = {0.0f, 0.0f, 0.0f};
+		
+		/*for now, use face normal*/
+
+		/* make a fake  plane thats at rightangles to the normal
+		we cant make a crossvec from a vec thats the same as the vec
+		unlikely but possible, so make sure if the normal is (0,0,1)
+		that vec isnt the same or in the same direction even.*/
+		if (efa->no[0]<0.5)		vec[0]=1.0f;
+		else if (efa->no[1]<0.5)	vec[1]=1.0f;
+		else				vec[2]=1.0f;
+		Crossf(plane, efa->no, vec);
+#if 0
+
+		if (efa->v4) { /*if its a quad- set the plane along the 2 longest edges.*/
+			float vecA[3], vecB[3];
+			VecSubf(vecA, efa->v4->co, efa->v3->co);
+			VecSubf(vecB, efa->v1->co, efa->v2->co);
+			VecAddf(plane, vecA, vecB);
+			
+			VecSubf(vecA, efa->v1->co, efa->v4->co);
+			VecSubf(vecB, efa->v2->co, efa->v3->co);
+			VecAddf(vec, vecA, vecB);						
+			/*use the biggest edge length*/
+			if (plane[0]*plane[0]+plane[1]*plane[1]+plane[2]*plane[2] < vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2])
+				VecCopyf(plane, vec);
+		} else {
+			/*start with v1-2 */
+			VecSubf(plane, efa->v1->co, efa->v2->co);
+			
+			/*test the edge between v2-3, use if longer */
+			VecSubf(vec, efa->v2->co, efa->v3->co);
+			if (plane[0]*plane[0]+plane[1]*plane[1]+plane[2]*plane[2] < vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2])
+				VecCopyf(plane, vec);
+			
+			/*test the edge between v1-3, use if longer */
+			VecSubf(vec, efa->v3->co, efa->v1->co);
+			if (plane[0]*plane[0]+plane[1]*plane[1]+plane[2]*plane[2] < vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2])
+				VecCopyf(plane, vec);
+		}
+#endif
+	}
+	Normalize(plane);
+}
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list