[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44392] trunk/blender/source/blender: bmesh py api (some api changes and doc additions)

Campbell Barton ideasman42 at gmail.com
Fri Feb 24 06:56:16 CET 2012


Revision: 44392
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44392
Author:   campbellbarton
Date:     2012-02-24 05:56:06 +0000 (Fri, 24 Feb 2012)
Log Message:
-----------
bmesh py api (some api changes and doc additions)
* remove 'select' and 'hide' from BMLoop
* remove BMesh.update
* add BMesh.normal_update(skip_hidden=False)
* add BMElemSet.index_update(), eg: bm.verts.index_update()


bmesh api
* BM_mesh_normals_update() now takes skip_hidden as an argument
(previously this was default behavior), however this isnt good when
using BMesh modifiers, where you want all normals to be recalculated.
* add bm_iter_itype_htype_map[], to get the iter type from a BMesh
iterator.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/bmesh.h
    trunk/blender/source/blender/bmesh/bmesh_iterators.h
    trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c
    trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/mesh/bmesh_selecthistory.c
    trunk/blender/source/blender/editors/mesh/bmesh_tools.c
    trunk/blender/source/blender/editors/mesh/bmesh_utils.c
    trunk/blender/source/blender/editors/space_view3d/view3d_snap.c
    trunk/blender/source/blender/modifiers/intern/MOD_bevel.c
    trunk/blender/source/blender/modifiers/intern/MOD_edgesplit.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_types.h

Modified: trunk/blender/source/blender/bmesh/bmesh.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh.h	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/bmesh/bmesh.h	2012-02-24 05:56:06 UTC (rev 44392)
@@ -123,7 +123,7 @@
 
 /* frees mesh, but not actual BMesh struct */
 void BM_mesh_data_free(BMesh *bm);
-void BM_mesh_normals_update(BMesh *bm);
+void BM_mesh_normals_update(BMesh *bm, const short skip_hidden);
 
 /* Construction */
 BMVert *BM_vert_create(BMesh *bm, const float co[3], const BMVert *example);

Modified: trunk/blender/source/blender/bmesh/bmesh_iterators.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh_iterators.h	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/bmesh/bmesh_iterators.h	2012-02-24 05:56:06 UTC (rev 44392)
@@ -49,7 +49,9 @@
  */
 
 /* these iterator over all elements of a specific
- * type in the mesh.*/
+ * type in the mesh.
+ *
+ * be sure to keep 'bm_iter_itype_htype_map' in sync with any changes */
 typedef enum BMIterType {
 	BM_VERTS_OF_MESH = 1,
 	BM_EDGES_OF_MESH = 2,
@@ -74,7 +76,12 @@
 	BM_LOOPS_OF_EDGE = 14
 } BMIterType;
 
+#define BM_ITYPE_MAX 15
 
+/* the iterator htype for each iterator */
+extern const char bm_iter_itype_htype_map[BM_ITYPE_MAX];
+
+
 #define BM_ITER(ele, iter, bm, itype, data)                                   \
 	ele = BM_iter_new(iter, bm, itype, data);                                 \
 	for ( ; ele; ele=BM_iter_step(iter))

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_iterators.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -32,6 +32,24 @@
 #include "bmesh.h"
 #include "bmesh_private.h"
 
