initial bmesh python api.

corrently allows to create and loop over verts/edges/faces, access selection and selection modes.

this is still WIP, access to face, edge verts is still missing, no access to UV's, no access to editing operations yet.

When the api is ready it will be documented by sphinx like mathutils, blf, aud.
This commit is contained in:
Campbell Barton 2012-02-22 09:19:53 +00:00
parent 3788adb8cb
commit e7d98179ea
9 changed files with 1620 additions and 2 deletions

@ -19,3 +19,4 @@
add_subdirectory(intern)
add_subdirectory(generic)
add_subdirectory(mathutils)
add_subdirectory(bmesh)

@ -5,12 +5,18 @@
Import ('env')
incs = '. ../editors/include ../makesdna ../makesrna ../blenfont ../blenlib ../blenkernel ../nodes'
incs += ' ../imbuf ../blenloader ../gpu ../render/extern/include ../windowmanager'
incs += ' ../imbuf ../blenloader ../bmesh ../gpu ../render/extern/include ../windowmanager'
incs += ' #intern/guardedalloc #intern/memutil #extern/glew/include #intern/cycles/blender'
incs += ' #intern/audaspace/intern ' + env['BF_PYTHON_INC']
is_debug = (env['OURPLATFORM'] in ('win32-mingw', 'win32-vc','win64-vc') and env['BF_DEBUG'])
# bmesh
defs = []
sources = env.Glob('bmesh/*.c')
env.BlenderLib( libname = 'bf_python_bmesh', sources = Split(sources), includes = Split(incs), defines = defs, libtype = ['core','player'], priority = [362,165])
# generic
defs = []

@ -0,0 +1,43 @@
# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Contributor(s): Campbell Barton
#
# ***** END GPL LICENSE BLOCK *****
set(INC
.
../../bmesh
../../blenkernel
../../blenlib
../../blenloader
../../makesdna
../../../../intern/guardedalloc
)
set(INC_SYS
${PYTHON_INCLUDE_DIRS}
)
set(SRC
bmesh_py_api.c
bmesh_py_types.c
bmesh_py_api.h
bmesh_py_types.h
)
blender_add_lib(bf_python_bmesh "${SRC}" "${INC}" "${INC_SYS}")

