[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18264] branches/bmesh/bmesh: Pattern-based subdivider works.

Joseph Eagar joeedh at gmail.com
Fri Jan 2 16:25:58 CET 2009


Revision: 18264
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18264
Author:   joeedh
Date:     2009-01-02 16:25:58 +0100 (Fri, 02 Jan 2009)

Log Message:
-----------
Pattern-based subdivider works.  Included is a 
version of editmesh_tools.c (based off of trunk)
that uses it.

I had to write a new function, BM_Connect_Edges,
that connects two verts automagically (without
knowing the shared face beforehand) for it to work.

Some issues:
We need to figure out how BM_Split_Edge/Face 
should handle flags.

Customdata isn't being handle properly, most likely
int the conversion functions.

There's memory leak warnings on exit.

Modified Paths:
--------------
    branches/bmesh/bmesh/bmesh.h
    branches/bmesh/bmesh/bmesh_marking.h
    branches/bmesh/bmesh/bmesh_operators.h
    branches/bmesh/bmesh/intern/bmesh_iterators.c
    branches/bmesh/bmesh/intern/bmesh_mesh.c
    branches/bmesh/bmesh/intern/bmesh_mods.c
    branches/bmesh/bmesh/intern/bmesh_operators.c
    branches/bmesh/bmesh/intern/bmesh_to_editmesh.c
    branches/bmesh/bmesh/operators/subdivideop.c

Added Paths:
-----------
    branches/bmesh/bmesh/editmesh_tools.c

Modified: branches/bmesh/bmesh/bmesh.h
===================================================================
--- branches/bmesh/bmesh/bmesh.h	2009-01-02 14:48:03 UTC (rev 18263)
+++ branches/bmesh/bmesh/bmesh.h	2009-01-02 15:25:58 UTC (rev 18264)
@@ -214,12 +214,17 @@
 void BM_Collapse_Vert(struct BMesh *bm, struct BMEdge *ke, struct BMVert *kv, float fac, int calcnorm);
 struct BMVert *BM_Split_Edge(struct BMesh *bm, struct BMVert *v, struct BMEdge *e, struct BMEdge **ne, float percent, int calcnorm);
 struct BMVert  *BM_Split_Edge_Multi(struct BMesh *bm, struct BMEdge *e, int numcuts);
+BMEdge *BM_Connect_Verts(BMesh *bm, BMVert *v1, BMVert *v2, BMFace **nf);
 
 /*Interpolation*/
 void BM_Data_Interp_From_Verts(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, float fac);
 void BM_Data_Facevert_Edgeinterp(struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, struct BMEdge *e1, float fac);
 //void bmesh_data_interp_from_face(struct BMesh *bm, struct BMFace *source, struct BMFace *target);
 
+struct EditMesh;
+BMesh *editmesh_to_bmesh(struct EditMesh *em);
+struct EditMesh *bmesh_to_editmesh(BMesh *bm);
+
 /*include the rest of the API*/
 #include "bmesh_filters.h"
 #include "bmesh_iterators.h"

Modified: branches/bmesh/bmesh/bmesh_marking.h
===================================================================
--- branches/bmesh/bmesh/bmesh_marking.h	2009-01-02 14:48:03 UTC (rev 18263)
+++ branches/bmesh/bmesh/bmesh_marking.h	2009-01-02 15:25:58 UTC (rev 18264)
@@ -8,5 +8,6 @@
 void BM_Selectmode_Set(struct BMesh *bm, int selectmode);
 
 void BM_Select(struct BMesh *bm, void *element, int select);
+int BM_Is_Selected(BMesh *bm, void *element);
 
 #endif

Modified: branches/bmesh/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/bmesh/bmesh_operators.h	2009-01-02 14:48:03 UTC (rev 18263)
+++ branches/bmesh/bmesh/bmesh_operators.h	2009-01-02 15:25:58 UTC (rev 18264)
@@ -59,6 +59,7 @@
 void BMO_CopySlot(struct BMOperator *source_op, struct BMOperator *dest_op, int src, int dst);
 void BMO_Set_Float(struct BMOperator *op, int slotcode, float f);
 void BMO_Set_Int(struct BMOperator *op, int slotcode, int i);
+void BMO_Set_PntBuf(struct BMOperator *op, int slotcode, void *p, int len);
 void BMO_Set_Pnt(struct BMOperator *op, int slotcode, void *p);
 void BMO_Set_Vec(struct BMOperator *op, int slotcode, float *vec);
 void BMO_SetFlag(struct BMesh *bm, void *element, int flag);

