[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20572] branches/bmesh/blender/source/ blender: Added a matrix slot type for bmops.

Joseph Eagar joeedh at gmail.com
Tue Jun 2 09:40:33 CEST 2009


Revision: 20572
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20572
Author:   joeedh
Date:     2009-06-02 09:40:32 +0200 (Tue, 02 Jun 2009)

Log Message:
-----------
Added a matrix slot type for bmops.  Coded a simple transform
bmop, that just multiplies input verts with a matrix.  Also
made a derivative translate bmop.

BMO_CallOpf now has a %s format code, which is used to
copy data from another slot.

Also cleaned the extrude code up some more, and restored extrude-repeat
(which is bound to ctrl-alt-4), though this doesn't work right yet
(the view matrix it uses is incorrect, or something like that).

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenlib/intern/arithb.c
    branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h
    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/intern/bmesh_operators_private.h
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
    branches/bmesh/blender/source/blender/editors/mesh/editmesh_add.c
    branches/bmesh/blender/source/blender/editors/mesh/mesh_ops.c
    branches/bmesh/blender/source/blender/editors/transform/transform_generics.c

Added Paths:
-----------
    branches/bmesh/blender/source/blender/bmesh/operators/utils.c

Modified: branches/bmesh/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/intern/arithb.c	2009-06-02 01:40:53 UTC (rev 20571)
+++ branches/bmesh/blender/source/blender/blenlib/intern/arithb.c	2009-06-02 07:40:32 UTC (rev 20572)
@@ -872,7 +872,7 @@
 	vec[2]=(int)(x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2] + mat[3][2]);
 }
 
-void Mat4MulVecfl( float mat[][4], float *vec)
+void Mat4MulVecfl(float mat[][4], float *vec)
 {
 	float x,y;
 

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h	2009-06-02 01:40:53 UTC (rev 20571)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h	2009-06-02 07:40:32 UTC (rev 20572)
@@ -48,6 +48,7 @@
 #define BMOP_OPSLOT_INT			1
 #define BMOP_OPSLOT_FLT			2
 #define BMOP_OPSLOT_PNT			3
+#define BMOP_OPSLOT_MAT			4
 #define BMOP_OPSLOT_VEC			7
 
 /*after BMOP_OPSLOT_VEC, everything is 
@@ -159,6 +160,13 @@
 	  %hv will do verts, etc.  must pass in at least one
 	  element type letter.
      %f[f/e/v] - same as %h.
+     %v - pointer to a float vector of length 3.
+     %m[3/4] - matrix, 3/4 refers to the matrix size, 3 or 4.  the
+               corrusponding argument must be a pointer to
+	       a float matrix.
+     %s - copy a slot from another op, instead of mapping to one
+          argument, it maps to two, a pointer to an operator and
+	  a slot name.
 */
 /*executes an operator*/
 int BMO_CallOpf(BMesh *bm, char *fmt, ...);
@@ -196,6 +204,13 @@
 void BMO_Set_Vec(struct BMOperator *op, char *slotname, float *vec);
 void BMO_Get_Vec(BMOperator *op, char *slotname, float *vec_out);
 
+/*only supports square mats*/
+/*size must be 3 or 4; this api is meant only for transformation matrices.
+  note that internally the matrix is stored in 4x4 form, and it's safe to
+  call whichever BMO_Get_Mat* function you want.*/
+void BMO_Set_Mat(struct BMOperator *op, char *slotname, float *mat, int size);
+void BMO_Get_Mat4(struct BMOperator *op, char *slotname, float mat[4][4]);
+void BMO_Get_Mat3(struct BMOperator *op, char *slotname, float mat[3][3]);
 
 /*puts every element of type type (which is a bitmask) with tool flag flag,
   into a slot.*/

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-06-02 01:40:53 UTC (rev 20571)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-06-02 07:40:32 UTC (rev 20572)
@@ -3,15 +3,35 @@
 
 #include <stdio.h>
 
+/*applies a transform to vertices*/
+
+BMOpDefine def_translate= {
+	"translate",
+	{{BMOP_OPSLOT_VEC, "vec"},
+	{BMOP_OPSLOT_ELEMENT_BUF, "verts"},
+	{0, /*null-terminating sentinel*/}},
+	bmesh_translate_exec,
+	0,
+};
+
+
+BMOpDefine def_transform = {
+	"transform",
+	{{BMOP_OPSLOT_MAT, "mat"},
+	{BMOP_OPSLOT_ELEMENT_BUF, "verts"},
+	{0, /*null-terminating sentinel*/}},
+	bmesh_transform_exec,
+	0,
+};
+
 /*loads a bmesh into an object*/
 BMOpDefine def_object_load_bmesh = {
 	"object_load_bmesh",
-	/*pointer to a mesh struct*/
 	{{BMOP_OPSLOT_PNT, "scene"},
 	{BMOP_OPSLOT_PNT, "object"},
 	{0, /*null-terminating sentinel*/}},
 	bmesh_to_mesh_exec,
-	0
+	0,
 };
 
 
@@ -191,6 +211,8 @@
 	&def_extrudeverts_indiv,
 	&def_mesh_to_bmesh,
 	&def_object_load_bmesh,
+	&def_transform,
+	&def_translate,
 };
 
 int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-06-02 01:40:53 UTC (rev 20571)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-06-02 07:40:32 UTC (rev 20572)
