bmesh py api, new submodules
* bmesh.types, just allows access to BMVert, BMEdge etc. * bmesh.utils, so far only added edge_split() function, this module will give access to mesh editing functions.
This commit is contained in:
@@ -23,7 +23,6 @@ set(INC
|
||||
../../bmesh
|
||||
../../blenkernel
|
||||
../../blenlib
|
||||
../../blenloader
|
||||
../../makesdna
|
||||
../../../../intern/guardedalloc
|
||||
)
|
||||
@@ -35,9 +34,11 @@ set(INC_SYS
|
||||
set(SRC
|
||||
bmesh_py_api.c
|
||||
bmesh_py_types.c
|
||||
bmesh_py_utils.c
|
||||
|
||||
bmesh_py_api.h
|
||||
bmesh_py_types.h
|
||||
bmesh_py_utils.h
|
||||
)
|
||||
|
||||
blender_add_lib(bf_python_bmesh "${SRC}" "${INC}" "${INC_SYS}")
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* 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.
|
||||
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
@@ -23,10 +23,10 @@
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/generic/blf_py_api.c
|
||||
* \ingroup pygen
|
||||
/** \file blender/python/bmesh/bmesh_py_api.c
|
||||
* \ingroup pybmesh
|
||||
*
|
||||
* This file defines the 'bme' bmesh main module.
|
||||
* This file defines the 'bmesh' module.
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "bmesh.h"
|
||||
|
||||
#include "bmesh_py_types.h"
|
||||
#include "bmesh_py_utils.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
@@ -93,5 +94,9 @@ PyObject *BPyInit_bmesh(void)
|
||||
|
||||
submodule = PyModule_Create(&BPy_BM_module_def);
|
||||
|
||||
/* bmesh.types */
|
||||
PyModule_AddObject(submodule, "types", BPyInit_bmesh_types());
|
||||
PyModule_AddObject(submodule, "utils", BPyInit_bmesh_utils());
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* 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.
|
||||
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
@@ -23,7 +23,7 @@
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/bmesh/bme.h
|
||||
/** \file blender/python/bmesh/bmesh_py_api.h
|
||||
* \ingroup pybmesh
|
||||
*/
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* 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.
|
||||
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
@@ -23,7 +23,7 @@
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/bmesh/bme_types.c
|
||||
/** \file blender/python/bmesh/bmesh_py_types.c
|
||||
* \ingroup pybmesh
|
||||
*/
|
||||
|
||||
@@ -797,7 +797,7 @@ static PyObject *bpy_bmvert_seq_new(BPy_BMElemSeq *self, PyObject *args)
|
||||
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
|
||||
if(!PyArg_ParseTuple(args, "|O:verts.new", py_co)) {
|
||||
if (!PyArg_ParseTuple(args, "|O:verts.new", py_co)) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
@@ -831,7 +831,7 @@ static PyObject *bpy_bmedge_seq_new(BPy_BMElemSeq *self, PyObject *args)
|
||||
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O!O!:edges.new",
|
||||
if (!PyArg_ParseTuple(args, "O!O!:edges.new",
|
||||
&BPy_BMVert_Type, &v1,
|
||||
&BPy_BMVert_Type, &v2))
|
||||
{
|
||||
@@ -877,7 +877,7 @@ static PyObject *bpy_bmface_seq_new(BPy_BMElemSeq *self, PyObject *args)
|
||||
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
|
||||
if(!PyArg_ParseTuple(args, "O:faces.new", &vert_seq)) {
|
||||
if (!PyArg_ParseTuple(args, "O:faces.new", &vert_seq)) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
@@ -1001,7 +1001,7 @@ static PyObject *bpy_bmvert_seq_remove(BPy_BMElemSeq *self, BPy_BMVert *value)
|
||||
{
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
|
||||
if(!BPy_BMVert_Check(value)) {
|
||||
if (!BPy_BMVert_Check(value)) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
@@ -1025,7 +1025,7 @@ static PyObject *bpy_bmedge_seq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value)
|
||||
{
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
|
||||
if(!BPy_BMEdge_Check(value)) {
|
||||
if (!BPy_BMEdge_Check(value)) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
@@ -1049,7 +1049,7 @@ static PyObject *bpy_bmface_seq_remove(BPy_BMElemSeq *self, BPy_BMFace *value)
|
||||
{
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
|
||||
if(!BPy_BMFace_Check(value)) {
|
||||
if (!BPy_BMFace_Check(value)) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
@@ -1572,6 +1572,42 @@ void BPy_BM_init_types(void)
|
||||
PyType_Ready(&BPy_BMIter_Type);
|
||||
}
|
||||
|
||||
/* bmesh.types submodule
|
||||
* ********************* */
|
||||
|
||||
static struct PyModuleDef BPy_BM_types_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bmesh.types", /* m_name */
|
||||
NULL, /* m_doc */
|
||||
0, /* m_size */
|
||||
NULL, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
NULL, /* m_traverse */
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
};
|
||||
|
||||
PyObject *BPyInit_bmesh_types(void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&BPy_BM_types_module_def);
|
||||
|
||||
#define mod_type_add(s, t) \
|
||||
PyModule_AddObject(s, t.tp_name, (PyObject *)&t); Py_INCREF((PyObject *)&t)
|
||||
|
||||
mod_type_add(submodule, BPy_BMesh_Type);
|
||||
mod_type_add(submodule, BPy_BMVert_Type);
|
||||
mod_type_add(submodule, BPy_BMEdge_Type);
|
||||
mod_type_add(submodule, BPy_BMFace_Type);
|
||||
mod_type_add(submodule, BPy_BMLoop_Type);
|
||||
mod_type_add(submodule, BPy_BMElemSeq_Type);
|
||||
mod_type_add(submodule, BPy_BMIter_Type);
|
||||
|
||||
#undef mod_type_add
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
/* Utility Functions
|
||||
* ***************** */
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* 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.
|
||||
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
@@ -23,7 +23,7 @@
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/bmesh/bme_types.h
|
||||
/** \file blender/python/bmesh/bmesh_py_types.h
|
||||
* \ingroup pybmesh
|
||||
*/
|
||||
|
||||
@@ -117,6 +117,8 @@ typedef struct BPy_BMIter {
|
||||
|
||||
void BPy_BM_init_types(void);
|
||||
|
||||
PyObject *BPyInit_bmesh_types(void);
|
||||
|
||||
PyObject *BPy_BMesh_CreatePyObject(BMesh *bm);
|
||||
PyObject *BPy_BMVert_CreatePyObject(BMesh *bm, BMVert *v);
|
||||
PyObject *BPy_BMEdge_CreatePyObject(BMesh *bm, BMEdge *e);
|
||||
|
||||
133
source/blender/python/bmesh/bmesh_py_utils.c
Normal file
133
source/blender/python/bmesh/bmesh_py_utils.c
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* ***** 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) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/bmesh/bmesh_py_api.c
|
||||
* \ingroup pybmesh
|
||||
*
|
||||
* This file defines the 'bmesh.utils' module.
|
||||
* Utility functions for operating on 'bmesh.types'
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "bmesh.h"
|
||||
|
||||
#include "bmesh_py_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "bmesh_py_utils.h" /* own include */
|
||||
|
||||
PyDoc_STRVAR(bpy_bm_utils_edge_split_doc,
|
||||
".. method:: edge_split(vert, edge, fac)\n"
|
||||
"\n"
|
||||
" Split an edge, return the newly created data.\n"
|
||||
"\n"
|
||||
" :arg edge: The edge to split.\n"
|
||||
" :type edge: :class:`bmesh.tupes.BMEdge`\n"
|
||||
" :arg vert: One of the verts on the edge, defines the split direction.\n"
|
||||
" :type vert: :class:`bmesh.tupes.BMVert`\n"
|
||||
" :arg fac: The point on the edge where the new vert will be created.\n"
|
||||
" :type fac: float\n"
|
||||
" :return: The newly created (edge, vert) pair.\n"
|
||||
" :rtype: tuple\n"
|
||||
);
|
||||
|
||||
static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
BPy_BMEdge *py_edge;
|
||||
BPy_BMVert *py_vert;
|
||||
float fac;
|
||||
|
||||
BMesh *bm;
|
||||
BMVert *v_new = NULL;
|
||||
BMEdge *e_new = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!O!f:edge_split",
|
||||
&BPy_BMEdge_Type, &py_edge,
|
||||
&BPy_BMVert_Type, &py_vert,
|
||||
&fac))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_edge);
|
||||
BPY_BM_CHECK_OBJ(py_vert);
|
||||
|
||||
if (!(py_edge->e->v1 == py_vert->v ||
|
||||
py_edge->e->v2 == py_vert->v))
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"edge_split(edge, vert): the vertex is not found in the edge");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bm = py_edge->bm;
|
||||
|
||||
v_new = BM_edge_split(bm, py_edge->e, py_vert->v, &e_new, fac);
|
||||
|
||||
if (v_new && e_new) {
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, BPy_BMEdge_CreatePyObject(bm, e_new));
|
||||
PyTuple_SET_ITEM(ret, 1, BPy_BMVert_CreatePyObject(bm, v_new));
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"edge_split(edge, vert): couldn't split the edge, internal error");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static struct PyMethodDef BPy_BM_utils_methods[] = {
|
||||
{"edge_split", (PyCFunction)bpy_bm_utils_edge_split, METH_VARARGS, bpy_bm_utils_edge_split_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
PyDoc_STRVAR(BPy_BM_doc,
|
||||
"This module provides access to blenders bmesh data structures."
|
||||
);
|
||||
static struct PyModuleDef BPy_BM_types_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bmesh.utils", /* m_name */
|
||||
BPy_BM_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
BPy_BM_utils_methods, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
NULL, /* m_traverse */
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
};
|
||||
|
||||
PyObject *BPyInit_bmesh_utils(void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&BPy_BM_types_module_def);
|
||||
|
||||
return submodule;
|
||||
}
|
||||
35
source/blender/python/bmesh/bmesh_py_utils.h
Normal file
35
source/blender/python/bmesh/bmesh_py_utils.h
Normal file
@@ -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) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/python/bmesh/bmesh_py_utils.h
|
||||
* \ingroup pybmesh
|
||||
*/
|
||||
|
||||
#ifndef __BMESH_PY_UTILS_H__
|
||||
#define __BMESH_PY_UTILS_H__
|
||||
|
||||
PyObject *BPyInit_bmesh_utils(void);
|
||||
|
||||
#endif /* __BMESH_PY_UTILS_H__ */
|
||||
Reference in New Issue
Block a user