@ -0,0 +1,97 @@
/*
* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2011 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/generic/blf_py_api.c
* \ingroup pygen
*
* This file defines the 'bme' bmesh main module.
*/
#include <Python.h>
#include "bmesh.h"
#include "bmesh_py_types.h"
#include "BLI_utildefines.h"
#include "BKE_tessmesh.h"
#include "DNA_mesh_types.h"
#include "../generic/py_capi_utils.h"
#include "bmesh_py_api.h" /* own include */
PyDoc_STRVAR(bpy_bm_from_mesh_doc,
".. method:: from_mesh(mesh)\n"
"\n"
" todo.\n"
);
static PyObject *bpy_bm_from_mesh(PyObject *UNUSED(self), PyObject *value)
{
Mesh *me = PyC_RNA_AsPointer(value, "Mesh");
/* temp! */
if (!me->edit_btmesh) {
PyErr_SetString(PyExc_ValueError,
"Mesh is not in editmode");
return NULL;
}
return BPy_BMesh_CreatePyObject(me->edit_btmesh->bm);
}
static struct PyMethodDef BPy_BM_methods[] = {
{"from_mesh", (PyCFunction)bpy_bm_from_mesh, METH_O, bpy_bm_from_mesh_doc},
{NULL, NULL, 0, NULL}
};
PyDoc_STRVAR(BPy_BM_doc,
"This module provides access to blenders bmesh data structures."
);
static struct PyModuleDef BPy_BM_module_def = {
PyModuleDef_HEAD_INIT,
"bme", /* m_name */
BPy_BM_doc, /* m_doc */
0, /* m_size */
BPy_BM_methods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
PyObject *BPyInit_bmesh(void)
{
PyObject *submodule;
BPy_BM_init_types();
submodule = PyModule_Create(&BPy_BM_module_def);
return submodule;
}

@ -0,0 +1,35 @@
/*
* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2011 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bme.h
* \ingroup pybmesh
*/
#ifndef __BMESH_PY_API_H__
#define __BMESH_PY_API_H__
PyObject *BPyInit_bmesh(void);
#endif /* __BMESH_PY_API_H__ */

File diff suppressed because it is too large Load Diff

@ -0,0 +1,124 @@
/*
* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2011 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bme_types.h
* \ingroup pybmesh
*/
#ifndef __BMESH_TYPES_H__
#define __BMESH_TYPES_H__
extern PyTypeObject BPy_BMesh_Type;
extern PyTypeObject BPy_BMVert_Type;
extern PyTypeObject BPy_BMEdge_Type;
extern PyTypeObject BPy_BMFace_Type;
extern PyTypeObject BPy_BMLoop_Type;
extern PyTypeObject BPy_BMVertSeq_Type;
extern PyTypeObject BPy_BMEdgeSeq_Type;
extern PyTypeObject BPy_BMFaceSeq_Type;
extern PyTypeObject BPy_BMIter_Type;
#define BPy_BMesh_Check(v) (Py_TYPE(v) == &BPy_BMesh_Type)
#define BPy_BMVert_Check(v) (Py_TYPE(v) == &BPy_BMVert_Type)
#define BPy_BMEdge_Check(v) (Py_TYPE(v) == &BPy_BMEdge_Type)
#define BPy_BMFace_Check(v) (Py_TYPE(v) == &BPy_BMFace_Type)
#define BPy_BMLoop_Check(v) (Py_TYPE(v) == &BPy_BMLoop_Type)
#define BPy_BMVertSeq_Check(v) (Py_TYPE(v) == &BPy_BMVertSeq_Type)
#define BPy_BMEdgeSeq_Check(v) (Py_TYPE(v) == &BPy_BMEdgeSeq_Type)
#define BPy_BMFaceSeq_Check(v) (Py_TYPE(v) == &BPy_BMFaceSeq_Type)
#define BPy_BMIter_Check(v) (Py_TYPE(v) == &BPy_BMIter_Type)
/* cast from _any_ bmesh type - they all have BMesh first */
typedef struct BPy_BMGeneric {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
} BPy_BMGeneric;
/* BPy_BMVert/BPy_BMEdge/BPy_BMFace/BPy_BMLoop can cast to this */
typedef struct BPy_BMElem {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
struct BMHeader *ele;
} BPy_BMElem;
typedef struct BPy_BMesh {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
} BPy_BMesh;
/* element types */
typedef struct BPy_BMVert {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
struct BMVert *v;
} BPy_BMVert;
typedef struct BPy_BMEdge {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
struct BMEdge *e;
} BPy_BMEdge;
typedef struct BPy_BMFace {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
struct BMFace *f;
} BPy_BMFace;
typedef struct BPy_BMLoop {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
struct BMLoop *l;
} BPy_BMLoop;
/* iterators */
typedef struct BPy_BMIter {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
BMIter iter;
} BPy_BMIter;
void BPy_BM_init_types(void);
PyObject *BPy_BMesh_CreatePyObject(BMesh *bm);
PyObject *BPy_BMVert_CreatePyObject(BMesh *bm, BMVert *v);
PyObject *BPy_BMEdge_CreatePyObject(BMesh *bm, BMEdge *e);
PyObject *BPy_BMFace_CreatePyObject(BMesh *bm, BMFace *f);
PyObject *BPy_BMLoop_CreatePyObject(BMesh *bm, BMLoop *l);
PyObject *BPy_BMVertSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMEdgeSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMFaceSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMIter_CreatePyObject(BMesh *bm);
PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele); /* just checks type and creates v/e/f/l */
int bpy_bm_generic_valid_check(BPy_BMGeneric *self);
void bpy_bm_generic_invalidate(BPy_BMGeneric *self);
#define BPY_BM_CHECK_OBJ(obj) if (bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1) { return NULL; } (void)NULL
#define BPY_BM_CHECK_INT(obj) if (bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1) { return -1; } (void)NULL
#endif /* __BMESH_TYPES_H__ */

@ -72,6 +72,7 @@
/* inittab initialization functions */
#include "../generic/bgl.h"
#include "../generic/blf_py_api.h"
#include "../bmesh/bmesh_py_api.h"
#include "../mathutils/mathutils.h"
/* for internal use, when starting and ending python scripts */
@ -192,6 +193,7 @@ static struct _inittab bpy_internal_modules[] = {
// {(char *)"mathutils.noise", PyInit_mathutils_noise},
{(char *)"bgl", BPyInit_bgl},
{(char *)"blf", BPyInit_blf},
{(char *)"bme", BPyInit_bmesh},
#ifdef WITH_AUDASPACE
{(char *)"aud", AUD_initPython},
#endif
@ -699,7 +701,6 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
return done;
}
#ifdef WITH_PYTHON_MODULE
#include "BLI_fileops.h"
/* TODO, reloading the module isnt functional at the moment. */

@ -797,6 +797,7 @@ endif()
bf_python
bf_python_ext
bf_python_mathutils
bf_python_bmesh
bf_ikplugin
bf_bmesh
bf_modifiers