+const char bm_iter_itype_htype_map[BM_ITYPE_MAX] = {
+	'\0',
+	BM_VERT, /* BM_VERTS_OF_MESH */
+	BM_EDGE, /* BM_EDGES_OF_MESH */
+	BM_FACE, /* BM_FACES_OF_MESH */
+	BM_EDGE, /* BM_EDGES_OF_VERT */
+	BM_FACE, /* BM_FACES_OF_VERT */
+	BM_LOOP, /* BM_LOOPS_OF_VERT */
+	BM_VERT, /* BM_VERTS_OF_EDGE */
+	BM_FACE, /* BM_FACES_OF_EDGE */
+	BM_VERT, /* BM_VERTS_OF_FACE */
+	BM_EDGE, /* BM_EDGES_OF_FACE */
+	BM_LOOP, /* BM_LOOPS_OF_FACE */
+	BM_LOOP, /* BM_ALL_LOOPS_OF_FACE */
+	BM_LOOP, /* BM_LOOPS_OF_LOOP */
+	BM_LOOP  /* BM_LOOPS_OF_EDGE */
+};
+
 /*
  * note, we have BM_vert_at_index/BM_edge_at_index/BM_face_at_index for arrays
  */

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_mesh.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -208,7 +208,7 @@
  *
  */
 
-void BM_mesh_normals_update(BMesh *bm)
+void BM_mesh_normals_update(BMesh *bm, const short skip_hidden)
 {
 	BMVert *v;
 	BMFace *f;
@@ -225,7 +225,7 @@
 
 	/* first, find out the largest face in mesh */
 	BM_ITER(f, &faces, bm, BM_FACES_OF_MESH, NULL) {
-		if (BM_elem_flag_test(f, BM_ELEM_HIDDEN))
+		if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN))
 			continue;
 
 		if (f->len > maxlength) maxlength = f->len;
@@ -239,7 +239,7 @@
 	
 	/* calculate all face normals */
 	BM_ITER(f, &faces, bm, BM_FACES_OF_MESH, NULL) {
-		if (BM_elem_flag_test(f, BM_ELEM_HIDDEN))
+		if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN))
 			continue;
 #if 0	/* UNUSED */
 		if (f->head.flag & BM_NONORMCALC)
