[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18788] branches/bmesh/blender/source/ blender: Begin port of edge subdivide (with multicut) to

Joseph Eagar joeedh at gmail.com
Mon Feb 2 04:25:47 CET 2009


Revision: 18788
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18788
Author:   joeedh
Date:     2009-02-02 04:25:23 +0100 (Mon, 02 Feb 2009)

Log Message:
-----------
Begin port of edge subdivide (with multicut) to
bmesh.  Basic infrastructure is in place, and
subdivision patterns for quads are implemented. 
Properly handling of the (many) flags and options
related to edge subdivide isn't complete, but I've
made a good start.  

Goal is eventual 100% api compatibility with old
esubdivide function, with some of the uglier design
aspects refactored after some of the tools that rely
on them are redone.

Some notes: Customdata interpolation wasn't working
right.  I thought maybe the weights were off, so I
swapped them, which surprising made it work.  It's
still not completely identical to old edge
subdivide though.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h
    branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
    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/operators/subdivideop.c
    branches/bmesh/blender/source/blender/editors/mesh/editmesh_mods.c
    branches/bmesh/blender/source/blender/editors/mesh/mesh_intern.h

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h	2009-02-02 00:31:46 UTC (rev 18787)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h	2009-02-02 03:25:23 UTC (rev 18788)
@@ -204,5 +204,34 @@
 #define SET_INT_IN_POINTER(i) ((void*)(intptr_t)(i))
 #define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i))
 