@@ -1,5 +1,6 @@
 #include "MEM_guardedalloc.h"
 
+#include "BLI_arithb.h"
 #include "BLI_memarena.h"
 #include "BLI_mempool.h"
 #include "BLI_blenlib.h"
@@ -259,7 +260,46 @@
 	slot->data.i = i;
 }
 
+/*only supports square mats*/
+void BMO_Set_Mat(struct BMOperator *op, char *slotname, float *mat, int size)
+{
+	BMOpSlot *slot = BMO_GetSlot(op, slotname);
+	if( !(slot->slottype == BMOP_OPSLOT_MAT) )
+		return 0;
 
+	slot->len = 4;
+	slot->data.p = BLI_memarena_alloc(op->arena, sizeof(float)*4*4);
+	
+	if (size == 4) {
+		memcpy(slot->data.p, mat, sizeof(float)*4*4);
+	} else if (size == 3) {
+		Mat4CpyMat3(slot->data.p, mat);
+	} else {
+		printf("yeek! invalid size in BMO_Set_Mat!\n");
+
+		memset(slot->data.p, 0, sizeof(float)*4*4);
+		return;
+	}
+}
+
+void BMO_Get_Mat4(struct BMOperator *op, char *slotname, float mat[4][4])
+{
+	BMOpSlot *slot = BMO_GetSlot(op, slotname);
+	if( !(slot->slottype == BMOP_OPSLOT_MAT) )
+		return;
+
+	memcpy(mat, slot->data.p, sizeof(float)*4*4);
+}
+
+void BMO_Get_Mat3(struct BMOperator *op, char *slotname, float mat[3][3])
+{
+	BMOpSlot *slot = BMO_GetSlot(op, slotname);
+	if( !(slot->slottype == BMOP_OPSLOT_MAT) )
+		return;
+
+	Mat3CpyMat4(mat, slot->data.p);
+}
+
 void BMO_Set_Pnt(BMOperator *op, char *slotname, void *p)
 {
 	BMOpSlot *slot = BMO_GetSlot(op, slotname);
@@ -1028,6 +1068,33 @@
 			case '=':
 			case '%':
 				break;
+			case 'm': {
+				int size, c;
+				
+				c = nextc(fmt);
+				fmt++;
+
+				if (c == '3') size = 3;
+				else if (c == '4') size = 4;
+				else goto error;
+
+				BMO_Set_Mat(op, slotname, va_arg(vlist, void*), size);
+				state = 1;
+				break;
+			}
+			case 'v': {
+				BMO_Set_Vec(op, slotname, va_arg(vlist, float*));
+				state = 1;
+				break;
+			}
+			case 's': {
+				BMOperator *op2 = va_arg(vlist, void*);
+				char *slotname2 = va_arg(vlist, char*);
+
+				BMO_CopySlot(op2, op, slotname2, slotname);
+				state = 1;
+				break;
+			}
 			case 'i':
 			case 'd':
 				BMO_Set_Int(op, slotname, va_arg(vlist, int));

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2009-06-02 01:40:53 UTC (rev 20571)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2009-06-02 07:40:32 UTC (rev 20572)
@@ -23,5 +23,7 @@
 void extrude_vert_indiv_exec(BMesh *bm, BMOperator *op);
 void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op);
 void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op);
+void bmesh_translate_exec(BMesh *bm, BMOperator *op);
+void bmesh_transform_exec(BMesh *bm, BMOperator *op);
 
 #endif