Added: branches/bmesh/bmesh/editmesh_tools.c
===================================================================
--- branches/bmesh/bmesh/editmesh_tools.c	                        (rev 0)
+++ branches/bmesh/bmesh/editmesh_tools.c	2009-01-02 15:25:58 UTC (rev 18264)
@@ -0,0 +1,7239 @@
+/**
+ * $Id: 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2004 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Johnny Matthews, Geoffrey Bantle.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/*
+
+editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise in mods.c
+
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "MEM_guardedalloc.h"
+
+#include "BMF_Api.h"
+#include "DNA_mesh_types.h"
+#include "DNA_material_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_key_types.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+#include "BLI_editVert.h"
+#include "BLI_rand.h"
+#include "BLI_ghash.h"
+#include "BLI_linklist.h"
+#include "BLI_heap.h"
+
+#include "BKE_depsgraph.h"
+#include "BKE_customdata.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_utildefines.h"
+#include "BKE_bmesh.h"
+
+#ifdef WITH_VERSE
+#include "BKE_verse.h"
+#endif
+
+#include "BIF_cursors.h"
+#include "BIF_editmesh.h"
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+#include "BIF_graphics.h"
+#include "BIF_interface.h"
+#include "BIF_mywindow.h"
+#include "BIF_screen.h"
+#include "BIF_space.h"
+#include "BIF_resources.h"
+#include "BIF_toolbox.h"
+#include "BIF_transform.h"
+#include "transform.h"
+
+#ifdef WITH_VERSE
+#include "BIF_verse.h"
+#endif
+
+#include "BDR_drawobject.h"
+#include "BDR_editobject.h"
+
+#include "BSE_view.h"
+#include "BSE_edit.h"
+
+#include "blendef.h"
+#include "multires.h"
+#include "mydevice.h"
+
+#include "editmesh.h"
+
+#include "MTC_vectorops.h"
+
+#include "PIL_time.h"
+
+#include "BLO_sys_types.h" // for intptr_t support
+
+/* local prototypes ---------------*/
+void bevel_menu(void);
+static void free_tagged_edges_faces(EditEdge *eed, EditFace *efa);
+
+/********* qsort routines *********/
+
+
+typedef struct xvertsort {
+	float x;
+	EditVert *v1;
+} xvertsort;
+
+static int vergxco(const void *v1, const void *v2)
+{
+	const xvertsort *x1=v1, *x2=v2;
+
+	if( x1->x > x2->x ) return 1;
+	else if( x1->x < x2->x) return -1;
+	return 0;
+}
+
+struct facesort {
+	uintptr_t x;
+	struct EditFace *efa;
+};
+
+
+static int vergface(const void *v1, const void *v2)
+{
+	const struct facesort *x1=v1, *x2=v2;
+	
+	if( x1->x > x2->x ) return 1;
+	else if( x1->x < x2->x) return -1;
+	return 0;
+}
+
+
+/* *********************************** */
+
+void convert_to_triface(int direction)
+{
+	EditMesh *em = G.editMesh;
+	EditFace *efa, *efan, *next;
+	float fac;
+	
+	if(multires_test()) return;
+	
+	efa= em->faces.last;
+	while(efa) {
+		next= efa->prev;
+		if(efa->v4) {
+			if(efa->f & SELECT) {
+				/* choose shortest diagonal for split */
+				fac= VecLenf(efa->v1->co, efa->v3->co) - VecLenf(efa->v2->co, efa->v4->co);
+				/* this makes sure exact squares get split different in both cases */
+				if( (direction==0 && fac<FLT_EPSILON) || (direction && fac>0.0f) ) {
+					efan= EM_face_from_faces(efa, NULL, 0, 1, 2, -1);
+					if(efa->f & SELECT) EM_select_face(efan, 1);
+					efan= EM_face_from_faces(efa, NULL, 0, 2, 3, -1);
+					if(efa->f & SELECT) EM_select_face(efan, 1);
+				}
+				else {
+					efan= EM_face_from_faces(efa, NULL, 0, 1, 3, -1);
+					if(efa->f & SELECT) EM_select_face(efan, 1);
+					efan= EM_face_from_faces(efa, NULL, 1, 2, 3, -1);
+					if(efa->f & SELECT) EM_select_face(efan, 1);
+				}
+				
+				BLI_remlink(&em->faces, efa);
+				free_editface(efa);
+			}
+		}
+		efa= next;
+	}
+	
+	EM_fgon_flags();	// redo flags and indices for fgons
+
+#ifdef WITH_VERSE
+	if(G.editMesh->vnode)
+		sync_all_versefaces_with_editfaces((VNode*)G.editMesh->vnode);
+#endif
+	BIF_undo_push("Convert Quads to Triangles");
+	
+}
+
+int removedoublesflag(short flag, short automerge, float limit)		/* return amount */
+{
+	/*
+		flag -		Test with vert->flags
+		automerge -	Alternative operation, merge unselected into selected.
+					Used for "Auto Weld" mode. warning.
+		limit -		Quick manhattan distance between verts.
+	*/
+	
+	EditMesh *em = G.editMesh;
+	/* all verts with (flag & 'flag') are being evaluated */
+	EditVert *eve, *v1, *nextve;
+	EditEdge *eed, *e1, *nexted;
+	EditFace *efa, *nextvl;
+	xvertsort *sortblock, *sb, *sb1;
+	struct facesort *vlsortblock, *vsb, *vsb1;
+	int a, b, test, amount;
+	
+	if(multires_test()) return 0;
+
+	
+	/* flag 128 is cleared, count */
+
+	/* Normal non weld operation */
+	eve= em->verts.first;
+	amount= 0;
+	while(eve) {
+		eve->f &= ~128;
+		if(eve->h==0 && (automerge || (eve->f & flag))) amount++;
+		eve= eve->next;
+	}
+	if(amount==0) return 0;
+
+	/* allocate memory and qsort */
+	sb= sortblock= MEM_mallocN(sizeof(xvertsort)*amount,"sortremovedoub");
+	eve= em->verts.first;
+	while(eve) {
+		if(eve->h==0 && (automerge || (eve->f & flag))) {
+			sb->x= eve->co[0]+eve->co[1]+eve->co[2];
+			sb->v1= eve;
+			sb++;
+		}
+		eve= eve->next;
+	}
+	qsort(sortblock, amount, sizeof(xvertsort), vergxco);
+
+	
+	/* test for doubles */
+	sb= sortblock;	
+	if (automerge) {
+		for(a=0; a<amount; a++, sb++) {
+			eve= sb->v1;
+			if( (eve->f & 128)==0 ) {
+				sb1= sb+1;
+				for(b=a+1; b<amount && (eve->f & 128)==0; b++, sb1++) {
+					if(sb1->x - sb->x > limit) break;
+					
+					/* when automarge, only allow unselected->selected */
+					v1= sb1->v1;
+					if( (v1->f & 128)==0 ) {
+						if ((eve->f & flag)==0 && (v1->f & flag)==1) {
+							if(	(float)fabs(v1->co[0]-eve->co[0])<=limit && 
+								(float)fabs(v1->co[1]-eve->co[1])<=limit &&
+								(float)fabs(v1->co[2]-eve->co[2])<=limit)
+							{	/* unique bit */
+								eve->f|= 128;
+								eve->tmp.v = v1;
+							}
+						} else if(	(eve->f & flag)==1 && (v1->f & flag)==0 ) {
+							if(	(float)fabs(v1->co[0]-eve->co[0])<=limit && 
+								(float)fabs(v1->co[1]-eve->co[1])<=limit &&
+								(float)fabs(v1->co[2]-eve->co[2])<=limit)
+							{	/* unique bit */
+								v1->f|= 128;
+								v1->tmp.v = eve;
+							}
+						}
+					}
+				}
+			}
+		}
+	} else {
+		for(a=0; a<amount; a++, sb++) {
+			eve= sb->v1;
+			if( (eve->f & 128)==0 ) {
+				sb1= sb+1;
+				for(b=a+1; b<amount; b++, sb1++) {
+					/* first test: simpel dist */
+					if(sb1->x - sb->x > limit) break;
+					v1= sb1->v1;
+					
+					/* second test: is vertex allowed */
+					if( (v1->f & 128)==0 ) {
+						if(	(float)fabs(v1->co[0]-eve->co[0])<=limit && 
+							(float)fabs(v1->co[1]-eve->co[1])<=limit &&
+							(float)fabs(v1->co[2]-eve->co[2])<=limit)
+						{
+							v1->f|= 128;
+							v1->tmp.v = eve;
+						}
+					}
+				}
+			}
+		}
+	}
+	MEM_freeN(sortblock);
+	
+	if (!automerge)
+		for(eve = em->verts.first; eve; eve=eve->next)
+			if((eve->f & flag) && (eve->f & 128))

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list