[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10866] branches/bmesh/source/blender/ python/api2_2x: Experemental BMesh api
Campbell Barton
cbarton at metavr.com
Sun Jun 3 16:44:06 CEST 2007
Revision: 10866
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=10866
Author: campbellbarton
Date: 2007-06-03 16:44:06 +0200 (Sun, 03 Jun 2007)
Log Message:
-----------
Experemental BMesh api
Added Paths:
-----------
branches/bmesh/source/blender/python/api2_2x/BMesh.c
branches/bmesh/source/blender/python/api2_2x/BMesh.h
Added: branches/bmesh/source/blender/python/api2_2x/BMesh.c
===================================================================
--- branches/bmesh/source/blender/python/api2_2x/BMesh.c (rev 0)
+++ branches/bmesh/source/blender/python/api2_2x/BMesh.c 2007-06-03 14:44:06 UTC (rev 10866)
@@ -0,0 +1,1949 @@
+/*
+ * ***** BEGIN GPL/BL DUAL 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. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * 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) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * This is a new part of Blender.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#include "BMesh.h" /* This must come first */
+#include "Mathutils.h" /* This must come first */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_meshdata_types.h"
+
+#include "BKE_mesh.h"
+#include "BKE_library.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+#include "BKE_bmesh.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+
+#include "blendef.h"
+#include "Object.h"
+#include "gen_utils.h"
+#include "gen_library.h"
+
+
+/* bmesh spesific includes */
+#include "BKE_bmesh.h"
+
+#define BMESH_SEQ_NORMAL 0
+#define BMESH_SEQ_SELECTED 1
+#define BMESH_SEQ_UNSELECTED 2
+#define BMESH_SEQ_VISIBLE 3
+#define BMESH_SEQ_HIDDEN 4
+
+/* easy way to get the next selected or hidden item */
+#define NEXT_FLAGGED(lb_item, f) \
+ while ((lb_item) && ((lb_item)->flag & f)==0) (lb_item) = (lb_item)->next;
+
+#define NEXT_UNFLAGGED(lb_item, f) \
+ while ((lb_item) && ((lb_item)->flag & f)==1) (lb_item) = (lb_item)->next;
+
+/* This advances to the next item based on context */
+#define NEXT_MODE(mode, iter)\
+ switch (mode) {\
+ case BMESH_SEQ_NORMAL:\
+ break;\
+ case BMESH_SEQ_SELECTED:\
+ NEXT_FLAGGED(iter, SELECT);\
+ break;\
+ case BMESH_SEQ_UNSELECTED:\
+ NEXT_UNFLAGGED(iter, SELECT);\
+ break;\
+ case BMESH_SEQ_VISIBLE:\
+ NEXT_UNFLAGGED(iter, ME_HIDE);\
+ break;\
+ case BMESH_SEQ_HIDDEN:\
+ NEXT_FLAGGED(iter, ME_HIDE);\
+ break;\
+ }\
+
+/*
+ * Python API function prototypes for the Blender module.
+ */
+/*static PyObject *M_BMesh_New( PyObject * self, PyObject * args );*/
+PyObject *M_BMesh_GetEditMesh( PyObject * self, PyObject * args );
+
+/* CreatePyObject */
+PyObject *BMesh_CreatePyObject( BME_Mesh * bmesh )
+{
+ BPy_BMesh *bpybmesh;
+
+ if( !bmesh )
+ Py_RETURN_NONE;
+
+ bpybmesh = ( BPy_BMesh * ) PyObject_NEW( BPy_BMesh, &BMesh_Type );
+
+ if( bpybmesh == NULL ) {
+ return ( NULL );
+ }
+ bpybmesh->bmesh= bmesh;
+ return ( ( PyObject * ) bpybmesh );
+}
+
+PyObject *BMesh_Vert_CreatePyObject( BME_Vert *data)
+{
+ BPy_BMesh_Vert *value = PyObject_NEW( BPy_BMesh_Vert, &BMesh_Vert_Type);
+ value->bvert= data;
+ return (PyObject *)value;
+}
+PyObject *BMesh_Edge_CreatePyObject( BME_Edge *data)
+{
+ BPy_BMesh_Edge *value = PyObject_NEW( BPy_BMesh_Edge, &BMesh_Edge_Type);
+ value->bedge= data;
+ return (PyObject *)value;
+}
+
+PyObject *BMesh_Loop_CreatePyObject( BME_Loop *data)
+{
+ BPy_BMesh_Loop *value = PyObject_NEW( BPy_BMesh_Loop, &BMesh_Loop_Type);
+ value->bloop= data;
+ return (PyObject *)value;
+}
+
+PyObject *BMesh_Poly_CreatePyObject( BME_Poly *data)
+{
+ BPy_BMesh_Poly *value = PyObject_NEW( BPy_BMesh_Poly, &BMesh_Poly_Type);
+ value->bpoly= data;
+ return (PyObject *)value;
+}
+
+PyObject *BMesh_VertSeq_CreatePyObject( BME_Mesh *bmesh, BME_Vert *iter, void * mode)
+{
+ BPy_BMesh_VertSeq *value = PyObject_NEW( BPy_BMesh_VertSeq, &BMesh_VertSeq_Type);
+ value->bmesh= bmesh;
+ value->iter= iter;
+ value->mode= (long)mode;
+ return (PyObject *)value;
+}
+PyObject *BMesh_EdgeSeq_CreatePyObject( BME_Mesh *bmesh, BME_Edge *iter, void * mode)
+{
+ BPy_BMesh_EdgeSeq *value = PyObject_NEW( BPy_BMesh_EdgeSeq, &BMesh_EdgeSeq_Type);
+ value->bmesh= bmesh;
+ value->iter= iter;
+ value->mode= (long)mode;
+ return (PyObject *)value;
+}
+PyObject *BMesh_LoopSeq_CreatePyObject( BME_Loop *iter )
+{
+ BPy_BMesh_LoopSeq *value = PyObject_NEW( BPy_BMesh_LoopSeq, &BMesh_LoopSeq_Type);
+ value->iter= iter;
+ value->iter_init= iter; /* this is a reference */
+ return (PyObject *)value;
+}
+PyObject *BMesh_PolySeq_CreatePyObject( BME_Mesh *bmesh, BME_Poly *iter, void * mode)
+{
+ BPy_BMesh_PolySeq *value = PyObject_NEW( BPy_BMesh_PolySeq, &BMesh_PolySeq_Type);
+ value->bmesh= bmesh;
+ value->iter= iter;
+ value->mode= (long)mode;
+ return (PyObject *)value;
+}
+
+
+static void BMesh_dealloc( BPy_BMesh * self )
+{
+ PyObject_DEL( self );
+}
+
+static void BMesh_Vert_dealloc( BPy_BMesh_Vert* self )
+{
+ PyObject_DEL( self );
+}
+
+static void BMesh_Edge_dealloc( BPy_BMesh_Edge* self )
+{
+ PyObject_DEL( self );
+}
+static void BMesh_Loop_dealloc( BPy_BMesh_Loop* self )
+{
+ PyObject_DEL( self );
+}
+static void BMesh_Poly_dealloc( BPy_BMesh_Poly* self )
+{
+ PyObject_DEL( self );
+}
+
+static void BMesh_VertSeq_dealloc( BPy_BMesh_VertSeq * self )
+{
+ PyObject_DEL( self );
+}
+
+static void BMesh_EdgeSeq_dealloc( BPy_BMesh_EdgeSeq * self )
+{
+ PyObject_DEL( self );
+}
+static void BMesh_LoopSeq_dealloc( BPy_BMesh_LoopSeq * self )
+{
+ PyObject_DEL( self );
+}
+static void BMesh_PolySeq_dealloc( BPy_BMesh_PolySeq * self )
+{
+ PyObject_DEL( self );
+}
+
+/*
+ * Visible Methods for BMesh datatypes
+ */
+PyObject *BMesh_Poly_flip( BPy_BMesh_Poly *self )
+{
+ if (BME_loop_reverse(self->bmesh, self->bpoly))
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
+
+
+PyObject *BMesh_VertSeq_add( BPy_BMesh_VertSeq *self, PyObject * args)
+{
+ VectorObject *vec=NULL;
+
+ if(!PyArg_ParseTuple(args, "O!", &vector_Type, &vec) || vec->size != 3)
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "bmesh.verts.add expects a 3D vector\n");
+
+ return BMesh_Vert_CreatePyObject( BME_MV(self->bmesh, vec->vec) );
+}
+
+PyObject *BMesh_VertSeq_remove( BPy_BMesh_VertSeq *self, PyObject * args)
+{
+ BPy_BMesh_Vert *bpybvert;
+
+ if(!PyArg_ParseTuple(args, "O!", &BMesh_Vert_Type, &bpybvert))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "bmesh.verts.remove expects a bmesh vertex\n");
+
+ if (BME_KV(self->bmesh, bpybvert->bvert))
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
+
+PyObject *BMesh_VertSeq_transform( BPy_BMesh_VertSeq *self, PyObject * args)
+{
+ MatrixObject *bpymat=NULL;
+ BME_Vert *bvert = self->bmesh->verts.first;
+
+ if(!PyArg_ParseTuple(args, "O!", &matrix_Type, &bpymat))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "bmesh.verts.transform expects a matrix\n");
+
+ if( bpymat->colSize != 4 || bpymat->rowSize != 4 )
+ return EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "matrix must be a 4x4 transformation matrix\n"
+ "for example as returned by object.getMatrix()" );
+
+
+ switch (self->mode) {
+ case BMESH_SEQ_NORMAL:
+ for (;bvert;bvert=bvert->next)
+ Mat4MulVecfl( (float(*)[4])*bpymat->matrix, bvert->co );
+ break;
+ case BMESH_SEQ_SELECTED:
+ for (;bvert;bvert=bvert->next)
+ if (bvert->flag & SELECT)
+ Mat4MulVecfl( (float(*)[4])*bpymat->matrix, bvert->co );
+ break;
+ case BMESH_SEQ_UNSELECTED:
+ for (;bvert;bvert=bvert->next)
+ if ((bvert->flag & SELECT)==0)
+ Mat4MulVecfl( (float(*)[4])*bpymat->matrix, bvert->co );
+ break;
+ case BMESH_SEQ_VISIBLE:
+ for (;bvert;bvert=bvert->next)
+ if ((bvert->flag & ME_HIDE)==0)
+ Mat4MulVecfl( (float(*)[4])*bpymat->matrix, bvert->co );
+ break;
+ case BMESH_SEQ_HIDDEN:
+ for (;bvert;bvert=bvert->next)
+ if (bvert->flag & ME_HIDE)
+ Mat4MulVecfl( (float(*)[4])*bpymat->matrix, bvert->co );
+ break;
+ }
+
+ Py_RETURN_NONE;
+}
+
+
+PyObject *BMesh_EdgeSeq_add( BPy_BMesh_VertSeq *self, PyObject * args)
+{
+ BPy_BMesh_Vert *bpybvert1, *bpybvert2;
+ BME_Edge *bedge;
+ if(!PyArg_ParseTuple(args, "O!O!", &BMesh_Vert_Type, &bpybvert1,
+ &BMesh_Vert_Type, &bpybvert2))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "bmesh.edges.add expects 2 bmesh verts\n");
+ bedge = BME_ME(self->bmesh, bpybvert1->bvert, bpybvert2->bvert);
+
+ if (bedge)
+ return BMesh_Edge_CreatePyObject(bedge);
+ Py_RETURN_NONE;
+}
+
+PyObject *BMesh_EdgeSeq_remove( BPy_BMesh_VertSeq *self, PyObject * args)
+{
+ BPy_BMesh_Edge *bpybedge;
+ if(!PyArg_ParseTuple(args, "O!", &BMesh_Edge_Type, &bpybedge))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "bmesh.edges.remove expects 1 edge\n");
+
+ if (BME_KE(self->bmesh, bpybedge->bedge))
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
+PyObject *BMesh_PolySeq_add( BPy_BMesh_VertSeq *self, PyObject * args)
+{
+ BPy_BMesh_Vert *bpybvert1, *bpybvert2;
+ PyObject *pylist, *list_item;
+ BME_Edge **edge_array;
+ BME_Poly *new_poly;
+ int list_len, i, final_list_len;
+
+ if(!PyArg_ParseTuple(args, "O!O!O!",&BMesh_Vert_Type, &bpybvert1,
+ &BMesh_Vert_Type, &bpybvert2,
+ &PyList_Type, &pylist))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "bmesh.edges.add expects 2 bmesh verts and a list of edges\n");
+
+ list_len= PyList_Size(pylist);
+ edge_array = MEM_mallocN(sizeof(BME_Edge*)*list_len, "bmesh edge array");
+ for (i=0, final_list_len=0; i<list_len; i++) {
+ list_item= PyList_GET_ITEM(pylist, i);
+
+ if (BPy_BMesh_Edge_Check(list_item)) {
+ edge_array[final_list_len] = ((BPy_BMesh_Edge *)list_item)->bedge;
+ final_list_len++;
+ }
+ }
+
+ new_poly = BME_MF(self->bmesh, bpybvert1->bvert, bpybvert2->bvert, edge_array, final_list_len);
+ MEM_freeN(edge_array);
+
+ if (new_poly)
+ return BMesh_Poly_CreatePyObject(new_poly);
+
+ Py_RETURN_NONE;
+}
+PyObject *BMesh_PolySeq_remove( BPy_BMesh_VertSeq *self, PyObject * args)
+{
+ BPy_BMesh_Poly *bpybpoly;
+ if(!PyArg_ParseTuple(args, "O!", &BMesh_Poly_Type, &bpybpoly))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "bmesh.polys.remove expects 1 poly\n");
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list