@@ -251,7 +251,7 @@
 	
 	/* Zero out vertex normals */
 	BM_ITER(v, &verts, bm, BM_VERTS_OF_MESH, NULL) {
-		if (BM_elem_flag_test(v, BM_ELEM_HIDDEN))
+		if (skip_hidden && BM_elem_flag_test(v, BM_ELEM_HIDDEN))
 			continue;
 
 		zero_v3(v->no);
@@ -280,7 +280,7 @@
 	/* add weighted face normals to vertices */
 	BM_ITER(f, &faces, bm, BM_FACES_OF_MESH, NULL) {
 
-		if (BM_elem_flag_test(f, BM_ELEM_HIDDEN))
+		if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN))
 			continue;
 
 		BM_ITER(l, &loops, bm, BM_LOOPS_OF_FACE, f) {
@@ -310,7 +310,7 @@
 	
 	/* normalize the accumulated vertex normals */
 	BM_ITER(v, &verts, bm, BM_VERTS_OF_MESH, NULL) {
-		if (BM_elem_flag_test(v, BM_ELEM_HIDDEN))
+		if (skip_hidden && BM_elem_flag_test(v, BM_ELEM_HIDDEN))
 			continue;
 
 		if (normalize_v3(v->no) == 0.0f) {
@@ -473,7 +473,7 @@
 	bm->opflag = 0;
 
 	/* compute normals, clear temp flags and flush selections */
-	BM_mesh_normals_update(bm);
+	BM_mesh_normals_update(bm, TRUE);
 	BM_mesh_select_mode_flush(bm);
 }
 

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2012-02-24 05:56:06 UTC (rev 44392)
@@ -157,7 +157,7 @@
 
 /**
  * Calculate the view transformation matrix from RegionView3D input.
- * The resulting matrix is equivilent to RegionView3D.viewinv
+ * The resulting matrix is equivalent to RegionView3D.viewinv
  * @param mat The view 4x4 transformation matrix to calculate.
  * @param ofs The view offset, normally from RegionView3D.ofs.
  * @param quat The view rotation, quaternion normally from RegionView3D.viewquat.

Modified: trunk/blender/source/blender/editors/mesh/bmesh_selecthistory.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/bmesh_selecthistory.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/editors/mesh/bmesh_selecthistory.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -30,7 +30,7 @@
 #include "BKE_tessmesh.h"
 
 
-/* these wrap equivilent bmesh functions.  I'm in two minds of it we should
+/* these wrap equivalent bmesh functions.  I'm in two minds of it we should
  * just use the bm functions directly; on the one hand, there's no real
  * need (at the moment) to wrap them, but on the other hand having these
  * wrapped avoids a confusing mess of mixing BM_ and EDBM_ namespaces. */

Modified: trunk/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/bmesh_tools.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/editors/mesh/bmesh_tools.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -3262,7 +3262,7 @@
 
 	EDBM_CallOpf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_VERTS);
 
-	BM_mesh_normals_update(bmnew);
+	BM_mesh_normals_update(bmnew, TRUE);
 	BMO_op_callf(bmnew, "bmesh_to_mesh mesh=%p object=%p notesselation=%b",
 	             basenew->object->data, basenew->object, TRUE);
 		

Modified: trunk/blender/source/blender/editors/mesh/bmesh_utils.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/bmesh_utils.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/editors/mesh/bmesh_utils.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -50,7 +50,7 @@
 
 void EDBM_RecalcNormals(BMEditMesh *em)
 {
-	BM_mesh_normals_update(em->bm);
+	BM_mesh_normals_update(em->bm, TRUE);
 }
 
 void EDBM_ClearMesh(BMEditMesh *em)

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_snap.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_snap.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_snap.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -102,7 +102,7 @@
 		
 		if (obedit->type==OB_MESH) {
 			Mesh *me= obedit->data;
-			BM_mesh_normals_update(me->edit_btmesh->bm);	// does face centers too
+			BM_mesh_normals_update(me->edit_btmesh->bm, TRUE);	// does face centers too
 		}
 		else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
 			Curve *cu= obedit->data;

Modified: trunk/blender/source/blender/modifiers/intern/MOD_bevel.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_bevel.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/modifiers/intern/MOD_bevel.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -121,7 +121,7 @@
 	em = DM_to_editbmesh(ob, dm, NULL, FALSE);
 	bm = em->bm;
 
-	BM_mesh_normals_update(bm);
+	BM_mesh_normals_update(bm, FALSE);
 	BMO_push(bm, NULL);
 
 	if (bmd->lim_flags & BME_BEVEL_ANGLE) {

Modified: trunk/blender/source/blender/modifiers/intern/MOD_edgesplit.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_edgesplit.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/modifiers/intern/MOD_edgesplit.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -69,7 +69,7 @@
 	em = DM_to_editbmesh(ob, dm, NULL, FALSE);
 	bm = em->bm;
 
-	BM_mesh_normals_update(bm);	
+	BM_mesh_normals_update(bm, FALSE);
 	BMO_push(bm, NULL);
 	
 	if (emd->flags & MOD_EDGESPLIT_FROMANGLE) {

Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types.c	2012-02-24 04:59:13 UTC (rev 44391)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types.c	2012-02-24 05:56:06 UTC (rev 44392)
@@ -159,7 +159,7 @@
 		return -1;
 	}
 	else {
-		BM_elem_index_set(self->ele, param);
+		BM_elem_index_set(self->ele, param); /* set_dirty! */
 
 		/* when setting the index assume its set invalid */
 		if (self->ele->htype & (BM_VERT | BM_EDGE | BM_FACE)) {
@@ -474,8 +474,9 @@
 
 static PyGetSetDef bpy_bmloop_getseters[] = {
     /* generic */
-    {(char *)"select", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_select_doc, (void *)BM_ELEM_SELECT},
-    {(char *)"hide",   (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_hide_doc,   (void *)BM_ELEM_SELECT},
+    // flags are available but not used for loops.
+    // {(char *)"select", (getter)bpy_bm_elem_hflag_get, (setter)bpy_bm_elem_hflag_set, (char *)bpy_bm_elem_select_doc, (void *)BM_ELEM_SELECT},

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list