+/*little pointer array macro library.  example of usage:
+
+int *arr = NULL;
+V_DECLARE(arr);
+int i;
+
+for (i=0; i<10; i++) {
+	V_GROW(arr);
+	arr[i] = something;
+}
+V_FREE(arr);
+*/
+
+#define V_DECLARE(vec) int _##vec##_count=0; void *_##vec##_tmp
+#define V_SIZE(vec) ((vec)==NULL ? 0 : MEM_allocN_len(vec) / sizeof(*vec))
+#define V_COUNT(vec) _##vec##_count
+#define MSTR(s) #s
+#define V_GROW(vec) \
+	V_SIZE(vec) > _##vec##_count ? _##vec##_count++ : \
+	((_##vec##_tmp = MEM_callocN(sizeof(*vec)*(_##vec##_count*2+2), #vec " " __FILE__ " ")),\
+	(vec && memcpy(_##vec##_tmp, vec, sizeof(*vec) * _##vec##_count)),\
+	(vec && (MEM_freeN(vec),1)),\
+	(vec = _##vec##_tmp),\
+	_##vec##_count++)
+
+//(vec) ? WMEM_freeN(vec), 1 : 0
+#define V_FREE(vec) if (vec) MEM_freeN(vec);
+#define V_RESET(vec) _##vec##_count=0
+
 #endif
 

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-02-02 00:31:46 UTC (rev 18787)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-02-02 03:25:23 UTC (rev 18788)
@@ -22,7 +22,7 @@
 	int len;
 	int index; /*index within slot array*/
 	union {
-		int	i;
+		int i;
 		float f;					
 		void *p;					
 		float vec[3];				/*vector*/
@@ -52,7 +52,6 @@
 
 /*BMOpDefine->flag*/
 //doesn't do anything at the moment.
-#define BMO_NOFLAGS		1
 
 /*API for operators*/
 void BMO_Init_Op(struct BMOperator *op, int opcode);
@@ -152,16 +151,31 @@
 
 /*edge subdivide op*/
 #define BMOP_ESUBDIVIDE			5
-#define BMOP_ESUBDIVIDE_EDGES	0
-#define BMOP_ESUBDIVIDE_TOTSLOT	1
+enum {
+	BMOP_ESUBDIVIDE_EDGES,
+	BMOP_ESUBDIVIDE_NUMCUTS,
+	BMOP_ESUBDIVIDE_FLAG, //beauty flag in esubdivide
+	BMOP_ESUBDIVIDE_RADIUS,
+	BMOP_ESUBDIVIDE_SELACTION,
+	BMOP_ESUBDIVIDE_TOTSLOT,
+};
+/*
+SUBDIV_SELECT_INNER
+SUBDIV_SELECT_ORIG
+SUBDIV_SELECT_INNER_SEL
+SUBDIV_SELECT_LOOPCUT
+DOUBLEOPFILL
+*/
 
 /*triangulate*/
 #define BMOP_TRIANGULATE		6
 
-#define BMOP_TRIANG_FACEIN		0
-#define BMOP_TRIANG_NEW_EDGES	1
-#define BMOP_TRIANG_NEW_FACES	2
-#define BMOP_TRIANG_TOTSLOT		3
+enum {
+	BMOP_TRIANG_FACEIN,
+	BMOP_TRIANG_NEW_EDGES,
+	BMOP_TRIANG_NEW_FACES,
+	BMOP_TRIANG_TOTSLOT,
+};
 
 /*dissolve faces*/
 #define BMOP_DISSOLVE_FACES		7

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2009-02-02 00:31:46 UTC (rev 18787)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2009-02-02 03:25:23 UTC (rev 18788)
@@ -79,8 +79,8 @@
 	float w[2];
 	BMLoop *l=NULL, *v1loop = NULL, *vloop = NULL, *v2loop = NULL;
 	
-	w[0] = 1.0f - fac;
-	w[1] = fac;
+	w[1] = 1.0f - fac;
+	w[0] = fac;
 
 	if(!e1->loop) return;
 	l = e1->loop;

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2009-02-02 00:31:46 UTC (rev 18787)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2009-02-02 03:25:23 UTC (rev 18788)
@@ -39,7 +39,7 @@
  *  Returns -
  *	1 for success, 0 for failure.
  */
-
+#if 1
 void BM_Dissolve_Disk(BMesh *bm, BMVert *v) {
 	BMFace *f, *f2;
 	BMEdge *e, *keepedge=NULL, *baseedge=NULL;
@@ -111,6 +111,38 @@
 		BM_Join_Faces(bm, f, f2, NULL, 0, 0);
 	}
 }
+#else
+void BM_Dissolve_Disk(BMesh *bm, BMVert *v){
+	BMFace *f;
+	BMEdge *e;
+	BMIter iter;
+	int done, len;
+	
+	if(v->edge){
+		done = 0;
+		while(!done){
+			done = 1;
+			
+			/*loop the edges looking for an edge to dissolve*/
+			for (e=BMIter_New(&iter, bm, BM_EDGES_OF_VERT, v); e;
+			     e = BMIter_Step(&iter)) {
+				f = NULL;
+				len = bmesh_cycle_length(&(e->loop->radial));
+				if(len == 2){
+					f = BM_Join_Faces(bm,e->loop->f,((BMLoop*)
+					      (e->loop->radial.next->data))->f, 
+					       e, 1, 0);
+				}
+				if(f){ 
+					done = 0;
+					break;
+				}
+			};
+		}
+		BM_Collapse_Vert(bm, v->edge, v, 1.0, 1);
+	}
+}
+#endif
 
 /**
  *			bmesh_join_faces

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-02-02 00:31:46 UTC (rev 18787)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-02-02 03:25:23 UTC (rev 18788)
@@ -34,7 +34,11 @@
 };
 
 BMOpDefine def_subdop = {
-	{BMOP_OPSLOT_PNT_BUF},
+	{BMOP_OPSLOT_PNT_BUF,
+	 BMOP_OPSLOT_INT,
+	 BMOP_OPSLOT_INT,
+	 BMOP_OPSLOT_FLT,
+	 BMOP_OPSLOT_INT},
 	esubdivide_exec,
 	BMOP_ESUBDIVIDE_TOTSLOT,
 	0

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-02-02 00:31:46 UTC (rev 18787)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-02-02 03:25:23 UTC (rev 18788)
@@ -80,9 +80,6 @@
 	memset(op, 0, sizeof(BMOperator));
 	op->type = opcode;
 	
-	//currently not used, flags are always allocated
-	op->needflag = !(opdefines[opcode]->flag & BMO_NOFLAGS);
-
 	/*initialize the operator slot types*/
 	for(i = 0; i < opdefines[opcode]->totslot; i++) {
 		op->slots[i].slottype = opdefines[opcode]->slottypes[i];

Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2009-02-02 00:31:46 UTC (rev 18787)
+++ branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2009-02-02 03:25:23 UTC (rev 18788)
@@ -2,45 +2,37 @@
 
 #include "BKE_utildefines.h"
 
-#include "bmesh.h"
 #include "BLI_arithb.h"
+#include "BLI_rand.h"
 
-#include <stdio.h>
+#include "DNA_object_types.h"
 
-/*
-note: this is a pattern-based edge subdivider.
-it tries to match a pattern to edge selections on faces.
-it was a fairly easy exercise to test the bmesh api; it
-doesn't support multicuts, so it won't actually be used.
+#include "ED_mesh.h"
 
-the patterns are defined as followed:
+#include "bmesh.h"
+#include "mesh_intern.h"
 
-the patterns are defined for the state of the face after
-initial splitting.  each edge that was split is flagged, as is
-the new resulting edge.
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
 
-subdpattern pattern = {
-	//boolean flags for if an edge should have been split or not
-	{1, 0, 0, 0},
-	//connection values for verts,
-	{2, -1, -1, -1},
-	//second stage split flags, splits newly created edges
-	{0, 0, 0, 0, 1},
-	//second stage connection values for verts, connects stuff again.
-	{-1, -1, -1, -1, 3},
-	4 //len of face before second stage splits, but after initial edge splits
-};
+#define SUBD_SPLIT	1
+#define FACE_NEW	1
+#define MAX_FACE	800
 
+/*
+note: this is a pattern-based edge subdivider.
+it tries to match a pattern to edge selections on faces,
+then executes functions to cut them.
 */
 typedef struct subdpattern {
 	int seledges[20]; //selected edges mask, for splitting
-	int connectverts[20]; //verts to connect;
 
-	int secondstage_splitedges[20];
-	//verts to connect afterwards.  size must be len + number 
-	//of edges split in secondstage_splitedges
-	int secondstage_connect[20];
-
+	/*verts starts at the first new vert cut, not the first vert in the
+	  face*/
+	void (*connectexec)(BMesh *bm, BMFace *face, BMVert **verts, 
+		            int numcuts, int beauty, float rad);
 	int len; /*total number of verts*/
 } subdpattern;
 
@@ -53,269 +45,485 @@
     split the edge only?
 */
 
-/*note: the patterns are rotated as necassary to
-  match the input geometry.  they're also based on the
-  post-splitted state of the faces.  note that
-  second stage splitted stuff doesn't count
-  for pattern->len!*/
 
-/*
-     v2
-    /  \
-v1 s_e1 e2
-  /e0     \
-v0---e3----v3
+/* calculates offset for co, based on fractal, sphere or smooth settings  */
+static void alter_co(float *co, BMEdge *edge, float rad, int beauty, float perc)
+{
+	float vec1[3], fac;
+	
+	if(beauty & B_SMOOTH) {
+		/* we calculate an offset vector vec1[], to be added to *co */
+		float len, fac, nor[3], nor1[3], nor2[3];
+		
+		VecSubf(nor, edge->v1->co, edge->v2->co);
+		len= 0.5f*Normalize(nor);
+	
+		VECCOPY(nor1, edge->v1->no);
+		VECCOPY(nor2, edge->v2->no);
+	
+		/* cosine angle */
+		fac= nor[0]*nor1[0] + nor[1]*nor1[1] + nor[2]*nor1[2] ;
+		
+		vec1[0]= fac*nor1[0];
+		vec1[1]= fac*nor1[1];
+		vec1[2]= fac*nor1[2];
+	
+		/* cosine angle */
+		fac= -nor[0]*nor2[0] - nor[1]*nor2[1] - nor[2]*nor2[2] ;
+		
+		vec1[0]+= fac*nor2[0];
+		vec1[1]+= fac*nor2[1];
+		vec1[2]+= fac*nor2[2];
+		
+		vec1[0]*= rad*len;
+		vec1[1]*= rad*len;
+		vec1[2]*= rad*len;
+		
+		co[0] += vec1[0];
+		co[1] += vec1[1];
+		co[2] += vec1[2];
+	}
+	else {
+		if(rad > 0.0) {   /* subdivide sphere */
+			Normalize(co);
+			co[0]*= rad;
+			co[1]*= rad;
+			co[2]*= rad;
+		}
+		else if(rad< 0.0) {  /* fractal subdivide */
+			fac= rad* VecLenf(edge->v1->co, edge->v2->co);
+			vec1[0]= fac*(float)(0.5-BLI_drand());
+			vec1[1]= fac*(float)(0.5-BLI_drand());
+			vec1[2]= fac*(float)(0.5-BLI_drand());
+			VecAddf(co, co, vec1);
+		}
 
-handle case of one edge selected.
-*/
+	}
+}
 
-subdpattern t_1edge = {
-	{1, 1, 0, 0},
-	{-1, 3, -1, -1},
-	{0},
-	{-1, -1, -1, -1, -1, -1, -1, -1, -1},
-	4
-};
+/* assumes in the edge is the correct interpolated vertices already */
+/* percent defines the interpolation, rad and beauty are for special options */
+/* results in new vertex with correct coordinate, vertex normal and weight group info */
+static BMVert *bm_subdivide_edge_addvert(BMesh *bm, BMEdge *edge, float rad, 
+					 int beauty, float percent, BMEdge **out)
+{
+	BMVert *ev;
+//	float co[3];
+	
+	ev = BM_Split_Edge(bm, edge->v1, edge, out, percent, 1);
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list