diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-27 01:40:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-27 01:40:01 +0400 |
commit | 3e305c1018be797dbf114914459ece402903dd08 (patch) | |
tree | a4d634038df2f8bcf9cb2b3eb7b78b054fb5e744 /source | |
parent | 200584e5c6e020dcb77038a0e399ddfebe91ce63 (diff) |
bmesh.ops module for bmesh operator access, only remove_doubles and convex_hull at the moment.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 8 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators_private.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_primitive.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_removedoubles.c | 2 | ||||
-rw-r--r-- | source/blender/python/bmesh/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_api.c | 5 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_ops.c | 200 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_ops.h | 35 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.h | 9 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_utils.c | 8 |
10 files changed, 263 insertions, 12 deletions
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 4186f5d47eb..f606347baf6 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -245,12 +245,12 @@ static BMOpDefine bmo_finddoubles_def = { * Finds groups of vertices closer then dist and merges them together, * using the weld verts bmop. */ -static BMOpDefine bmo_removedoubles_def = { - "removedoubles", +static BMOpDefine bmo_remove_doubles_def = { + "remove_doubles", {{BMO_OP_SLOT_ELEMENT_BUF, "verts"}, //input verts {BMO_OP_SLOT_FLT, "dist"}, //minimum distance {0, /* null-terminating sentinel */}}, - bmo_removedoubles_exec, + bmo_remove_doubles_exec, BMO_OP_FLAG_UNTAN_MULTIRES, }; @@ -1199,7 +1199,7 @@ BMOpDefine *opdefines[] = { &bmo_contextual_create_def, &bmo_makevert_def, &bmo_weldverts_def, - &bmo_removedoubles_def, + &bmo_remove_doubles_def, &bmo_finddoubles_def, &bmo_mirror_def, &bmo_edgebisect_def, diff --git a/source/blender/bmesh/intern/bmesh_operators_private.h b/source/blender/bmesh/intern/bmesh_operators_private.h index df48ec8468f..baccb3e9a10 100644 --- a/source/blender/bmesh/intern/bmesh_operators_private.h +++ b/source/blender/bmesh/intern/bmesh_operators_private.h @@ -57,7 +57,7 @@ void bmo_makevert_exec(BMesh *bm, BMOperator *op); void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op); void bmo_dissolve_edgeloop_exec(BMesh *bm, BMOperator *op); void bmo_weldverts_exec(BMesh *bm, BMOperator *op); -void bmo_removedoubles_exec(BMesh *bm, BMOperator *op); +void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op); void bmo_finddoubles_exec(BMesh *bm, BMOperator *op); void bmo_mirror_exec(BMesh *bm, BMOperator *op); void bmo_edgebisect_exec(BMesh *bm, BMOperator *op); diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index 08cd3835b2d..49b0679be3d 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -365,7 +365,7 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) len2 = len_v3v3(vec, vec2); /* use shortest segment length divided by 3 as merge threshold */ - BMO_op_callf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f); + BMO_op_callf(bm, "remove_doubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f); } /* and now do imat */ @@ -661,7 +661,7 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op) BM_face_create_quad_tri(bm, v1, v2, firstv2, firstv1, NULL, FALSE); - BMO_op_callf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, 0.000001); + BMO_op_callf(bm, "remove_doubles verts=%fv dist=%f", VERT_MARK, 0.000001); BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK); } diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index 52c693efc84..296d598ae3b 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -557,7 +557,7 @@ void bmesh_finddoubles_common(BMesh *bm, BMOperator *op, BMOperator *optarget, c BLI_array_free(verts); } -void bmo_removedoubles_exec(BMesh *bm, BMOperator *op) +void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op) { BMOperator weldop; diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt index 40bde7161b6..032a914fb70 100644 --- a/source/blender/python/bmesh/CMakeLists.txt +++ b/source/blender/python/bmesh/CMakeLists.txt @@ -33,6 +33,7 @@ set(INC_SYS set(SRC bmesh_py_api.c + bmesh_py_ops.c bmesh_py_types.c bmesh_py_types_customdata.c bmesh_py_types_meshdata.c @@ -40,6 +41,7 @@ set(SRC bmesh_py_utils.c bmesh_py_api.h + bmesh_py_ops.h bmesh_py_types.h bmesh_py_types_customdata.h bmesh_py_types_meshdata.h diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index 4d8d4e3bc23..2cfe5847e55 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -40,6 +40,7 @@ #include "bmesh_py_types_customdata.h" #include "bmesh_py_types_meshdata.h" +#include "bmesh_py_ops.h" #include "bmesh_py_utils.h" #include "BKE_tessmesh.h" @@ -143,6 +144,10 @@ PyObject *BPyInit_bmesh(void) PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); Py_INCREF(submodule); + PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops())); + PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); + Py_INCREF(submodule); + PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils())); PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); Py_INCREF(submodule); diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c new file mode 100644 index 00000000000..5e327e878ef --- /dev/null +++ b/source/blender/python/bmesh/bmesh_py_ops.c @@ -0,0 +1,200 @@ +/* + * ***** 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_ops.c + * \ingroup pybmesh + * + * This file defines the 'bmesh.ops' module. + * Operators from 'opdefines' are wrapped. + */ + +#include <Python.h> + +#include "BLI_utildefines.h" + +#include "MEM_guardedalloc.h" + +#include "../generic/py_capi_utils.h" + +#include "../mathutils/mathutils.h" + +#include "bmesh.h" + +#include "bmesh_py_types.h" + +#include "bmesh_py_utils.h" /* own include */ + +static int bpy_bm_op_as_py_error(BMesh *bm) +{ + if (BMO_error_occurred(bm)) { + const char *errmsg; + if (BMO_error_get(bm, &errmsg, NULL)) { + PyErr_Format(PyExc_RuntimeError, + "bmesh operator: %.200s", + errmsg); + return -1; + } + } + return 0; +} + +PyDoc_STRVAR(bpy_bm_ops_convex_hull_doc, +".. method:: convex_hull(bmesh, filter)\n" +"\n" +" Face split with optional intermediate points.\n" +"\n" +" :arg bmesh: The face to cut.\n" +" :type bmesh: :class:`bmesh.types.BMFace`\n" +" :arg filter: Set containing vertex flags to apply the operator.\n" +" :type filter: set\n" +); +static PyObject *bpy_bm_ops_convex_hull(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + static const char *kwlist[] = {"bmesh", "filter", NULL}; + + BPy_BMesh *py_bm; + BMesh *bm; + + PyObject *filter; + int filter_flags; + BMOperator bmop; + + if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!:convex_hull", (char **)kwlist, + &BPy_BMesh_Type, &py_bm, + &PySet_Type, &filter)) + { + return NULL; + } + + BPY_BM_CHECK_OBJ(py_bm); + bm = py_bm->bm; + + if (filter != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter, + &filter_flags, "convex_hull") == -1) + { + return NULL; + } + + BMO_op_initf(bm, &bmop, + "convex_hull input=%hv", + filter_flags); + BMO_op_exec(bm, &bmop); + BMO_op_finish(bm, &bmop); + + if (bpy_bm_op_as_py_error(bm) == -1) { + return NULL; + } + + /* TODO, return values */ + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpy_bm_ops_remove_doubles_doc, +".. method:: remove_doubles(bmesh, filter, dist)\n" +"\n" +" Face split with optional intermediate points.\n" +"\n" +" :arg bmesh: The face to cut.\n" +" :type bmesh: :class:`bmesh.types.BMFace`\n" +" :arg filter: Set containing vertex flags to apply the operator.\n" +" :type filter: set\n" +" :arg dist: Distance limit.\n" +" :type dist: float\n" +); +static PyObject *bpy_bm_ops_remove_doubles(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + static const char *kwlist[] = {"bmesh", "filter", "dist", NULL}; + + BPy_BMesh *py_bm; + BMesh *bm; + + PyObject *filter; + int filter_flags; + float dist = 0.0f; + + BMOperator bmop; + + if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!|f:remove_doubles", (char **)kwlist, + &BPy_BMesh_Type, &py_bm, + &PySet_Type, &filter, + &dist)) + { + return NULL; + } + + BPY_BM_CHECK_OBJ(py_bm); + bm = py_bm->bm; + + if (filter != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter, + &filter_flags, "remove_doubles") == -1) + { + return NULL; + } + + BMO_op_initf(bm, &bmop, + "remove_doubles verts=%hv dist=%f", + filter_flags, dist); + BMO_op_exec(bm, &bmop); + BMO_op_finish(bm, &bmop); + + if (bpy_bm_op_as_py_error(bm) == -1) { + return NULL; + } + + /* TODO, return values */ + Py_RETURN_NONE; +} + +static struct PyMethodDef BPy_BM_ops_methods[] = { + {"convex_hull", (PyCFunction)bpy_bm_ops_convex_hull, METH_VARARGS | METH_KEYWORDS, bpy_bm_ops_convex_hull_doc}, + {"remove_doubles", (PyCFunction)bpy_bm_ops_remove_doubles, METH_VARARGS | METH_KEYWORDS, bpy_bm_ops_remove_doubles_doc}, + {NULL, NULL, 0, NULL} +}; + + +PyDoc_STRVAR(BPy_BM_ops_doc, + "This module provides access to bmesh operators (EXPEREMENTAL)." + ); +static struct PyModuleDef BPy_BM_ops_module_def = { + PyModuleDef_HEAD_INIT, + "bmesh.ops", /* m_name */ + BPy_BM_ops_doc, /* m_doc */ + 0, /* m_size */ + BPy_BM_ops_methods, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ +}; + + +PyObject *BPyInit_bmesh_ops(void) +{ + PyObject *submodule; + + submodule = PyModule_Create(&BPy_BM_ops_module_def); + + return submodule; +} diff --git a/source/blender/python/bmesh/bmesh_py_ops.h b/source/blender/python/bmesh/bmesh_py_ops.h new file mode 100644 index 00000000000..56c980b57ea --- /dev/null +++ b/source/blender/python/bmesh/bmesh_py_ops.h @@ -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_ops.h + * \ingroup pybmesh + */ + +#ifndef __BMESH_PY_OPS_H__ +#define __BMESH_PY_OPS_H__ + +PyObject *BPyInit_bmesh_ops(void); + +#endif /* __BMESH_PY_OPS_H__ */ diff --git a/source/blender/python/bmesh/bmesh_py_types.h b/source/blender/python/bmesh/bmesh_py_types.h index 85bbd5d7b09..947e66bf24e 100644 --- a/source/blender/python/bmesh/bmesh_py_types.h +++ b/source/blender/python/bmesh/bmesh_py_types.h @@ -186,4 +186,13 @@ char *BPy_BMElem_StringFromHType(const char htype); ele; \ ele = BM_iter_step(iter)) + +#ifdef __PY_CAPI_UTILS_H__ +struct PyC_FlagSet; +extern struct PyC_FlagSet bpy_bm_scene_vert_edge_face_flags[]; +extern struct PyC_FlagSet bpy_bm_htype_vert_edge_face_flags[]; +extern struct PyC_FlagSet bpy_bm_htype_all_flags[]; +extern struct PyC_FlagSet bpy_bm_hflag_all_flags[]; +#endif + #endif /* __BMESH_TYPES_H__ */ diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c index 6a2ba90a330..4417bc2ce8d 100644 --- a/source/blender/python/bmesh/bmesh_py_utils.c +++ b/source/blender/python/bmesh/bmesh_py_utils.c @@ -668,13 +668,13 @@ static struct PyMethodDef BPy_BM_utils_methods[] = { }; -PyDoc_STRVAR(BPy_BM_doc, +PyDoc_STRVAR(BPy_BM_utils_doc, "This module provides access to blenders bmesh data structures." ); -static struct PyModuleDef BPy_BM_types_module_def = { +static struct PyModuleDef BPy_BM_utils_module_def = { PyModuleDef_HEAD_INIT, "bmesh.utils", /* m_name */ - BPy_BM_doc, /* m_doc */ + BPy_BM_utils_doc, /* m_doc */ 0, /* m_size */ BPy_BM_utils_methods, /* m_methods */ NULL, /* m_reload */ @@ -688,7 +688,7 @@ PyObject *BPyInit_bmesh_utils(void) { PyObject *submodule; - submodule = PyModule_Create(&BPy_BM_types_module_def); + submodule = PyModule_Create(&BPy_BM_utils_module_def); return submodule; } |