Added: branches/bmesh/blender/source/blender/bmesh/operators/utils.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/utils.c	                        (rev 0)
+++ branches/bmesh/blender/source/blender/bmesh/operators/utils.c	2009-06-02 07:40:32 UTC (rev 20572)
@@ -0,0 +1,63 @@
+
+#include "MEM_guardedalloc.h"
+#include "BKE_customdata.h" 
+#include "DNA_listBase.h"
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include <string.h>
+#include "BKE_utildefines.h"
+#include "BKE_mesh.h"
+#include "BKE_global.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_cdderivedmesh.h"
+
+#include "BLI_editVert.h"
+#include "mesh_intern.h"
+#include "ED_mesh.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+#include "BLI_edgehash.h"
+
+#include "bmesh.h"
+
+/*
+ * UTILS.C
+ *
+ * utility bmesh operators, e.g. transform, 
+ * translate, rotate, scale, etc.
+ *
+*/
+
+void bmesh_transform_exec(BMesh *bm, BMOperator *op) {
+	BMOIter iter;
+	BMVert *v;
+	float mat[4][4];
+
+	BMO_Get_Mat4(op, "mat", mat);
+
+	BMO_ITER(v, &iter, bm, op, "verts") {
+		Mat4MulVecfl(mat, v->co);
+	}
+}
+
+/*this operator calls the transform operator, which
+  is a little complex, but makes it easier to make
+  sure the transform op is working, since initially
+  only this one will be used.*/
+void bmesh_translate_exec(BMesh *bm, BMOperator *op) {
+	BMOIter iter;
+	BMVert *v;
+	float mat[4][4], vec[3];
+	
+	BMO_Get_Vec(op, "offset", vec);
+
+	Mat4One(mat);
+	VECCOPY(mat[3], vec);
+
+	BMO_CallOpf(bm, "transform mat=%m4 verts=%s", mat, op, "verts");
+}
+

Modified: branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2009-06-02 01:40:53 UTC (rev 20571)
+++ branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c	2009-06-02 07:40:32 UTC (rev 20572)
@@ -466,7 +466,7 @@
 	return 'g'; // g is grab
 }
 
-short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, int eflag, float *nor)
+short EDBM_Extrude_edge(Object *obedit, BMEditMesh *em, int flag, float *nor)
 {
 	BMesh *bm = em->bm;
 	BMIter iter;
@@ -475,24 +475,9 @@
 	BMVert *vert;
 	BMEdge *edge;
 	BMFace *f;
-	void *el;
 	ModifierData *md;
-	int flag;
+	BMHeader *el;
 	
-	switch (eflag) {
-		case SELECT:
-			flag = BM_SELECT;
-			break;
-		default:
-			flag = BM_SELECT;
-			break;
-	}
-
-	for (f=BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL);f;f=BMIter_Step(&iter)) {
-		add_normal_aligned(nor, f->no);
-	}
-	Normalize(nor);
-
 	BMO_Init_Op(&extop, "extrudefaceregion");
 	BMO_HeaderFlag_To_Slot(bm, &extop, "edgefacein",
 		               flag, BM_VERT|BM_EDGE|BM_FACE);
@@ -561,10 +546,19 @@
 
 	BMO_Exec_Op(bm, &extop);
 
+	nor[0] = nor[1] = nor[2] = 0.0f;
+	
 	BMO_ITER(el, &siter, bm, &extop, "geomout") {
 		BM_Select(bm, el, 1);
+
+		if (el->type == BM_FACE) {
+			f = (BMFace*)el;
+			add_normal_aligned(nor, f->no);
+		};
 	}
 
+	Normalize(nor);
+
 	BMO_Finish_Op(bm, &extop);
 
 	if(nor[0]==0.0 && nor[1]==0.0 && nor[2]==0.0) return 'g'; // grab
@@ -580,29 +574,6 @@
 		eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL);
 		for ( ; eed; eed=BMIter_Step(&iter)) {
 			if (BM_TestHFlag(eed, flag)) {
-				BM_SetHFlag(eed->v1, flag);
-				BM_SetHFlag(eed->v2, flag);
-			} else {
-				if (BM_TestHFlag(eed->v1, flag) && BM_TestHFlag(eed->v2, flag))
-					BM_SetHFlag(eed, flag);
-			}
-		}
-
-		return EDBM_Extrude_edge(obedit, em, flag, nor);
-
-}
-
-/* generic extrude */
-short EDBM_Extrude(Object *obedit, BMEditMesh *em, short flag, float *nor)
-{
-	if(em->selectmode & SCE_SELECT_VERTEX) {
-		BMIter iter;
-		BMEdge *eed;
-		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list